7-11-25 7:00pm
This commit is contained in:
40
Gameplay/Cue.cs
Normal file
40
Gameplay/Cue.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user