diff --git a/Scenes/Levels/Components/Render.cs b/Scenes/Levels/Components/Render.cs index 8ec2ac7..9eea249 100644 --- a/Scenes/Levels/Components/Render.cs +++ b/Scenes/Levels/Components/Render.cs @@ -20,6 +20,7 @@ internal class Render public bool CanRotate = true; public float ZIndex = 0f; public float RotationAsRadians => RenderRotation * (float)(Math.PI / 180); + public Vector2 RotationAsVector2 => Vector2.Normalize(new Vector2((float)Math.Cos(RenderRotation), (float)Math.Sin(RenderRotation))); public Vector2 Position; public Color Color; diff --git a/Scenes/Levels/Components/Ship.cs b/Scenes/Levels/Components/Ship.cs index dc3d002..267bbeb 100644 --- a/Scenes/Levels/Components/Ship.cs +++ b/Scenes/Levels/Components/Ship.cs @@ -31,8 +31,6 @@ public Ship(HullType hull, BoatColor color, Team team) internal List Cannons = new List(); - internal int NextPatrolPoint = 1; - internal List Route = new(); internal float WindInSail; internal int Crew; @@ -45,10 +43,7 @@ public Ship(HullType hull, BoatColor color, Team team) internal float HalfSailSpeedModifier; internal float FullSailSpeedModifier; internal float SailSpeedEasing; - internal Vector2 Goal; internal float Currency; - internal Port? TargetPort; - internal List SailingRoute; public Task> NavTask { get; set; } } diff --git a/Scenes/Levels/Systems/EnemyAISystem.cs b/Scenes/Levels/Systems/EnemyAISystem.cs index e373d7c..88bc079 100644 --- a/Scenes/Levels/Systems/EnemyAISystem.cs +++ b/Scenes/Levels/Systems/EnemyAISystem.cs @@ -50,15 +50,13 @@ internal override void Update(World world) { if (npc.TargetPosition == Vector2.Zero) { - Console.WriteLine("fresh ship"); npc.TargetPosition = GetNearestPort(world, sprite.Position); } - if (npc.TargetPosition.DistanceTo(sprite.Position) < 200) { - Console.WriteLine("Port Hit!"); npc.TargetPosition = GetSecondNearestPort(world, sprite.Position); } + } }); } diff --git a/Scenes/Levels/Systems/EnemyControlSystem.cs b/Scenes/Levels/Systems/EnemyControlSystem.cs index e2225d9..4a52861 100644 --- a/Scenes/Levels/Systems/EnemyControlSystem.cs +++ b/Scenes/Levels/Systems/EnemyControlSystem.cs @@ -64,6 +64,11 @@ internal override void Update(World world) return; } + if (npc.TargetPosition.DistanceTo(sprite.Position) < 200) + { + npc.TimeSinceLastGoalChange += 100; + } + if (singleton.Debug >= DebugLevel.Low) Raylib.DrawLine((int)npc.TargetPosition.X, (int)npc.TargetPosition.Y, (int)sprite.Position.X, (int)sprite.Position.Y, Raylib.RED); @@ -116,9 +121,29 @@ internal override void Update(World world) } if (!centerGood && !leftGood) - npc.TargetOffsetInDegrees += 3; + { + var moveBy = tileFrontLeft?.MovementCost > 2 ? 3f : 1f; + + if (ship.Sail == SailStatus.Rowing) + moveBy = 1f; + + if (Math.Abs(npc.TargetOffsetInDegrees) > 90 && Vector2.Dot(sprite.RotationAsVector2, targetDirection) < 0) + npc.TargetOffsetInDegrees += 200; + else + npc.TargetOffsetInDegrees += moveBy; + } else if (!centerGood && !rightGood) - npc.TargetOffsetInDegrees -= 3; + { + var moveBy = tileFrontRight?.MovementCost > 2 ? 3f : 1f; + + if (ship.Sail == SailStatus.Rowing) + moveBy = 1f; + + if (Math.Abs(npc.TargetOffsetInDegrees) > 90 && Vector2.Dot(sprite.RotationAsVector2, targetDirection) < 0) + npc.TargetOffsetInDegrees -= 200; + else + npc.TargetOffsetInDegrees -= moveBy; + } else if (!leftGood) npc.TargetOffsetInDegrees += 2; else if (!rightGood) @@ -153,7 +178,7 @@ internal override void Update(World world) if (singleton.Debug > DebugLevel.None) { - Raylib.DrawText($"Route Size:{ship.Route?.Count} \nTarget:{ship.Route?.LastOrDefault()}", sprite.Position.X, sprite.Position.Y, 12, Raylib.RED); + //Raylib.DrawText($"Route Size:{ship.Route?.Count} \nTarget:{ship.Route?.LastOrDefault()}", sprite.Position.X, sprite.Position.Y, 12, Raylib.RED); } ship.Sail = SailStatus.Closed;