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 0000000..2e6a1ae Binary files /dev/null and b/assets/graphics/player/death/Player Death 64x64.png differ diff --git a/assets/graphics/player/death/Player Death 64x64.png.import b/assets/graphics/player/death/Player Death 64x64.png.import new file mode 100644 index 0000000..be52fec --- /dev/null +++ b/assets/graphics/player/death/Player Death 64x64.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://fjan00ormd84" +path="res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/death/Player Death 64x64.png" +dest_files=["res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.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/graphics/player/hurt/Player Hurt 48x48.png b/assets/graphics/player/hurt/Player Hurt 48x48.png new file mode 100644 index 0000000..57d8783 Binary files /dev/null and b/assets/graphics/player/hurt/Player Hurt 48x48.png differ diff --git a/assets/graphics/player/hurt/Player Hurt 48x48.png.import b/assets/graphics/player/hurt/Player Hurt 48x48.png.import new file mode 100644 index 0000000..e86a95b --- /dev/null +++ b/assets/graphics/player/hurt/Player Hurt 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://djicmvbecbmr8" +path="res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/hurt/Player Hurt 48x48.png" +dest_files=["res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.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/project.godot b/project.godot index cb9a8e2..9882af1 100644 --- a/project.godot +++ b/project.godot @@ -39,3 +39,13 @@ shoot={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) ] } +save={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +] +} +load={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"location":0,"echo":false,"script":null) +] +} diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn index e23caf1..b97c418 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -20,4 +20,5 @@ rotation = 3.14159 scale = Vector2(0.06, 0.06) 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 8b44610..ef0313d 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -482,5 +482,8 @@ position = Vector2(630, 375) [node name="enemies" type="Node2D" parent="."] -[node name="Slime" parent="enemies" instance=ExtResource("11_dinhu")] +[node name="Slime" parent="enemies" groups=["shootables"] instance=ExtResource("11_dinhu")] position = Vector2(467, 343) + +[node name="Slime2" parent="enemies" groups=["shootables"] instance=ExtResource("11_dinhu")] +position = Vector2(586, 280) diff --git a/scenes/player.tscn b/scenes/player.tscn index c3b0ba3..9826ecf 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,16 +1,74 @@ -[gd_scene load_steps=28 format=3 uid="uid://boqg1nyudmkh4"] +[gd_scene load_steps=44 format=3 uid="uid://boqg1nyudmkh4"] [ext_resource type="Script" uid="uid://b7rahgxxw1yuw" path="res://scripts/player.gd" id="1_3vyb7"] [ext_resource type="Texture2D" uid="uid://c3uwl6agc6dhb" path="res://assets/graphics/player/jump_fall/player jump 48x48.png" id="2_dqkch"] [ext_resource type="Texture2D" uid="uid://be0vnx023iw65" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"] +[ext_resource type="Texture2D" uid="uid://fjan00ormd84" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_tuyoq"] [ext_resource type="Texture2D" uid="uid://dmmtik7twhga4" path="res://assets/graphics/player/run/player run 48x48.png" id="3_qhqgy"] +[ext_resource type="Texture2D" uid="uid://djicmvbecbmr8" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_qlg0r"] [sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"] +[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"] +atlas = ExtResource("2_tuyoq") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"] +atlas = ExtResource("2_tuyoq") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"] +atlas = ExtResource("2_tuyoq") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"] +atlas = ExtResource("2_tuyoq") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"] +atlas = ExtResource("2_tuyoq") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"] +atlas = ExtResource("2_tuyoq") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"] +atlas = ExtResource("2_tuyoq") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"] +atlas = ExtResource("2_tuyoq") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"] +atlas = ExtResource("2_tuyoq") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"] +atlas = ExtResource("2_tuyoq") +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_l71n6"] +atlas = ExtResource("3_qlg0r") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ke2ow"] +atlas = ExtResource("3_qlg0r") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ujl30"] +atlas = ExtResource("3_qlg0r") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_31cv2"] +atlas = ExtResource("3_qlg0r") +region = Rect2(144, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"] atlas = ExtResource("2_g2els") region = Rect2(0, 0, 48, 48) @@ -95,6 +153,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, @@ -103,6 +196,23 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_l71n6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ke2ow") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ujl30") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_31cv2") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_qhqgy") }, { "duration": 1.0, @@ -205,7 +315,7 @@ one_shot = true texture_filter = 1 position = Vector2(0, -7) sprite_frames = SubResource("SpriteFrames_jej6c") -animation = &"fall" +animation = &"death" autoplay = "idle" [node name="Camera2D" type="Camera2D" parent="."] diff --git a/scenes/slime.tscn b/scenes/slime.tscn index 3c09a04..18d79c6 100644 --- a/scenes/slime.tscn +++ b/scenes/slime.tscn @@ -1,10 +1,22 @@ -[gd_scene load_steps=9 format=3 uid="uid://dpltbyp8ku2mi"] +[gd_scene load_steps=12 format=3 uid="uid://dpltbyp8ku2mi"] [ext_resource type="Script" uid="uid://cuaxw7eh73a1i" path="res://scripts/slime.gd" id="1_p2gj0"] [ext_resource type="Texture2D" uid="uid://dwwlva8pi3da2" path="res://assets/graphics/enemies/slime_purple (1).png" id="2_n6pvg"] [sub_resource type="CircleShape2D" id="CircleShape2D_pjw23"] +[sub_resource type="AtlasTexture" id="AtlasTexture_p2gj0"] +atlas = ExtResource("2_n6pvg") +region = Rect2(24, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_n6pvg"] +atlas = ExtResource("2_n6pvg") +region = Rect2(48, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pjw23"] +atlas = ExtResource("2_n6pvg") +region = Rect2(72, 48, 24, 24) + [sub_resource type="AtlasTexture" id="AtlasTexture_2npkn"] atlas = ExtResource("2_n6pvg") region = Rect2(0, 24, 24, 24) @@ -25,6 +37,20 @@ region = Rect2(72, 24, 24, 24) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_p2gj0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_n6pvg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_pjw23") +}], +"loop": false, +"name": &"hurt", +"speed": 10.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_2npkn") }, { "duration": 1.0, @@ -37,7 +63,7 @@ animations = [{ "texture": SubResource("AtlasTexture_v5wyi") }], "loop": true, -"name": &"default", +"name": &"idle", "speed": 12.0 }] @@ -53,8 +79,8 @@ debug_color = Color(0.932998, 0.222862, 0.34393, 0.42) texture_filter = 1 position = Vector2(0, -3) sprite_frames = SubResource("SpriteFrames_0l8pv") -autoplay = "default" -frame_progress = 0.665587 +animation = &"idle" +autoplay = "idle" [node name="RightCast" type="RayCast2D" parent="."] target_position = Vector2(13, 0) @@ -71,3 +97,4 @@ position = Vector2(8, 0) target_position = Vector2(0, 10) [connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="animation_finished" from="SlimeGraphic" to="." method="_on_slime_graphic_animation_finished"] diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 0e36f23..979f159 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -21,3 +21,10 @@ func _on_body_entered(body: Node2D) -> void: if body.is_in_group("shootables"): print("This is shootable") bulletDamageSignal.emit(body, self) + + +func _on_area_entered(area: Area2D) -> void: + print("Bullet hitting") + if area.is_in_group("shootables"): + print("This is shootable") + bulletDamageSignal.emit(area, self) diff --git a/scripts/gamecontroller.gd b/scripts/gamecontroller.gd index a764299..b2807c0 100644 --- a/scripts/gamecontroller.gd +++ b/scripts/gamecontroller.gd @@ -1,6 +1,7 @@ extends Node2D -signal playerDamage +signal playerDamageSignal(health, maxhealth) +signal playerDeathSignal signal destroySignal(body) signal levelChangeSignal(level) @@ -16,6 +17,11 @@ var enemy:CharacterStats var player:CharacterStats var playerCurrentHealth:int +var enemiesDict = {} + +var saveObject = {} +var loadIntent = false + # Called when the node enters the scene tree for the first time. func _ready() -> void: enemy = load("res://scripts/rscs/slimeStats.tres") @@ -29,7 +35,20 @@ func _ready() -> void: timer.start() func reset(): + enemiesDict.clear() timeAvailable = timers[currentLevel] + playerCurrentHealth = player.max_health + + if loadIntent: + var saved_game:SavedGame = load("res://scripts/rscs/gameSaveStats.tres") + saveObject = saved_game.gameData + playerCurrentHealth = saveObject["PlayerHealth"] + timeAvailable = saveObject["TimeAvailable"] + loadIntent = false + return saveObject + + return{} + func secondCounter(): timeAvailable -=1 @@ -38,9 +57,12 @@ func secondCounter(): print("You lose") levelChangeSignal.emit(levels[currentLevel]) -# Called every frame. 'delta' is the elapsed time since the previous frame. + func _process(delta: float) -> void: - pass + if Input.is_action_just_pressed("save"): + saveGame() + if Input.is_action_just_pressed("load"): + loadGame() func _on_trigger(effect: Variant, body: Variant) -> void: @@ -49,14 +71,25 @@ func _on_trigger(effect: Variant, body: Variant) -> void: "player_hurt": if body is Player: print("hurt the player") - playerDamage.emit() + #playerDamage.emit() #if not body is Player: # body.queue_free() func bulletDamage(body, bullet): print("GC know about bullet hit") - body.queue_free() - + if body is Slime: + #give damage to this individual enemy + enemiesDict[body]["health"] -= player.rangeDamage + if enemiesDict[body]["health"] <=0: + print("enemy is dead") + removeEnemyFromLevel(body) + destroySignal.emit(body) + else: + print("enemy is damaged") + body.handle_damage() +func removeEnemyFromLevel(body)->void: + enemiesDict.erase(body) + func coinCollected(body, coin): print("GC knows coin collected") destroySignal.emit(coin) @@ -71,9 +104,50 @@ func totalCoinCount(count): func playerAttacked(body, slime): print("GC knows slime attack") - print("Damge : "+str(enemy.meleeDamage) ) + print("Damge : "+str(enemiesDict[slime]["damage"]) ) print("Player health : "+str(playerCurrentHealth)) - playerCurrentHealth -= enemy.meleeDamage + playerCurrentHealth -= enemiesDict[slime]["damage"] if playerCurrentHealth <=0: print("YOU DEAD") + playerDeathSignal.emit() + else: + print("taking damage") + playerDamageSignal.emit(playerCurrentHealth, player.max_health) +func deathComplete()->void: + levelChangeSignal.emit(levels[currentLevel]) + +func addEnemyToLevel(slime)->void: + var randHealth:int = randi() % 20 + var randDamage:int = randi() % 10 + var enemyStat = { + "health": enemy.health + randHealth, + "damage": enemy.meleeDamage + randDamage + } + enemiesDict[slime] = enemyStat +func saveGame()->void: + saveObject["enemies"]={} + var index = 0 + + #create an object with all critical game data + print("Game Level "+str(currentLevel) ) + print("Time Remaining "+str(timeAvailable)) + print("Player Health "+str(playerCurrentHealth)) + # bad guy stuff.... + for key in enemiesDict: + var tempObj = {} + tempObj["health"]=enemiesDict[key]["health"] + tempObj["damage"]=enemiesDict[key]["damage"] + tempObj["global_position"] = key.global_position + saveObject["enemies"]["slime"+str(index)]=tempObj + index +=1 + saveObject["GameLevel"] = currentLevel + saveObject["TimeAvailable"] = timeAvailable + saveObject["PlayerHealth"] = playerCurrentHealth + var saved_game:SavedGame = SavedGame.new() + saved_game.gameData = saveObject + ResourceSaver.save(saved_game, "res://scripts/rscs/gameSaveStats.tres") + +func loadGame()->void: + loadIntent = true + levelChangeSignal.emit(levels[saveObject["GameLevel"]]) diff --git a/scripts/player.gd b/scripts/player.gd index bf1aeef..8a03da8 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -15,21 +15,33 @@ var upJump:bool = false var direction enum FaceDirection{LEFT, RIGHT} var facing:FaceDirection = FaceDirection.RIGHT -enum State{IDLE, RUN,JUMP,FALLING} +enum State{IDLE, RUN,JUMP,FALLING, HURT, DEATH} var current_state:State = State.IDLE var pushTarget var pushEnabled := false +signal playerDeathCompleteSignal + func _physics_process(delta: float) -> void: # Add the gravity. - handle_input() + if current_state != State.HURT and current_state != State.DEATH: + handle_input() handle_movement(delta) handle_states() handle_animation() move_and_slide() handle_collisions() - + +func handle_damage(health, maxhealth)->void: + print("player takes damage") + current_state = State.HURT + +func handle_death()->void: + print("player is dead") + current_state = State.DEATH + + func handle_states() -> void: match current_state: State.IDLE when velocity.x !=0: @@ -60,6 +72,10 @@ func handle_animation() -> void: State.JUMP: if upJump: player_graphic.play("jump") + State.HURT: + player_graphic.play("hurt") + State.DEATH: + player_graphic.play("death") func handle_movement(delta:float) -> void: if direction == 0: @@ -131,3 +147,7 @@ func _on_animation_finished() -> void: match current_state: State.JUMP: upJump = false + State.HURT: + current_state = State.IDLE + State.DEATH: + playerDeathCompleteSignal.emit() diff --git a/scripts/rscs/gameSaveStats.tres b/scripts/rscs/gameSaveStats.tres new file mode 100644 index 0000000..6fdd3fc --- /dev/null +++ b/scripts/rscs/gameSaveStats.tres @@ -0,0 +1,23 @@ +[gd_resource type="Resource" script_class="SavedGame" load_steps=2 format=3 uid="uid://cib08qg83a6o6"] + +[ext_resource type="Script" uid="uid://c3kd5uh5y8ml1" path="res://scripts/rscs/savedgame.gd" id="1_v2d26"] + +[resource] +script = ExtResource("1_v2d26") +gameData = { +"GameLevel": 0, +"PlayerHealth": 100, +"TimeAvailable": 7, +"enemies": { +"slime0": { +"damage": 33, +"global_position": Vector2(489.403, 343), +"health": 66 +}, +"slime1": { +"damage": 25, +"global_position": Vector2(626.901, 280), +"health": 61 +} +} +} diff --git a/scripts/rscs/playerStats.tres b/scripts/rscs/playerStats.tres index 239a5df..3615832 100644 --- a/scripts/rscs/playerStats.tres +++ b/scripts/rscs/playerStats.tres @@ -8,5 +8,5 @@ health = 100 max_health = 100 starting_health = 100 meleeDamage = 10 -rangeDamage = 0 +rangeDamage = 30 metadata/_custom_type_script = "uid://r408skwtvisy" diff --git a/scripts/rscs/savedgame.gd b/scripts/rscs/savedgame.gd new file mode 100644 index 0000000..e251422 --- /dev/null +++ b/scripts/rscs/savedgame.gd @@ -0,0 +1,3 @@ +class_name SavedGame extends Resource + +@export var gameData:Dictionary diff --git a/scripts/rscs/savedgame.gd.uid b/scripts/rscs/savedgame.gd.uid new file mode 100644 index 0000000..b1906b0 --- /dev/null +++ b/scripts/rscs/savedgame.gd.uid @@ -0,0 +1 @@ +uid://c3kd5uh5y8ml1 diff --git a/scripts/rscs/slimeStats.tres b/scripts/rscs/slimeStats.tres index beda283..3ccc39e 100644 --- a/scripts/rscs/slimeStats.tres +++ b/scripts/rscs/slimeStats.tres @@ -4,9 +4,9 @@ [resource] script = ExtResource("1_ppipo") -health = 100 -max_health = 100 -starting_health = 100 +health = 50 +max_health = 50 +starting_health = 50 meleeDamage = 25 rangeDamage = 0 metadata/_custom_type_script = "uid://r408skwtvisy" diff --git a/scripts/scene_manager.gd b/scripts/scene_manager.gd index 50cd7f8..c4e81f4 100644 --- a/scripts/scene_manager.gd +++ b/scripts/scene_manager.gd @@ -2,15 +2,21 @@ class_name SceneManager extends Node2D var bulletArray =[] var totalAllowedBullets = 7 var bullet = preload("res://scenes/bullet.tscn") +var slime=preload("res://scenes/slime.tscn") + @onready var triggers: Node2D = $"../triggers" @onready var coins: Node2D = $"../coins" @onready var enemies: Node2D = $"../enemies" +@onready var player: Player = $"../Player" # Called when the node enters the scene tree for the first time. func _ready() -> void: - Gamecontroller.reset() + var loadObject = Gamecontroller.reset() + print("LOAD OBJECT:::::") + print(loadObject) + loadSceneInfo(loadObject) if triggers: for obj in triggers.get_children(): @@ -24,12 +30,18 @@ func _ready() -> void: Gamecontroller.destroySignal.connect(destroy) Gamecontroller.levelChangeSignal.connect(changeScene) + Gamecontroller.playerDamageSignal.connect(player.handle_damage) + Gamecontroller.playerDeathSignal.connect(player.handle_death) + + player.playerDeathCompleteSignal.connect(Gamecontroller.deathComplete) + func updateEnemies(): for obj in enemies.get_children(): if obj is Slime: if not obj.playerDamageSignal.is_connected(Gamecontroller.playerAttacked): obj.playerDamageSignal.connect(Gamecontroller.playerAttacked) + Gamecontroller.addEnemyToLevel(obj) func updateCoins(): @@ -72,3 +84,22 @@ func destroy(body): body.queue_free() func changeScene(level): get_tree().call_deferred("change_scene_to_file", level) +func loadSceneInfo(loadObject)->void: + print("make the scene") + if loadObject.size()<1: + print("bailing out") + return + #remove current bad guys + if enemies: + for obj in enemies.get_children(): + if obj is Slime: + obj.queue_free() + + #build and place save game badguys + var enemiesList = loadObject["enemies"] + for key in enemiesList: + print(enemiesList[key]) + # create a slime + var badguy = slime.instantiate() + enemies.add_child(badguy) + badguy.global_position = enemiesList[key]["global_position"] diff --git a/scripts/slime.gd b/scripts/slime.gd index 6a8c112..620b465 100644 --- a/scripts/slime.gd +++ b/scripts/slime.gd @@ -10,11 +10,23 @@ var direction = 1 signal playerDamageSignal(body, slime) +enum State{IDLE, HURT, DEATH} +var currentState = State.IDLE + + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. - - +func updateAnimation()->void: + match currentState: + State.IDLE: + slime_graphic.play("idle") + State.HURT: + slime_graphic.play("hurt") + +func handle_damage()->void: + currentState = State.HURT + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: if not right_down_cast.is_colliding(): @@ -26,9 +38,15 @@ func _process(delta: float) -> void: slime_graphic.flip_h = false position.x += direction * speed * delta - + updateAnimation() func _on_body_entered(body: Node2D) -> void: if body is Player: print("Slime attack!") playerDamageSignal.emit(body, self) + + +func _on_slime_graphic_animation_finished() -> void: + match currentState: + State.HURT: + currentState = State.IDLE