diff --git a/Assets/Art/cannon.json b/Assets/Art/cannon.json new file mode 100644 index 0000000..dc2ffdb --- /dev/null +++ b/Assets/Art/cannon.json @@ -0,0 +1,23 @@ +{ "frames": [ + { + "filename": "Cannon-0", + "frame": { "x": 1, "y": 1, "w": 29, "h": 16 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 29, "h": 16 }, + "sourceSize": { "w": 29, "h": 16 }, + "duration": 100 + } + ], + "meta": { + "app": "https://www.aseprite.org/", + "version": "1.3-rc6-x64", + "image": "cannon.png", + "format": "RGBA8888", + "size": { "w": 31, "h": 18 }, + "scale": "1", + "frameTags": [ + { "name": "Cannon", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" } + ] + } +} diff --git a/Assets/Art/cannon.png b/Assets/Art/cannon.png new file mode 100644 index 0000000..c41df36 Binary files /dev/null and b/Assets/Art/cannon.png differ diff --git a/Assets/Art/cannonBall.json b/Assets/Art/cannonBall.json new file mode 100644 index 0000000..eeb7882 --- /dev/null +++ b/Assets/Art/cannonBall.json @@ -0,0 +1,23 @@ +{ "frames": [ + { + "filename": "Ball-0", + "frame": { "x": 1, "y": 1, "w": 10, "h": 10 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 10, "h": 10 }, + "sourceSize": { "w": 10, "h": 10 }, + "duration": 100 + } + ], + "meta": { + "app": "https://www.aseprite.org/", + "version": "1.3-rc6-x64", + "image": "cannonBall.png", + "format": "RGBA8888", + "size": { "w": 12, "h": 12 }, + "scale": "1", + "frameTags": [ + { "name": "Ball", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" } + ] + } +} diff --git a/Assets/Art/cannonBall.png b/Assets/Art/cannonBall.png new file mode 100644 index 0000000..0692f9b Binary files /dev/null and b/Assets/Art/cannonBall.png differ diff --git a/Assets/Art/cannonLoose.json b/Assets/Art/cannonLoose.json new file mode 100644 index 0000000..773a0ff --- /dev/null +++ b/Assets/Art/cannonLoose.json @@ -0,0 +1,23 @@ +{ "frames": [ + { + "filename": "Cannon-0", + "frame": { "x": 1, "y": 1, "w": 20, "h": 12 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 20, "h": 12 }, + "sourceSize": { "w": 20, "h": 12 }, + "duration": 100 + } + ], + "meta": { + "app": "https://www.aseprite.org/", + "version": "1.3-rc6-x64", + "image": "cannonLoose.png", + "format": "RGBA8888", + "size": { "w": 22, "h": 14 }, + "scale": "1", + "frameTags": [ + { "name": "Cannon", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" } + ] + } +} diff --git a/Assets/Art/cannonLoose.png b/Assets/Art/cannonLoose.png new file mode 100644 index 0000000..a90e161 Binary files /dev/null and b/Assets/Art/cannonLoose.png differ diff --git a/Assets/Aseprite/cannon.ase b/Assets/Aseprite/cannon.ase new file mode 100644 index 0000000..8a13716 Binary files /dev/null and b/Assets/Aseprite/cannon.ase differ diff --git a/Assets/Aseprite/cannonBall.ase b/Assets/Aseprite/cannonBall.ase new file mode 100644 index 0000000..d07c8e9 Binary files /dev/null and b/Assets/Aseprite/cannonBall.ase differ diff --git a/Assets/Aseprite/cannonLoose.ase b/Assets/Aseprite/cannonLoose.ase new file mode 100644 index 0000000..48a9b73 Binary files /dev/null and b/Assets/Aseprite/cannonLoose.ase differ diff --git a/Components/Cannonball.cs b/Components/Cannonball.cs new file mode 100644 index 0000000..5e1908f --- /dev/null +++ b/Components/Cannonball.cs @@ -0,0 +1,9 @@ +using System.Numerics; + +namespace NovemberPirates.Components +{ + internal class Cannonball + { + internal Vector2 Motion; + } +} diff --git a/Components/Ship.cs b/Components/Ship.cs new file mode 100644 index 0000000..6c03dc0 --- /dev/null +++ b/Components/Ship.cs @@ -0,0 +1,11 @@ +using NovemberPirates.Utilities; + +namespace NovemberPirates.Components +{ + internal class Ship + { + public BoatCondition BoatCondition = BoatCondition.Good; + + + } +} diff --git a/Entities/Archetypes/CannonballBuilder.cs b/Entities/Archetypes/CannonballBuilder.cs new file mode 100644 index 0000000..27673ff --- /dev/null +++ b/Entities/Archetypes/CannonballBuilder.cs @@ -0,0 +1,27 @@ +using Arch.Core; +using Arch.Core.Extensions; +using NovemberPirates.Components; +using NovemberPirates.Utilities; +using Raylib_CsLo; +using System.Numerics; + +namespace NovemberPirates.Entities.Archetypes +{ + internal static class CannonballBuilder + { + internal static void Create(World world, Vector2 pos, float rotation) + { + var cannonballEntity = world.Create(); + + var cannonball = new Cannonball(); + var rotationInRadians = rotation * (float)(Math.PI / 180); + cannonball.Motion = RayMath.Vector2Rotate(new Vector2(1000, 0), rotationInRadians); + cannonballEntity.Set(cannonball); + + var cannonballSprite = new Sprite(TextureKey.Cannonball, "Assets/Art/cannonball", 1f, true); + cannonballSprite.Position = pos; + cannonballEntity.Set(cannonballSprite); + + } + } +} diff --git a/Scenes/Levels/OceanScene.cs b/Scenes/Levels/OceanScene.cs index 56c9843..23bf8e4 100644 --- a/Scenes/Levels/OceanScene.cs +++ b/Scenes/Levels/OceanScene.cs @@ -15,11 +15,12 @@ internal OceanScene() //var entity = World.Create(mapTilesArchetype); Systems.Add(new RenderSystem()); - Systems.Add(new BoatMovementSystem()); + Systems.Add(new ShipControlSystem()); Systems.Add(new CameraSystem()); Systems.Add(new WindSystem()); Systems.Add(new UiSystem()); Systems.Add(new DebugSystem()); + Systems.Add(new CannonBallSystem()); var mapDetails = MapManager.Instance.LoadMap("Level_0", World); MapEdge = mapDetails.MapEdge; diff --git a/Scenes/Levels/Systems/CannonBallSystem.cs b/Scenes/Levels/Systems/CannonBallSystem.cs new file mode 100644 index 0000000..fa64f8c --- /dev/null +++ b/Scenes/Levels/Systems/CannonBallSystem.cs @@ -0,0 +1,26 @@ +using Arch.Core; +using Arch.Core.Extensions; +using NovemberPirates.Components; +using NovemberPirates.Systems; +using Raylib_CsLo; + +namespace NovemberPirates.Scenes.Levels.Systems +{ + internal class CannonBallSystem : GameSystem + { + internal override void Update(World world) + { + var cannonballQuery = new QueryDescription().WithAll(); + + var allShips = new QueryDescription().WithAll(); + + world.Query(in cannonballQuery, (entity) => + { + var cannonball = entity.Get(); + var sprite = entity.Get(); + + sprite.Position += cannonball.Motion * Raylib.GetFrameTime(); + }); + } + } +} diff --git a/Scenes/Levels/Systems/BoatMovementSystem.cs b/Scenes/Levels/Systems/ShipControlSystem.cs similarity index 89% rename from Scenes/Levels/Systems/BoatMovementSystem.cs rename to Scenes/Levels/Systems/ShipControlSystem.cs index 3a713ea..62027d0 100644 --- a/Scenes/Levels/Systems/BoatMovementSystem.cs +++ b/Scenes/Levels/Systems/ShipControlSystem.cs @@ -1,6 +1,7 @@ using Arch.Core; using Arch.Core.Extensions; using NovemberPirates.Components; +using NovemberPirates.Entities.Archetypes; using NovemberPirates.Extensions; using NovemberPirates.Systems; using NovemberPirates.Utilities; @@ -9,9 +10,9 @@ namespace NovemberPirates.Scenes.Levels.Systems { - internal class BoatMovementSystem : GameSystem + internal class ShipControlSystem : GameSystem { - public BoatMovementSystem() + public ShipControlSystem() { } @@ -58,7 +59,6 @@ internal override void Update(World world) if (boatChanged) sprite.Texture = (ShipSpriteBuilder.GenerateBoat(new BoatOptions(BoatType.HullLarge, BoatColor.Red, player.Sail, BoatCondition.Good))).Texture; - movement = RayMath.Vector2Rotate(movement, sprite.RotationAsRadians); var boatAngle = (sprite.Rotation + 360) % 360; @@ -83,25 +83,17 @@ internal override void Update(World world) if (player.Sail == SailStatus.Closed) movement = new Vector2(0, 0); - //singleton.DebugText += $"\n2:{movement}"; if (player.Sail == SailStatus.Rowing) movement = movement * player.RowingPower; - //singleton.DebugText += $"\n3:{movement}"; if (player.Sail == SailStatus.Half) movement = movement * ((windStrength / 2) + player.RowingPower); - //singleton.DebugText += $"\n4:{movement}"; if (player.Sail == SailStatus.Full) movement = movement * (windStrength + player.RowingPower); - singleton.DebugText += $"\n5:{movement}"; - movement *= Raylib.GetFrameTime(); - singleton.DebugText += $"\n6:{movement}"; - - var adjustedPosition = sprite.Position with { @@ -155,6 +147,18 @@ internal override void Update(World world) //Console.WriteLine($"Collision {collidingTile.Collision}"); } } + + if (Raylib.IsKeyPressed(KeyboardKey.KEY_Q) || Raylib.IsKeyPressed(KeyboardKey.KEY_LEFT)) + { + // fire cannon Port + CannonballBuilder.Create(world, sprite.Position, sprite.RenderRotation + 180); + } + if (Raylib.IsKeyPressed(KeyboardKey.KEY_E) || Raylib.IsKeyPressed(KeyboardKey.KEY_RIGHT)) + { + // fire cannon Starboard + CannonballBuilder.Create(world, sprite.Position, sprite.RenderRotation); + } + }); } } diff --git a/Utilities/ShipSpriteBuilder.cs b/Utilities/ShipSpriteBuilder.cs index 41642ca..9cbf2b3 100644 --- a/Utilities/ShipSpriteBuilder.cs +++ b/Utilities/ShipSpriteBuilder.cs @@ -19,6 +19,44 @@ internal static Sprite GenerateBoat(BoatOptions options) baseHullSprite.Play("HullLarge1"); //Cannons + var cannons = new List(); + + var cannonHeight = 38; + var verticalOffset = 20; + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 + verticalOffset, cannonHeight), + }); + + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 - verticalOffset, cannonHeight), + Rotation = 180, + }); + + cannonHeight += 18; + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 + verticalOffset, cannonHeight), + }); + + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 - verticalOffset, cannonHeight), + Rotation = 180, + }); + + cannonHeight += 19; + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 + verticalOffset, cannonHeight), + }); + + cannons.Add(new Sprite(TextureKey.CannonLoose, "Assets/Art/cannonLoose") + { + Position = new Vector2(shipSize.X / 2 - verticalOffset, cannonHeight), + Rotation = 180, + }); // Main sail @@ -55,6 +93,7 @@ internal static Sprite GenerateBoat(BoatOptions options) Raylib.ClearBackground(new Color(0, 0, 0, 0)); baseHullSprite.Draw(); + cannons.ForEach(x => x.Draw()); if (options.Sails >= SailStatus.Full) mainSailSprite.Draw(); nestSprite.Draw(); diff --git a/Utilities/TextureManager.cs b/Utilities/TextureManager.cs index b355c77..faf11be 100644 --- a/Utilities/TextureManager.cs +++ b/Utilities/TextureManager.cs @@ -22,6 +22,9 @@ private void LoadTextures() TextureStore.Add(TextureKey.Pole, Raylib.LoadTexture("Assets/Art/pole.png")); TextureStore.Add(TextureKey.SailLarge, Raylib.LoadTexture("Assets/Art/sailLarge1.png")); TextureStore.Add(TextureKey.SailSmall, Raylib.LoadTexture("Assets/Art/sailSmall1.png")); + TextureStore.Add(TextureKey.Cannon, Raylib.LoadTexture("Assets/Art/cannon.png")); + TextureStore.Add(TextureKey.CannonLoose, Raylib.LoadTexture("Assets/Art/cannonLoose.png")); + TextureStore.Add(TextureKey.Cannonball, Raylib.LoadTexture("Assets/Art/cannonBall.png")); } internal Texture GetTexture(TextureKey key) @@ -44,5 +47,8 @@ internal enum TextureKey Pole, SailLarge, SailSmall, + Cannon, + CannonLoose, + Cannonball, } }