add logic for bolts

This commit is contained in:
Chris Cromer 2022-11-19 23:07:33 -03:00
parent c188688bcf
commit 70a2292f10
2 changed files with 34 additions and 3 deletions

View 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();
}
}

View File

@ -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"]