sg pushin' shovin' squishin' some snails n' skeles with rocks
This commit is contained in:
parent
56fb173a24
commit
3ba9afd2be
4 changed files with 117 additions and 17 deletions
|
@ -10,6 +10,8 @@ const DeathSplatter = preload("res://objects/player/player_death_particles.tscn"
|
|||
# EXPORTS #
|
||||
## horizontal movement speed
|
||||
export var walk_speed: float = 50.0
|
||||
## speed to push pushable objects at
|
||||
export var push_speed: float = 25.0
|
||||
## climbing speed
|
||||
export var climb_speed: float = 39.0
|
||||
## gravity force
|
||||
|
@ -43,15 +45,22 @@ onready var grounded_shape: CollisionShape2D = $"%GroundedShape"
|
|||
onready var airborne_shape: CollisionShape2D = $"%AirborneShape"
|
||||
onready var ladder_detector: RayCast2D = $"%LadderDetector"
|
||||
onready var death_splatter_position: Position2D = $"%DeathSplatterPosition"
|
||||
onready var pushable_detector: RayCast2D = $"%PushableDetector"
|
||||
|
||||
|
||||
# OVERRIDES #
|
||||
func _ready() -> void:
|
||||
# death handling
|
||||
Game.respawn_point = global_position
|
||||
connect("died", Game, "_on_player_died")
|
||||
# to detect floor on first frame
|
||||
move_and_slide(Vector2(0.0, 1.0), Vector2.UP)
|
||||
# make certain pushable detector will not detect player
|
||||
pushable_detector.add_exception(self)
|
||||
# set up state chart
|
||||
state_chart.initialize()
|
||||
state_chart.set_guard_property("can_respawn", true)
|
||||
# state chart debug
|
||||
$StateDebugLayer/StateChartDebug.target = state_chart
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
@ -103,6 +112,9 @@ func _on_Grounded_state_entered() -> void:
|
|||
snap.y = 2.5 # snap when in grounded state
|
||||
velocity.y = 1.0
|
||||
|
||||
func _on_Pushing_state_entered() -> void:
|
||||
animation_player.play("push")
|
||||
|
||||
func _on_Airborne_state_entered() -> void:
|
||||
grounded_shape.disabled = true
|
||||
airborne_shape.disabled = false
|
||||
|
@ -208,6 +220,21 @@ func _process_can_walk(delta: float) -> void:
|
|||
else:
|
||||
animation_player.play("idle")
|
||||
|
||||
## rubbing up against a wall or pushing an object
|
||||
func _process_pushing(delta: float) -> void:
|
||||
if not is_on_wall():
|
||||
state_chart.send_event("push_stop")
|
||||
var input_dir = sign(Input.get_axis("ui_left", "ui_right"))
|
||||
if input_dir != 0.0:
|
||||
pushable_detector.force_raycast_update()
|
||||
if pushable_detector.is_colliding():
|
||||
var col = pushable_detector.get_collider()
|
||||
if col.is_in_group("pushable"):
|
||||
col.push(input_dir * push_speed)
|
||||
velocity.x = input_dir * push_speed * 2.0
|
||||
else:
|
||||
state_chart.send_event("push_stop")
|
||||
|
||||
## climbing on ladders
|
||||
func _process_climbing(delta: float) -> void:
|
||||
# climbing movement
|
||||
|
@ -271,10 +298,13 @@ func _process_movement(delta: float) -> void:
|
|||
if col != null:
|
||||
if col.remainder.y >= 1.0 and col.normal.y == 0.0:
|
||||
position.x += col.normal.x * 0.001
|
||||
|
||||
# check for wall
|
||||
if is_on_wall():
|
||||
state_chart.send_event("push_start")
|
||||
|
||||
|
||||
# COLLISION CALLBACKS #
|
||||
func _on_Hitbox_body_entered(body: Node) -> void:
|
||||
if body.is_in_group("death"):
|
||||
die()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue