still updating enemy movement and pathing and tweening
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 250 B |
@@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://m4wfj36twmqy"
|
||||||
|
path="res://.godot/imported/attack.png-c625624f48e39eb3c9d0bdfb20bcabb8.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Art/attack.png"
|
||||||
|
dest_files=["res://.godot/imported/attack.png-c625624f48e39eb3c9d0bdfb20bcabb8.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
@@ -13,7 +13,7 @@ public partial class Enemy : StaticBody2D
|
|||||||
[Signal]
|
[Signal]
|
||||||
public delegate void RightClickedEventHandler(Enemy THIS);
|
public delegate void RightClickedEventHandler(Enemy THIS);
|
||||||
public bool _hovered = false, _track = false, _warp = false;
|
public bool _hovered = false, _track = false, _warp = false;
|
||||||
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange;
|
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1;
|
||||||
public Dictionary<string, int> _priorities = new()
|
public Dictionary<string, int> _priorities = new()
|
||||||
{
|
{
|
||||||
{"attack", 0}, // 0 to 999999 reserved for attacking priorities
|
{"attack", 0}, // 0 to 999999 reserved for attacking priorities
|
||||||
@@ -23,10 +23,12 @@ public partial class Enemy : StaticBody2D
|
|||||||
public List<Vector2I> _path = new(), _pathStored = new();
|
public List<Vector2I> _path = new(), _pathStored = new();
|
||||||
public float _movement = 0;
|
public float _movement = 0;
|
||||||
public EnemyController _enemyController;
|
public EnemyController _enemyController;
|
||||||
|
public Sprite2D _attack;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
|
_attack = GetNode<Sprite2D>("Attack");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
@@ -49,31 +51,37 @@ public partial class Enemy : StaticBody2D
|
|||||||
base._PhysicsProcess(delta);
|
base._PhysicsProcess(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AnimateMovement(EnemyController CONTROLLER)
|
public void Attack(EnemyController CONTROLLER)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _path.Count; i++)
|
_attack.Visible = true;
|
||||||
|
Tween subtween = CreateTween();
|
||||||
|
subtween.TweenProperty(_attack, "global_position", Vector2.Zero, 0.5f);
|
||||||
|
subtween.TweenCallback(Callable.From(() =>
|
||||||
{
|
{
|
||||||
Tween subtween = CreateTween();
|
CONTROLLER._playerController.ChangeHealth(-1, this);
|
||||||
subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(_path[i]), 0.25f);
|
_attack.Position = Vector2.Zero;
|
||||||
int key = _priorities["movement"] + i;
|
_attack.Visible = false;
|
||||||
|
}));
|
||||||
|
int key = _priorities["attack"];
|
||||||
|
|
||||||
if (!CONTROLLER._tweenStages.ContainsKey(key))
|
if (!CONTROLLER._tweenStages.ContainsKey(key))
|
||||||
{
|
{
|
||||||
CONTROLLER._tweenStages[key] = new();
|
CONTROLLER._tweenStages[key] = new();
|
||||||
}
|
|
||||||
CONTROLLER._tweenStages[key].Add(subtween);
|
|
||||||
}
|
}
|
||||||
|
CONTROLLER._tweenStages[key].Add(subtween);
|
||||||
|
_staminaRemaining = Math.Max(_staminaRemaining - 2, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attack(PlayerController PLAYER)
|
public bool CanAttack(EnemyController CONTROLLER)
|
||||||
{
|
{
|
||||||
PLAYER.ChangeHealth(-1, this);
|
return _staminaRemaining > 0 && _address.Y <= _hitRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanAttack()
|
public bool CanMove(EnemyController CONTROLLER)
|
||||||
{
|
{
|
||||||
return _address.Y <= _hitRange;
|
// GD.Print(_staminaRemaining," ",_address.Y," ", CONTROLLER._playArea._map._firstOpenRow);
|
||||||
|
return _staminaRemaining > 0 && _address.Y > CONTROLLER._playArea._map._firstOpenRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CounterAttack(Commander COMMANDER)
|
public void CounterAttack(Commander COMMANDER)
|
||||||
@@ -81,11 +89,6 @@ public partial class Enemy : StaticBody2D
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<Vector2I> GetGoals(Map MAP)
|
|
||||||
{
|
|
||||||
return [.. MAP._cells.Where(c => c.Y == Math.Max(_address.Y - _visibilityRange, MAP._firstOpenRow)).Where(c => !MAP._astar.IsPointSolid(c))];
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual List<Vector2I> GetBestPath(Map MAP)
|
public virtual List<Vector2I> GetBestPath(Map MAP)
|
||||||
{
|
{
|
||||||
List<Vector2I> goals = GetGoals(MAP);
|
List<Vector2I> goals = GetGoals(MAP);
|
||||||
@@ -95,10 +98,33 @@ public partial class Enemy : StaticBody2D
|
|||||||
{
|
{
|
||||||
paths.Add(MAP.GetPath(_address, goals[i]));
|
paths.Add(MAP.GetPath(_address, goals[i]));
|
||||||
}
|
}
|
||||||
List<Vector2I> bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ThenBy(p => p.Last().X % 2).ToList()[0];
|
List<Vector2I> bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ToList()[0];
|
||||||
return bestPath;
|
return bestPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual List<Vector2I> GetGoals(Map MAP)
|
||||||
|
{
|
||||||
|
return [.. MAP._cells.Where(c => c.Y == Math.Max(_address.Y - _visibilityRange, MAP._firstOpenRow)).Where(c => !MAP._astar.IsPointSolid(c))];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Move(Vector2I PATH_STEP, EnemyController CONTROLLER)
|
||||||
|
{
|
||||||
|
CONTROLLER._playArea._map.SetCellEnemy(PATH_STEP, this);
|
||||||
|
_path.Add(PATH_STEP);
|
||||||
|
|
||||||
|
Tween subtween = CreateTween();
|
||||||
|
subtween.TweenProperty(this, "global_position", CONTROLLER._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
|
||||||
|
int key = _priorities["movement"] + CONTROLLER._actionLoop;
|
||||||
|
|
||||||
|
if (!CONTROLLER._tweenStages.ContainsKey(key))
|
||||||
|
{
|
||||||
|
CONTROLLER._tweenStages[key] = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
CONTROLLER._tweenStages[key].Add(subtween);
|
||||||
|
_staminaRemaining--;
|
||||||
|
}
|
||||||
|
|
||||||
public void StartTurn()
|
public void StartTurn()
|
||||||
{
|
{
|
||||||
_staminaRemaining = _stamina;
|
_staminaRemaining = _stamina;
|
||||||
|
|||||||
+62
-63
@@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
public partial class EnemyController : TurnController
|
public partial class EnemyController : TurnController
|
||||||
{
|
{
|
||||||
|
public int _actionLoop = 0;
|
||||||
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||||
public List<Enemy> _enemies = new();
|
public List<Enemy> _enemies = new(), _remainingEnemies = new();
|
||||||
public PlayerController _playerController;
|
public PlayerController _playerController;
|
||||||
public Dictionary<int, List<Tween>> _tweenStages = new();
|
public Dictionary<int, List<Tween>> _tweenStages = new();
|
||||||
public Tween _tween;
|
public Tween _tween;
|
||||||
@@ -19,7 +19,7 @@ public partial class EnemyController : TurnController
|
|||||||
for (int i = 0; i < ENEMY_COUNT; i++)
|
for (int i = 0; i < ENEMY_COUNT; i++)
|
||||||
{
|
{
|
||||||
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
||||||
newEnemy.Death += RemoveEnemy;
|
newEnemy.Death += HandleEnemyRemoval;
|
||||||
newEnemy.Clicked += HandleEnemyClick;
|
newEnemy.Clicked += HandleEnemyClick;
|
||||||
newEnemy.RightClicked += HandleEnemyRightClick;
|
newEnemy.RightClicked += HandleEnemyRightClick;
|
||||||
|
|
||||||
@@ -38,13 +38,13 @@ public partial class EnemyController : TurnController
|
|||||||
for (int i = 0; i < POSITIONS.Count; i++)
|
for (int i = 0; i < POSITIONS.Count; i++)
|
||||||
{
|
{
|
||||||
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
||||||
newEnemy.Death += RemoveEnemy;
|
newEnemy.Death += HandleEnemyRemoval;
|
||||||
newEnemy.Clicked += HandleEnemyClick;
|
newEnemy.Clicked += HandleEnemyClick;
|
||||||
newEnemy.RightClicked += HandleEnemyRightClick;
|
newEnemy.RightClicked += HandleEnemyRightClick;
|
||||||
|
|
||||||
newEnemy._stamina = Globals._rng.Next(2,4+1);
|
newEnemy._stamina = Globals._rng.Next(2,4+1);
|
||||||
newEnemy._hitRange = Globals._rng.Next(1,2+1);
|
newEnemy._hitRange = Globals._rng.Next(1,2+1);
|
||||||
newEnemy.Modulate = new Color(newEnemy._stamina == 2 ? "#FF0000" : newEnemy._stamina == 3 ? "#00FF00" : "#0000FF");
|
newEnemy.GetNode<Sprite2D>("Sprite2D").SelfModulate = new Color(newEnemy._stamina == 2 ? "#FF0000" : newEnemy._stamina == 3 ? "#00FF00" : "#0000FF");
|
||||||
newEnemy._enemyController = this;
|
newEnemy._enemyController = this;
|
||||||
|
|
||||||
SetEnemy(newEnemy, POSITIONS[i]);
|
SetEnemy(newEnemy, POSITIONS[i]);
|
||||||
@@ -54,59 +54,35 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuildAnimationTween()
|
public void HandleEnemyActions()
|
||||||
{
|
{
|
||||||
|
_actionLoop = 0;
|
||||||
_tweenStages.Clear();
|
_tweenStages.Clear();
|
||||||
for (int i= 0; i < _enemies.Count; i++)
|
|
||||||
{
|
|
||||||
Enemy enemy = _enemies[i];
|
|
||||||
enemy.AnimateMovement(this);
|
|
||||||
}
|
|
||||||
_tweenStages.OrderBy(s => s.Key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BuildEnemyPaths()
|
|
||||||
{
|
|
||||||
Map map = _playArea._map;
|
Map map = _playArea._map;
|
||||||
|
|
||||||
_enemies.ForEach(e => e._path.Clear());
|
_enemies.ForEach(e => e._path.Clear());
|
||||||
while (_enemies.Any(e => e._staminaRemaining > 0))
|
|
||||||
|
_remainingEnemies = [.. _enemies.Where(e => e.CanMove(this) || e.CanAttack(this))];
|
||||||
|
while (_remainingEnemies.Count > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _enemies.Count; i++)
|
for (int i = 0; i < _remainingEnemies.Count; i++)
|
||||||
{
|
{
|
||||||
Enemy enemy = _enemies[i];
|
Enemy enemy = _remainingEnemies[i];
|
||||||
if (enemy._staminaRemaining <= 0 || enemy._address.Y <= map._firstOpenRow)
|
HandleEnemyPathing(enemy);
|
||||||
{
|
HandleEnemyAttacking(enemy);
|
||||||
GD.Print(enemy._staminaRemaining <= 0, enemy._address.Y <= map._firstOpenRow);
|
HandleEnemyStaminaCheck(enemy);
|
||||||
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Vector2I> path = enemy.GetBestPath(map);
|
|
||||||
|
|
||||||
if (path.Count == 0)
|
|
||||||
{
|
|
||||||
enemy._path.Add(enemy._path.LastOrDefault(enemy._address));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Vector2I cell = path[0];
|
|
||||||
map.SetCellEnemy(cell, enemy);
|
|
||||||
enemy._path.Add(cell);
|
|
||||||
|
|
||||||
enemy._staminaRemaining--;
|
|
||||||
}
|
}
|
||||||
|
_actionLoop++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnemyAttacks()
|
public void HandleEnemyAttacking(Enemy ENEMY)
|
||||||
{
|
{
|
||||||
List<Enemy> attackingEnemies = [.. _enemies.Where(e => e.CanAttack())];
|
if (!ENEMY.CanAttack(this))
|
||||||
for (int i = 0; i < attackingEnemies.Count; i++)
|
|
||||||
{
|
{
|
||||||
Enemy enemy = attackingEnemies[i];
|
return;
|
||||||
enemy.Attack(_playerController);
|
|
||||||
enemy._staminaRemaining = Math.Max(enemy._staminaRemaining - 2, 0);
|
|
||||||
}
|
}
|
||||||
|
ENEMY.Attack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +104,44 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public void HandleEnemyRightClick(Enemy ENEMY)
|
public void HandleEnemyRightClick(Enemy ENEMY)
|
||||||
{
|
{
|
||||||
RemoveEnemy(ENEMY);
|
HandleEnemyRemoval(ENEMY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleEnemyPathing(Enemy ENEMY)
|
||||||
|
{
|
||||||
|
if (!ENEMY.CanMove(this))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Vector2I> path = ENEMY.GetBestPath(_playArea._map);
|
||||||
|
|
||||||
|
if (path.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENEMY.Move(path[0], this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleEnemyRemoval(Enemy ENEMY_TO_REMOVE)
|
||||||
|
{
|
||||||
|
_enemies.Remove(ENEMY_TO_REMOVE);
|
||||||
|
_playArea._map.SetCellEnemy(ENEMY_TO_REMOVE._address, null);
|
||||||
|
ENEMY_TO_REMOVE.QueueFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleEnemySort()
|
||||||
|
{
|
||||||
|
_enemies = [.. _enemies.OrderBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleEnemyStaminaCheck(Enemy ENEMY)
|
||||||
|
{
|
||||||
|
if (ENEMY._staminaRemaining <= 0)
|
||||||
|
{
|
||||||
|
_remainingEnemies.Remove(ENEMY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initiate()
|
public void Initiate()
|
||||||
@@ -140,6 +153,7 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
public void ProcessTween()
|
public void ProcessTween()
|
||||||
{
|
{
|
||||||
|
_tweenStages.OrderBy(s => s.Key);
|
||||||
|
|
||||||
if (_tweenStages.Count <= 0)
|
if (_tweenStages.Count <= 0)
|
||||||
{
|
{
|
||||||
@@ -167,20 +181,9 @@ public partial class EnemyController : TurnController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
|
||||||
{
|
|
||||||
_enemies.Remove(ENEMY_TO_REMOVE);
|
|
||||||
_playArea._map.SetCellEnemy(ENEMY_TO_REMOVE._address, null);
|
|
||||||
ENEMY_TO_REMOVE.QueueFree();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SortEnemies()
|
|
||||||
{
|
|
||||||
_enemies = [.. _enemies.OrderBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void StartTurn()
|
public override void StartTurn()
|
||||||
{
|
{
|
||||||
|
|
||||||
AddEnemies(1);
|
AddEnemies(1);
|
||||||
|
|
||||||
for (int i = 0; i < _enemies.Count; i++)
|
for (int i = 0; i < _enemies.Count; i++)
|
||||||
@@ -188,13 +191,9 @@ public partial class EnemyController : TurnController
|
|||||||
_enemies[i].StartTurn();
|
_enemies[i].StartTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
SortEnemies();
|
HandleEnemySort();
|
||||||
|
|
||||||
EnemyAttacks();
|
HandleEnemyActions();
|
||||||
|
|
||||||
BuildEnemyPaths();
|
|
||||||
|
|
||||||
BuildAnimationTween();
|
|
||||||
|
|
||||||
ProcessTween();
|
ProcessTween();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://Enemy.cs" id="1_4gyqm"]
|
[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://Enemy.cs" id="1_4gyqm"]
|
||||||
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="1_7k104"]
|
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="1_7k104"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://m4wfj36twmqy" path="res://Art/attack.png" id="3_qi2p4"]
|
||||||
|
|
||||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
||||||
bounce = 0.5
|
bounce = 0.5
|
||||||
@@ -18,8 +19,14 @@ script = ExtResource("1_4gyqm")
|
|||||||
shape = SubResource("CircleShape2D_4gyqm")
|
shape = SubResource("CircleShape2D_4gyqm")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
||||||
|
texture_filter = 1
|
||||||
scale = Vector2(0.5, 0.5)
|
scale = Vector2(0.5, 0.5)
|
||||||
texture = ExtResource("1_7k104")
|
texture = ExtResource("1_7k104")
|
||||||
|
|
||||||
|
[node name="Attack" type="Sprite2D" parent="." unique_id=1776738311]
|
||||||
|
visible = false
|
||||||
|
texture_filter = 1
|
||||||
|
texture = ExtResource("3_qi2p4")
|
||||||
|
|
||||||
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
||||||
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
||||||
|
|||||||
Reference in New Issue
Block a user