From 74afca6823ffd598301dca8d6f9edb3f1a085613 Mon Sep 17 00:00:00 2001 From: John Pavek Date: Fri, 3 Nov 2023 21:58:41 -0500 Subject: [PATCH] Start of cannons, weeeeee --- Assets/Art/cannon.json | 23 +++++++++++ Assets/Art/cannon.png | Bin 0 -> 603 bytes Assets/Art/cannonBall.json | 23 +++++++++++ Assets/Art/cannonBall.png | Bin 0 -> 349 bytes Assets/Art/cannonLoose.json | 23 +++++++++++ Assets/Art/cannonLoose.png | Bin 0 -> 460 bytes Assets/Aseprite/cannon.ase | Bin 0 -> 1032 bytes Assets/Aseprite/cannonBall.ase | Bin 0 -> 581 bytes Assets/Aseprite/cannonLoose.ase | Bin 0 -> 761 bytes Components/Cannonball.cs | 9 ++++ Components/Ship.cs | 11 +++++ Entities/Archetypes/CannonballBuilder.cs | 27 ++++++++++++ Scenes/Levels/OceanScene.cs | 3 +- Scenes/Levels/Systems/CannonBallSystem.cs | 26 ++++++++++++ ...MovementSystem.cs => ShipControlSystem.cs} | 26 +++++++----- Utilities/ShipSpriteBuilder.cs | 39 ++++++++++++++++++ Utilities/TextureManager.cs | 6 +++ 17 files changed, 204 insertions(+), 12 deletions(-) create mode 100644 Assets/Art/cannon.json create mode 100644 Assets/Art/cannon.png create mode 100644 Assets/Art/cannonBall.json create mode 100644 Assets/Art/cannonBall.png create mode 100644 Assets/Art/cannonLoose.json create mode 100644 Assets/Art/cannonLoose.png create mode 100644 Assets/Aseprite/cannon.ase create mode 100644 Assets/Aseprite/cannonBall.ase create mode 100644 Assets/Aseprite/cannonLoose.ase create mode 100644 Components/Cannonball.cs create mode 100644 Components/Ship.cs create mode 100644 Entities/Archetypes/CannonballBuilder.cs create mode 100644 Scenes/Levels/Systems/CannonBallSystem.cs rename Scenes/Levels/Systems/{BoatMovementSystem.cs => ShipControlSystem.cs} (89%) 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 0000000000000000000000000000000000000000..c41df365004fd676ce5b10fc2196da7b271c8cb9 GIT binary patch literal 603 zcmV-h0;K(kP)M00004XF*Lt006O$ zeEU(80006KNklHbmlkZmt(UqN#5c&sg>T^txRAcU zc>_1yh){}jEp_9fD?ysJIXf}37c1@X$S{E7-D15$%SDQO(+2ONBWyj?&`tf z_Ih$+vh$wBelv|5n7Ba%O9Z4NJ_*?$8Ur1cU3_8jRo-;8)&;bFzq_^dd~W#9zRBw! ztN2<1V8`QhJrAYSv;qt%(7JSbac$FoJkGbzpJ>#og9oXv&605RJpX4@lUuO%)nmCj^n)T#`+ zYG(MMYhgwrL@aC8kdT(r%K&I0!eyVPe*q6A%mJ5JVYHu!h-tJTPC5>8@rBr(4o{r}Ywb}p{jTMllNuyf5FtpwY!M~ik zW8v$v&jESL$KPqzsv&>UgL7UfU(U7G^>(`*hEGyH+Tp>{8T-vN-e2WU$Q~Ip{Jd5g z9lBVYiPRo|7NXSacAYod+eZMVQj`D;gTlw7`jjKoxySLW=Vc90iqeahyN^cs21+?7 pe*wJn&{2RWoo)aC002ovPDHLkV1h8#AVmNG literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..0692f9b0cf3b868d7b6035f739e56a997bc625a5 GIT binary patch literal 349 zcmV-j0iyniP)4B>HTa`JCf0#Mc^tY`tcgrT|o&RGZFwy+_A!`hVFl#tg?vat+{A&9~X? v=`@aC$@7*d6_z$qW9`j2N$xA|;7@-6)%{oq#~30I00000NkvXXu0mjf0N;_U literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a90e161459916bde21ac705bd5325b2b5428b745 GIT binary patch literal 460 zcmV;-0W3ZN00004XF*Lt006O$ zeEU(80004lNkl{*PP})j>b&=k3dR^~f}p3W7S+j*%gb-899u#@4+eVx-EP;3NE0AV67np= zd%uxbq3Zr#U-tmQkDbmrfQU4khex!!pVo@+vJ77oL*$ zJ_QI7=~s(h(uiXKc6N7P?Xrv?v|7w(Q^c61ura0&5Y}qc>h+DTUS;p#5C9cfK1G>$ zi)cwbinz~n3-9cTAXxSJzQWmUy4r_@ssqT<)V@hHT>#*{9|MGo4?cvtLSH1D);5iFnyuM&?rwU^4b!@JTe@bZPAyyh zD>6i56h-;ai#_$ygGd(i)RZva*CmP@j;vGEgw-!dh`T|**Irn#2yW0~ZvbbEJJahx(&$ofzn|iAxupg4DDRxQavHVVZe<(_ zg6I5QVE5fga9FAW8_za^b)pD*Tg~8w!RugKU;wl6H zghMjKLM8-48bm=3gg}CW*ug#=uYZp1WDq4umUdwV$8DX!ST^p|9FA&YKnNw1N$hfZ zU$K&lKZzyIEc>ARp`P%&w1LAJ6{lWA9xr#x0dvwq{*PGnPGEwY5X^I66;5zEL- za5OdVxPEnR{Navco5KgLg}tkjw!Bg`y-BY+QKK)b;7jb0g6N(_*M=r*r|dpiEtaaL zb3==L3!KOFv}7nNw3O>!F(hX;7p=@cpVF;;|G4}*|MRo-x((G>Ed1r`uTVfM`I<8> aF3r5pX)vs>zx?etWKK(;Hj~?}Li7(P1t>}Y literal 0 HcmV?d00001 diff --git a/Assets/Aseprite/cannonBall.ase b/Assets/Aseprite/cannonBall.ase new file mode 100644 index 0000000000000000000000000000000000000000..d07c8e93e2cc6e7db19bc5cb1e47ca24b2f34964 GIT binary patch literal 581 zcmZ=|Vqkc%l#zi82ss!S85kH+fEWU}fs_~nBS?@z00?OTjsi{p^^qNHD?88vF(77F zU~8fx*n#c|Mqo2g<8;Q4>Qc#)AK(AgHu2NkaY0(2a;YqB>m#!fuyCI+kYRR5iFpv69c*h=n$YQfKC9~540R;GtgQf0$K=^ z0;&Ys1GEHa1JHP&*+7GVrUH!wng=vY9jHPA=zpAmg~2H?Cx;Ixub==8p#QQ!9*Y7q zk{+PT7+4v65-U@Sl0i%bh}?g8kb>g7Vvg<^PoV|_9%e@cZ87gT5&!>d85%6NThS8m z{iaaEiR~Rn>UeY6Cx6%yxp>0%(>00vTV4ftrOBr)HeOt#&+2gZ#8xJL?MgN&01M?| AApigX literal 0 HcmV?d00001 diff --git a/Assets/Aseprite/cannonLoose.ase b/Assets/Aseprite/cannonLoose.ase new file mode 100644 index 0000000000000000000000000000000000000000..48a9b73d1b4a901c3bc59e3074f6db6dd556e7e5 GIT binary patch literal 761 zcmey##K7=iDI01uE-WncseG6(=6EkGsE{$C&2!M3skEf51@ zb_GVDON@+xQc&;%NJ}cHLU}4MVKD6!6eQ2U;1d&*&%odn7w6Bw;2Rg$&%odp7k8e4 z!Pv!xA1v~ofx#_2Tpy@1Hg-J&gLiavJOhJgWTZWi9TztrW+ae(AFO6S*vxtchP3LM z{|pSJy?sD3qqZJMhG%90$+)6oAerCR4kTj>3c>6SAX(Je4J3n7Qh;PgS{jh7o-z$c zCRbDf$$-Q}AeqzL3M8`{nt)_tX&I0V&jOiQH)9r%^ox%Nk|jNT|0{vcVgbd9D$tie zF9Q7s^c>JLA~18vp>nk4~@2AqJ6!8tK6FF%hDs6s&j8dLve zfjkxkW+Yuek1((@_#{@Q7WILc3J|&f@VEsfyox!w=T9;<8SuCUioSHX91>W_aPZsL z|NAdC%*khADY1{WTr^Xa3F6HKV_j9*u z#gWqL2ixcVGr8FlYTd-!cHYEq(c8<6(Q5@<3%B07a8CdD>GDH{*1q{OZ%Fe40P7dO Aw*UYD literal 0 HcmV?d00001 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, } }