|
|
|
|
@ -33,7 +33,8 @@ var can_grab_obstacles = { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@onready var grab_ray = get_node('grab_ray') |
|
|
|
|
@onready var grab_ray = get_node('oriented_container/grab_ray') |
|
|
|
|
@onready var sprite = get_node('oriented_container/sprite') |
|
|
|
|
|
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes. |
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") |
|
|
|
|
@ -98,11 +99,11 @@ func jump_state(_delta): |
|
|
|
|
$fsm.set_next_state("climb") |
|
|
|
|
|
|
|
|
|
func on_enter_climb_state(): |
|
|
|
|
$sprite.modulate = Color(1, 0, 0) |
|
|
|
|
sprite.modulate = Color(1, 0, 0) |
|
|
|
|
velocity = Vector2(0, 0) |
|
|
|
|
|
|
|
|
|
func on_exit_climb_state(): |
|
|
|
|
$sprite.modulate = Color(1, 1, 1) |
|
|
|
|
sprite.modulate = Color(1, 1, 1) |
|
|
|
|
|
|
|
|
|
func climb_state(_delta): |
|
|
|
|
if is_on_wall(): |
|
|
|
|
@ -136,6 +137,8 @@ func after_state(delta): |
|
|
|
|
if can_grab_obstacles[$fsm.current_state] == true: |
|
|
|
|
handle_grab() |
|
|
|
|
|
|
|
|
|
handle_sprite_orientation() |
|
|
|
|
|
|
|
|
|
func handle_grab(): |
|
|
|
|
if Input.is_action_just_pressed('player_action'): |
|
|
|
|
if grabbed_obstacle == null: |
|
|
|
|
@ -152,12 +155,35 @@ func handle_grab(): |
|
|
|
|
|
|
|
|
|
func do_grab(obstacle): |
|
|
|
|
grabbed_obstacle = obstacle |
|
|
|
|
obstacle.grabbed(self) |
|
|
|
|
obstacle.grabbed($oriented_container) |
|
|
|
|
|
|
|
|
|
func drop_obstacle(): |
|
|
|
|
grabbed_obstacle.dropped() |
|
|
|
|
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 |
|
|
|
|
var wall_position = get_slide_collision(0).get_position().x |
|
|
|
|
var player_position = $oriented_container.get_global_position().x |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif is_on_ceiling(): |
|
|
|
|
if velocity.x != 0: |
|
|
|
|
$oriented_container.rotation = PI if (velocity.x > 0) else -PI |
|
|
|
|
else: |
|
|
|
|
if velocity.x != 0: |
|
|
|
|
$oriented_container.rotation = 0 if (velocity.x > 0) else PI |
|
|
|
|
sprite.flip_v = velocity.x < 0 |
|
|
|
|
|
|
|
|
|
func die(): |
|
|
|
|
$fsm.set_next_state("die") |
|
|
|
|
|
|
|
|
|
|