diff --git a/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png b/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png new file mode 100644 index 0000000..57d8783 Binary files /dev/null and b/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png differ diff --git a/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png.import b/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png.import new file mode 100644 index 0000000..60c8dfd --- /dev/null +++ b/augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b2brlauvni08o" +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/augustgamecourse/scenes/player.tscn b/augustgamecourse/scenes/player.tscn index 8b8266d..c1c8535 100644 --- a/augustgamecourse/scenes/player.tscn +++ b/augustgamecourse/scenes/player.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=39 format=3 uid="uid://dbgc24hrbtvxm"] +[gd_scene load_steps=44 format=3 uid="uid://dbgc24hrbtvxm"] [ext_resource type="Script" path="res://scripts/player.gd" id="1_5qpif"] [ext_resource type="Texture2D" uid="uid://d6d3re6epsh4" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_t1yra"] [ext_resource type="Texture2D" uid="uid://pdvgf3y1lquv" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_vcmr0"] [ext_resource type="Texture2D" uid="uid://cvh48exhs1ir1" path="res://assets/graphics/player/run/player run 48x48.png" id="3_a03rx"] +[ext_resource type="Texture2D" uid="uid://b2brlauvni08o" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_a70o5"] [ext_resource type="Texture2D" uid="uid://d0kfe5ms2vjbr" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_mvdmt"] [sub_resource type="AtlasTexture" id="AtlasTexture_uru55"] @@ -46,6 +47,22 @@ region = Rect2(384, 0, 48, 48) atlas = ExtResource("2_t1yra") region = Rect2(432, 0, 48, 48) +[sub_resource type="AtlasTexture" id="AtlasTexture_me361"] +atlas = ExtResource("3_a70o5") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_5yslj"] +atlas = ExtResource("3_a70o5") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_l8y4s"] +atlas = ExtResource("3_a70o5") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_vc70i"] +atlas = ExtResource("3_a70o5") +region = Rect2(144, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_etdvv"] atlas = ExtResource("2_vcmr0") region = Rect2(0, 0, 48, 48) @@ -169,6 +186,23 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_me361") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_5yslj") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_l8y4s") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_vc70i") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_etdvv") }, { "duration": 1.0, @@ -256,7 +290,7 @@ metadata/_edit_group_ = true texture_filter = 1 position = Vector2(0, -7) sprite_frames = SubResource("SpriteFrames_wlxdo") -animation = &"death" +animation = &"hurt" autoplay = "idle" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] @@ -274,3 +308,5 @@ position = Vector2(12, -5) [node name="MarkerLeft" type="Node2D" parent="."] position = Vector2(-15, -5) + +[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"] diff --git a/augustgamecourse/scripts/game_controller.gd b/augustgamecourse/scripts/game_controller.gd index 290de5b..55313b0 100644 --- a/augustgamecourse/scripts/game_controller.gd +++ b/augustgamecourse/scripts/game_controller.gd @@ -4,6 +4,7 @@ var coinsCollected:int = 0 var player:Resource signal playerDeath +signal playerHurt func _ready() -> void: print("Game controller is ready") @@ -25,4 +26,6 @@ func playerDamage(): if player.health <= 0: #kill him playerDeath.emit() + else: + playerHurt.emit() diff --git a/augustgamecourse/scripts/player.gd b/augustgamecourse/scripts/player.gd index 2b11021..f048a14 100644 --- a/augustgamecourse/scripts/player.gd +++ b/augustgamecourse/scripts/player.gd @@ -8,6 +8,8 @@ const PUSH_FORCE = 700 var faceLeft = false var living = true +signal playerDead + # can i push right or left var pushLeftEnabled = false var pushRightEnabled = false @@ -18,18 +20,24 @@ var pushRightEnabled = false @onready var playerSprite: AnimatedSprite2D = $AnimatedSprite2D var pushTarget +var animPlaying = "idle" var bullet = preload("res://scenes/bullet.tscn") func killPlayer(): - print("kill the player") if living: living = false + animPlaying = "death" #play death animation playerSprite.play("death") + +func hurtPlayer(): + animPlaying="hurt" + print("player should get hurt") + playerSprite.play("hurt") func _physics_process(delta: float) -> void: - if living: + if living and not animPlaying=="hurt": # Add the gravity. if not is_on_floor(): velocity += get_gravity() * delta @@ -102,3 +110,11 @@ func _physics_process(delta: float) -> void: pushTarget = collider else: pushRightEnabled = false + + +func _on_animation_finished() -> void: + print(animPlaying + " finished playing.") + if animPlaying == "hurt": + animPlaying="idle" + if animPlaying=="death": + playerDead.emit() diff --git a/augustgamecourse/scripts/scene_manager.gd b/augustgamecourse/scripts/scene_manager.gd index a4fda1d..d1da8b5 100644 --- a/augustgamecourse/scripts/scene_manager.gd +++ b/augustgamecourse/scripts/scene_manager.gd @@ -28,6 +28,8 @@ func _ready() -> void: n.playerDamage.connect(GameController.playerDamage) #GameController signals GameController.playerDeath.connect(killPlayer) + GameController.playerHurt.connect(hurtPlayer) + player.playerDead.connect(deadPlayer) func boxTrap(): print("Trigger a box trap!") @@ -66,11 +68,13 @@ func crateFactory(): func killPlayer(): # tell player to die - starts death animation player.killPlayer() - if timer.is_stopped(): - timer.start(4) - +func hurtPlayer(): + player.hurtPlayer() +func deadPlayer(): + if timer.is_stopped(): + timer.start(1) + func resetWorld(): - print("screne manager resetting world") GameController.resetPlayer() get_tree().reload_current_scene()