-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Directly connect signals to target methods when possible - Improve coin animations so the audio can't trigger twice in the editor and so the coins' properties are reset every time you start the game
- Loading branch information
1 parent
c687ff1
commit ea90101
Showing
6 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
extends Area2D | ||
class_name Coin | ||
|
||
""" | ||
Collectible that disappears when the player touches it. | ||
""" | ||
|
||
onready var animation_player: AnimationPlayer = $AnimationPlayer | ||
|
||
|
||
""" | ||
If a body comes in contact with the Coin, we play the animation | ||
that will remove it from the game. | ||
The Coins only look for collisions on the Player layer as shown in the | ||
collision mask. | ||
This prevents other characters such as enemies picking them up. | ||
We set monitoring to false in the picked animation so the Coin isn't picked up again. | ||
The Coins only detects collisions with the Player thanks to its collision mask. | ||
This prevents other characters such as enemies from picking up coins. | ||
""" | ||
func _on_body_entered(body: PhysicsBody2D): | ||
func _on_body_entered(body: Node) -> void: | ||
picked() | ||
|
||
|
||
""" | ||
When the player collides with a coin, the coin plays its 'picked' animation. | ||
The animation takes cares of making the coin disappear, but also deactivates its collisions | ||
and frees it from memory, saving us from writing more complex code. | ||
Click the AnimationPlayer node to see the animation timeline. | ||
""" | ||
func picked() -> void: | ||
animation_player.play("picked") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
extends Node2D | ||
class_name MovingPlatform | ||
|
||
|
||
onready var animation_player: AnimationPlayer = $AnimationPlayer | ||
|
||
|
||
|