Am I punching trees or pounding sand?

This commit is contained in:
2025-11-05 13:48:01 +11:00
parent b65134d283
commit cb85608dfe
5 changed files with 34 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
extends CharacterBody2D class_name Character extends CharacterBody2D
var _grid_pos: Vector2i = Vector2i.ZERO var _grid_pos: Vector2i = Vector2i.ZERO
var _grid_tween: Tween = null 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 var _cached_dir: Vector2i = Vector2i.ZERO #used for reversing the current input
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
#WARNING: this has the potential for getting stuck
if _grid_pos * 32 == Vector2i(position): if _grid_pos * 32 == Vector2i(position):
_check_grid_move(delta) _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"): if Input.is_action_pressed("input_north"):
_set_grid_move(Vector2i.UP) _set_grid_move(Vector2i.UP)
elif Input.is_action_pressed("input_south"): elif Input.is_action_pressed("input_south"):

24
items/inventory.gd Normal file
View File

@@ -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))

1
items/inventory.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://cf0cv8j7r1qjm

View File

@@ -15,6 +15,10 @@ run/main_scene="uid://8o4ffx055dof"
config/features=PackedStringArray("4.5", "GL Compatibility") config/features=PackedStringArray("4.5", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
Inventory="*res://items/inventory.gd"
[input] [input]
input_north={ input_north={
@@ -45,5 +49,4 @@ input_west={
[rendering] [rendering]
textures/canvas_textures/default_texture_filter=0 textures/canvas_textures/default_texture_filter=0
renderer/rendering_method="gl_compatibility" renderer/rendering_method="mobile"
renderer/rendering_method.mobile="gl_compatibility"

View File

@@ -3,9 +3,9 @@ extends Area2D
var _durability: int = 3 var _durability: int = 3
func _on_body_entered(body: Node2D) -> void: func _on_body_entered(body: Node2D) -> void:
if body is CharacterBody2D: if body is Character:
_durability -= 1 _durability -= 1
body.repel_collision(self) body.repel_collision(self)
if _durability <= 0: if _durability <= 0:
print("tree dead") Inventory.add_item(Inventory.Wood.new())
queue_free() queue_free()