FINAL JAM COMMIT
This commit is contained in:
@@ -8,9 +8,11 @@ public partial class GameController : Node
|
||||
[Export] private float _ShrineStartHP;
|
||||
[Export] private Label _CurrencyLabel;
|
||||
[Export] private Label _ShrineHealthLabel;
|
||||
[Export] private Label _scoreLabel;
|
||||
|
||||
public int Wave { get; private set; }
|
||||
public int Currency { get; private set; }
|
||||
public int Score { get; private set; }
|
||||
public float ShrineHealth { get; private set; }
|
||||
|
||||
private bool _waveOnGoing = false;
|
||||
@@ -20,10 +22,11 @@ public partial class GameController : Node
|
||||
GameController.Instance = this;
|
||||
Wave = 0;
|
||||
Currency = 300;
|
||||
ShrineHealth = 100;
|
||||
|
||||
ShrineHealth = _ShrineStartHP;
|
||||
|
||||
_CurrencyLabel.Text = Currency.ToString();
|
||||
_ShrineHealthLabel.Text = $"{(100f * (ShrineHealth /_ShrineStartHP)):F1}%";
|
||||
_scoreLabel.Text = "0";
|
||||
|
||||
CallDeferred(nameof(DelayNextWave));
|
||||
}
|
||||
@@ -34,12 +37,7 @@ public partial class GameController : Node
|
||||
Wave++;
|
||||
_waveOnGoing = true;
|
||||
|
||||
int amountToSpawn = (int)Math.Round(5 * Math.Pow(Wave, 1.05));
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
// GD.Print((int)Math.Round(5 * Math.Pow(i + 1, 1.05)));
|
||||
}
|
||||
int amountToSpawn = (int)Math.Round(5 * Math.Pow(Wave, 1.025));
|
||||
|
||||
EnemySpawner.Instance.EnemiesSpawned = amountToSpawn;
|
||||
|
||||
@@ -73,7 +71,7 @@ public partial class GameController : Node
|
||||
_ShrineHealthLabel.Text = $"{(100f * (ShrineHealth /_ShrineStartHP)):F1}%";
|
||||
if (ShrineHealth <= 0)
|
||||
{
|
||||
// TODO LOSE SCENARIO
|
||||
SceneManager.Instance.ChangeScene(Scenes.End);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +79,8 @@ public partial class GameController : Node
|
||||
{
|
||||
v = Math.Abs(v);
|
||||
Currency += v;
|
||||
Score += v;
|
||||
_scoreLabel.Text = Score.ToString();
|
||||
_CurrencyLabel.Text = Currency.ToString();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PauseManager : Node
|
||||
{
|
||||
[Export] private CanvasLayer _hud;
|
||||
[Export] private CanvasLayer _pauseMenu;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("pause"))
|
||||
{
|
||||
bool paused = GetTree().Paused;
|
||||
if (!paused)
|
||||
{
|
||||
PauseGame();
|
||||
return;
|
||||
}
|
||||
ContinueGame();
|
||||
}
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
GetTree().Paused = true;
|
||||
_hud.Visible = false;
|
||||
_pauseMenu.Visible = true;
|
||||
}
|
||||
|
||||
public void ContinueGame()
|
||||
{
|
||||
GetTree().Paused = false;
|
||||
_hud.Visible = true;
|
||||
_pauseMenu.Visible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ch2o7voah6o3o
|
||||
@@ -0,0 +1,84 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public enum Scenes
|
||||
{
|
||||
Menu,
|
||||
Game,
|
||||
End
|
||||
}
|
||||
|
||||
public partial class SceneManager : Node
|
||||
{
|
||||
public static SceneManager Instance;
|
||||
|
||||
[Export] private Node _root;
|
||||
|
||||
[Export] private PackedScene _gameScene;
|
||||
[Export] private PackedScene _menuScene;
|
||||
[Export] private PackedScene _endScene;
|
||||
|
||||
private Node _game;
|
||||
private Node _menu;
|
||||
private Node _end;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
CallDeferred(nameof(EnterMenu));
|
||||
}
|
||||
|
||||
public void ChangeScene(Scenes s)
|
||||
{
|
||||
GetTree().Paused = false;
|
||||
switch (s)
|
||||
{
|
||||
case Scenes.Menu:
|
||||
EnterMenu();
|
||||
break;
|
||||
case Scenes.Game:
|
||||
EnterGame();
|
||||
break;
|
||||
case Scenes.End:
|
||||
EnterEnd();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(s), s, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterMenu()
|
||||
{
|
||||
RemoveScene(ref _game);
|
||||
RemoveScene(ref _end);
|
||||
AddScene(ref _menuScene, ref _menu);
|
||||
}
|
||||
|
||||
private void EnterGame()
|
||||
{
|
||||
RemoveScene(ref _menu);
|
||||
RemoveScene(ref _end);
|
||||
AddScene(ref _gameScene, ref _game);
|
||||
}
|
||||
|
||||
private void EnterEnd() // Not the Minecraft
|
||||
{
|
||||
RemoveScene(ref _game);
|
||||
RemoveScene(ref _menu);
|
||||
AddScene(ref _endScene, ref _end);
|
||||
}
|
||||
|
||||
private void RemoveScene(ref Node n)
|
||||
{
|
||||
if (n == null) return;
|
||||
n.GetParent()?.RemoveChild(n);
|
||||
n.QueueFree();
|
||||
n = null;
|
||||
}
|
||||
|
||||
private void AddScene(ref PackedScene s, ref Node n)
|
||||
{
|
||||
n = s.Instantiate();
|
||||
_root.AddChild(n);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bmdb22du7uvr1
|
||||
@@ -8,7 +8,7 @@ public partial class EnemyMovement : Node
|
||||
[Export] private float _speed;
|
||||
|
||||
private float _finalSpeed => _speed + 0.15f * (float)Math.Log(GameController.Instance.Wave + 1);
|
||||
|
||||
|
||||
private double _time = 0;
|
||||
|
||||
public override void _EnterTree()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -53,10 +54,10 @@ public partial class EnemyPool : Node
|
||||
|
||||
private void Died(Enemy e)
|
||||
{
|
||||
GameController.Instance.AddCurrency(25);
|
||||
GameController.Instance.AddCurrency((int)Math.Floor(e.Health.MaxHP));
|
||||
ReturnToPool(e);
|
||||
}
|
||||
|
||||
|
||||
private void ReturnToPool(Enemy e)
|
||||
{
|
||||
EnemySpawner.Instance.EnemiesSpawned--;
|
||||
|
||||
@@ -13,6 +13,7 @@ public partial class Projectile : Node2D
|
||||
|
||||
public event Action<Projectile> OnDespawn;
|
||||
public Vector2 Direction;
|
||||
public float Damage;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -34,7 +35,7 @@ public partial class Projectile : Node2D
|
||||
if (area is EnemyArea earea)
|
||||
{
|
||||
float isSe = _superEffective.Contains(earea.Enemy.Type) ? 2f : 1f;
|
||||
earea.Enemy.Health.Substract(_baseDamage * isSe);
|
||||
earea.Enemy.Health.Substract(Damage * isSe);
|
||||
}
|
||||
|
||||
CallDeferred(nameof(Despawn));
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PriceUpdater : Label
|
||||
{
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
Text = TurretController.Instance.TurretPrice.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://fxb27qlab5nb
|
||||
@@ -0,0 +1,4 @@
|
||||
extends TextureButton
|
||||
|
||||
func _on_QuitButton_pressed():
|
||||
get_tree().quit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dsjivlkkwvwqs
|
||||
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
|
||||
public partial class SceneChangerBtn : TextureButton
|
||||
{
|
||||
[Export] private Scenes _changeTo;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
ButtonUp += Change;
|
||||
}
|
||||
|
||||
private void Change()
|
||||
{
|
||||
SceneManager.Instance.ChangeScene(_changeTo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bsmpt1ig823du
|
||||
Reference in New Issue
Block a user