From cb85608dfe63dbc43888095438e44d5d21ca9434 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 5 Nov 2025 13:48:01 +1100 Subject: [PATCH] Am I punching trees or pounding sand? --- character/character.gd | 5 ++--- items/inventory.gd | 24 ++++++++++++++++++++++++ items/inventory.gd.uid | 1 + project.godot | 7 +++++-- tree/small_tree.gd | 4 ++-- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 items/inventory.gd create mode 100644 items/inventory.gd.uid diff --git a/character/character.gd b/character/character.gd index 73c7b7d..4135bed 100644 --- a/character/character.gd +++ b/character/character.gd @@ -1,4 +1,4 @@ -extends CharacterBody2D +class_name Character extends CharacterBody2D var _grid_pos: Vector2i = Vector2i.ZERO var _grid_tween: Tween = null @@ -6,11 +6,10 @@ var _grid_tween: Tween = null var _cached_dir: Vector2i = Vector2i.ZERO #used for reversing the current input func _physics_process(delta: float) -> void: - #WARNING: this has the potential for getting stuck if _grid_pos * 32 == Vector2i(position): _check_grid_move(delta) -func _check_grid_move(delta: float) -> void: +func _check_grid_move(_delta: float) -> void: if Input.is_action_pressed("input_north"): _set_grid_move(Vector2i.UP) elif Input.is_action_pressed("input_south"): diff --git a/items/inventory.gd b/items/inventory.gd new file mode 100644 index 0000000..ee0fda6 --- /dev/null +++ b/items/inventory.gd @@ -0,0 +1,24 @@ +#Inventory Singleton +extends Node + +#game items +@abstract +class Item: + var name: String + func _init(_name: String): + name = _name + +class Wood extends Item: + func _init(): + super("Wood") + +class Stone extends Item: + func _init(): + super("Stone") + +#inventory controls +var _inventory_contents: Array[Item] = [] + +func add_item(item: Item) -> void: + _inventory_contents.push_back(item) + print("Inventory: ", _inventory_contents.map(func (i: Item) -> String: return i.name)) diff --git a/items/inventory.gd.uid b/items/inventory.gd.uid new file mode 100644 index 0000000..b68bc74 --- /dev/null +++ b/items/inventory.gd.uid @@ -0,0 +1 @@ +uid://cf0cv8j7r1qjm diff --git a/project.godot b/project.godot index f290b7b..3baf97a 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="uid://8o4ffx055dof" config/features=PackedStringArray("4.5", "GL Compatibility") config/icon="res://icon.svg" +[autoload] + +Inventory="*res://items/inventory.gd" + [input] input_north={ @@ -45,5 +49,4 @@ input_west={ [rendering] textures/canvas_textures/default_texture_filter=0 -renderer/rendering_method="gl_compatibility" -renderer/rendering_method.mobile="gl_compatibility" +renderer/rendering_method="mobile" diff --git a/tree/small_tree.gd b/tree/small_tree.gd index a93404a..1130860 100644 --- a/tree/small_tree.gd +++ b/tree/small_tree.gd @@ -3,9 +3,9 @@ extends Area2D var _durability: int = 3 func _on_body_entered(body: Node2D) -> void: - if body is CharacterBody2D: + if body is Character: _durability -= 1 body.repel_collision(self) if _durability <= 0: - print("tree dead") + Inventory.add_item(Inventory.Wood.new()) queue_free()