add logic for checkpoints
This commit is contained in:
parent
70a2292f10
commit
2a9f4fe500
26
scenes/checkpoint/Checkpoint.cs
Normal file
26
scenes/checkpoint/Checkpoint.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Godot;
|
||||
|
||||
public class Checkpoint : Area2D
|
||||
{
|
||||
private AnimatedSprite _sprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = GetNode<AnimatedSprite>("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");
|
||||
}
|
||||
}
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user