From 6355c31a7c3876601ebe664ff0abf61c34527d00 Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Mon, 7 Oct 2024 14:24:38 -0400 Subject: [PATCH] player hurt working with signals --- .../player/hurt/Player Hurt 48x48.png | Bin 0 -> 1448 bytes .../player/hurt/Player Hurt 48x48.png.import | 34 +++++++++++++++ augustgamecourse/scenes/player.tscn | 40 +++++++++++++++++- augustgamecourse/scripts/game_controller.gd | 3 ++ augustgamecourse/scripts/player.gd | 20 ++++++++- augustgamecourse/scripts/scene_manager.gd | 12 ++++-- 6 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png create mode 100644 augustgamecourse/assets/graphics/player/hurt/Player Hurt 48x48.png.import 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 0000000000000000000000000000000000000000..57d878395e3581c75dc07562589c4c209606485d GIT binary patch literal 1448 zcmV;Z1y}lsP)Px)Vo5|nRCt{2n@>y}RUF4ZkJerOE#kjMStQgHNr?OjDhY`uTxqn~MsGFI8%cX2 z#+wHZ-nkf)9-7#Lo=hNMy_gUWrUz6Ku)&lxmefL8tXe6HK*8r>dAl>i%(BbQ?!JNF zC)s3n-t6r6_vZI~zxQT#K@bE%5ClOG1VIo4K@bE%5ClOG1VIo4;mDxEKB3kcfQ3g} z+PS|g5mx|8h5nVH@&3Aq|r=_kK&wGEuT zmfemKQw=rs)TufE&aa%SkiuY`+5tYA+TfG-rd`JjoV~_c_tUEBm%q4lf25-N3dI?R zUkp~>2EDsErvcVCHeLJM9_;Qr_Ro850JOfDbbVj7&EV|#;VTb$bTgKVnw}Fa`j(3H%HIITHZHRh;MEc($q) z;h^LizHn7g?I6s=!@9VRFw`3-wCCUn zV_s{X2{^C8L2>M%6RMH%mPy82CPUG1@~|IF#(UKA)_k@zm$&A1JmA>6jzQJhk=b@8 z{@!-g=0Uxk?TjQR)aSs|g?8;7MNf|{Dp&-rnq5{cU`CP?%1^fg)m*>By^L;W;#alb zA!lTB4TdkY2O85gm8(gZr5l*ZT~pTRL4wxs)cg|^>Sl% zyOL6hCP;fe-GkqKW;U%dZ!vUqUso|=WvOI`t^i6YwATA70YG|N(-6z_cU{Mz@_we; zCNPX7C-&*E-2?`&cCYTYzg+TLs9VwRP9vKt2ALTAs_^YmNH4qtWvFB&RRA-pC*wUT zeruiht@UhMdRu3!fpej&lybdnU@D;e2JNpFeuh12+*sXqy#P*+Etbv1hpqqyGpa|K zw$UK~?u>m8Kr-FuXkDtboV<8V;MH!JO{H}IM6?a#tYT1}N>;J~47D#d1F-pfZZ#j@ zZ3Hq8&1@O%^NpfyqeJX|TF~7H>u?&uZD4yb*P?B7XrF;AMJPXoaAJ&LlK;{Cd}PW) z)RKShrw{h^Z4{D!Bsrn{Dw#1cWa5}j1>dj;i%^~etgkJ&gqq}!0w#%~mi&H1F$S-R z+eU|6CN8%LWZ>4FSbiKUbdha!@ z?QwYZo8uN4{ZRfGN}2+h 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()