|
|
|
|
@ -93,20 +93,24 @@ func jump_state(_delta): |
|
|
|
|
if(direction): |
|
|
|
|
velocity.x = move_toward(velocity.x, direction * SPEED, SPEED) |
|
|
|
|
|
|
|
|
|
if velocity.y > 0: |
|
|
|
|
if is_on_floor(): |
|
|
|
|
if direction: |
|
|
|
|
$fsm.set_next_state("walk") |
|
|
|
|
else: |
|
|
|
|
velocity.x = 0 |
|
|
|
|
$fsm.set_next_state("idle") |
|
|
|
|
|
|
|
|
|
if is_on_floor(): |
|
|
|
|
if direction: |
|
|
|
|
$fsm.set_next_state("walk") |
|
|
|
|
else: |
|
|
|
|
velocity.x = 0 |
|
|
|
|
$fsm.set_next_state("idle") |
|
|
|
|
|
|
|
|
|
if is_on_wall() || (is_on_ceiling() ): |
|
|
|
|
$fsm.set_next_state("climb") |
|
|
|
|
if is_on_wall() || (is_on_ceiling() and Input.is_action_pressed("player_up")): |
|
|
|
|
$fsm.set_next_state("climb") |
|
|
|
|
|
|
|
|
|
func on_enter_climb_state(): |
|
|
|
|
sprite.modulate = Color(1, 0, 0) |
|
|
|
|
velocity = Vector2(0, 0) |
|
|
|
|
|
|
|
|
|
func on_exit_climb_state(): |
|
|
|
|
sprite.modulate = Color(1, 1, 1) |
|
|
|
|
|
|
|
|
|
func climb_state(_delta): |
|
|
|
|
if is_on_wall(): |
|
|
|
|
var direction = Input.get_axis("player_up", "player_down") |
|
|
|
|
@ -174,6 +178,10 @@ func drop_obstacle(): |
|
|
|
|
grabbed_obstacle = null |
|
|
|
|
|
|
|
|
|
func handle_sprite_orientation(): |
|
|
|
|
# rotates oriented_container to face |
|
|
|
|
# the direction of the velocity |
|
|
|
|
# if is_on_wall, rotated regarding velocity.y, with up by default |
|
|
|
|
# if is_on_ceiling, rotated regarding velocity.x, with right by default |
|
|
|
|
if is_on_wall_only(): |
|
|
|
|
if velocity.y != 0: |
|
|
|
|
$oriented_container.rotation = PI/2 if (velocity.y > 0) else - PI / 2 |
|
|
|
|
@ -182,21 +190,17 @@ func handle_sprite_orientation(): |
|
|
|
|
var should_flip_with_wall_left = (wall_position > player_position) && (velocity.y > 0) |
|
|
|
|
var should_flip_with_wall_right = (wall_position < player_position) && (velocity.y < 0) |
|
|
|
|
sprite.flip_v = should_flip_with_wall_left || should_flip_with_wall_right |
|
|
|
|
sprite.flip_h = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif is_on_ceiling_only(): |
|
|
|
|
elif is_on_ceiling(): |
|
|
|
|
if velocity.x != 0: |
|
|
|
|
$oriented_container.rotation = PI if (velocity.x > 0) else -PI |
|
|
|
|
sprite.flip_h = velocity.x > 0 |
|
|
|
|
else: |
|
|
|
|
if velocity.x != 0: |
|
|
|
|
$oriented_container.rotation = 0 if (velocity.x > 0) else PI |
|
|
|
|
sprite.flip_v = velocity.x < 0 |
|
|
|
|
sprite.flip_h = false |
|
|
|
|
|
|
|
|
|
func on_enter_swim_state(): |
|
|
|
|
sprite.modulate = Color(0, 0, 1) |
|
|
|
|
gravity = WORLD_GRAVITY / 2 |
|
|
|
|
|
|
|
|
|
func swim_state(_delta): |
|
|
|
|
@ -211,7 +215,6 @@ func swim_state(_delta): |
|
|
|
|
die() |
|
|
|
|
|
|
|
|
|
func on_exit_swim_state(): |
|
|
|
|
sprite.modulate = Color(1, 1, 1) |
|
|
|
|
gravity = WORLD_GRAVITY |
|
|
|
|
sprite.modulate = Color(1,1,1) |
|
|
|
|
|
|
|
|
|
|