summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 03:17:22 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 03:17:22 -0600
commit36874a535a3d5f7f2955f33e34aa1a4768b6fec1 (patch)
tree8f4eaa57d5e82d962719a8a399cfc210ced672e6 /src/tools
parentf922fe4669080d1633e0a345a3f8981867c9e841 (diff)
added hud for snake size and grow progress
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/score_manager/ScoreManager.tscn6
-rw-r--r--src/tools/score_manager/score_manager.gd26
2 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/score_manager/ScoreManager.tscn b/src/tools/score_manager/ScoreManager.tscn
new file mode 100644
index 0000000..136b294
--- /dev/null
+++ b/src/tools/score_manager/ScoreManager.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=2]
+
+[ext_resource path="res://tools/score_manager/score_manager.gd" type="Script" id=1]
+
+[node name="ScoreManager" type="Node2D"]
+script = ExtResource( 1 )
diff --git a/src/tools/score_manager/score_manager.gd b/src/tools/score_manager/score_manager.gd
new file mode 100644
index 0000000..3b5ddba
--- /dev/null
+++ b/src/tools/score_manager/score_manager.gd
@@ -0,0 +1,26 @@
+extends Node
+
+
+var score: int = 0
+var growth: int = 0
+
+
+func _ready():
+ Event.connect("food_eaten", self, "_on_food_eaten")
+
+
+func _on_food_eaten(properties: Dictionary) -> void:
+ var points: int = properties["points"]
+ var score_to_grow: int = (growth + 1) * Global.POINTS_TO_GROW - score
+ var amount_to_grow: int = 0
+ score += points
+ if points >= score_to_grow:
+ amount_to_grow += 1
+ points -= score_to_grow
+ # maybe be careful with this
+ amount_to_grow += points / Global.POINTS_TO_GROW
+ growth += amount_to_grow
+ Event.emit_signal("snake_add_new_segment", amount_to_grow)
+
+ score_to_grow = Global.POINTS_TO_GROW - ((growth + 1) * Global.POINTS_TO_GROW - score)
+ Event.emit_signal("snake_growth_progress", score_to_grow)