diff --git a/scenes/checkpoint/Checkpoint.cs b/scenes/checkpoint/Checkpoint.cs new file mode 100644 index 0000000..a94bd2a --- /dev/null +++ b/scenes/checkpoint/Checkpoint.cs @@ -0,0 +1,26 @@ +using Godot; + +public class Checkpoint : Area2D +{ + private AnimatedSprite _sprite; + + public override void _Ready() + { + _sprite = GetNode("AnimatedSprite"); + } + + public void OnCheckpointBodyEntered(Node body) + { + SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false); + SetCollisionLayerBit((int) Game.PhysicsLayer.Checkpoint, false); + Disconnect("body_entered", this, "OnCheckpointBodyEntered"); + _sprite.Play("reached"); + _sprite.Connect("animation_finished", this, "OnReachedAnimationFinished"); + } + + public void OnReachedAnimationFinished() + { + _sprite.Disconnect("animation_finished", this, "OnReachedAnimationFinished"); + _sprite.Play("activated"); + } +} diff --git a/scenes/checkpoint/Checkpoint.tscn b/scenes/checkpoint/Checkpoint.tscn index 9ab9e44..25008a7 100644 --- a/scenes/checkpoint/Checkpoint.tscn +++ b/scenes/checkpoint/Checkpoint.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://assets/checkpoint/checkpoint.png" type="Texture" id=1] +[ext_resource path="res://scenes/checkpoint/Checkpoint.cs" type="Script" id=2] [sub_resource type="AtlasTexture" id=1] atlas = ExtResource( 1 ) @@ -48,12 +49,17 @@ animations = [ { extents = Vector2( 5, 10.5 ) [node name="Checkpoint" type="Area2D"] +collision_layer = 16 +script = ExtResource( 2 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 7 ) animation = "deactivated" +centered = false [node name="CollisionShape2D" type="CollisionShape2D" parent="."] visible = false -position = Vector2( 0, 5.5 ) +position = Vector2( 8, 21.5 ) shape = SubResource( 8 ) + +[connection signal="body_entered" from="." to="." method="OnCheckpointBodyEntered"]