added jump animation
This commit is contained in:
1 parent
a245ebc135
commit
579397cd8b
4 files changed
+106
-6
No files matched your search
+26
-4
@@ -12,8 +12,9 @@ var direction : float = 0
|
||||
enum FaceDirection { LEFT, RIGHT }
|
||||
var facing: FaceDirection = FaceDirection.LEFT
|
||||
var shove_target: RigidBody2D
|
||||
enum State { IDLE, RUNNING }
|
||||
enum State { IDLE, RUN, JUMP, APEX, FALL }
|
||||
var state: State = State.IDLE
|
||||
var up_jump:bool = false
|
||||
|
||||
func _physics_process(delta: float):
|
||||
handle_input()
|
||||
@@ -73,13 +74,34 @@ func handle_collisions():
|
||||
func handle_state():
|
||||
match state:
|
||||
State.IDLE when velocity.x != 0:
|
||||
state = State.RUNNING
|
||||
State.RUNNING when velocity.x == 0:
|
||||
state = State.RUN
|
||||
State.RUN when velocity.x == 0:
|
||||
state = State.IDLE
|
||||
State.RUN when velocity.y < 0:
|
||||
state = State.JUMP
|
||||
State.IDLE when velocity.y < 0:
|
||||
state = State.JUMP
|
||||
State.JUMP when velocity.y > 0:
|
||||
state = State.APEX
|
||||
# from APEX to FALL is handled when apex animation finishes
|
||||
State.FALL when velocity.y == 0:
|
||||
state = State.IDLE
|
||||
|
||||
func handle_animation():
|
||||
match state:
|
||||
State.IDLE:
|
||||
graphic.play("idle")
|
||||
State.RUNNING:
|
||||
State.RUN:
|
||||
graphic.play("run")
|
||||
State.JUMP:
|
||||
graphic.play("jump")
|
||||
State.APEX:
|
||||
graphic.play("apex")
|
||||
State.FALL:
|
||||
graphic.play("fall")
|
||||
|
||||
func _on_graphic_animation_finished() -> void:
|
||||
# switch state from apex to fall
|
||||
match state:
|
||||
State.APEX:
|
||||
state = State.FALL
|
||||
Reference in new issue
Block a user