diff --git a/assets/boots.png.import b/assets/boots.png.import new file mode 100644 index 0000000..ba59b37 --- /dev/null +++ b/assets/boots.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cn5lvdmjt2xue" +path="res://.godot/imported/boots.png-84b46c52c44b068496caeb3f7ead2e77.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/boots.png" +dest_files=["res://.godot/imported/boots.png-84b46c52c44b068496caeb3f7ead2e77.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/chest.png.import b/assets/chest.png.import new file mode 100644 index 0000000..e6375b3 --- /dev/null +++ b/assets/chest.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b0h7llq1qb706" +path="res://.godot/imported/chest.png-ec5c0ce22911c81d595ed790e257ceb9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/chest.png" +dest_files=["res://.godot/imported/chest.png-ec5c0ce22911c81d595ed790e257ceb9.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/chest_opened.png.import b/assets/chest_opened.png.import new file mode 100644 index 0000000..01d5f6a --- /dev/null +++ b/assets/chest_opened.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cgkq30nhsygpe" +path="res://.godot/imported/chest_opened.png-79ff976633dae8a5bb7215b9c4c5529f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/chest_opened.png" +dest_files=["res://.godot/imported/chest_opened.png-79ff976633dae8a5bb7215b9c4c5529f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/dot.png.import b/assets/dot.png.import new file mode 100644 index 0000000..795dc6a --- /dev/null +++ b/assets/dot.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d32ory5gus4lm" +path="res://.godot/imported/dot.png-8f4927301bfe25b36ae6b38c2d837062.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/dot.png" +dest_files=["res://.godot/imported/dot.png-8f4927301bfe25b36ae6b38c2d837062.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/eye.png.import b/assets/eye.png.import new file mode 100644 index 0000000..af9f2f3 --- /dev/null +++ b/assets/eye.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c3ck7s86qc37a" +path="res://.godot/imported/eye.png-a84d27eb76574b804de06889c29718a8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/eye.png" +dest_files=["res://.godot/imported/eye.png-a84d27eb76574b804de06889c29718a8.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/heart.png.import b/assets/heart.png.import new file mode 100644 index 0000000..7cf80e0 --- /dev/null +++ b/assets/heart.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://doxv0y43t4770" +path="res://.godot/imported/heart.png-9a2fa56e49d8a002fed7c28ce07513e0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/heart.png" +dest_files=["res://.godot/imported/heart.png-9a2fa56e49d8a002fed7c28ce07513e0.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/data/buffs/blue_buff.tres b/data/buffs/blue_buff.tres new file mode 100644 index 0000000..ef25f10 --- /dev/null +++ b/data/buffs/blue_buff.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="Buff" load_steps=3 format=3 uid="uid://djb1iyhb8gwqb"] + +[ext_resource type="Texture2D" uid="uid://cn5lvdmjt2xue" path="res://assets/boots.png" id="1_8dq50"] +[ext_resource type="Script" path="res://scripts/buff.gd" id="1_qg760"] + +[resource] +script = ExtResource("1_qg760") +image = ExtResource("1_8dq50") +color = 2 diff --git a/data/buffs/green_buff.tres b/data/buffs/green_buff.tres new file mode 100644 index 0000000..71d0ccb --- /dev/null +++ b/data/buffs/green_buff.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="Buff" load_steps=3 format=3 uid="uid://bo7k3kmsq57xy"] + +[ext_resource type="Script" path="res://scripts/buff.gd" id="1_iyogh"] +[ext_resource type="Texture2D" uid="uid://c3ck7s86qc37a" path="res://assets/eye.png" id="1_jskem"] + +[resource] +script = ExtResource("1_iyogh") +image = ExtResource("1_jskem") +color = 1 diff --git a/data/buffs/red_buff.tres b/data/buffs/red_buff.tres new file mode 100644 index 0000000..90280e5 --- /dev/null +++ b/data/buffs/red_buff.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="Buff" load_steps=3 format=3 uid="uid://tiv2o1xk5g7e"] + +[ext_resource type="Texture2D" uid="uid://doxv0y43t4770" path="res://assets/heart.png" id="1_gshhk"] +[ext_resource type="Script" path="res://scripts/buff.gd" id="2_8wfcu"] + +[resource] +script = ExtResource("2_8wfcu") +image = ExtResource("1_gshhk") +color = 0 diff --git a/data/themes/blue_progress_bar_theme.tres b/data/themes/blue_progress_bar_theme.tres new file mode 100644 index 0000000..620b708 --- /dev/null +++ b/data/themes/blue_progress_bar_theme.tres @@ -0,0 +1,15 @@ +[gd_resource type="Theme" load_steps=3 format=3 uid="uid://dm1sx57hw07cn"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_brxtc"] +bg_color = Color(0, 0, 0, 1) +corner_radius_top_left = 2 +corner_radius_top_right = 2 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qebp0"] +bg_color = Color(0, 0, 1, 1) +corner_radius_top_left = 1 +corner_radius_top_right = 1 + +[resource] +ProgressBar/styles/background = SubResource("StyleBoxFlat_brxtc") +ProgressBar/styles/fill = SubResource("StyleBoxFlat_qebp0") diff --git a/data/themes/green_progress_bar_theme.tres b/data/themes/green_progress_bar_theme.tres new file mode 100644 index 0000000..ca3af78 --- /dev/null +++ b/data/themes/green_progress_bar_theme.tres @@ -0,0 +1,15 @@ +[gd_resource type="Theme" load_steps=3 format=3 uid="uid://ewgo3qi2xs54"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_brxtc"] +bg_color = Color(0, 0, 0, 1) +corner_radius_top_left = 2 +corner_radius_top_right = 2 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qebp0"] +bg_color = Color(0, 1, 0, 1) +corner_radius_top_left = 1 +corner_radius_top_right = 1 + +[resource] +ProgressBar/styles/background = SubResource("StyleBoxFlat_brxtc") +ProgressBar/styles/fill = SubResource("StyleBoxFlat_qebp0") diff --git a/data/themes/red_progress_bar_theme.tres b/data/themes/red_progress_bar_theme.tres new file mode 100644 index 0000000..0e7635e --- /dev/null +++ b/data/themes/red_progress_bar_theme.tres @@ -0,0 +1,15 @@ +[gd_resource type="Theme" load_steps=3 format=3 uid="uid://7w47qwaweedo"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_brxtc"] +bg_color = Color(0, 0, 0, 1) +corner_radius_top_left = 2 +corner_radius_top_right = 2 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qebp0"] +bg_color = Color(1, 0, 0, 1) +corner_radius_top_left = 1 +corner_radius_top_right = 1 + +[resource] +ProgressBar/styles/background = SubResource("StyleBoxFlat_brxtc") +ProgressBar/styles/fill = SubResource("StyleBoxFlat_qebp0") diff --git a/project.godot b/project.godot index d8c606d..f626278 100644 --- a/project.godot +++ b/project.godot @@ -11,6 +11,7 @@ config_version=5 [application] config/name="rgb" +run/main_scene="res://scene/maze_1.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" diff --git a/scene/enemy.tscn b/scene/enemy.tscn new file mode 100644 index 0000000..3751314 --- /dev/null +++ b/scene/enemy.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=3 uid="uid://beopqphfymjik"] + +[ext_resource type="Script" path="res://scripts/enemy.gd" id="1_a6qhu"] +[ext_resource type="Texture2D" uid="uid://d32ory5gus4lm" path="res://assets/dot.png" id="2_jkluv"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_c7wcn"] +radius = 6.0 + +[node name="Enemy" type="CharacterBody2D"] +script = ExtResource("1_a6qhu") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_jkluv") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_c7wcn") diff --git a/scene/hud.tscn b/scene/hud.tscn new file mode 100644 index 0000000..4b2cc70 --- /dev/null +++ b/scene/hud.tscn @@ -0,0 +1,91 @@ +[gd_scene load_steps=7 format=3 uid="uid://dcpeowc6xcfcv"] + +[ext_resource type="Texture2D" uid="uid://d32ory5gus4lm" path="res://assets/dot.png" id="1_tsiui"] +[ext_resource type="Script" path="res://scripts/hud.gd" id="1_yk6cu"] +[ext_resource type="Texture2D" uid="uid://doxv0y43t4770" path="res://assets/heart.png" id="2_4hybp"] +[ext_resource type="Theme" uid="uid://7w47qwaweedo" path="res://data/themes/red_progress_bar_theme.tres" id="2_lvcgk"] +[ext_resource type="Theme" uid="uid://ewgo3qi2xs54" path="res://data/themes/green_progress_bar_theme.tres" id="3_wvu2t"] +[ext_resource type="Theme" uid="uid://dm1sx57hw07cn" path="res://data/themes/blue_progress_bar_theme.tres" id="4_n8d17"] + +[node name="HUD" type="CanvasLayer"] +script = ExtResource("1_yk6cu") + +[node name="PanelContainer" type="PanelContainer" parent="."] +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_left = 16.0 +offset_top = -184.0 +offset_right = 64.0 +offset_bottom = -24.0 +grow_vertical = 0 + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 2 +theme_override_constants/margin_top = 2 +theme_override_constants/margin_right = 2 +theme_override_constants/margin_bottom = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 + +[node name="LivesContainer" type="GridContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +columns = 3 + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/MarginContainer/VBoxContainer/LivesContainer"] +layout_mode = 2 +texture = ExtResource("2_4hybp") + +[node name="TextureRect" type="TextureRect" parent="PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +texture = ExtResource("1_tsiui") +expand_mode = 4 +stretch_mode = 4 + +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="PanelContainerRed" type="PanelContainer" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerRed"] +layout_mode = 2 +size_flags_vertical = 1 +theme = ExtResource("2_lvcgk") +max_value = 1.0 +step = 0.1 +value = 1.0 +fill_mode = 3 +show_percentage = false + +[node name="PanelContainerGreen" type="PanelContainer" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerGreen"] +layout_mode = 2 +size_flags_vertical = 1 +theme = ExtResource("3_wvu2t") +max_value = 1.0 +step = 0.1 +value = 1.0 +fill_mode = 3 +show_percentage = false + +[node name="PanelContainerBlue" type="PanelContainer" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ProgressBar" type="ProgressBar" parent="PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerBlue"] +layout_mode = 2 +size_flags_vertical = 1 +theme = ExtResource("4_n8d17") +max_value = 1.0 +step = 0.1 +value = 1.0 +fill_mode = 3 +show_percentage = false diff --git a/scene/maze_1.tscn b/scene/maze_1.tscn index 7b45eea..f47f35f 100644 --- a/scene/maze_1.tscn +++ b/scene/maze_1.tscn @@ -1,8 +1,12 @@ -[gd_scene load_steps=7 format=3 uid="uid://b2amoasy4e08i"] +[gd_scene load_steps=11 format=3 uid="uid://b2amoasy4e08i"] [ext_resource type="Texture2D" uid="uid://bsrmtons1ov7x" path="res://assets/maze.png" id="1_jp5wf"] -[ext_resource type="PackedScene" uid="uid://cd57rr2jffwqu" path="res://scene/player.tscn" id="2_s6cts"] +[ext_resource type="Script" path="res://scripts/maze.gd" id="1_u2iw0"] [ext_resource type="PackedScene" uid="uid://c267u62jmp3dq" path="res://scene/chest.tscn" id="3_uyb5m"] +[ext_resource type="Resource" uid="uid://djb1iyhb8gwqb" path="res://data/buffs/blue_buff.tres" id="4_2gr0s"] +[ext_resource type="PackedScene" uid="uid://dcpeowc6xcfcv" path="res://scene/hud.tscn" id="4_7uel4"] +[ext_resource type="Resource" uid="uid://bo7k3kmsq57xy" path="res://data/buffs/green_buff.tres" id="5_ho55u"] +[ext_resource type="Resource" uid="uid://tiv2o1xk5g7e" path="res://data/buffs/red_buff.tres" id="6_ll7oj"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_e47fw"] texture = ExtResource("1_jp5wf") @@ -67,6 +71,7 @@ sources/0 = SubResource("TileSetAtlasSource_e47fw") size = Vector2(64, 64) [node name="maze_1" type="Node2D"] +script = ExtResource("1_u2iw0") [node name="TileMap" type="TileMap" parent="."] tile_set = SubResource("TileSet_dy2x8") @@ -99,43 +104,54 @@ shape = SubResource("RectangleShape2D_hodhv") position = Vector2(64, 224) shape = SubResource("RectangleShape2D_hodhv") -[node name="Player" parent="." instance=ExtResource("2_s6cts")] -position = Vector2(144, 128) - [node name="ChestContainer" type="Node" parent="."] [node name="Chest" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(56, 328) +buff = ExtResource("4_2gr0s") [node name="Chest2" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(152, 184) +buff = ExtResource("4_2gr0s") [node name="Chest3" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(152, 88) +buff = ExtResource("5_ho55u") [node name="Chest4" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(248, -56) +buff = ExtResource("5_ho55u") [node name="Chest10" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(312, -72) +buff = ExtResource("6_ll7oj") [node name="Chest11" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(184, -72) +buff = ExtResource("6_ll7oj") [node name="Chest12" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(120, -56) +buff = ExtResource("5_ho55u") [node name="Chest5" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(-56, 40) +buff = ExtResource("5_ho55u") [node name="Chest6" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(360, 232) +buff = ExtResource("4_2gr0s") [node name="Chest7" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(120, 344) +buff = ExtResource("6_ll7oj") [node name="Chest8" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(184, 328) +buff = ExtResource("4_2gr0s") [node name="Chest9" parent="ChestContainer" instance=ExtResource("3_uyb5m")] position = Vector2(-8, 344) +buff = ExtResource("6_ll7oj") + +[node name="HUD" parent="." instance=ExtResource("4_7uel4")] diff --git a/scene/player.tscn b/scene/player.tscn index 52448d8..7fc7412 100644 --- a/scene/player.tscn +++ b/scene/player.tscn @@ -1,13 +1,13 @@ [gd_scene load_steps=4 format=3 uid="uid://cd57rr2jffwqu"] -[ext_resource type="Script" path="res://scripts/player.gd" id="1_yhpqp"] +[ext_resource type="Script" path="res://scripts/player.gd" id="1_veifk"] [ext_resource type="Texture2D" uid="uid://d32ory5gus4lm" path="res://assets/dot.png" id="2_up8am"] [sub_resource type="CircleShape2D" id="CircleShape2D_c7wcn"] radius = 6.0 [node name="Player" type="CharacterBody2D"] -script = ExtResource("1_yhpqp") +script = ExtResource("1_veifk") [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("2_up8am") diff --git a/scripts/buff.gd b/scripts/buff.gd new file mode 100644 index 0000000..2742fd6 --- /dev/null +++ b/scripts/buff.gd @@ -0,0 +1,11 @@ +extends Resource +class_name Buff + +enum colors { + RED, + GREEN, + BLUE +} + +@export var image: Texture2D +@export var color: colors diff --git a/scripts/chest.gd b/scripts/chest.gd index 05d086d..6b96070 100644 --- a/scripts/chest.gd +++ b/scripts/chest.gd @@ -1 +1,20 @@ extends StaticBody2D +class_name Chest + +@export var buff: Buff + +const CHEST_OPENED = preload("res://assets/chest_opened.png") +var recipients = [] +var opened := false + +func open(entity) -> Buff: + if not recipients.has(entity): + if not opened: + opened = true + $Sprite2D.texture = CHEST_OPENED + var buff_texture := Sprite2D.new() + buff_texture.texture = buff.image + add_child(buff_texture) + recipients.append(entity) + return buff + return null diff --git a/scripts/enemy.gd b/scripts/enemy.gd new file mode 100644 index 0000000..bbf4348 --- /dev/null +++ b/scripts/enemy.gd @@ -0,0 +1,37 @@ +extends CharacterBody2D +class_name Enemy + +@onready var sprite_2d: Sprite2D = $Sprite2D + +var color := Color.WHITE +@export var speed = 100 +var lives: int = 1 + +func _physics_process(delta: float) -> void: + velocity = Vector2.ZERO + if Input.is_action_pressed("ui_down"): + velocity += Vector2.DOWN + if Input.is_action_pressed("ui_up"): + velocity += Vector2.UP + if Input.is_action_pressed("ui_left"): + velocity += Vector2.LEFT + if Input.is_action_pressed("ui_right"): + velocity += Vector2.RIGHT + velocity = velocity.normalized() * speed + move_and_slide() + for i in range(get_slide_collision_count()): + var collision := get_slide_collision(i) + if collision.get_collider() is Chest: + var buff: Buff = collision.get_collider().open(self) + if buff: + match(buff.color): + buff.colors.RED: + lives += 1 + color.r -= 0.25 + buff.colors.GREEN: + #$Camera2D.zoom -= Vector2(0.4, 0.4) + color.g -= 0.25 + buff.colors.BLUE: + speed += 12 + color.b -= 0.25 + sprite_2d.modulate = color diff --git a/scripts/hud.gd b/scripts/hud.gd new file mode 100644 index 0000000..05f32a2 --- /dev/null +++ b/scripts/hud.gd @@ -0,0 +1,25 @@ +extends CanvasLayer +class_name HUD + +@onready var progress_bar_red: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerRed/ProgressBar +@onready var progress_bar_green: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerGreen/ProgressBar +@onready var progress_bar_blue: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerBlue/ProgressBar +@onready var texture_rect: TextureRect = $PanelContainer/MarginContainer/VBoxContainer/TextureRect +@onready var lives_container: GridContainer = $PanelContainer/MarginContainer/VBoxContainer/LivesContainer +const HEART = preload("res://assets/heart.png") + +func _on_player_color_changed(color: Color) -> void: + progress_bar_red.value = color.r + progress_bar_green.value = color.g + progress_bar_blue.value = color.b + texture_rect.modulate = color + + +func _on_player_lives_changed(lives: int) -> void: + var heart_containers = lives_container.get_children() + if heart_containers.size() < lives: + var life = TextureRect.new() + life.texture = HEART + lives_container.add_child(life) + elif heart_containers.size() > lives: + heart_containers.pop_back().queue_free() diff --git a/scripts/maze.gd b/scripts/maze.gd new file mode 100644 index 0000000..2c62d98 --- /dev/null +++ b/scripts/maze.gd @@ -0,0 +1,30 @@ +extends Node2D +class_name Maze + +const PLAYER = preload("res://scene/player.tscn") +const ENEMY = preload("res://scene/enemy.tscn") + +var spawn_locations: Array[Vector2] = [] + +@onready var hud: HUD = $HUD +@onready var spawn_zones: Node2D = $SpawnZones + +func _ready() -> void: + var spawn_zone_array := spawn_zones.get_children() + for spawn_zone in spawn_zone_array: + var zone := spawn_zone.get_child(0) as CollisionShape2D + var top_left = zone.transform.get_origin() - Vector2(24, 24) + for x in range(zone.shape.size.x / 16): + for y in range(zone.shape.size.y / 16): + spawn_locations.append(top_left + Vector2(x * 16, y * 16)) + var player_loc: Vector2 = spawn_locations.pick_random() + for spawn in spawn_locations: + var entity + if spawn == player_loc: + entity = PLAYER.instantiate() + entity.color_changed.connect(hud._on_player_color_changed) + entity.lives_changed.connect(hud._on_player_lives_changed) + else: + entity = ENEMY.instantiate() + entity.position = spawn + add_child(entity) diff --git a/scripts/player.gd b/scripts/player.gd index 730337a..ca3149c 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,7 +1,14 @@ extends CharacterBody2D class_name Player +signal color_changed(color: Color) +signal lives_changed(lives: int) + +@onready var sprite_2d: Sprite2D = $Sprite2D + +var color := Color.WHITE @export var speed = 100 +var lives: int = 1 func _physics_process(delta: float) -> void: velocity = Vector2.ZERO @@ -15,3 +22,21 @@ func _physics_process(delta: float) -> void: velocity += Vector2.RIGHT velocity = velocity.normalized() * speed move_and_slide() + for i in range(get_slide_collision_count()): + var collision := get_slide_collision(i) + if collision.get_collider() is Chest: + var buff: Buff = collision.get_collider().open(self) + if buff: + match(buff.color): + buff.colors.RED: + lives += 1 + color.r -= 0.25 + lives_changed.emit(lives) + buff.colors.GREEN: + $Camera2D.zoom -= Vector2(0.4, 0.4) + color.g -= 0.25 + buff.colors.BLUE: + speed += 12 + color.b -= 0.25 + sprite_2d.modulate = color + color_changed.emit(color)