summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 05:17:12 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 05:17:12 -0600
commite6beb7d4d3450c68ca5ebfae040f42dd82db1b31 (patch)
treeba8fae52c6f60c09f4aab2958231969ea571a7e3 /src
parentfa98822a569c1efa2bebc705073c3921b9ae4217 (diff)
add text for points when eating food
Diffstat (limited to 'src')
-rw-r--r--src/Main.tscn4
-rw-r--r--src/entities/food/scripts/food.gd1
-rw-r--r--src/tools/score_manager/ScoreManager.tscn4
-rw-r--r--src/tools/score_manager/score_manager.gd26
-rw-r--r--src/ui/UI.tscn25
-rw-r--r--src/ui/hud/progress_bars/scenes/GrowthProgress.tscn12
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_icon.pngbin0 -> 152 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_icon.png.import (renamed from src/ui/hud/progress_bars/sprites/under.png.import)6
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_over.pngbin0 -> 114 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_over.png.import (renamed from src/ui/hud/progress_bars/sprites/over.png.import)6
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_progress.pngbin0 -> 104 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_progress.png.import35
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_under.pngbin0 -> 104 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/grow_progress_under.png.import (renamed from src/ui/hud/progress_bars/sprites/progress.png.import)6
-rw-r--r--src/ui/hud/progress_bars/sprites/over.pngbin111 -> 0 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/progress.pngbin113 -> 0 bytes
-rw-r--r--src/ui/hud/progress_bars/sprites/under.pngbin103 -> 0 bytes
17 files changed, 96 insertions, 29 deletions
diff --git a/src/Main.tscn b/src/Main.tscn
index 83f263d..e874cc8 100644
--- a/src/Main.tscn
+++ b/src/Main.tscn
@@ -15,10 +15,10 @@ script = ExtResource( 4 )
[node name="FoodManager" parent="." instance=ExtResource( 5 )]
WORLD_GENERATOR_NP = NodePath("../WorldGenerator")
-[node name="ScoreManager" parent="." instance=ExtResource( 2 )]
-
[node name="Snake" parent="." instance=ExtResource( 1 )]
+[node name="ScoreManager" parent="." instance=ExtResource( 2 )]
+
[node name="UI" parent="." instance=ExtResource( 3 )]
__meta__ = {
"_edit_horizontal_guides_": [ 8.0 ]
diff --git a/src/entities/food/scripts/food.gd b/src/entities/food/scripts/food.gd
index 2e00978..ca27acc 100644
--- a/src/entities/food/scripts/food.gd
+++ b/src/entities/food/scripts/food.gd
@@ -43,6 +43,7 @@ func set_property(property: String, value) -> void:
func _set_properties() -> void:
set_property("points", points)
+ set_property("global_position", global_position)
func randomize_stats() -> void:
diff --git a/src/tools/score_manager/ScoreManager.tscn b/src/tools/score_manager/ScoreManager.tscn
index 136b294..e54e089 100644
--- a/src/tools/score_manager/ScoreManager.tscn
+++ b/src/tools/score_manager/ScoreManager.tscn
@@ -1,6 +1,8 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=3 format=2]
[ext_resource path="res://tools/score_manager/score_manager.gd" type="Script" id=1]
+[ext_resource path="res://fonts/MonogramExtended.tres" type="DynamicFont" id=2]
[node name="ScoreManager" type="Node2D"]
script = ExtResource( 1 )
+TEXT_FONT = ExtResource( 2 )
diff --git a/src/tools/score_manager/score_manager.gd b/src/tools/score_manager/score_manager.gd
index 3b5ddba..63c78a7 100644
--- a/src/tools/score_manager/score_manager.gd
+++ b/src/tools/score_manager/score_manager.gd
@@ -1,9 +1,13 @@
extends Node
+export(Resource) var TEXT_FONT: Resource
var score: int = 0
var growth: int = 0
+var point_text_time: float = 2.0
+var _point_text_fmt: String = "+%s"
+
func _ready():
Event.connect("food_eaten", self, "_on_food_eaten")
@@ -11,8 +15,15 @@ func _ready():
func _on_food_eaten(properties: Dictionary) -> void:
var points: int = properties["points"]
+ var location: Vector2 = properties["global_position"]
+ _process_points(points)
+ _spawn_added_score_text(points, location)
+
+
+func _process_points(points: int) -> void:
var score_to_grow: int = (growth + 1) * Global.POINTS_TO_GROW - score
var amount_to_grow: int = 0
+ var growth_progress: int
score += points
if points >= score_to_grow:
amount_to_grow += 1
@@ -22,5 +33,16 @@ func _on_food_eaten(properties: Dictionary) -> void:
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)
+ growth_progress = Global.POINTS_TO_GROW - ((growth + 1) * Global.POINTS_TO_GROW - score)
+ Event.emit_signal("snake_growth_progress", growth_progress)
+
+
+func _spawn_added_score_text(points: int, location: Vector2) -> void:
+ var label: Label = Label.new()
+ label.text = _point_text_fmt % points
+ label.add_color_override("font_color", Color.red)
+ label.add_font_override("font", TEXT_FONT)
+ label.set_global_position(location)
+ add_child(label)
+ yield(get_tree().create_timer(point_text_time), "timeout")
+ remove_child(label)
diff --git a/src/ui/UI.tscn b/src/ui/UI.tscn
index 980faf4..79d8f93 100644
--- a/src/ui/UI.tscn
+++ b/src/ui/UI.tscn
@@ -1,6 +1,7 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
[ext_resource path="res://ui/ui.gd" type="Script" id=1]
+[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_icon.png" type="Texture" id=2]
[ext_resource path="res://ui/hud/snake/scenes/SnakeHUD.tscn" type="PackedScene" id=3]
[ext_resource path="res://ui/hud/progress_bars/scenes/GrowthProgress.tscn" type="PackedScene" id=4]
@@ -18,21 +19,27 @@ margin_right = 124.0
margin_bottom = 44.0
[node name="VBox" type="VBoxContainer" parent="Root/StatsHUD"]
-margin_right = 120.0
-margin_bottom = 40.0
+custom_constants/separation = 2
[node name="SnakeHUD" parent="Root/StatsHUD/VBox" instance=ExtResource( 3 )]
-margin_right = 120.0
+margin_right = 30.0
margin_bottom = 8.0
[node name="HBoxProgressBars" type="HBoxContainer" parent="Root/StatsHUD/VBox"]
-margin_top = 12.0
-margin_right = 120.0
-margin_bottom = 16.0
+margin_top = 10.0
+margin_right = 30.0
+margin_bottom = 18.0
+custom_constants/separation = 2
+
+[node name="GrowthProgressIcon" type="TextureRect" parent="Root/StatsHUD/VBox/HBoxProgressBars"]
+margin_right = 8.0
+margin_bottom = 8.0
+texture = ExtResource( 2 )
[node name="GrowthProgress" parent="Root/StatsHUD/VBox/HBoxProgressBars" instance=ExtResource( 4 )]
-margin_right = 20.0
-margin_bottom = 4.0
+margin_left = 10.0
+margin_right = 30.0
+margin_bottom = 8.0
[node name="MarginContainer" type="MarginContainer" parent="Root"]
anchor_top = 1.0
diff --git a/src/ui/hud/progress_bars/scenes/GrowthProgress.tscn b/src/ui/hud/progress_bars/scenes/GrowthProgress.tscn
index 0a0d9a8..a2478f1 100644
--- a/src/ui/hud/progress_bars/scenes/GrowthProgress.tscn
+++ b/src/ui/hud/progress_bars/scenes/GrowthProgress.tscn
@@ -1,12 +1,12 @@
[gd_scene load_steps=5 format=2]
-[ext_resource path="res://ui/hud/progress_bars/sprites/progress.png" type="Texture" id=1]
-[ext_resource path="res://ui/hud/progress_bars/sprites/over.png" type="Texture" id=2]
-[ext_resource path="res://ui/hud/progress_bars/sprites/under.png" type="Texture" id=3]
+[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_over.png" type="Texture" id=1]
+[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_under.png" type="Texture" id=2]
+[ext_resource path="res://ui/hud/progress_bars/sprites/grow_progress_progress.png" type="Texture" id=3]
[ext_resource path="res://ui/hud/progress_bars/scripts/growth_progress.gd" type="Script" id=4]
[node name="GrowthProgress" type="TextureProgress"]
-texture_under = ExtResource( 3 )
-texture_over = ExtResource( 2 )
-texture_progress = ExtResource( 1 )
+texture_under = ExtResource( 2 )
+texture_over = ExtResource( 1 )
+texture_progress = ExtResource( 3 )
script = ExtResource( 4 )
diff --git a/src/ui/hud/progress_bars/sprites/grow_progress_icon.png b/src/ui/hud/progress_bars/sprites/grow_progress_icon.png
new file mode 100644
index 0000000..0d913c5
--- /dev/null
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_icon.png
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/under.png.import b/src/ui/hud/progress_bars/sprites/grow_progress_icon.png.import
index c6f0d16..8d2488f 100644
--- a/src/ui/hud/progress_bars/sprites/under.png.import
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_icon.png.import
@@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
-path="res://.import/under.png-2db90a564085e100d8ec82ea8500cf5d.stex"
+path="res://.import/grow_progress_icon.png-3e4c84862319cfedeea45e4e79c3d47f.stex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://ui/hud/progress_bars/sprites/under.png"
-dest_files=[ "res://.import/under.png-2db90a564085e100d8ec82ea8500cf5d.stex" ]
+source_file="res://ui/hud/progress_bars/sprites/grow_progress_icon.png"
+dest_files=[ "res://.import/grow_progress_icon.png-3e4c84862319cfedeea45e4e79c3d47f.stex" ]
[params]
diff --git a/src/ui/hud/progress_bars/sprites/grow_progress_over.png b/src/ui/hud/progress_bars/sprites/grow_progress_over.png
new file mode 100644
index 0000000..ef2d175
--- /dev/null
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_over.png
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/over.png.import b/src/ui/hud/progress_bars/sprites/grow_progress_over.png.import
index 6dab18d..f0d7eb9 100644
--- a/src/ui/hud/progress_bars/sprites/over.png.import
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_over.png.import
@@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
-path="res://.import/over.png-0642cc73272ad1f8af9be593e496f68d.stex"
+path="res://.import/grow_progress_over.png-6d8306b6318e040ab2863f474941ffab.stex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://ui/hud/progress_bars/sprites/over.png"
-dest_files=[ "res://.import/over.png-0642cc73272ad1f8af9be593e496f68d.stex" ]
+source_file="res://ui/hud/progress_bars/sprites/grow_progress_over.png"
+dest_files=[ "res://.import/grow_progress_over.png-6d8306b6318e040ab2863f474941ffab.stex" ]
[params]
diff --git a/src/ui/hud/progress_bars/sprites/grow_progress_progress.png b/src/ui/hud/progress_bars/sprites/grow_progress_progress.png
new file mode 100644
index 0000000..24c1a2a
--- /dev/null
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_progress.png
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/grow_progress_progress.png.import b/src/ui/hud/progress_bars/sprites/grow_progress_progress.png.import
new file mode 100644
index 0000000..77593c5
--- /dev/null
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_progress.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/grow_progress_progress.png-30487fff60fbbf02be101653c4371a7b.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://ui/hud/progress_bars/sprites/grow_progress_progress.png"
+dest_files=[ "res://.import/grow_progress_progress.png-30487fff60fbbf02be101653c4371a7b.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=false
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=false
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=false
+svg/scale=1.0
diff --git a/src/ui/hud/progress_bars/sprites/grow_progress_under.png b/src/ui/hud/progress_bars/sprites/grow_progress_under.png
new file mode 100644
index 0000000..4597575
--- /dev/null
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_under.png
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/progress.png.import b/src/ui/hud/progress_bars/sprites/grow_progress_under.png.import
index 342daaf..462f187 100644
--- a/src/ui/hud/progress_bars/sprites/progress.png.import
+++ b/src/ui/hud/progress_bars/sprites/grow_progress_under.png.import
@@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
-path="res://.import/progress.png-30af99e69a9aa36165f02ed64d480a2f.stex"
+path="res://.import/grow_progress_under.png-c290c9f56bc4c33b22faafc5bd944210.stex"
metadata={
"vram_texture": false
}
[deps]
-source_file="res://ui/hud/progress_bars/sprites/progress.png"
-dest_files=[ "res://.import/progress.png-30af99e69a9aa36165f02ed64d480a2f.stex" ]
+source_file="res://ui/hud/progress_bars/sprites/grow_progress_under.png"
+dest_files=[ "res://.import/grow_progress_under.png-c290c9f56bc4c33b22faafc5bd944210.stex" ]
[params]
diff --git a/src/ui/hud/progress_bars/sprites/over.png b/src/ui/hud/progress_bars/sprites/over.png
deleted file mode 100644
index c5e102d..0000000
--- a/src/ui/hud/progress_bars/sprites/over.png
+++ /dev/null
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/progress.png b/src/ui/hud/progress_bars/sprites/progress.png
deleted file mode 100644
index 1ddfd77..0000000
--- a/src/ui/hud/progress_bars/sprites/progress.png
+++ /dev/null
Binary files differ
diff --git a/src/ui/hud/progress_bars/sprites/under.png b/src/ui/hud/progress_bars/sprites/under.png
deleted file mode 100644
index f31d502..0000000
--- a/src/ui/hud/progress_bars/sprites/under.png
+++ /dev/null
Binary files differ