mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-19 14:33:48 +00:00
Strawberry Explosion
This commit is contained in:
parent
2b53936f8b
commit
b9d03efbb8
5 changed files with 42 additions and 6 deletions
|
|
@ -7,9 +7,14 @@ public partial class fragola : RigidBody2D
|
|||
[Signal]
|
||||
public delegate void HitEventHandler();
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
private bool _isAlive = true;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>("./AnimatedSprite2D");
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
|
@ -20,15 +25,34 @@ public partial class fragola : RigidBody2D
|
|||
private void _on_body_entered(Node body)
|
||||
{
|
||||
Debug.WriteLine("Collision");
|
||||
Hide();
|
||||
|
||||
EmitSignal(SignalName.Hit);
|
||||
// Must be deferred as we can't change physics properties on a physics callback.
|
||||
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred(CollisionShape2D.PropertyName.Disabled, true);
|
||||
|
||||
}
|
||||
private void _on_area_2d_area_entered(Area2D area)
|
||||
{
|
||||
// Replace with function body.
|
||||
Debug.WriteLine("Collision area");
|
||||
EmitSignal(SignalName.Hit);
|
||||
|
||||
if (_isAlive)
|
||||
{
|
||||
Explode();
|
||||
}
|
||||
}
|
||||
|
||||
private void Explode()
|
||||
{
|
||||
_isAlive = false;
|
||||
_animatedSprite.Play("explode");
|
||||
|
||||
//Hide();
|
||||
DisableCollision();
|
||||
}
|
||||
|
||||
private void DisableCollision()
|
||||
{
|
||||
// Must be deferred as we can't change physics properties on a physics callback.
|
||||
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred(CollisionShape2D.PropertyName.Disabled, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue