add energy code
This commit is contained in:
parent
65149fcb42
commit
c2d1da5746
25
scenes/collectables/Energy.cs
Normal file
25
scenes/collectables/Energy.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Energy : Area2D
|
||||
{
|
||||
Event eventBus;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
eventBus = GetNode<Event>("/root/Event");
|
||||
GetNode<AnimatedSprite>("AnimatedSprite").Play();
|
||||
}
|
||||
|
||||
public void OnEnergyBodyEntered(Node body)
|
||||
{
|
||||
Disconnect("body_entered", this, "OnEnergyBodyEntered");
|
||||
SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false);
|
||||
SetCollisionLayerBit((int) Game.PhysicsLayer.Collectable, false);
|
||||
if (String.Equals(body.Name, "Player"))
|
||||
{
|
||||
eventBus.EmitSignal("EnergyCollected", 1);
|
||||
}
|
||||
QueueFree();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://assets/collectable/energy.png" type="Texture" id=1]
|
||||
[ext_resource path="res://scenes/collectables/Energy.cs" type="Script" id=2]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=1]
|
||||
atlas = ExtResource( 1 )
|
||||
@ -22,13 +23,16 @@ animations = [ {
|
||||
extents = Vector2( 2.5, 6.5 )
|
||||
|
||||
[node name="Energy" type="Area2D"]
|
||||
collision_layer = 8
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
frames = SubResource( 3 )
|
||||
animation = "glow"
|
||||
playing = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
position = Vector2( -0.5, -0.5 )
|
||||
shape = SubResource( 4 )
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="OnEnergyBodyEntered"]
|
||||
|
Loading…
Reference in New Issue
Block a user