Skip to content

Commit

Permalink
Stop player when goal reached
Browse files Browse the repository at this point in the history
Stop player movement (except gravity), run animation and orientation
changes when goal is reached
  • Loading branch information
yndajas committed Oct 2, 2023
1 parent 4014a1c commit 213fc5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const JUMP_VELOCITY = -350.0

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
var goal_reached: bool = false

func _physics_process(delta: float) -> void:
goal_reached = get_parent().goal_reached
set_animation()
set_orientation()
set_movement(delta)
Expand All @@ -20,28 +22,28 @@ func get_direction() -> int:
func set_animation() -> void:
if not is_on_floor():
$AnimatedSprite2D.play("jump_middle")
elif get_direction():
elif get_direction() && !goal_reached:
$AnimatedSprite2D.play("run")
else:
$AnimatedSprite2D.play("idle")

func set_movement(delta: float) -> void:
if not is_on_floor():
velocity.y += gravity * delta
elif Input.is_action_just_pressed("jump"):
elif Input.is_action_just_pressed("jump") && !goal_reached:
velocity.y = JUMP_VELOCITY
play_jump_sfx()

var direction := get_direction()
if direction:
if direction && !goal_reached:
var target_velocity_x := direction * SPEED
velocity.x = move_toward(velocity.x, target_velocity_x, SPEED / 10)
else:
velocity.x = move_toward(velocity.x, 0, SPEED / 2)

func set_orientation() -> void:
var direction := get_direction()
if direction:
if direction && !goal_reached:
if direction == -1:
$AnimatedSprite2D.flip_h = true
else:
Expand Down
1 change: 1 addition & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
- Hide full screen and exit buttons on non-PC builds
- Add timer
- Add level end zone/body
- Stop player when goal reached

0 comments on commit 213fc5a

Please sign in to comment.