FINAL JAM COMMIT
This commit is contained in:
@@ -7,6 +7,7 @@ public partial class DragMover : Node
|
||||
[Export] public Area2D CheckArea; // Overlap validation
|
||||
[Export] public Area2D ShootArea; // This gets disabled while dragging
|
||||
|
||||
private bool _tresholdReached = false;
|
||||
private bool _dragging;
|
||||
private Vector2 _dragOffset;
|
||||
private Vector2 _originalPosition;
|
||||
@@ -30,36 +31,52 @@ public partial class DragMover : Node
|
||||
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;
|
||||
|
||||
Parent.SetModulate(Color.FromHtml("ffffff20"));
|
||||
_dragOffset = Parent.GlobalPosition - Parent.GetGlobalMousePosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dragging = false;
|
||||
ShootArea.Monitoring = true;
|
||||
|
||||
// Check overlaps when released
|
||||
if (CheckArea.HasOverlappingAreas() || CheckArea.HasOverlappingBodies())
|
||||
if (CheckArea.HasOverlappingAreas() || CheckArea.HasOverlappingBodies() || !_tresholdReached)
|
||||
{
|
||||
Parent.GlobalPosition = _originalPosition;
|
||||
Parent.SetModulate(Color.FromHtml("ffffffff"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MovementDelay();
|
||||
}
|
||||
_tresholdReached = false;
|
||||
_dragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if ((Parent.GetGlobalMousePosition() + _dragOffset).DistanceTo(_originalPosition) >= 10f && _dragging)
|
||||
{
|
||||
_tresholdReached = true;
|
||||
}
|
||||
|
||||
if ((Parent.GetGlobalMousePosition() + _dragOffset).DistanceTo(_originalPosition) <= 10f && !_tresholdReached) return;
|
||||
if (!_dragging) return;
|
||||
|
||||
if (CheckArea.HasOverlappingAreas() || CheckArea.HasOverlappingBodies())
|
||||
{
|
||||
Parent.SetModulate(Color.FromHtml("ff000020"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Parent.SetModulate(Color.FromHtml("ffffff20"));
|
||||
}
|
||||
|
||||
Parent.GlobalPosition = Parent.GetGlobalMousePosition() + _dragOffset;
|
||||
}
|
||||
|
||||
@@ -68,7 +85,7 @@ public partial class DragMover : Node
|
||||
ShootArea.Monitoring = false;
|
||||
_canMove = false;
|
||||
Parent.SetModulate(Color.FromHtml("ffffff20"));
|
||||
await ToSignal(GetTree().CreateTimer(4), SceneTreeTimer.SignalName.Timeout);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
Parent.SetModulate(Color.FromHtml("ffffffff"));
|
||||
ShootArea.Monitoring = true;
|
||||
_canMove = true;
|
||||
|
||||
@@ -13,9 +13,20 @@ public partial class Turret : Node
|
||||
[Export] private ProjectilePool _projectilePool;
|
||||
[Export] private AudioStreamPlayer2D _audio;
|
||||
private float _fireTimer = 0f;
|
||||
|
||||
|
||||
public int Level { get; private set; } = 1;
|
||||
public int UpgradeCost => 31 + (int)(31 * Math.Pow(Level, 1.75f));
|
||||
|
||||
public float FireRate => _fireRate + (Level - 1) * 0.05f;
|
||||
public float Damage => 25 + (int)(10 + Math.Pow(Level, 1.5f));
|
||||
|
||||
private HashSet<Enemy> _enemiesInRange = new HashSet<Enemy>();
|
||||
|
||||
public void Upgrade()
|
||||
{
|
||||
Level++;
|
||||
}
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_Attackrange.AreaEntered += EnemyEntered;
|
||||
@@ -42,7 +53,7 @@ public partial class Turret : Node
|
||||
{
|
||||
if (_enemiesInRange.Count == 0) return;
|
||||
_fireTimer += (float)delta;
|
||||
if (!(_fireTimer >= 1f / _fireRate)) return;
|
||||
if (!(_fireTimer >= 1f / FireRate)) return;
|
||||
_fireTimer = 0;
|
||||
_audio?.SetPitchScale(RandomHelper.Float(0.8f, 1.2f));
|
||||
_audio?.Play();
|
||||
@@ -50,6 +61,7 @@ public partial class Turret : Node
|
||||
var dir = (t.GlobalPosition - _parent.GlobalPosition).Normalized();
|
||||
var proj = _projectilePool.Get();
|
||||
proj.Direction = dir;
|
||||
proj.Damage = Damage;
|
||||
proj.GlobalPosition = _parent.GlobalPosition;
|
||||
proj.Rotation = dir.Angle();
|
||||
ProjectileParent.Instance.AddChild(proj);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public enum TurretType
|
||||
{
|
||||
@@ -11,10 +11,17 @@ public enum TurretType
|
||||
|
||||
public partial class TurretController : Node2D
|
||||
{
|
||||
[Export] private Dictionary<TurretType, PackedScene> _typeToPrefab;
|
||||
[Export] private Dictionary<TurretType, PackedScene> _typeToPlaceholder;
|
||||
public static TurretController Instance;
|
||||
|
||||
[Export] private Godot.Collections.Dictionary<TurretType, PackedScene> _typeToPrefab;
|
||||
[Export] private Godot.Collections.Dictionary<TurretType, PackedScene> _typeToPlaceholder;
|
||||
[Export] private Node2D _turretParent;
|
||||
|
||||
[Export] public int BasePrice;
|
||||
public int TurretAmount => _allTurrets.Count;
|
||||
|
||||
public int TurretPrice => BasePrice + (int)Math.Round(30f * Math.Pow(TurretAmount, 1.5f));
|
||||
|
||||
[Signal]
|
||||
public delegate void PlaceTurretEventHandler(TurretType t);
|
||||
|
||||
@@ -23,8 +30,11 @@ public partial class TurretController : Node2D
|
||||
private TurretPlaceholder _turretPlaceholder;
|
||||
private TurretType _currentlyPlacingType;
|
||||
|
||||
private HashSet<Node2D> _allTurrets = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
PlaceTurret += StartPlaceingTurret;
|
||||
}
|
||||
|
||||
@@ -40,8 +50,9 @@ public partial class TurretController : Node2D
|
||||
{
|
||||
case MouseButton.Left:
|
||||
if (!_turretPlaceholder.CanPlace) return;
|
||||
if (!GameController.Instance.TryRemoveCurrency(_turretPlaceholder.Cost)) return;
|
||||
if (!GameController.Instance.TryRemoveCurrency(TurretPrice)) return;
|
||||
var newT = _typeToPrefab[_currentlyPlacingType].Instantiate() as Node2D;
|
||||
_allTurrets.Add(newT);
|
||||
_turretParent.AddChild(newT);
|
||||
newT.GlobalPosition = mpos;
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
public partial class TurretUpgrader : Node
|
||||
{
|
||||
[Export] private Turret _turret;
|
||||
[Export] private Area2D _clickArea;
|
||||
[Export] private Control _ui;
|
||||
[Export] private Label _costLabel;
|
||||
[Export] private Label _damageLabel;
|
||||
[Export] private Label _fireRateLabel;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_clickArea.InputEvent += OnClickAreaInputEvent;
|
||||
_clickArea.MouseEntered += MouseEntered;
|
||||
_clickArea.MouseExited += MouseExited;
|
||||
}
|
||||
|
||||
private void OnClickAreaInputEvent(Node viewport, InputEvent @event, long shapeIdx)
|
||||
{
|
||||
if (@event is not InputEventMouseButton m)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m.ButtonIndex != MouseButton.Right) return;
|
||||
|
||||
if (!GameController.Instance.TryRemoveCurrency(_turret.UpgradeCost)) return;
|
||||
_turret.Upgrade();
|
||||
_costLabel.Text = _turret.UpgradeCost.ToString();
|
||||
_damageLabel.Text = _turret.Damage.ToString();
|
||||
_fireRateLabel.Text = _turret.FireRate.ToString();
|
||||
}
|
||||
|
||||
private void MouseEntered()
|
||||
{
|
||||
if (_ui == null) return;
|
||||
_ui.Visible = true;
|
||||
_costLabel.Text = _turret.UpgradeCost.ToString();
|
||||
_damageLabel.Text = _turret.Damage.ToString();
|
||||
_fireRateLabel.Text = _turret.FireRate.ToString();
|
||||
}
|
||||
|
||||
private void MouseExited()
|
||||
{
|
||||
if (_ui == null) return;
|
||||
_ui.Visible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://qf0qrqg0l7np
|
||||
Reference in New Issue
Block a user