First builds and stuff done yipewaho
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using Godot;
|
||||
|
||||
public partial class DragArea : Area2D
|
||||
{
|
||||
public override void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx)
|
||||
{
|
||||
if (@event is InputEventMouseButton mb && mb.Pressed)
|
||||
{
|
||||
GD.Print("Area clicked");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bwgxw6ox8b1tq
|
||||
@@ -0,0 +1,76 @@
|
||||
using Godot;
|
||||
|
||||
public partial class DragMover : Node
|
||||
{
|
||||
[Export] public Node2D Parent; // The node that will move
|
||||
[Export] public Area2D DragArea; // Click detection
|
||||
[Export] public Area2D CheckArea; // Overlap validation
|
||||
[Export] public Area2D ShootArea; // This gets disabled while dragging
|
||||
|
||||
private bool _dragging;
|
||||
private Vector2 _dragOffset;
|
||||
private Vector2 _originalPosition;
|
||||
|
||||
private bool _canMove = true;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Parent == null || DragArea == null || CheckArea == null)
|
||||
{
|
||||
GD.PushError("DragMover exports are not assigned.");
|
||||
return;
|
||||
}
|
||||
|
||||
DragArea.InputEvent += OnDragAreaInputEvent;
|
||||
_originalPosition = Parent.GlobalPosition;
|
||||
}
|
||||
|
||||
private void OnDragAreaInputEvent(Node viewport, InputEvent @event, long shapeIdx)
|
||||
{
|
||||
if (!_canMove) return;
|
||||
if (@event is not InputEventMouseButton mb) return;
|
||||
if (mb.ButtonIndex != MouseButton.Left) return;
|
||||
|
||||
if (mb.Pressed)
|
||||
{
|
||||
_dragging = true;
|
||||
ShootArea.Monitoring = false;
|
||||
_originalPosition = Parent.GlobalPosition;
|
||||
|
||||
_dragOffset = Parent.GlobalPosition - Parent.GetGlobalMousePosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dragging = false;
|
||||
ShootArea.Monitoring = true;
|
||||
|
||||
// Check overlaps when released
|
||||
if (CheckArea.HasOverlappingAreas() || CheckArea.HasOverlappingBodies())
|
||||
{
|
||||
Parent.GlobalPosition = _originalPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
MovementDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!_dragging) return;
|
||||
|
||||
Parent.GlobalPosition = Parent.GetGlobalMousePosition() + _dragOffset;
|
||||
}
|
||||
|
||||
private async void MovementDelay()
|
||||
{
|
||||
ShootArea.Monitoring = false;
|
||||
_canMove = false;
|
||||
Parent.SetModulate(Color.FromHtml("ffffff20"));
|
||||
await ToSignal(GetTree().CreateTimer(4), SceneTreeTimer.SignalName.Timeout);
|
||||
Parent.SetModulate(Color.FromHtml("ffffffff"));
|
||||
ShootArea.Monitoring = true;
|
||||
_canMove = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bpqof3jshxnug
|
||||
@@ -11,6 +11,7 @@ public partial class Turret : Node
|
||||
[Export] private float _fireRate;
|
||||
[Export] private Node2D _parent;
|
||||
[Export] private ProjectilePool _projectilePool;
|
||||
[Export] private AudioStreamPlayer2D _audio;
|
||||
private float _fireTimer = 0f;
|
||||
|
||||
private HashSet<Enemy> _enemiesInRange = new HashSet<Enemy>();
|
||||
@@ -26,7 +27,6 @@ public partial class Turret : Node
|
||||
if (enemyHitBox is EnemyArea earea)
|
||||
{
|
||||
_enemiesInRange.Add(earea.Enemy);
|
||||
GD.Print(earea.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public partial class Turret : Node
|
||||
if (enemyHitBox is EnemyArea earea)
|
||||
{
|
||||
_enemiesInRange.Remove(earea.Enemy);
|
||||
GD.Print(earea.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +44,8 @@ public partial class Turret : Node
|
||||
_fireTimer += (float)delta;
|
||||
if (!(_fireTimer >= 1f / _fireRate)) return;
|
||||
_fireTimer = 0;
|
||||
_audio?.SetPitchScale(RandomHelper.Float(0.8f, 1.2f));
|
||||
_audio?.Play();
|
||||
var t = Helpers.GetClosest(_parent,_enemiesInRange.ToArray());
|
||||
var dir = (t.GlobalPosition - _parent.GlobalPosition).Normalized();
|
||||
var proj = _projectilePool.Get();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using Godot;
|
||||
|
||||
public partial class TurretPlaceholder : Node2D
|
||||
{
|
||||
[Export] private Area2D _placementChecker;
|
||||
[Export] public int Cost = 75;
|
||||
|
||||
public bool CanPlace { get; private set; }
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
CanPlace = !_placementChecker.HasOverlappingAreas() && !_placementChecker.HasOverlappingBodies();
|
||||
SetModulate(CanPlace ? Color.FromHtml("ffffff80") : Color.FromHtml("ff000080"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c4764ubjc3tan
|
||||
Reference in New Issue
Block a user