60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Commander : Sprite2D
|
|
{
|
|
[Signal]
|
|
public delegate void ActionsUpEventHandler();
|
|
public int _actionsMax = 1, _actions;
|
|
public PackedScene _ballScene = GD.Load<PackedScene>("res://Ball.tscn");
|
|
public Ball _ball;
|
|
public PlayerController _playerController;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (_ball != null)
|
|
{
|
|
if (_ball.Position.Y > GetViewportRect().Size.Y + 50)
|
|
{
|
|
UnloadBall();
|
|
if (_actions <= 0)
|
|
{
|
|
EmitSignal(SignalName.ActionsUp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void BallEnteredBucket()
|
|
{
|
|
_actions += (_actions + 1) > _actionsMax ? 0 : 1;
|
|
UnloadBall();
|
|
}
|
|
|
|
public void LoadBall(Vector2 OFFSET)
|
|
{
|
|
if (_ball == null)
|
|
{
|
|
_ball = _ballScene.Instantiate<Ball>();
|
|
_ball.Position = OFFSET;
|
|
_ball._commanderOwner = this;
|
|
_ball.GravityScale = 0;
|
|
_ball.BucketEntered += BallEnteredBucket;
|
|
AddChild(_ball);
|
|
}
|
|
}
|
|
|
|
public void ShootCurrentBall(Vector2 FORCE){
|
|
|
|
_ball.Shoot(FORCE);
|
|
_actions--;
|
|
}
|
|
|
|
public void UnloadBall()
|
|
{
|
|
_ball.QueueFree();
|
|
_ball = null;
|
|
}
|
|
}
|