From 491755209f850d75b1e9ed3fb4c03e9d32cd36bb Mon Sep 17 00:00:00 2001 From: Kilokem Date: Thu, 13 Mar 2025 17:25:00 +0100 Subject: [PATCH] Sidebar and lives --- Game/Maps/map_1.gd | 9 +++++++ Game/Maps/map_1.tscn | 11 ++++++-- Game/Mobs/enemy.gd | 6 +++++ Game/sidepanel.gd | 4 +++ Game/sidepanel.gd.uid | 1 + Game/sidepanel.tscn | 63 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Game/sidepanel.gd create mode 100644 Game/sidepanel.gd.uid create mode 100644 Game/sidepanel.tscn diff --git a/Game/Maps/map_1.gd b/Game/Maps/map_1.gd index 1a8d93e..1194ab3 100644 --- a/Game/Maps/map_1.gd +++ b/Game/Maps/map_1.gd @@ -8,6 +8,8 @@ const COBOLD = preload("res://Game/Mobs/cobold.tscn") const enemies = [FORKMAN, COBOLD, ORK] +var lives = 20 + func _on_timer_timeout() -> void: spawnMonster() @@ -17,3 +19,10 @@ func spawnMonster(): path.add_child(monster) path_2d.add_child(path) + +func decrease_life(damage) -> void: + lives -= damage + print(lives) + if lives == 0: + print("DEAD") + diff --git a/Game/Maps/map_1.tscn b/Game/Maps/map_1.tscn index 6263740..219e5a3 100644 --- a/Game/Maps/map_1.tscn +++ b/Game/Maps/map_1.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=133 format=4 uid="uid://bgme05i7taycc"] +[gd_scene load_steps=134 format=4 uid="uid://bgme05i7taycc"] [ext_resource type="Texture2D" uid="uid://f1npbjsw71nk" path="res://Assets/Tiles/Fields/FieldsTile_01.png" id="1_fdpq6"] [ext_resource type="Script" uid="uid://xo6vbicdva8d" path="res://Game/Maps/map_1.gd" id="1_rec5e"] @@ -66,6 +66,7 @@ [ext_resource type="Texture2D" uid="uid://5wec1pm5l10c" path="res://Assets/Tiles/Fields/FieldsTile_63.png" id="63_gsp4q"] [ext_resource type="Texture2D" uid="uid://bof7eh3ttmi2f" path="res://Assets/Tiles/Fields/FieldsTile_64.png" id="64_5s0ky"] [ext_resource type="Texture2D" uid="uid://do3u4pgcgn7g3" path="res://Assets/Castles/Asset 27.png" id="65_ef8wx"] +[ext_resource type="PackedScene" uid="uid://ddn64i6logtw0" path="res://Game/sidepanel.tscn" id="67_rec5e"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_3uxyt"] texture = ExtResource("1_fdpq6") @@ -474,7 +475,7 @@ tile_map_data = PackedByteArray("AAAAAAAAgAAAAAAAAAABAAAAgAAAAAAAAAACAAAAgAAAAAA tile_set = SubResource("TileSet_4e145") rendering_quadrant_size = 64 -[node name="Asset27" type="Sprite2D" parent="."] +[node name="Castle" type="Sprite2D" parent="."] position = Vector2(1152, 448) scale = Vector2(0.238927, 0.171569) texture = ExtResource("65_ef8wx") @@ -486,4 +487,10 @@ curve = SubResource("Curve2D_6abe5") wait_time = 1.5 autostart = true +[node name="SidePanel" parent="." instance=ExtResource("67_rec5e")] +offset_left = -2.0 +offset_top = 583.0 +offset_right = 1152.0 +offset_bottom = 647.0 + [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/Game/Mobs/enemy.gd b/Game/Mobs/enemy.gd index 56ae429..f24ca8f 100644 --- a/Game/Mobs/enemy.gd +++ b/Game/Mobs/enemy.gd @@ -3,6 +3,7 @@ extends Node2D var speed = 0 var health = 0 var shield = 0 +var damage = 0 var current_health = 0 var current_shield = 0 @@ -11,6 +12,7 @@ var last_position: Vector2 = Vector2.ZERO # To store the previous position func _ready() -> void: last_position = get_parent().position + set_character_data() adjust_health_bar() @@ -38,6 +40,7 @@ func move_character(delta: float) -> void: #if reached the end of the path remove both the path, and the character if path_follow.get_progress_ratio() >= 0.999: + get_parent().get_parent().get_parent().decrease_life(damage) get_parent().queue_free() @@ -47,14 +50,17 @@ func set_character_data(): speed = 120 health = 100 shield = 100 + damage = 2 "Ork": speed = 80 health = 150 shield = 100 + damage = 5 "Cobold": speed = 200 health = 50 shield = 0 + damage = 1 get_node("CharacterBody2D/AnimatedSprite2D").speed_scale = float(speed) / 100 #adjust animation speed based on the character speed current_health = health diff --git a/Game/sidepanel.gd b/Game/sidepanel.gd new file mode 100644 index 0000000..7dee425 --- /dev/null +++ b/Game/sidepanel.gd @@ -0,0 +1,4 @@ +extends Panel + + + diff --git a/Game/sidepanel.gd.uid b/Game/sidepanel.gd.uid new file mode 100644 index 0000000..0d929cf --- /dev/null +++ b/Game/sidepanel.gd.uid @@ -0,0 +1 @@ +uid://c6sh5em844tx2 diff --git a/Game/sidepanel.tscn b/Game/sidepanel.tscn new file mode 100644 index 0000000..c65cb1e --- /dev/null +++ b/Game/sidepanel.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=2 format=3 uid="uid://ddn64i6logtw0"] + +[ext_resource type="Script" uid="uid://c6sh5em844tx2" path="res://Game/sidepanel.gd" id="1_klyhg"] + +[node name="SidePanel" type="Panel"] +custom_minimum_size = Vector2(0, 60) +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 +size_flags_horizontal = 0 +size_flags_vertical = 8 +script = ExtResource("1_klyhg") + +[node name="HBoxContainer4" type="HBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer4"] +layout_mode = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="Label" type="Label" parent="HBoxContainer4/HBoxContainer"] +layout_mode = 2 +text = "Coins: " + +[node name="HBoxContainer2" type="HBoxContainer" parent="HBoxContainer4"] +layout_mode = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="Button2" type="Button" parent="HBoxContainer4/HBoxContainer2"] +custom_minimum_size = Vector2(120, 0) +layout_mode = 2 +text = "Archer" + +[node name="Button3" type="Button" parent="HBoxContainer4/HBoxContainer2"] +custom_minimum_size = Vector2(120, 0) +layout_mode = 2 +text = "Wizard" + +[node name="Button4" type="Button" parent="HBoxContainer4/HBoxContainer2"] +custom_minimum_size = Vector2(120, 0) +layout_mode = 2 +text = "Mortar" + +[node name="HBoxContainer3" type="HBoxContainer" parent="HBoxContainer4"] +layout_mode = 2 +theme_override_constants/separation = 120 +alignment = 1 + +[node name="Label" type="Label" parent="HBoxContainer4/HBoxContainer3"] +layout_mode = 2 +text = "Lives: "