Files
peggle-roguelike/Commander.cs
T
2026-05-28 00:06:51 -04:00

64 lines
1.8 KiB
C#

using Godot;
using System;
public partial class Commander : Sprite2D
{
[Signal]
public delegate void TurnDoneEventHandler();
public bool _aiming = false;
public int _health = 10;
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
public Attack _currentAttack;
public override void _Process(double delta)
{
base._Process(delta);
if (_currentAttack != null)
{
if (Input.IsActionJustPressed("leftClick")){
if (_currentAttack._hovered){
_aiming = true;
}
}
if (_aiming){
Vector2 offset = (_currentAttack.GlobalPosition - GetGlobalMousePosition()) * 500;
if (Input.IsActionJustReleased("leftClick")){
ShootCurrentAttack(offset);
}
}
if (_currentAttack.Position.Y > GetViewportRect().Size.Y + 50){
_currentAttack.QueueFree();
_currentAttack = null;
EmitSignal(SignalName.TurnDone);
}
}
}
public void StartTurn()
{
if (_currentAttack == null){
GD.Print("Loading attack");
_currentAttack = _attackScene.Instantiate<Attack>();
_currentAttack._commanderOwner = this;
_currentAttack.GravityScale = 0;
AddChild(_currentAttack);
}
}
public void TakeDamage(int DAMAGE, Enemy ATTACKER)
{
_health -= DAMAGE;
if (_health <= 0)
{
GD.Print("GAME OVER");
GetTree().Quit();
}
}
public void ShootCurrentAttack(Vector2 FORCE){
GD.Print("Shooting attack");
_currentAttack.Shoot(FORCE);
_aiming = false;
}
}