week6 player enemy damage death cycle

This commit is contained in:
OddlyTimbot committed 2026-11-03 17:03:06 -05:00
1 parent c1bdb544a6
commit ed7e5c4740
12 files changed
+306 -25

No files matched your search

+18 -6
View File
@@ -11,10 +11,11 @@ class_name Player extends CharacterBody2D
var direction
signal bulletSignal(pos, speed)
signal deathCompleteSignal
enum FaceDirection {LEFT,RIGHT}
var facing:FaceDirection = FaceDirection.RIGHT
enum PlayerStates {IDLE,RUNNING,JUMPING,FALLING}
enum PlayerStates {IDLE,RUNNING,JUMPING,FALLING, HURT, DEAD}
var current_player_state:PlayerStates = PlayerStates.IDLE
var upJump:bool = false
@@ -31,8 +32,8 @@ func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
handle_input()
if not current_player_state == PlayerStates.DEAD:
handle_input()
handle_movement()
handle_states()
handle_animations()
@@ -40,7 +41,11 @@ func _physics_process(delta: float) -> void:
handle_collisions()
func takeDamage()->void:
current_player_state = PlayerStates.HURT
func kill()->void:
current_player_state = PlayerStates.DEAD
func handle_input()->void:
# Handle shoot
if Input.is_action_just_pressed("shoot"):
@@ -91,7 +96,6 @@ func handle_collisions()->void:
c.get_collider().apply_central_impulse(-c.get_normal() * bump_power )
if right_cast.is_colliding():
print("Something on my right")
#get the thing I can shove
var collider = right_cast.get_collider()
if collider is RigidBody2D:
@@ -101,7 +105,6 @@ func handle_collisions()->void:
pushRightEnabled = false
if left_cast.is_colliding():
print("Something on my left")
var collider = left_cast.get_collider()
if collider is RigidBody2D:
pushLeftEnabled = true
@@ -133,9 +136,18 @@ func handle_animations()->void:
player_graphic.play("jump")
PlayerStates.FALLING:
player_graphic.play("fall")
PlayerStates.HURT:
player_graphic.play("hurt")
PlayerStates.DEAD:
player_graphic.play("death")
func _animation_finished() -> void:
match current_player_state:
PlayerStates.JUMPING:
upJump = false
PlayerStates.HURT:
current_player_state = PlayerStates.IDLE
PlayerStates.DEAD:
#death animation complete
deathCompleteSignal.emit()