diff --git a/Scenes/Levels/OceanScene.cs b/Scenes/Levels/OceanScene.cs index d68d246..6c8eb5a 100644 --- a/Scenes/Levels/OceanScene.cs +++ b/Scenes/Levels/OceanScene.cs @@ -57,6 +57,7 @@ internal OceanScene() Systems.Add(new NavigationSystem()); Systems.Add(new PlayerControlSystem()); Systems.Add(new PortSystem()); + Systems.Add(new EnemyAISystem()); Systems.Add(new UiSystem()); }); } diff --git a/Scenes/Levels/Systems/EnemyControlSystem.cs b/Scenes/Levels/Systems/EnemyControlSystem.cs index 26edd24..b7a7144 100644 --- a/Scenes/Levels/Systems/EnemyControlSystem.cs +++ b/Scenes/Levels/Systems/EnemyControlSystem.cs @@ -43,10 +43,11 @@ internal override void Update(World world) } } - if (ship.BoatCondition == BoatCondition.Empty) - { - sprite.Position += wind.WindDirection * Raylib.GetFrameTime() * wind.WindStrength * .1f; - } + //if (ship.BoatCondition == BoatCondition.Empty) + //{ + // sprite.Position += wind.WindDirection * Raylib.GetFrameTime() * wind.WindStrength * .1f; + //} + if (ship.HullHealth < 0) { ship.Crew = 0; @@ -54,111 +55,112 @@ internal override void Update(World world) sprite.Color.a = (byte)(255 * percent); ship.HullHealth -= Raylib.GetFrameTime(); } + if (ship.HullHealth <= -100) { world.Destroy(entity); return; } - var maxPatrolPoint = 0; + //var maxPatrolPoint = 0; - var npc = entity.Get(); - if (npc.Purpose == Purpose.Patrol) - { - if (ship.Goal == Vector2.Zero) - { - world.Query(in patrolQuery, (patrolEntity) => - { - var point = patrolEntity.Get(); - maxPatrolPoint = Math.Max(maxPatrolPoint, point.Order); - if (point.Order == ship.NextPatrolPoint) - { - ship.Goal = point.Position; - } - }); - } - } - if (npc.Purpose == Purpose.Trade) - { - if (ship.Route.Count == 0) - { - ship.Route = ship.SailingRoute.First().RoutePoints; - ship.SailingRoute.Add(ship.SailingRoute.First()); - ship.SailingRoute.RemoveAt(0); - } - } - else if (npc.Purpose == Purpose.Patrol) - { - if ((ship.Route.Count < 10)) + //var npc = entity.Get(); + //if (npc.Purpose == Purpose.Patrol) + //{ + // if (ship.Goal == Vector2.Zero) + // { + // world.Query(in patrolQuery, (patrolEntity) => + // { + // var point = patrolEntity.Get(); + // maxPatrolPoint = Math.Max(maxPatrolPoint, point.Order); + // if (point.Order == ship.NextPatrolPoint) + // { + // ship.Goal = point.Position; + // } + // }); + // } + //} + //if (npc.Purpose == Purpose.Trade) + //{ + // if (ship.Route.Count == 0) + // { + // ship.Route = ship.SailingRoute.First().RoutePoints; + // ship.SailingRoute.Add(ship.SailingRoute.First()); + // ship.SailingRoute.RemoveAt(0); + // } + //} + //else if (npc.Purpose == Purpose.Patrol) + //{ + // if ((ship.Route.Count < 10)) - { - if (ship.NavTask == null) - ship.NavTask = new Task>(() => NavigationUtilities.CalculateRouteFromShip(world, entity).ToList()); - - if (ship.NavTask.IsCompleted) - { - ship.Route = ship.NavTask.Result; - ship.NavTask = null; - } - else if (ship.NavTask.Status == TaskStatus.Created) - { - ship.NavTask.Start(); - } - } - } - var sailTargetVec = ship.Route?.FirstOrDefault(); - if (sailTargetVec is not null) - { - ship.Target = sailTargetVec.Value; - if (sprite.Position.DistanceTo(ship.Target) < 300) - { - if (ship.Route?.Count > 0) - ship.Route?.RemoveAt(0); - - if (ship.Route?.Count == 0 && npc.Purpose == Purpose.Patrol) - { - ship.NextPatrolPoint += 1; - if (ship.NextPatrolPoint > maxPatrolPoint) - ship.NextPatrolPoint = 1; - } - if (ship.Route?.Count == 0 && npc.Purpose == Purpose.Trade) - { - ship.Goal = Vector2.Zero; - var availableMoney = 10; - //ship.TargetPort.Currency -= availableMoney; - ship.Currency += availableMoney; - } - } - if (singleton.Debug >= DebugLevel.Low) - Raylib.DrawLine((int)ship.Target.X, (int)ship.Target.Y, (int)sprite.Position.X, (int)sprite.Position.Y, Raylib.RED); + // { + // if (ship.NavTask == null) + // ship.NavTask = new Task>(() => NavigationUtilities.CalculateRouteFromShip(world, entity).ToList()); - if (ship.Target != Vector2.Zero) - { - if (ship.CanDo(ShipAbilities.Steering)) - { - var targetDirection = Vector2.Normalize(sprite.Position - ship.Target); - - var rotationInDegrees = Math.Atan2(targetDirection.Y, targetDirection.X) * (180 / Math.PI); - if (sprite.Rotation != rotationInDegrees) - { - var rotationNeeded = (float)Math.Min(sprite.Rotation - rotationInDegrees, ship.RotationSpeed * Raylib.GetFrameTime()); - if (Math.Abs(rotationInDegrees) > 1) - { - sprite.Rotation -= rotationNeeded; - } - } - else - { - var rotationNeeded = (float)Math.Min(rotationInDegrees - sprite.Rotation, ship.RotationSpeed * Raylib.GetFrameTime()); - if (Math.Abs(rotationInDegrees) > 1) - { - sprite.Rotation += rotationNeeded; - } - sprite.Rotation += ship.RotationSpeed * Raylib.GetFrameTime(); - } - } - } - } + // if (ship.NavTask.IsCompleted) + // { + // ship.Route = ship.NavTask.Result; + // ship.NavTask = null; + // } + // else if (ship.NavTask.Status == TaskStatus.Created) + // { + // ship.NavTask.Start(); + // } + // } + //} + //var sailTargetVec = ship.Route?.FirstOrDefault(); + //if (sailTargetVec is not null) + //{ + // ship.Target = sailTargetVec.Value; + // if (sprite.Position.DistanceTo(ship.Target) < 300) + // { + // if (ship.Route?.Count > 0) + // ship.Route?.RemoveAt(0); + + // if (ship.Route?.Count == 0 && npc.Purpose == Purpose.Patrol) + // { + // ship.NextPatrolPoint += 1; + // if (ship.NextPatrolPoint > maxPatrolPoint) + // ship.NextPatrolPoint = 1; + // } + // if (ship.Route?.Count == 0 && npc.Purpose == Purpose.Trade) + // { + // ship.Goal = Vector2.Zero; + // var availableMoney = 10; + // //ship.TargetPort.Currency -= availableMoney; + // ship.Currency += availableMoney; + // } + // } + // if (singleton.Debug >= DebugLevel.Low) + // Raylib.DrawLine((int)ship.Target.X, (int)ship.Target.Y, (int)sprite.Position.X, (int)sprite.Position.Y, Raylib.RED); + + // if (ship.Target != Vector2.Zero) + // { + // if (ship.CanDo(ShipAbilities.Steering)) + // { + // var targetDirection = Vector2.Normalize(sprite.Position - ship.Target); + + // var rotationInDegrees = Math.Atan2(targetDirection.Y, targetDirection.X) * (180 / Math.PI); + // if (sprite.Rotation != rotationInDegrees) + // { + // var rotationNeeded = (float)Math.Min(sprite.Rotation - rotationInDegrees, ship.RotationSpeed * Raylib.GetFrameTime()); + // if (Math.Abs(rotationInDegrees) > 1) + // { + // sprite.Rotation -= rotationNeeded; + // } + // } + // else + // { + // var rotationNeeded = (float)Math.Min(rotationInDegrees - sprite.Rotation, ship.RotationSpeed * Raylib.GetFrameTime()); + // if (Math.Abs(rotationInDegrees) > 1) + // { + // sprite.Rotation += rotationNeeded; + // } + // sprite.Rotation += ship.RotationSpeed * Raylib.GetFrameTime(); + // } + // } + // } + //} //Console.WriteLine($"Target {ship.Target}");