Skip to content

Commit

Permalink
Treat stomping an enemy as a jump
Browse files Browse the repository at this point in the history
Previously, when the player stomped an enemy the enemy would set the
player's vertical velocity directly.

Instead, have the enemy call a new stomp() method on the player, which
internally triggers a jump having disarmed the double-jump. This makes a
difference in the following cases:

- If the player has a jump buffered, stomping on the enemy now consumes
  that jump.
- If the player is holding the jump key (because they buffered a jump)
  they can curtail the height of bouncing off the enemy.
- If double jump is enabled, it is now armed by stomping an enemy.
  • Loading branch information
wjt committed Oct 26, 2024
1 parent b14ffa8 commit 20f1ae4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/enemy/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func _on_gravity_changed(new_gravity):
func _on_hitbox_body_entered(body):
if body.name == "Player":
if squashable and body.velocity.y > 0 and body.position.y < position.y:
body.velocity.y = body.jump_velocity
body.stomp()
queue_free()
elif player_loses_life:
Global.lives -= 1
25 changes: 17 additions & 8 deletions scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ func _on_gravity_changed(new_gravity):
gravity = new_gravity


func _jump():
velocity.y = jump_velocity
coyote_timer = 0
jump_buffer_timer = 0
if double_jump_armed:
double_jump_armed = false
_double_jump_particles.emitting = true
elif double_jump:
double_jump_armed = true


func stomp():
double_jump_armed = false
_jump()


func _physics_process(delta):
# Don't move if there are no lives left.
if Global.lives <= 0:
Expand All @@ -100,14 +116,7 @@ func _physics_process(delta):
jump_buffer_timer = (jump_buffer + delta)

if jump_buffer_timer > 0 and (double_jump_armed or coyote_timer > 0):
velocity.y = jump_velocity
coyote_timer = 0
jump_buffer_timer = 0
if double_jump_armed:
double_jump_armed = false
_double_jump_particles.emitting = true
elif double_jump:
double_jump_armed = true
_jump()

# Reduce velocity if the player lets go of the jump key before the apex.
# This allows controlling the height of the jump.
Expand Down

0 comments on commit 20f1ae4

Please sign in to comment.