diff --git a/scenes/collectables/Bolt.cs b/scenes/collectables/Bolt.cs new file mode 100644 index 0000000..2c2ce18 --- /dev/null +++ b/scenes/collectables/Bolt.cs @@ -0,0 +1,25 @@ +using Godot; +using System; + +public class Bolt : Area2D +{ + private Event _eventBus; + + public override void _Ready() + { + _eventBus = GetNode("/root/Event"); + GetNode("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(); + } +} diff --git a/scenes/collectables/Bolt.tscn b/scenes/collectables/Bolt.tscn index 4c6c50b..e5954df 100644 --- a/scenes/collectables/Bolt.tscn +++ b/scenes/collectables/Bolt.tscn @@ -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://scenes/collectables/Bolt.cs" type="Script" id=2] [sub_resource type="AtlasTexture" id=1] atlas = ExtResource( 1 ) @@ -34,15 +35,20 @@ animations = [ { "speed": 6.0 } ] -[sub_resource type="RectangleShape2D" id=8] -extents = Vector2( 5, 5 ) +[sub_resource type="CircleShape2D" id=8] +radius = 5.38516 [node name="Bolt" type="Area2D"] +script = ExtResource( 2 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 7 ) animation = "spin" +centered = false [node name="CollisionShape2D" type="CollisionShape2D" parent="."] visible = false +position = Vector2( 8, 8 ) shape = SubResource( 8 ) + +[connection signal="body_entered" from="." to="." method="OnBoltBodyEntered"]