Am I punching trees or pounding sand?
This commit is contained in:
@@ -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"):
|
||||
|
||||
24
items/inventory.gd
Normal file
24
items/inventory.gd
Normal 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
1
items/inventory.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cf0cv8j7r1qjm
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user