First builds and stuff done yipewaho
This commit is contained in:
@@ -1,8 +1,78 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace fgj26.Scripts.Turrets;
|
||||
public enum TurretType
|
||||
{
|
||||
Kitsune,
|
||||
Oni,
|
||||
Tengu
|
||||
}
|
||||
|
||||
public partial class TurretController : Node2D
|
||||
{
|
||||
|
||||
}
|
||||
[Export] private Dictionary<TurretType, PackedScene> _typeToPrefab;
|
||||
[Export] private Dictionary<TurretType, PackedScene> _typeToPlaceholder;
|
||||
[Export] private Node2D _turretParent;
|
||||
|
||||
[Signal]
|
||||
public delegate void PlaceTurretEventHandler(TurretType t);
|
||||
|
||||
private bool _placingTurret = false;
|
||||
|
||||
private TurretPlaceholder _turretPlaceholder;
|
||||
private TurretType _currentlyPlacingType;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
PlaceTurret += StartPlaceingTurret;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (_turretPlaceholder == null) return;
|
||||
if (!_placingTurret) return;
|
||||
var mpos = GetGlobalMousePosition();
|
||||
_turretPlaceholder.GlobalPosition = mpos;
|
||||
if (@event is InputEventMouseButton mb)
|
||||
{
|
||||
switch (mb.ButtonIndex)
|
||||
{
|
||||
case MouseButton.Left:
|
||||
if (!_turretPlaceholder.CanPlace) return;
|
||||
if (!GameController.Instance.TryRemoveCurrency(_turretPlaceholder.Cost)) return;
|
||||
var newT = _typeToPrefab[_currentlyPlacingType].Instantiate() as Node2D;
|
||||
_turretParent.AddChild(newT);
|
||||
newT.GlobalPosition = mpos;
|
||||
break;
|
||||
case MouseButton.Right:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
StopPlacingTurret();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartPlaceingTurret(TurretType t)
|
||||
{
|
||||
if (_turretPlaceholder != null)
|
||||
{
|
||||
_turretPlaceholder.GetParent()?.RemoveChild(_turretPlaceholder);
|
||||
_turretPlaceholder.QueueFree();
|
||||
}
|
||||
|
||||
_turretPlaceholder = _typeToPlaceholder[t].Instantiate() as TurretPlaceholder;
|
||||
_turretParent.AddChild(_turretPlaceholder);
|
||||
_currentlyPlacingType = t;
|
||||
_placingTurret = true;
|
||||
}
|
||||
|
||||
private void StopPlacingTurret()
|
||||
{
|
||||
_turretPlaceholder.GetParent()?.RemoveChild(_turretPlaceholder);
|
||||
_turretPlaceholder.QueueFree();
|
||||
_turretPlaceholder = null;
|
||||
_placingTurret = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user