refactor bolt and energy

This commit is contained in:
Chris Cromer 2022-11-21 02:20:18 -03:00
parent b6a5a1f829
commit 63e4527fce
2 changed files with 3 additions and 14 deletions

View File

@ -18,7 +18,7 @@ public class Bolt : Area2D
Disconnect("body_entered", this, "OnBoltBodyEntered");
SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false);
SetCollisionLayerBit((int) Game.PhysicsLayer.Collectable, false);
if (String.Equals(body.Name, "Player"))
if (body.Name.Equals("Player"))
{
Collected();
}

View File

@ -4,12 +4,11 @@ using System;
public class Energy : Area2D
{
private Event _event;
private AnimatedSprite _sprite;
public override void _Ready()
{
_event = GetNode<Event>("/root/Event");
_sprite = GetNode<AnimatedSprite>("AnimatedSprite");
GetNode<AnimatedSprite>("AnimatedSprite").Play();
}
public void OnEnergyBodyEntered(Node body)
@ -17,20 +16,10 @@ public class Energy : Area2D
Disconnect("body_entered", this, "OnEnergyBodyEntered");
SetCollisionMaskBit((int) Game.PhysicsLayer.Player, false);
SetCollisionLayerBit((int) Game.PhysicsLayer.Collectable, false);
if (String.Equals(body.Name, "Player"))
if (body.Name.Equals("Player"))
{
_event.EmitSignal("EnergyCollected", 1);
}
QueueFree();
}
public void OnVisibilityNotifier2DScreenEntered()
{
_sprite.Play();
}
public void OnVisibilityNotifier2DScreenExited()
{
_sprite.Stop();
}
}