Add a system for changing tools

This commit is contained in:
2023-10-07 18:24:14 -07:00
parent cc26479b38
commit aea7ecc1ae
6 changed files with 120 additions and 2 deletions

View File

@ -14,8 +14,17 @@ var status = {
"health": 100, "health": 100,
"stamina": 100 "stamina": 100
} }
var current_tool = "none"
func change_tool(tool):
current_tool = tool
$body_pivot/body/tool.texture = load(game_data.tools[tool].image)
$body_pivot/body/tool.position = game_data.tools[tool].offset
func _ready():
change_tool("stick")
func _physics_process(delta): func _physics_process(delta):
var pre_velocity = Vector2(0, 0) var pre_velocity = Vector2(0, 0)
if !immobile: if !immobile:

View File

@ -2,7 +2,7 @@
[ext_resource type="Texture2D" uid="uid://gfxfxkfu8uk4" path="res://textures/character/character.svg" id="1_f7cgp"] [ext_resource type="Texture2D" uid="uid://gfxfxkfu8uk4" path="res://textures/character/character.svg" id="1_f7cgp"]
[ext_resource type="Script" path="res://data/character/character.gd" id="1_qlitf"] [ext_resource type="Script" path="res://data/character/character.gd" id="1_qlitf"]
[ext_resource type="Texture2D" uid="uid://b7hh5vuwdmg0v" path="res://textures/tools/stick.svg" id="3_1h5n2"] [ext_resource type="Texture2D" uid="uid://crw5j541ciab8" path="res://textures/tools/none.svg" id="3_c34pt"]
[ext_resource type="Script" path="res://data/character/hud.gd" id="3_eogh2"] [ext_resource type="Script" path="res://data/character/hud.gd" id="3_eogh2"]
[ext_resource type="Texture2D" uid="uid://ttb1b3k07qu5" path="res://textures/world/boulder.svg" id="4_t4sgq"] [ext_resource type="Texture2D" uid="uid://ttb1b3k07qu5" path="res://textures/world/boulder.svg" id="4_t4sgq"]
[ext_resource type="Texture2D" uid="uid://i7fjjduk8b0c" path="res://textures/world/biome/forest/tree.svg" id="5_j15j3"] [ext_resource type="Texture2D" uid="uid://i7fjjduk8b0c" path="res://textures/world/biome/forest/tree.svg" id="5_j15j3"]
@ -78,7 +78,7 @@ texture = ExtResource("1_f7cgp")
[node name="tool" type="Sprite2D" parent="body_pivot/body"] [node name="tool" type="Sprite2D" parent="body_pivot/body"]
z_index = -1 z_index = -1
position = Vector2(-80, -120) position = Vector2(-80, -120)
texture = ExtResource("3_1h5n2") texture = ExtResource("3_c34pt")
[node name="hud" type="Control" parent="."] [node name="hud" type="Control" parent="."]
z_index = 10 z_index = 10

View File

@ -15,6 +15,10 @@ run/main_scene="res://scenes/world.tscn"
config/features=PackedStringArray("4.1", "GL Compatibility") config/features=PackedStringArray("4.1", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
game_data="*res://script/game_data.gd"
[display] [display]
window/stretch/aspect="expand" window/stretch/aspect="expand"

13
script/game_data.gd Normal file
View File

@ -0,0 +1,13 @@
extends Node
var tools = {
"none": {
"image": "res://textures/tools/none.svg",
"offset": Vector2(0, 0)
},
"stick": {
"image": "res://textures/tools/stick.svg",
"offset": Vector2(-80, -120)
}
}

55
textures/tools/none.svg Normal file
View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1"
height="1"
viewBox="0 0 0.26458333 0.26458334"
version="1.1"
id="svg8"
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
sodipodi:docname="none.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="400"
inkscape:cy="560"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="false"
units="px"
inkscape:window-width="1410"
inkscape:window-height="1080"
inkscape:window-x="246"
inkscape:window-y="160"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1" />
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://crw5j541ciab8"
path="res://.godot/imported/none.svg-d6acfffb4a4bec01aae97ce1add71e20.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://textures/tools/none.svg"
dest_files=["res://.godot/imported/none.svg-d6acfffb4a4bec01aae97ce1add71e20.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false