From 77eccef08cfd618efb28aa91b291b8505f1f0621 Mon Sep 17 00:00:00 2001 From: AnicaCihla Date: Mon, 26 May 2025 20:57:02 -0400 Subject: [PATCH] Week 6: player health, damage animation, enemy damage --- .../player/death/Player Death 64x64.png | Bin 0 -> 1584 bytes .../death/Player Death 64x64.png.import | 34 +++++ .../player/hurt/Player Hurt 48x48.png | Bin 0 -> 1448 bytes .../player/hurt/Player Hurt 48x48.png.import | 34 +++++ bullet.gd | 5 +- scenes/bullet.tscn | 3 +- scenes/game.tscn | 11 +- scenes/player.tscn | 116 +++++++++++++++++- scenes/slime.tscn | 38 +++++- scenes/ui.tscn | 46 +++++++ scripts/gamecontroller.gd | 62 +++++++--- scripts/player.gd | 18 ++- scripts/res/characterstats.gd | 8 ++ scripts/res/characterstats.gd.uid | 1 + scripts/res/playerstats.tres | 12 ++ scripts/res/slimestats.tres | 12 ++ scripts/scene_manager.gd | 7 ++ scripts/slime.gd | 25 +++- scripts/ui.gd | 17 +++ scripts/ui.gd.uid | 1 + 20 files changed, 416 insertions(+), 34 deletions(-) create mode 100644 assets/graphics/player/death/Player Death 64x64.png create mode 100644 assets/graphics/player/death/Player Death 64x64.png.import create mode 100644 assets/graphics/player/hurt/Player Hurt 48x48.png create mode 100644 assets/graphics/player/hurt/Player Hurt 48x48.png.import create mode 100644 scenes/ui.tscn create mode 100644 scripts/res/characterstats.gd create mode 100644 scripts/res/characterstats.gd.uid create mode 100644 scripts/res/playerstats.tres create mode 100644 scripts/res/slimestats.tres create mode 100644 scripts/ui.gd create mode 100644 scripts/ui.gd.uid diff --git a/assets/graphics/player/death/Player Death 64x64.png b/assets/graphics/player/death/Player Death 64x64.png new file mode 100644 index 0000000000000000000000000000000000000000..2e6a1ae0514b237d754893f563c87ba5f95dc109 GIT binary patch literal 1584 zcmV-02G9A4P)6ha{(mSDs~=&eemLQhsu5De5)C{a8JIe3wvJ+;t7 zrHbvvg27;Ok>XiYQVE4ttTBeFjoM_}te8c|!|qIHrt@dByV-f4?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U|6CN8%LWZ>4FSbiKUbdha!@ z?QwYZo8uN4{ZRfGN}2+h 0: bullet_image.flip_h = false - func _on_body_entered(body: Node2D) -> void: if not body is Player: print("bullet hit!") bulletHit.emit(body, self) + +func _on_area_entered(area: Area2D) -> void: + print("bullet hit!") + bulletHit.emit(area, self) diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn index 5ed74c9..f90935c 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=3 uid="uid://cy02yf4v8q5v6"] [ext_resource type="Script" uid="uid://wmy17yj81te8" path="res://bullet.gd" id="1_mkf8s"] -[ext_resource type="Texture2D" uid="uid://dwn36dqvridjp" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_y25gk"] +[ext_resource type="Texture2D" uid="uid://c1a615uhr2yfd" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_y25gk"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_y25gk"] size = Vector2(34, 8) @@ -19,4 +19,5 @@ position = Vector2(-8, 5) scale = Vector2(-0.25, 0.225) texture = ExtResource("2_y25gk") +[connection signal="area_entered" from="." to="." method="_on_area_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index a7ab20b..66f4a9d 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=18 format=4 uid="uid://bvs868ncmeoj5"] +[gd_scene load_steps=19 format=4 uid="uid://bvs868ncmeoj5"] +[ext_resource type="PackedScene" uid="uid://b41kay5ja3tlt" path="res://scenes/ui.tscn" id="1_kvuet"] [ext_resource type="Script" uid="uid://bijvpac45v6s1" path="res://scripts/scene_manager.gd" id="2_lbhrr"] [ext_resource type="PackedScene" uid="uid://c5a5u2c250g6" path="res://scenes/player.tscn" id="2_lnu2h"] [ext_resource type="Texture2D" uid="uid://bsw50wv55u4rt" path="res://assets/graphics/terrain/vegetation/mushroom_32x64.png" id="3_0tnpc"] @@ -386,6 +387,10 @@ sources/2 = SubResource("TileSetAtlasSource_dinhu") [node name="Game" type="Node2D"] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Control" parent="CanvasLayer" instance=ExtResource("1_kvuet")] + [node name="SceneManager" type="Node" parent="."] unique_name_in_owner = true script = ExtResource("2_lbhrr") @@ -474,10 +479,10 @@ position = Vector2(391, 92) [node name="Enemies" type="Node2D" parent="."] [node name="e1" parent="Enemies" instance=ExtResource("12_dinhu")] -position = Vector2(376, 525) +position = Vector2(356, 519) [node name="e2" parent="Enemies" instance=ExtResource("12_dinhu")] -position = Vector2(536, 110) +position = Vector2(478, 78) [connection signal="triggerFired" from="Triggers/Trigger" to="." method="_on_trigger_trigger_fired"] [connection signal="triggerFired" from="Triggers/Trigger2" to="." method="_on_trigger_trigger_fired"] diff --git a/scenes/player.tscn b/scenes/player.tscn index 1a53521..c2722fd 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,18 +1,76 @@ -[gd_scene load_steps=35 format=3 uid="uid://c5a5u2c250g6"] +[gd_scene load_steps=51 format=3 uid="uid://c5a5u2c250g6"] [ext_resource type="Script" uid="uid://c3vqmu6nc4gb0" path="res://scripts/player.gd" id="1_3vyb7"] [ext_resource type="Texture2D" uid="uid://de6p78arhau1m" path="res://assets/graphics/player/jump/player jump 48x48.png" id="2_dqkch"] +[ext_resource type="Texture2D" uid="uid://bf0ysio1qxdu" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_fjrip"] [ext_resource type="Texture2D" uid="uid://dv34fblpejy5x" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"] [ext_resource type="Texture2D" uid="uid://bs8k1b6xj3gxb" path="res://assets/graphics/player/run/player run 48x48.png" id="3_qhqgy"] [ext_resource type="Texture2D" uid="uid://bkgyjj5bbx7r0" path="res://assets/graphics/player/melee/Player Punch 64x64.png" id="4_qlg0r"] +[ext_resource type="Texture2D" uid="uid://cwid3ull01xog" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="4_smehm"] [sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"] radius = 21.2132 +[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"] +atlas = ExtResource("2_fjrip") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"] +atlas = ExtResource("2_fjrip") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"] +atlas = ExtResource("2_fjrip") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"] +atlas = ExtResource("2_fjrip") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"] +atlas = ExtResource("2_fjrip") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"] +atlas = ExtResource("2_fjrip") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"] +atlas = ExtResource("2_fjrip") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"] +atlas = ExtResource("2_fjrip") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"] +atlas = ExtResource("2_fjrip") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"] +atlas = ExtResource("2_fjrip") +region = Rect2(432, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"] atlas = ExtResource("2_dqkch") region = Rect2(96, 0, 48, 48) +[sub_resource type="AtlasTexture" id="AtlasTexture_t4otl"] +atlas = ExtResource("4_smehm") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_j2b1d"] +atlas = ExtResource("4_smehm") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_cs1tg"] +atlas = ExtResource("4_smehm") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"] +atlas = ExtResource("4_smehm") +region = Rect2(144, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"] atlas = ExtResource("2_g2els") region = Rect2(0, 0, 48, 48) @@ -113,6 +171,41 @@ region = Rect2(336, 0, 48, 48) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_pf23h") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dt7fs") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wqfne") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wnwbv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gl8cc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_487ah") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_md1ol") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_bj30b") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_jc3p3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hax0n") +}], +"loop": false, +"name": &"death", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_i4ail") }], "loop": false, @@ -121,6 +214,23 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_t4otl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_j2b1d") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_cs1tg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2dvfe") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_qhqgy") }, { "duration": 1.0, @@ -251,8 +361,8 @@ one_shot = true texture_filter = 1 position = Vector2(1, -1) sprite_frames = SubResource("SpriteFrames_jej6c") -animation = &"melee" -autoplay = "idle" +animation = &"death" +autoplay = "death" [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2(0, -20) diff --git a/scenes/slime.tscn b/scenes/slime.tscn index 348c64f..2491914 100644 --- a/scenes/slime.tscn +++ b/scenes/slime.tscn @@ -1,8 +1,24 @@ -[gd_scene load_steps=9 format=3 uid="uid://b2lq6rp0aht6d"] +[gd_scene load_steps=13 format=3 uid="uid://b2lq6rp0aht6d"] [ext_resource type="Texture2D" uid="uid://cn1jvyyvb3g3c" path="res://assets/graphics/enemies/slime_green.png" id="1_371uh"] [ext_resource type="Script" uid="uid://bsmcx4pr1imsq" path="res://scripts/slime.gd" id="1_p2gj0"] +[sub_resource type="AtlasTexture" id="AtlasTexture_fd6lc"] +atlas = ExtResource("1_371uh") +region = Rect2(0, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gstla"] +atlas = ExtResource("1_371uh") +region = Rect2(24, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"] +atlas = ExtResource("1_371uh") +region = Rect2(48, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0l8pv"] +atlas = ExtResource("1_371uh") +region = Rect2(72, 48, 24, 24) + [sub_resource type="AtlasTexture" id="AtlasTexture_p2gj0"] atlas = ExtResource("1_371uh") region = Rect2(0, 24, 24, 24) @@ -23,6 +39,23 @@ region = Rect2(72, 24, 24, 24) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_fd6lc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gstla") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_v5wyi") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_0l8pv") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_p2gj0") }, { "duration": 1.0, @@ -48,9 +81,8 @@ script = ExtResource("1_p2gj0") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] texture_filter = 1 sprite_frames = SubResource("SpriteFrames_fd6lc") -animation = &"run" +animation = &"hurt" autoplay = "run" -frame_progress = 0.256611 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 4) diff --git a/scenes/ui.tscn b/scenes/ui.tscn new file mode 100644 index 0000000..5a3be4d --- /dev/null +++ b/scenes/ui.tscn @@ -0,0 +1,46 @@ +[gd_scene load_steps=2 format=3 uid="uid://b41kay5ja3tlt"] + +[ext_resource type="Script" uid="uid://cv1at33pu2ae2" path="res://scripts/ui.gd" id="1_nt7q6"] + +[node name="Control" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_nt7q6") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer"] +layout_mode = 2 +text = "Health" + +[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Timer" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2"] +layout_mode = 2 +horizontal_alignment = 1 + +[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Coins" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3"] +layout_mode = 2 +text = "Coins" +horizontal_alignment = 2 diff --git a/scripts/gamecontroller.gd b/scripts/gamecontroller.gd index 8772f68..5681da6 100644 --- a/scripts/gamecontroller.gd +++ b/scripts/gamecontroller.gd @@ -1,4 +1,4 @@ -class_name GameController extends Node2D +extends Node2D var totalCrates = 3 var timeLimit = 10 @@ -12,13 +12,25 @@ var currentLevel = 0 var playerHealth = 100 +var player:CharacterStats +var slime:CharacterStats + +var enemiesDict = {} + signal levelCompleteSignal(level) signal destroySignal(body) -signal playerDamage +signal playerDamage(health, maxHealth) signal playerDeath +signal countDown(timeRemaining) +signal coinUpdate(totalCoins) +signal enemyHurt(enemy) # Called when the node enters the scene tree for the first time. -func _ready() -> void: +func _ready() -> void: + #load custom resources for player and slime + player = load("res://scripts/res/playerstats.tres") + slime = load("res://scripts/res/slimestats.tres") + add_child(timer) timer.wait_time = 1 timer.one_shot = false @@ -28,6 +40,7 @@ func _ready() -> void: func secondCounter(): print("tick "+str(timeLimit)) timeLimit -= 1 + countDown.emit(timeLimit) if timeLimit <= 0: print("YOU LOSE...") levelCompleteSignal.emit(levels[currentLevel]) @@ -50,32 +63,51 @@ func _on_trigger_fired(effect: Variant, body: Variant) -> void: func _on_coin_collected(body, coin): coinsCollectedTotal += 1 + coinUpdate.emit(coinsCollectedTotal) destroySignal.emit(coin) print("GC knows coin collected") func _on_player_damage(body, enemy): if enemy is Slime: print("slime attack!") - playerHealth -= 10 - if playerHealth > 0: - print("Player damaged") - playerDamage.emit() - else: - print("Player dead") - playerDeath.emit() + #playerHealth -= slime.meleeDamage + playerHealth -= enemiesDict[enemy]["damage"] + + if playerHealth > 0: + print("Player damaged") + playerDamage.emit(playerHealth, player.max_health) + else: + print("Player dead") + playerDeath.emit() + +func addEnemyToLevel(enemy): + var randHealth = randi() % 20 + var randDamage = randi() % 10 + var enemyStat = { + "health":slime.health + randHealth, + "damage":slime.meleeDamage + randDamage + } + enemiesDict[enemy] = enemyStat func numberOfCrates(value:int)->void: totalCrates = value func bulletDamage(body, bullet): - if body is Crate: - print("Crates remaining: " + str(totalCrates)) - destroySignal.emit(body) + #if body is Crate: + # print("Crates remaining: " + str(totalCrates)) + # destroySignal.emit(body) + if body is Slime: + enemiesDict[body]["health"] -= player.rangeDamage + print("Enemy Health "+str(enemiesDict[body]["health"])) + enemyHurt.emit(body) + if enemiesDict[body]["health"] <= 0: + destroySignal.emit(body) + enemiesDict.erase(body) func reset(): timeLimit = timers[currentLevel] - playerHealth = 100 + playerHealth = player.starting_health func death(): print("player death animation complete") - + levelCompleteSignal.emit(levels[currentLevel]) diff --git a/scripts/player.gd b/scripts/player.gd index 544f2bf..3c13b39 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -19,7 +19,7 @@ const JUMP_VELOCITY = -400.0 @export var acceleration = 50 @export var hard_gravity = 5 -enum State {IDLE, RUN, JUMP, FALLING, MELEE} +enum State {IDLE, RUN, JUMP, FALLING, MELEE, HURT, DEATH} var current_state = State.IDLE enum FaceDirection {LEFT, RIGHT} @@ -32,11 +32,13 @@ var upJump: bool = false signal deathComplete -func _player_damage(): +func _player_damage(_currentHealth, _maxHealth): print("Player taking damage!") + current_state = State.HURT func _player_death(): print("Player dead!!!") + current_state = State.DEATH func _physics_process(delta: float) -> void: # Add the gravity. @@ -46,7 +48,8 @@ func _physics_process(delta: float) -> void: velocity += get_gravity() * hard_gravity * delta # Handle input - handle_input() + if current_state != State.HURT and current_state != State.DEATH: + handle_input() update_movement() # Handle states and animation @@ -140,6 +143,10 @@ func update_animation()->void: player_graphic.play("fall") State.MELEE: player_graphic.play("melee") + State.HURT: + player_graphic.play("hurt") + State.DEATH: + player_graphic.play("death") func handle_collisions() -> void: for i in get_slide_collision_count(): @@ -173,3 +180,8 @@ func _on_animation_finished() -> void: upJump = false State.MELEE: current_state = State.IDLE + State.HURT: + current_state = State.IDLE + State.DEATH: + print("Death animation finished") + deathComplete.emit() diff --git a/scripts/res/characterstats.gd b/scripts/res/characterstats.gd new file mode 100644 index 0000000..ec435f1 --- /dev/null +++ b/scripts/res/characterstats.gd @@ -0,0 +1,8 @@ +class_name CharacterStats extends Resource + +@export var max_health:int = 100 +@export var starting_health:int = 100 +@export var health:int = 100 + +@export var meleeDamage:int = 10 +@export var rangeDamage:int = 0 diff --git a/scripts/res/characterstats.gd.uid b/scripts/res/characterstats.gd.uid new file mode 100644 index 0000000..83e9421 --- /dev/null +++ b/scripts/res/characterstats.gd.uid @@ -0,0 +1 @@ +uid://cb4odxbsudi2y diff --git a/scripts/res/playerstats.tres b/scripts/res/playerstats.tres new file mode 100644 index 0000000..b36fbee --- /dev/null +++ b/scripts/res/playerstats.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://d2w3olbk7mqqq"] + +[ext_resource type="Script" uid="uid://cb4odxbsudi2y" path="res://scripts/res/characterstats.gd" id="1_4nldt"] + +[resource] +script = ExtResource("1_4nldt") +max_health = 100 +starting_health = 100 +health = 100 +meleeDamage = 10 +rangeDamage = 30 +metadata/_custom_type_script = "uid://cb4odxbsudi2y" diff --git a/scripts/res/slimestats.tres b/scripts/res/slimestats.tres new file mode 100644 index 0000000..d5257a6 --- /dev/null +++ b/scripts/res/slimestats.tres @@ -0,0 +1,12 @@ +[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://b4ilwsa0a21fi"] + +[ext_resource type="Script" uid="uid://cb4odxbsudi2y" path="res://scripts/res/characterstats.gd" id="1_fftob"] + +[resource] +script = ExtResource("1_fftob") +max_health = 50 +starting_health = 50 +health = 50 +meleeDamage = 40 +rangeDamage = 0 +metadata/_custom_type_script = "uid://cb4odxbsudi2y" diff --git a/scripts/scene_manager.gd b/scripts/scene_manager.gd index d9db10f..4056117 100644 --- a/scripts/scene_manager.gd +++ b/scripts/scene_manager.gd @@ -5,6 +5,7 @@ extends Node @onready var coins: Node2D = $"../Coins" @onready var enemies: Node2D = $"../Enemies" @onready var player: Player = $"../CharacterBody2D" +@onready var control: Control = $"../CanvasLayer/Control" var bullet = preload("res://scenes/bullet.tscn") var bulletArray = [] @@ -29,9 +30,13 @@ func buildLevel() -> void: Gamecontroller.levelCompleteSignal.connect(loadLevel) Gamecontroller.destroySignal.connect(destroy) Gamecontroller.playerDamage.connect(player._player_damage) + Gamecontroller.playerDamage.connect(control.healthUpdate) + Gamecontroller.coinUpdate.connect(control.coinsUpdate) Gamecontroller.playerDeath.connect(player._player_death) # player connection player.deathComplete.connect(Gamecontroller.death) + # UI signals + Gamecontroller.countDown.connect(control.timerUpdate) # Connect trigger signals if triggers: @@ -48,6 +53,8 @@ func buildLevel() -> void: for obj in enemies.get_children(): if obj is Slime: obj.playerDamageSignal.connect(Gamecontroller._on_player_damage) + Gamecontroller.enemyHurt.connect(obj.damage) + Gamecontroller.addEnemyToLevel(obj) func countCrates()->int: # count crates diff --git a/scripts/slime.gd b/scripts/slime.gd index 3b72d35..766d105 100644 --- a/scripts/slime.gd +++ b/scripts/slime.gd @@ -11,14 +11,29 @@ var speed = 100 var direction = 1 func _process(delta: float) -> void: - if not right_down_cast.is_colliding() or right_side_cast.is_colliding(): + if not right_down_cast.is_colliding(): direction = -1 sprite.flip_h = true - if not left_down_cast.is_colliding() or left_side_cast.is_colliding(): + if right_side_cast.is_colliding(): + if not right_side_cast.get_collider() is Player: + direction = -1 + sprite.flip_h = true + + if not left_down_cast.is_colliding(): direction = 1 sprite.flip_h = false + if left_side_cast.is_colliding(): + if not left_side_cast.get_collider() is Player: + direction = 1 + sprite.flip_h = false + position.x += direction * speed * delta -func _on_body_entered(body: Node2D) -> void: - print("Slime Contact") - playerDamageSignal.emit(body, self) +func _on_body_entered(body: Node2D) -> void: + if body is Player: + print("Slime Contact") + playerDamageSignal.emit(body, self) + +func damage(body)->void: + if body == self: + sprite.play("hurt") diff --git a/scripts/ui.gd b/scripts/ui.gd new file mode 100644 index 0000000..3bc968c --- /dev/null +++ b/scripts/ui.gd @@ -0,0 +1,17 @@ +extends Control + +@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/Health +@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer2/Timer +@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer3/Coins + +func _ready() -> void: + pass + +func healthUpdate(currentHealth, maxHealth) -> void: + health.text = "Health: "+str(currentHealth)+"/"+str(maxHealth) + +func coinsUpdate(currentCoins) -> void: + coins.text = "Coins: "+str(currentCoins) + +func timerUpdate(currentTimer) -> void: + timer.text = "Timer: "+str(currentTimer) diff --git a/scripts/ui.gd.uid b/scripts/ui.gd.uid new file mode 100644 index 0000000..ef818b0 --- /dev/null +++ b/scripts/ui.gd.uid @@ -0,0 +1 @@ +uid://cv1at33pu2ae2