From 36874a535a3d5f7f2955f33e34aa1a4768b6fec1 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sat, 4 Jun 2022 03:17:22 -0600 Subject: added hud for snake size and grow progress --- src/ui/hud/snake/scenes/SnakeHUD.tscn | 12 ++++++ src/ui/hud/snake/scenes/SnakeHead.tscn | 8 ++++ src/ui/hud/snake/scenes/SnakeSegment.tscn | 5 +++ src/ui/hud/snake/scripts/snake_head.gd | 29 +++++++++++++ src/ui/hud/snake/scripts/snake_hud.gd | 69 ++++++++++++++++++++++++++++++ src/ui/hud/snake/sprites/body.png | Bin 0 -> 127 bytes src/ui/hud/snake/sprites/body.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/body1.png | Bin 0 -> 105 bytes src/ui/hud/snake/sprites/body1.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/body2.png | Bin 0 -> 105 bytes src/ui/hud/snake/sprites/body2.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/body3.png | Bin 0 -> 105 bytes src/ui/hud/snake/sprites/body3.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/head.png | Bin 0 -> 290 bytes src/ui/hud/snake/sprites/head.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/head1.png | Bin 0 -> 163 bytes src/ui/hud/snake/sprites/head1.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/head2.png | Bin 0 -> 172 bytes src/ui/hud/snake/sprites/head2.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/head3.png | Bin 0 -> 174 bytes src/ui/hud/snake/sprites/head3.png.import | 35 +++++++++++++++ src/ui/hud/snake/sprites/tail.png | Bin 0 -> 107 bytes src/ui/hud/snake/sprites/tail.png.import | 35 +++++++++++++++ 23 files changed, 438 insertions(+) create mode 100644 src/ui/hud/snake/scenes/SnakeHUD.tscn create mode 100644 src/ui/hud/snake/scenes/SnakeHead.tscn create mode 100644 src/ui/hud/snake/scenes/SnakeSegment.tscn create mode 100644 src/ui/hud/snake/scripts/snake_head.gd create mode 100644 src/ui/hud/snake/scripts/snake_hud.gd create mode 100644 src/ui/hud/snake/sprites/body.png create mode 100644 src/ui/hud/snake/sprites/body.png.import create mode 100644 src/ui/hud/snake/sprites/body1.png create mode 100644 src/ui/hud/snake/sprites/body1.png.import create mode 100644 src/ui/hud/snake/sprites/body2.png create mode 100644 src/ui/hud/snake/sprites/body2.png.import create mode 100644 src/ui/hud/snake/sprites/body3.png create mode 100644 src/ui/hud/snake/sprites/body3.png.import create mode 100644 src/ui/hud/snake/sprites/head.png create mode 100644 src/ui/hud/snake/sprites/head.png.import create mode 100644 src/ui/hud/snake/sprites/head1.png create mode 100644 src/ui/hud/snake/sprites/head1.png.import create mode 100644 src/ui/hud/snake/sprites/head2.png create mode 100644 src/ui/hud/snake/sprites/head2.png.import create mode 100644 src/ui/hud/snake/sprites/head3.png create mode 100644 src/ui/hud/snake/sprites/head3.png.import create mode 100644 src/ui/hud/snake/sprites/tail.png create mode 100644 src/ui/hud/snake/sprites/tail.png.import (limited to 'src/ui/hud/snake') diff --git a/src/ui/hud/snake/scenes/SnakeHUD.tscn b/src/ui/hud/snake/scenes/SnakeHUD.tscn new file mode 100644 index 0000000..4b33885 --- /dev/null +++ b/src/ui/hud/snake/scenes/SnakeHUD.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://ui/hud/snake/scenes/SnakeHead.tscn" type="PackedScene" id=1] +[ext_resource path="res://ui/hud/snake/scripts/snake_hud.gd" type="Script" id=2] +[ext_resource path="res://ui/hud/snake/sprites/head1.png" type="Texture" id=3] + +[node name="SnakeHUD" type="HBoxContainer"] +custom_constants/separation = 0 +script = ExtResource( 2 ) + +[node name="SnakeHead" parent="." instance=ExtResource( 1 )] +texture = ExtResource( 3 ) diff --git a/src/ui/hud/snake/scenes/SnakeHead.tscn b/src/ui/hud/snake/scenes/SnakeHead.tscn new file mode 100644 index 0000000..79eb7d1 --- /dev/null +++ b/src/ui/hud/snake/scenes/SnakeHead.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://ui/hud/snake/scripts/snake_head.gd" type="Script" id=1] + +[node name="SnakeHead" type="TextureRect"] +margin_right = 8.0 +margin_bottom = 8.0 +script = ExtResource( 1 ) diff --git a/src/ui/hud/snake/scenes/SnakeSegment.tscn b/src/ui/hud/snake/scenes/SnakeSegment.tscn new file mode 100644 index 0000000..069a812 --- /dev/null +++ b/src/ui/hud/snake/scenes/SnakeSegment.tscn @@ -0,0 +1,5 @@ +[gd_scene format=2] + +[node name="SnakeSegment" type="TextureRect"] +margin_right = 4.0 +margin_bottom = 4.0 diff --git a/src/ui/hud/snake/scripts/snake_head.gd b/src/ui/hud/snake/scripts/snake_head.gd new file mode 100644 index 0000000..a414e23 --- /dev/null +++ b/src/ui/hud/snake/scripts/snake_head.gd @@ -0,0 +1,29 @@ +extends TextureRect + +enum { + IDLE, + EAT, + DEAD +} + +var frames = { + IDLE: preload("res://ui/hud/snake/sprites/head1.png"), + EAT: preload("res://ui/hud/snake/sprites/head2.png"), + DEAD: preload("res://ui/hud/snake/sprites/head3.png") +} + + +func _ready(): + texture = frames[IDLE] + Event.connect("food_eaten", self, "_on_food_eaten") + Event.connect("game_over", self, "_on_game_over") + + +func _on_food_eaten(properties: Dictionary) -> void: + texture = frames[EAT] + yield(get_tree().create_timer(0.25), "timeout") + texture = frames[IDLE] + + +func _on_game_over() -> void: + texture = frames[DEAD] \ No newline at end of file diff --git a/src/ui/hud/snake/scripts/snake_hud.gd b/src/ui/hud/snake/scripts/snake_hud.gd new file mode 100644 index 0000000..b50b72e --- /dev/null +++ b/src/ui/hud/snake/scripts/snake_hud.gd @@ -0,0 +1,69 @@ +extends HBoxContainer + +enum { + BODY1, + BODY2, + BODY3, + TAIL +} + +var frames: Dictionary = { + BODY1: preload("res://ui/hud/snake/sprites/body1.png"), + BODY2: preload("res://ui/hud/snake/sprites/body2.png"), + BODY3: preload("res://ui/hud/snake/sprites/body3.png"), + TAIL: preload("res://ui/hud/snake/sprites/tail.png") +} + +var last_tail_index: int = -1 +var last_frame: int = -1 +var frame_direction: int = 1 + + +func _ready(): + Event.connect("snake_added_new_segment", self, "_on_snake_added_new_segment") + + +func _on_snake_added_new_segment(type: String) -> void: + match type: + "body": + _add_body_frame() + _move_tail_frame() + "tail": + _add_tail_frame() + + +func _add_body_frame() -> void: + var texture_rect: TextureRect = TextureRect.new() + texture_rect.texture = frames[_get_next_body_frame()] + add_child(texture_rect) + + +func _add_tail_frame() -> void: + var texture_rect: TextureRect = TextureRect.new() + texture_rect.texture = frames[TAIL] + add_child(texture_rect) + last_tail_index = get_child_count() - 1 + + +func _move_tail_frame() -> void: + var child_count: int = get_child_count() + if child_count > Global.SNAKE_INITIAL_SEGMENTS + 1: + var last_child: TextureRect = get_child(last_tail_index) + move_child(last_child, child_count - 1) + last_tail_index = child_count - 1 + + +func _get_next_body_frame() -> int: + match last_frame: + -1: + last_frame = BODY2 + BODY2: + last_frame += frame_direction + BODY3: + frame_direction = -1 + last_frame += frame_direction + BODY1: + frame_direction = 1 + last_frame += frame_direction + + return last_frame diff --git a/src/ui/hud/snake/sprites/body.png b/src/ui/hud/snake/sprites/body.png new file mode 100644 index 0000000..8fb53c1 Binary files /dev/null and b/src/ui/hud/snake/sprites/body.png differ diff --git a/src/ui/hud/snake/sprites/body.png.import b/src/ui/hud/snake/sprites/body.png.import new file mode 100644 index 0000000..3891d75 --- /dev/null +++ b/src/ui/hud/snake/sprites/body.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/body.png-cd3faf610a4d26eadd0148f5ade8a21a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/body.png" +dest_files=[ "res://.import/body.png-cd3faf610a4d26eadd0148f5ade8a21a.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/snake/sprites/body1.png b/src/ui/hud/snake/sprites/body1.png new file mode 100644 index 0000000..e2671b3 Binary files /dev/null and b/src/ui/hud/snake/sprites/body1.png differ diff --git a/src/ui/hud/snake/sprites/body1.png.import b/src/ui/hud/snake/sprites/body1.png.import new file mode 100644 index 0000000..9573e97 --- /dev/null +++ b/src/ui/hud/snake/sprites/body1.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/body1.png-5d85028b95914799a2aebc60349a56c2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/body1.png" +dest_files=[ "res://.import/body1.png-5d85028b95914799a2aebc60349a56c2.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/snake/sprites/body2.png b/src/ui/hud/snake/sprites/body2.png new file mode 100644 index 0000000..0b82cd9 Binary files /dev/null and b/src/ui/hud/snake/sprites/body2.png differ diff --git a/src/ui/hud/snake/sprites/body2.png.import b/src/ui/hud/snake/sprites/body2.png.import new file mode 100644 index 0000000..17356a4 --- /dev/null +++ b/src/ui/hud/snake/sprites/body2.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/body2.png-01a5c5dad5a83f4d4d299b857c658e39.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/body2.png" +dest_files=[ "res://.import/body2.png-01a5c5dad5a83f4d4d299b857c658e39.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/snake/sprites/body3.png b/src/ui/hud/snake/sprites/body3.png new file mode 100644 index 0000000..9ba7c5a Binary files /dev/null and b/src/ui/hud/snake/sprites/body3.png differ diff --git a/src/ui/hud/snake/sprites/body3.png.import b/src/ui/hud/snake/sprites/body3.png.import new file mode 100644 index 0000000..bfa7791 --- /dev/null +++ b/src/ui/hud/snake/sprites/body3.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/body3.png-5bcd745ab0fc40d3e8ef2d150e7b7d4d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/body3.png" +dest_files=[ "res://.import/body3.png-5bcd745ab0fc40d3e8ef2d150e7b7d4d.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/snake/sprites/head.png b/src/ui/hud/snake/sprites/head.png new file mode 100644 index 0000000..c2cd997 Binary files /dev/null and b/src/ui/hud/snake/sprites/head.png differ diff --git a/src/ui/hud/snake/sprites/head.png.import b/src/ui/hud/snake/sprites/head.png.import new file mode 100644 index 0000000..5b9b768 --- /dev/null +++ b/src/ui/hud/snake/sprites/head.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/head.png-4b4fedad924e66f19c046d3ce4c1b58a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/head.png" +dest_files=[ "res://.import/head.png-4b4fedad924e66f19c046d3ce4c1b58a.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/snake/sprites/head1.png b/src/ui/hud/snake/sprites/head1.png new file mode 100644 index 0000000..1d29792 Binary files /dev/null and b/src/ui/hud/snake/sprites/head1.png differ diff --git a/src/ui/hud/snake/sprites/head1.png.import b/src/ui/hud/snake/sprites/head1.png.import new file mode 100644 index 0000000..72d345d --- /dev/null +++ b/src/ui/hud/snake/sprites/head1.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/head1.png-b86145ede399b444d822e7b0ec71dada.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/head1.png" +dest_files=[ "res://.import/head1.png-b86145ede399b444d822e7b0ec71dada.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/snake/sprites/head2.png b/src/ui/hud/snake/sprites/head2.png new file mode 100644 index 0000000..473f669 Binary files /dev/null and b/src/ui/hud/snake/sprites/head2.png differ diff --git a/src/ui/hud/snake/sprites/head2.png.import b/src/ui/hud/snake/sprites/head2.png.import new file mode 100644 index 0000000..78c9241 --- /dev/null +++ b/src/ui/hud/snake/sprites/head2.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/head2.png-565eeac8eb1428ec8155a0982d857bb6.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/head2.png" +dest_files=[ "res://.import/head2.png-565eeac8eb1428ec8155a0982d857bb6.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/snake/sprites/head3.png b/src/ui/hud/snake/sprites/head3.png new file mode 100644 index 0000000..c95b2d7 Binary files /dev/null and b/src/ui/hud/snake/sprites/head3.png differ diff --git a/src/ui/hud/snake/sprites/head3.png.import b/src/ui/hud/snake/sprites/head3.png.import new file mode 100644 index 0000000..e51f75c --- /dev/null +++ b/src/ui/hud/snake/sprites/head3.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/head3.png-e8a18efff02063d9a43d2babeb798767.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/head3.png" +dest_files=[ "res://.import/head3.png-e8a18efff02063d9a43d2babeb798767.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/snake/sprites/tail.png b/src/ui/hud/snake/sprites/tail.png new file mode 100644 index 0000000..77f361d Binary files /dev/null and b/src/ui/hud/snake/sprites/tail.png differ diff --git a/src/ui/hud/snake/sprites/tail.png.import b/src/ui/hud/snake/sprites/tail.png.import new file mode 100644 index 0000000..fd6334d --- /dev/null +++ b/src/ui/hud/snake/sprites/tail.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/tail.png-292b09567a886543da0b95c4d3dfad3c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://ui/hud/snake/sprites/tail.png" +dest_files=[ "res://.import/tail.png-292b09567a886543da0b95c4d3dfad3c.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 -- cgit v1.2.3-70-g09d2