Added demon level prototype and child player form
This commit is contained in:
1 parent
7c7e607a6e
commit
22f2f0d8f4
34 files changed
+1477
-433
No files matched your search
+46
-9
@@ -10,12 +10,14 @@ const JUMP_VELOCITY = -400.0
|
||||
@onready var left_spawn: Node2D = $LeftSpawn
|
||||
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||
@onready var camera: Camera2D = $Camera2D
|
||||
@onready var child_graphic: AnimatedSprite2D = $ChildGraphic
|
||||
var using_child_form := false
|
||||
|
||||
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
|
||||
enum State{IDLE, RUN, JUMP, FALLING, HURT, DEATH}
|
||||
enum State{IDLE, RUN, JUMP, FALLING, HURT, DEATH, PUNCH}
|
||||
var current_state:State = State.IDLE
|
||||
|
||||
var pushTarget
|
||||
@@ -83,38 +85,54 @@ func update_states():
|
||||
else:
|
||||
current_state = State.RUN
|
||||
|
||||
func get_active_graphic() -> AnimatedSprite2D:
|
||||
if using_child_form:
|
||||
return child_graphic
|
||||
return player_graphic
|
||||
|
||||
func update_animation():
|
||||
var graphic = get_active_graphic()
|
||||
match current_state:
|
||||
State.IDLE:
|
||||
player_graphic.play("idle")
|
||||
graphic.play("idle")
|
||||
State.RUN:
|
||||
player_graphic.play("run")
|
||||
graphic.play("run")
|
||||
State.JUMP:
|
||||
if upJump:
|
||||
player_graphic.play("jump")
|
||||
graphic.play("jump")
|
||||
State.FALLING:
|
||||
player_graphic.play("falling")
|
||||
graphic.play("falling")
|
||||
State.HURT:
|
||||
player_graphic.play("hurt")
|
||||
graphic.play("hurt")
|
||||
State.DEATH:
|
||||
player_graphic.play("death")
|
||||
graphic.play("death")
|
||||
State.PUNCH:
|
||||
graphic.play("Punch")
|
||||
|
||||
func handle_movement(_delta):
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
if direction <0:
|
||||
facing = FaceDirection.LEFT
|
||||
player_graphic.flip_h = true
|
||||
get_active_graphic().flip_h = true
|
||||
if direction >0:
|
||||
facing = FaceDirection.RIGHT
|
||||
player_graphic.flip_h = false
|
||||
get_active_graphic().flip_h = false
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
func handle_input():
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
current_state = State.JUMP
|
||||
upJump = true
|
||||
|
||||
# Child punch attack
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
print("ATTACK PRESSED")
|
||||
print("using_child_form =", using_child_form)
|
||||
current_state = State.PUNCH
|
||||
|
||||
if Input.is_action_just_pressed("shove") && pushEnabled:
|
||||
print("shove pressed")
|
||||
if facing == FaceDirection.RIGHT:
|
||||
@@ -130,6 +148,7 @@ func handle_input():
|
||||
%SceneManager.makeBullet(right_spawn.global_transform, 700)
|
||||
if facing == FaceDirection.LEFT:
|
||||
%SceneManager.makeBullet(left_spawn.global_transform, -700)
|
||||
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
@@ -231,6 +250,24 @@ func _on_animation_finished() -> void:
|
||||
current_state = State.IDLE
|
||||
State.DEATH:
|
||||
deathAnimationCompleteSignal.emit()
|
||||
State.PUNCH:
|
||||
current_state = State.IDLE
|
||||
|
||||
func become_child() -> void:
|
||||
using_child_form = true
|
||||
|
||||
player_graphic.visible = false
|
||||
child_graphic.visible = true
|
||||
|
||||
print("Player switched to CHILD form")
|
||||
|
||||
func become_adult() -> void:
|
||||
using_child_form = false
|
||||
|
||||
player_graphic.visible = true
|
||||
child_graphic.visible = false
|
||||
|
||||
print("Player switched to ADULT form")
|
||||
|
||||
func playerTakesDamage(health):
|
||||
print("Player sees remaining health "+str(health))
|
||||
|
||||
@@ -13,6 +13,7 @@ var player: Player
|
||||
var ui: Control
|
||||
|
||||
func _ready() -> void:
|
||||
print("SCENE MANAGER READY")
|
||||
current_level_container = $"../CurrentLevel"
|
||||
current_level = current_level_container.get_child(0)
|
||||
|
||||
@@ -23,8 +24,9 @@ func _ready() -> void:
|
||||
player = get_parent().get_node("Player")
|
||||
ui = current_level.get_node_or_null("CanvasLayer/UI")
|
||||
|
||||
move_player_to_spawn()
|
||||
apply_camera_limits()
|
||||
|
||||
|
||||
Gamecontroller.reset()
|
||||
|
||||
for obj in triggers.get_children():
|
||||
@@ -66,6 +68,19 @@ func apply_camera_limits() -> void:
|
||||
int(bottom_right.global_position.y)
|
||||
)
|
||||
|
||||
func move_player_to_spawn() -> void:
|
||||
var spawn = current_level.get_node_or_null("PlayerSpawn")
|
||||
print("Trying to move player to spawn")
|
||||
|
||||
|
||||
if spawn == null:
|
||||
print("No PlayerSpawn found in level")
|
||||
return
|
||||
|
||||
player.global_position = spawn.global_position
|
||||
print("Player moved to spawn: ", spawn.global_position)
|
||||
|
||||
|
||||
#call this any time the coins change
|
||||
func updateCoins() -> void:
|
||||
var coinCount = 0
|
||||
|
||||
Reference in new issue
Block a user