starting to work on enemy attacks and player health
This commit is contained in:
+1
-12
@@ -3,11 +3,9 @@ using System;
|
||||
|
||||
public partial class Commander : Sprite2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Commander THIS);
|
||||
[Signal]
|
||||
public delegate void ActionsUpEventHandler();
|
||||
public int _health = 10, _actionsMax = 1, _actions;
|
||||
public int _actionsMax = 1, _actions;
|
||||
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
|
||||
public Attack _attack;
|
||||
public PlayerController _playerController;
|
||||
@@ -47,15 +45,6 @@ public partial class Commander : Sprite2D
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Enemy ATTACKER)
|
||||
{
|
||||
_health -= DAMAGE;
|
||||
if (_health <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.Death, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShootCurrentAttack(Vector2 FORCE){
|
||||
|
||||
_attack.Shoot(FORCE);
|
||||
|
||||
@@ -12,7 +12,7 @@ public partial class Enemy : StaticBody2D
|
||||
[Signal]
|
||||
public delegate void RightClickedEventHandler(Enemy THIS);
|
||||
public bool _hovered = false, _track = false;
|
||||
public int _damage = 1, _health = 2, _speed, _speedRemaining, _visibilityRange = 4, _hitRange = 1;
|
||||
public int _damage = 1, _health = 2, _speed, _speedRemaining, _visibilityRange = 4, _hitRange;
|
||||
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
|
||||
public List<Vector2I> _path = new();
|
||||
public float _movement = 0;
|
||||
@@ -43,9 +43,9 @@ public partial class Enemy : StaticBody2D
|
||||
base._PhysicsProcess(delta);
|
||||
}
|
||||
|
||||
public void Attack(Commander COMMANDER)
|
||||
public void Attack(PlayerController PLAYER)
|
||||
{
|
||||
COMMANDER.TakeDamage(_damage, this);
|
||||
PLAYER.ChangeHealth(-1, this);
|
||||
}
|
||||
|
||||
public void CounterAttack(Commander COMMANDER)
|
||||
|
||||
+11
-8
@@ -40,6 +40,7 @@ public partial class EnemyController : TurnController
|
||||
newEnemy.RightClicked += HandleEnemyRightClick;
|
||||
|
||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||
newEnemy._hitRange = Globals._rng.Next(1,2+1);
|
||||
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
||||
newEnemy._enemyController = this;
|
||||
|
||||
@@ -50,14 +51,15 @@ public partial class EnemyController : TurnController
|
||||
|
||||
}
|
||||
|
||||
public void EnemyAttacks()
|
||||
public List<Enemy> EnemyAttacks()
|
||||
{
|
||||
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e._address.Y <= e._hitRange)];
|
||||
for (int i = 0; i < attackingEnemies.Count; i++)
|
||||
{
|
||||
Enemy enemy = attackingEnemies[i];
|
||||
// enemy.Attack();
|
||||
enemy.Attack(_playerController);
|
||||
}
|
||||
return attackingEnemies;
|
||||
}
|
||||
|
||||
public void GetRemainingSpeed(Enemy ENEMY)
|
||||
@@ -93,12 +95,13 @@ public partial class EnemyController : TurnController
|
||||
AddEnemies(positions);
|
||||
}
|
||||
|
||||
public void MoveEnemies()
|
||||
public void MoveEnemies(List<Enemy> EXCLUDE_ENEMIES)
|
||||
{
|
||||
Map map = _playArea._map;
|
||||
for (int i = 0; i < _enemies.Count; i++)
|
||||
List<Enemy> movingEnmies = [.. _enemies.Where(e => !EXCLUDE_ENEMIES.Contains(e))];
|
||||
for (int i = 0; i < movingEnmies.Count; i++)
|
||||
{
|
||||
Enemy enemy = _enemies[i];
|
||||
Enemy enemy = movingEnmies[i];
|
||||
GetRemainingSpeed(enemy);
|
||||
|
||||
if (enemy._speedRemaining > 0)
|
||||
@@ -112,7 +115,7 @@ public partial class EnemyController : TurnController
|
||||
}
|
||||
}
|
||||
|
||||
List<Enemy> remainingEnemies = GetRemainingEnemies(_enemies);
|
||||
List<Enemy> remainingEnemies = GetRemainingEnemies(movingEnmies);
|
||||
_enemies.ForEach(e => e._path.Clear());
|
||||
if (remainingEnemies.Count == 0)
|
||||
{
|
||||
@@ -196,9 +199,9 @@ public partial class EnemyController : TurnController
|
||||
{
|
||||
AddEnemies(1);
|
||||
|
||||
MoveEnemies();
|
||||
List<Enemy> attackingEnemies = EnemyAttacks();
|
||||
|
||||
EnemyAttacks();
|
||||
MoveEnemies(attackingEnemies);
|
||||
}
|
||||
|
||||
public void SetEnemy(Enemy ENEMY, Vector2I CELL)
|
||||
|
||||
@@ -24,6 +24,7 @@ public partial class Main : Node
|
||||
_enemyController._playArea = _playArea;
|
||||
|
||||
_playerController.TurnDone += ChangeTurn;
|
||||
_playerController.Death += EndGame;
|
||||
_enemyController.TurnDone += ChangeTurn;
|
||||
|
||||
_enemyController.Initiate();
|
||||
@@ -36,7 +37,7 @@ public partial class Main : Node
|
||||
base._Process(delta);
|
||||
if (Input.IsActionJustPressed("escape"))
|
||||
{
|
||||
GetTree().Quit();
|
||||
|
||||
}
|
||||
if (Input.IsActionJustPressed("changeTurn"))
|
||||
{
|
||||
@@ -62,4 +63,9 @@ public partial class Main : Node
|
||||
}
|
||||
}
|
||||
|
||||
public void EndGame(PlayerController PLAYER)
|
||||
{
|
||||
GetTree().Quit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,30 @@ using System.Linq;
|
||||
|
||||
public partial class PlayerController : TurnController
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(PlayerController THIS);
|
||||
public int _health, _healthMax = 100;
|
||||
public EnemyController _enemyController;
|
||||
public PackedScene _commanderScene = GD.Load<PackedScene>("res://Commander.tscn");
|
||||
public List<Tower> _towers = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_health = _healthMax;
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public void ChangeHealth(int DAMAGE, Node IMPETUS = null)
|
||||
{
|
||||
_health += DAMAGE;
|
||||
_health = Math.Clamp(_health, 0, _healthMax);
|
||||
GD.Print(_health);
|
||||
if (_health == 0)
|
||||
{
|
||||
EmitSignal(SignalName.Death, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckForTurnEnd()
|
||||
{
|
||||
if (_towers.Where(t => t._commander != null).ToList().All(t=>t._commander._actions == 0))
|
||||
|
||||
Reference in New Issue
Block a user