Skip to content

Commit

Permalink
A bunch of clean up to support using json for stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Nov 18, 2023
1 parent 7f10ebc commit 7a160d0
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 122 deletions.
24 changes: 22 additions & 2 deletions Assets/Art/words.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,42 @@
"spriteSourceSize": { "x": 0, "y": 0, "w": 378, "h": 143 },
"sourceSize": { "w": 378, "h": 143 },
"duration": 100
},
{
"filename": "Exit-6",
"frame": { "x": 1, "y": 291, "w": 378, "h": 143 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 378, "h": 143 },
"sourceSize": { "w": 378, "h": 143 },
"duration": 100
},
{
"filename": "ExitHover-7",
"frame": { "x": 381, "y": 291, "w": 378, "h": 143 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 378, "h": 143 },
"sourceSize": { "w": 378, "h": 143 },
"duration": 100
}
],
"meta": {
"app": "https://www.aseprite.org/",
"version": "1.3-rc6-x64",
"image": "words.png",
"format": "RGBA8888",
"size": { "w": 1140, "h": 290 },
"size": { "w": 1140, "h": 435 },
"scale": "1",
"frameTags": [
{ "name": "Start", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" },
{ "name": "StartHover", "from": 1, "to": 1, "direction": "forward", "color": "#000000ff" },
{ "name": "HowToPlay", "from": 2, "to": 2, "direction": "forward", "color": "#000000ff" },
{ "name": "HowToPlayHover", "from": 3, "to": 3, "direction": "forward", "color": "#000000ff" },
{ "name": "Credits", "from": 4, "to": 4, "direction": "forward", "color": "#000000ff" },
{ "name": "CreditsHover", "from": 5, "to": 5, "direction": "forward", "color": "#000000ff" }
{ "name": "CreditsHover", "from": 5, "to": 5, "direction": "forward", "color": "#000000ff" },
{ "name": "Exit", "from": 6, "to": 6, "direction": "forward", "color": "#000000ff" },
{ "name": "ExitHover", "from": 7, "to": 7, "direction": "forward", "color": "#000000ff" }
]
}
}
Binary file modified Assets/Art/words.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Aseprite/words.ase
Binary file not shown.
Binary file added Assets/Fonts/AguafinaScript-Regular.ttf
Binary file not shown.
Binary file added Assets/Originals/Exit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Originals/exit_hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions Components/Cannon.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
using System.Numerics;
using NovemberPirates.Utilities.Data;
using System.Numerics;

namespace NovemberPirates.Components
{
internal class Cannon
{
internal BoatSide Placement;
internal CannonType CannonType;

internal float ReloadTime =0.5f;
internal float ReloadElapsed = 0f;
internal Vector2 Position;
internal BoatSide Placement;
internal int Row;

internal float ReloadElapsed = 0f;
internal float ReloadTime;
internal float ReloadRate;
internal float HullDamage;
internal float SailDamage;
internal float CrewKillChance;
internal float CrewKillChainLimit;
internal float Spread;
internal float BallSpeed;
internal float BallDuration;
internal float ShotPer;
}

internal enum BoatSide
Expand Down
1 change: 1 addition & 0 deletions Components/Cannonball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class Cannonball
internal Team FiredBy;
internal float Duration = 0.75f;
internal float Elapsed = 0f;
internal Cannon FiredByCannon;

Check warning on line 11 in Components/Cannonball.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'FiredByCannon' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 11 in Components/Cannonball.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'FiredByCannon' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
}
internal enum Team
{
Expand Down
37 changes: 30 additions & 7 deletions Components/Ship.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
using NovemberPirates.Utilities;
using NovemberPirates.Utilities.Data;
using System.Numerics;

namespace NovemberPirates.Components
{
internal class Ship
{
public Ship(HullType hull, BoatColor color, Team team)
{
BoatType = hull;
BoatColor = color;
Team = team;

Crew = (int)ShipData.Instance.Data[$"{hull}{Stats.InitialCrew}"];
MaxSpeed = ShipData.Instance.Data[$"{hull}{Stats.MaxSpeed}"];
RowingPower = ShipData.Instance.Data[$"{hull}{Stats.RowingSpeed}"];
RotationSpeed = ShipData.Instance.Data[$"{hull}{Stats.TurningSpeed}"];
HullHealth = ShipData.Instance.Data[$"{hull}{Stats.HullHealth}"];
SailHealth = ShipData.Instance.Data[$"{hull}{Stats.SailHealth}"];
HalfSailSpeedModifier = ShipData.Instance.Data[$"{hull}{Stats.HalfSailSpeed}"];
FullSailSpeedModifier = ShipData.Instance.Data[$"{hull}{Stats.FullSailSpeed}"];
SailSpeedEasing = ShipData.Instance.Data[$"{hull}{Stats.SailSpeedEasing}"];
}
public BoatCondition BoatCondition = BoatCondition.Good;

public BoatColor BoatColor;
public BoatType BoatType;
public HullType BoatType;
public Team Team;
internal SailStatus Sail = SailStatus.Closed;

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

internal int Crew = 10;
internal int NextPatrolPoint = 1;
internal Vector2 Target;
internal List<Vector2> Route = new();
internal float RowingPower = 100f;
internal float RotationSpeed = 100f;

internal float MaxSpeed = 500f;
internal float HullHealth = 100f;
internal float WindInSail;

internal int Crew;
internal float RowingPower;
internal float RotationSpeed;

internal float MaxSpeed;
internal float HullHealth;
internal float SailHealth;
internal float HalfSailSpeedModifier;
internal float FullSailSpeedModifier;
internal float SailSpeedEasing;
}
}
30 changes: 30 additions & 0 deletions Entities/Archetypes/CannonBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NovemberPirates.Components;
using NovemberPirates.Utilities.Data;

namespace NovemberPirates.Entities.Archetypes
{
internal static class CannonBuilder
{
internal static Cannon Create(CannonType cannonType, BoatSide boatSide, int row)
{
var cannon = new Cannon();
cannon.Placement = boatSide;
cannon.Row = row;

cannon.CannonType = cannonType;

cannon.ReloadTime = ShipData.Instance.Data[$"{cannonType}{Stats.CannonReloadTime}"];
cannon.ReloadRate = ShipData.Instance.Data[$"{cannonType}{Stats.CannonReloadRate}"];
cannon.HullDamage = ShipData.Instance.Data[$"{cannonType}{Stats.CannonHullDamage}"];
cannon.SailDamage = ShipData.Instance.Data[$"{cannonType}{Stats.CannonSailDamage}"];
cannon.CrewKillChance = ShipData.Instance.Data[$"{cannonType}{Stats.CannonCrewKillChance}"];
cannon.CrewKillChainLimit = ShipData.Instance.Data[$"{cannonType}{Stats.CannonCrewKillChainLimit}"];
cannon.Spread = ShipData.Instance.Data[$"{cannonType}{Stats.CannonSpread}"];
cannon.BallSpeed = ShipData.Instance.Data[$"{cannonType}{Stats.CannonballSpeed}"];
cannon.BallDuration = ShipData.Instance.Data[$"{cannonType}{Stats.CannonballDuration}"];
cannon.ShotPer = ShipData.Instance.Data[$"{cannonType}{Stats.CannonsShotPer}"];

return cannon;
}
}
}
5 changes: 3 additions & 2 deletions Entities/Archetypes/CannonballBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ namespace NovemberPirates.Entities.Archetypes
{
internal static class CannonballBuilder
{
internal static void Create(World world, Vector2 pos, float rotation, Team team)
internal static void Create(World world, Cannon cannon, Vector2 pos, float rotation, Team team)
{
var cannonballEntity = world.Create<Sprite, Cannonball>();

var cannonball = new Cannonball();
var rotationInRadians = rotation * (float)(Math.PI / 180);
var spread = Random.Shared.Next(-50, 50);
var spread = Random.Shared.Next(-(int)cannon.Spread, (int)cannon.Spread);
cannonball.Motion = RayMath.Vector2Rotate(new Vector2(1000, spread), rotationInRadians);
cannonball.FiredBy = team;
cannonball.FiredByCannon = cannon;
cannonballEntity.Set(cannonball);

var cannonballSprite = new Sprite(TextureKey.Cannonball, "Assets/Art/cannonball", 1f, true);
Expand Down
4 changes: 2 additions & 2 deletions Entities/Archetypes/EnemyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ internal static class EnemyBuilder
public static void CreateEnemyShip(World world, Vector2 position, Team team)
{
var entity = world.Create<Ship, Sprite, Npc>();
var ship = new Ship();
var ship = new Ship(HullType.Small, BoatColor.Yellow, Team.Yellow);
ship.Team = team;
ship.BoatColor = BoatColor.Yellow;
ship.BoatType = BoatType.HullLarge;
ship.BoatType = HullType.Large;
ship.Sail = SailStatus.Closed;
ship.Crew = 10;

Expand Down
15 changes: 3 additions & 12 deletions Entities/Archetypes/PlayerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ internal static void Create(World world)
var playerComponent = new Player();
player.Set(playerComponent);

var ship = new Ship();
ship.Team = Team.Player;
ship.BoatColor = BoatColor.Dead;
ship.BoatType = BoatType.HullMedium;
var ship = new Ship(HullType.Small, BoatColor.Dead, Team.Player);
ship.Sail = SailStatus.Closed;
ship.Crew = 10;
ship.RowingPower = 150f;
ship.Cannons.Add(new Cannon { Placement = BoatSide.Port, Row = 1 });
ship.Cannons.Add(new Cannon { Placement = BoatSide.Starboard, Row = 1 });
ship.Cannons.Add(new Cannon { Placement = BoatSide.Port, Row = 2 });
ship.Cannons.Add(new Cannon { Placement = BoatSide.Starboard, Row = 2 });
ship.Cannons.Add(new Cannon { Placement = BoatSide.Port, Row = 3 });
ship.Cannons.Add(new Cannon { Placement = BoatSide.Starboard, Row = 3 });

ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.BFC1700, BoatSide.Starboard, 1));

player.Set(ship);

Expand Down
9 changes: 8 additions & 1 deletion NovemberPiratesEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ private NovemberPiratesEngine() { }

public void StartGame()
{
Raylib.InitWindow(1280, 720, "November Pirates");
//Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_TOPMOST);
//Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_MAXIMIZED);
//Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_UNDECORATED);

var width = Raylib.GetMonitorWidth(0);
var height = Raylib.GetMonitorHeight(0);

Raylib.InitWindow(width, height, "November Pirates");
Raylib.SetTargetFPS(60);
Raylib.InitAudioDevice();
Raylib.SetExitKey(0);
Expand Down
8 changes: 4 additions & 4 deletions Scenes/Levels/Systems/PlayerControlSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal override void Update(World world)
var cannonPos = sprite.Position + RayMath.Vector2Rotate(nextCannon.Position, sprite.RotationAsRadians);
Raylib.DrawCircleV(cannonPos, 10, Raylib.RED);

CannonballBuilder.Create(world, cannonPos, sprite.RenderRotation + 180, Team.Player);
CannonballBuilder.Create(world, nextCannon, cannonPos, sprite.RenderRotation + 180, Team.Player);

var sound = world.Create<AudioEvent>();
sound.Set(new AudioEvent() { Position = cannonPos, Key = AudioKey.CannonFire });
Expand All @@ -84,7 +84,7 @@ internal override void Update(World world)
var cannonPos = sprite.Position + RayMath.Vector2Rotate(nextCannon.Position, sprite.RotationAsRadians);
//Raylib.DrawCircleV(cannonPos, 10, Raylib.RED);

CannonballBuilder.Create(world, cannonPos, sprite.RenderRotation, Team.Player);
CannonballBuilder.Create(world, nextCannon, cannonPos, sprite.RenderRotation, Team.Player);

var sound = world.Create<AudioEvent>();
sound.Set(new AudioEvent() { Position = cannonPos, Key = AudioKey.CannonFire });
Expand All @@ -95,13 +95,13 @@ internal override void Update(World world)
{
if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_UP))
{
playerShip.BoatType = (BoatType)Math.Min(Enum.GetValues<BoatType>().Length - 1, (int)playerShip.BoatType + 1);
playerShip.BoatType = (HullType)Math.Min(Enum.GetValues<HullType>().Length - 1, (int)playerShip.BoatType + 1);
boatChanged = true;

}
if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_DOWN))
{
playerShip.BoatType = (BoatType)Math.Max(0, (int)playerShip.BoatType - 1);
playerShip.BoatType = (HullType)Math.Max(0, (int)playerShip.BoatType - 1);
boatChanged = true;

}
Expand Down
4 changes: 4 additions & 0 deletions Scenes/Levels/Systems/RenderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NovemberPirates.Extensions;
using NovemberPirates.Systems;
using Raylib_CsLo;
using System.Numerics;

namespace NovemberPirates.Scenes.Levels.Systems
{
Expand All @@ -20,9 +21,12 @@ internal override void Update(World world)
var singleton = singletonEntity.Get<Singleton>();

var renders = new QueryDescription().WithAll<Render>().WithNone<Effect>();
var camera = NovemberPiratesEngine.Instance.Camera;
world.Query(in renders, (entity) =>
{
var myRender = entity.Get<Render>();
if (Vector2.Abs(myRender.Position - camera.target).Length() > Math.Max(Raylib.GetScreenWidth(), Raylib.GetScreenHeight()) + 200)
return;

if (singleton.Debug != DebugLevel.High)
{
Expand Down
28 changes: 20 additions & 8 deletions Scenes/Menus/MainMenu/MainMenuScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NovemberPirates.Scenes.Menus.Components;
using NovemberPirates.Scenes.Menus.Systems;
using NovemberPirates.Utilities;
using Raylib_CsLo;
using System.Numerics;

namespace NovemberPirates.Scenes.Menus.MainMenu
Expand All @@ -16,6 +17,7 @@ public MainMenuScene()
//var title = World.Create<UiTitle>();
//var uiTitle = new UiTitle() { Text = "November Pirates" };
//title.Set(uiTitle);
var width = Raylib.GetScreenWidth() * 0.7f;

World.Create(new SpriteButton
{
Expand All @@ -27,12 +29,12 @@ public MainMenuScene()
Order = 1,
TextSprite = new Sprite(TextureKey.Words, "Assets/Art/words")
{
Position = new Vector2(750, 150),
Position = new Vector2(width, 150),
OriginPos = Render.OriginAlignment.LeftTop
},
ButtonSprite = new Sprite(TextureKey.Button, "Assets/Art/Button")
{
Position = new Vector2(750, 150),
Position = new Vector2(width, 150),
OriginPos = Render.OriginAlignment.LeftTop
}
});
Expand All @@ -47,12 +49,12 @@ public MainMenuScene()
Order = 2,
TextSprite = new Sprite(TextureKey.Words, "Assets/Art/words")
{
Position = new Vector2(750, 300),
Position = new Vector2(width, 300),
OriginPos = Render.OriginAlignment.LeftTop,
},
ButtonSprite = new Sprite(TextureKey.Button, "Assets/Art/Button")
{
Position = new Vector2(750, 300),
Position = new Vector2(width, 300),
OriginPos = Render.OriginAlignment.LeftTop
}
});
Expand All @@ -67,24 +69,34 @@ public MainMenuScene()
Order = 3,
TextSprite = new Sprite(TextureKey.Words, "Assets/Art/words")
{
Position = new Vector2(750, 450),
Position = new Vector2(width, 450),
OriginPos = Render.OriginAlignment.LeftTop
},
ButtonSprite = new Sprite(TextureKey.Button, "Assets/Art/Button")
{
Position = new Vector2(750, 450),
Position = new Vector2(width, 450),
OriginPos = Render.OriginAlignment.LeftTop
}
});

World.Create(new UiButton
World.Create(new SpriteButton
{
Text = "Exit",
Action = () =>
{
Environment.Exit(0);
},
Order = 5
Order = 5,
TextSprite = new Sprite(TextureKey.Words, "Assets/Art/words")
{
Position = new Vector2(width, 750),
OriginPos = Render.OriginAlignment.LeftTop
},
ButtonSprite = new Sprite(TextureKey.Button, "Assets/Art/Button")
{
Position = new Vector2(width, 750),
OriginPos = Render.OriginAlignment.LeftTop
}
});
}
}
Expand Down
Loading

0 comments on commit 7a160d0

Please sign in to comment.