add logic for bolts
This commit is contained in:
parent
c188688bcf
commit
70a2292f10
25
scenes/collectables/Bolt.cs
Normal file
25
scenes/collectables/Bolt.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class Bolt : Area2D
|
||||||
|
{
|
||||||
|
private Event _eventBus;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
_eventBus = GetNode<Event>("/root/Event");
|
||||||
|
GetNode<AnimatedSprite>("AnimatedSprite").Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnBoltBodyEntered(Node body)
|
||||||
|
{
|
||||||
|
Disconnect("body_entered", this, "OnBoltBodyEntered");
|
||||||
|
SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false);
|
||||||
|
SetCollisionLayerBit((int) Game.PhysicsLayer.Collectable, false);
|
||||||
|
if (String.Equals(body.Name, "Player"))
|
||||||
|
{
|
||||||
|
_eventBus.EmitSignal("BoltCollected", 1);
|
||||||
|
}
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=10 format=2]
|
[gd_scene load_steps=11 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/collectable/bolt.png" type="Texture" id=1]
|
[ext_resource path="res://assets/collectable/bolt.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://scenes/collectables/Bolt.cs" type="Script" id=2]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id=1]
|
[sub_resource type="AtlasTexture" id=1]
|
||||||
atlas = ExtResource( 1 )
|
atlas = ExtResource( 1 )
|
||||||
@ -34,15 +35,20 @@ animations = [ {
|
|||||||
"speed": 6.0
|
"speed": 6.0
|
||||||
} ]
|
} ]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=8]
|
[sub_resource type="CircleShape2D" id=8]
|
||||||
extents = Vector2( 5, 5 )
|
radius = 5.38516
|
||||||
|
|
||||||
[node name="Bolt" type="Area2D"]
|
[node name="Bolt" type="Area2D"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 7 )
|
frames = SubResource( 7 )
|
||||||
animation = "spin"
|
animation = "spin"
|
||||||
|
centered = false
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
|
position = Vector2( 8, 8 )
|
||||||
shape = SubResource( 8 )
|
shape = SubResource( 8 )
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="OnBoltBodyEntered"]
|
||||||
|
Loading…
Reference in New Issue
Block a user