diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-06-04 03:17:22 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-06-04 03:17:22 -0600 |
commit | 36874a535a3d5f7f2955f33e34aa1a4768b6fec1 (patch) | |
tree | 8f4eaa57d5e82d962719a8a399cfc210ced672e6 /src/ui/hud/snake | |
parent | f922fe4669080d1633e0a345a3f8981867c9e841 (diff) |
added hud for snake size and grow progress
Diffstat (limited to 'src/ui/hud/snake')
23 files changed, 438 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 0000000..8fb53c1 --- /dev/null +++ b/src/ui/hud/snake/sprites/body.png 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 Binary files differnew file mode 100644 index 0000000..e2671b3 --- /dev/null +++ b/src/ui/hud/snake/sprites/body1.png 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 Binary files differnew file mode 100644 index 0000000..0b82cd9 --- /dev/null +++ b/src/ui/hud/snake/sprites/body2.png 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 Binary files differnew file mode 100644 index 0000000..9ba7c5a --- /dev/null +++ b/src/ui/hud/snake/sprites/body3.png 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 Binary files differnew file mode 100644 index 0000000..c2cd997 --- /dev/null +++ b/src/ui/hud/snake/sprites/head.png 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 Binary files differnew file mode 100644 index 0000000..1d29792 --- /dev/null +++ b/src/ui/hud/snake/sprites/head1.png 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 Binary files differnew file mode 100644 index 0000000..473f669 --- /dev/null +++ b/src/ui/hud/snake/sprites/head2.png 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 Binary files differnew file mode 100644 index 0000000..c95b2d7 --- /dev/null +++ b/src/ui/hud/snake/sprites/head3.png 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 Binary files differnew file mode 100644 index 0000000..77f361d --- /dev/null +++ b/src/ui/hud/snake/sprites/tail.png 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 |