From 9a55f2a3af00d5b9d10709046476ad166471044a Mon Sep 17 00:00:00 2001 From: Dusk Date: Wed, 4 Mar 2026 22:41:41 +0100 Subject: [PATCH] feat: Uprade system and stamina upgrade --- player.gd | 7 +++++-- player.tscn | 3 +++ stamina.gd | 10 ++++++++++ stamina.gd.uid | 1 + upgrades.gd | 19 +++++++++++++++++++ upgrades.gd.uid | 1 + upgrades.tscn | 10 ++++++++++ 7 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 stamina.gd create mode 100644 stamina.gd.uid create mode 100644 upgrades.gd create mode 100644 upgrades.gd.uid create mode 100644 upgrades.tscn diff --git a/player.gd b/player.gd index 32a6397..7130889 100644 --- a/player.gd +++ b/player.gd @@ -8,8 +8,11 @@ const STAMINA_RECOVER = 10 var pedestrian_area_count = 0 +var max_stamina: float = BASE_STAMINA +var stamina: float = max_stamina -var stamina: float = BASE_STAMINA +func _ready() -> void: + $Upgrades.update() func _process(delta: float) -> void: $StaminaLabel.text = str(int(stamina)) @@ -24,7 +27,7 @@ func _process(delta: float) -> void: if Input.is_action_pressed("player_sprint") and stamina > 0: stamina -= STAMINA_COST * delta speed *= SPRINT_MULT - elif stamina <= BASE_STAMINA: + elif stamina <= max_stamina: stamina += STAMINA_RECOVER * delta self.velocity = Vector3(dir.x * speed, 0, dir.y * speed) diff --git a/player.tscn b/player.tscn index 3577517..5f78f32 100644 --- a/player.tscn +++ b/player.tscn @@ -1,6 +1,7 @@ [gd_scene format=3 uid="uid://cmb3b7xrlboy3"] [ext_resource type="Script" uid="uid://bobw4cfg1v6gj" path="res://player.gd" id="1_4flbx"] +[ext_resource type="PackedScene" uid="uid://ct7cc7qg3hpu1" path="res://upgrades.tscn" id="2_onrkg"] [sub_resource type="PlaneMesh" id="PlaneMesh_sh265"] size = Vector2(1, 1) @@ -29,6 +30,8 @@ collision_layer = 4 collision_mask = 3 script = ExtResource("1_4flbx") +[node name="Upgrades" parent="." unique_id=1238785974 instance=ExtResource("2_onrkg")] + [node name="Mesh" type="MeshInstance3D" parent="." unique_id=1740724392] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0) mesh = SubResource("PlaneMesh_sh265") diff --git a/stamina.gd b/stamina.gd new file mode 100644 index 0000000..6ea05b4 --- /dev/null +++ b/stamina.gd @@ -0,0 +1,10 @@ +extends Node + +var enabled: bool = true + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func update() -> void: + if enabled: + print("Updating Stamina") + $"..".parent.max_stamina = $"..".parent.BASE_STAMINA * 2 + $"..".parent.stamina = $"..".parent.max_stamina diff --git a/stamina.gd.uid b/stamina.gd.uid new file mode 100644 index 0000000..072b928 --- /dev/null +++ b/stamina.gd.uid @@ -0,0 +1 @@ +uid://dk6j6kddvr2jc diff --git a/upgrades.gd b/upgrades.gd new file mode 100644 index 0000000..ace66f7 --- /dev/null +++ b/upgrades.gd @@ -0,0 +1,19 @@ +extends Node + +var parent: CharacterBody3D + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + assert(get_parent().name == "Player", "Upgrade must have player as parent") + parent = get_parent() + +## Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta: float) -> void: + #pass + +func update() -> void: + var upgrades: Array = get_children() + print("Updating all upgrades...") + for upgrade in upgrades: + upgrade.update() + diff --git a/upgrades.gd.uid b/upgrades.gd.uid new file mode 100644 index 0000000..7243e97 --- /dev/null +++ b/upgrades.gd.uid @@ -0,0 +1 @@ +uid://4f7orky5jeey diff --git a/upgrades.tscn b/upgrades.tscn new file mode 100644 index 0000000..0602826 --- /dev/null +++ b/upgrades.tscn @@ -0,0 +1,10 @@ +[gd_scene format=3 uid="uid://ct7cc7qg3hpu1"] + +[ext_resource type="Script" uid="uid://4f7orky5jeey" path="res://upgrades.gd" id="1_k80ou"] +[ext_resource type="Script" uid="uid://dk6j6kddvr2jc" path="res://stamina.gd" id="2_alr6r"] + +[node name="Upgrades" type="Node" unique_id=1238785974] +script = ExtResource("1_k80ou") + +[node name="Stamina" type="Node" parent="." unique_id=1030985851] +script = ExtResource("2_alr6r")