Skip to content

Commit

Permalink
Some clean up for navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Feb 12, 2024
1 parent 8f58ac7 commit ae33ba4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions Scenes/Levels/Components/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions Scenes/Levels/Components/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public Ship(HullType hull, BoatColor color, Team team)

internal List<Cannon> Cannons = new List<Cannon>();

internal int NextPatrolPoint = 1;
internal List<Vector2> Route = new();
internal float WindInSail;

internal int Crew;
Expand All @@ -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<Route> SailingRoute;

public Task<List<Vector2>> NavTask { get; set; }
}
Expand Down
4 changes: 1 addition & 3 deletions Scenes/Levels/Systems/EnemyAISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
});
}
Expand Down
31 changes: 28 additions & 3 deletions Scenes/Levels/Systems/EnemyControlSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ae33ba4

Please sign in to comment.