41 lines
763 B
C#
41 lines
763 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Cue : Sprite2D
|
|
{
|
|
[Signal]
|
|
public delegate void ShootEventHandler(Vector2 impulse);
|
|
public float _power = 0.0f;
|
|
public int _powerDirection = 1;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
Vector2 mousePosition = GetViewport().GetMousePosition();
|
|
LookAt(mousePosition);
|
|
if (Input.IsActionPressed("left_click"))
|
|
{
|
|
_power += 0.1f * _powerDirection;
|
|
if (_power >= ((Main)GetParent())._maxPower)
|
|
{
|
|
_powerDirection = -1;
|
|
}
|
|
else if (_power <= 0)
|
|
{
|
|
_powerDirection = 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_power > 0f)
|
|
{
|
|
_powerDirection = 1;
|
|
Vector2 direction = mousePosition - Position;
|
|
EmitSignal(SignalName.Shoot, _power * direction);
|
|
_power = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|