Skip to content

Commit

Permalink
Start of cannons, weeeeee
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Nov 4, 2023
1 parent d67deae commit 74afca6
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 12 deletions.
23 changes: 23 additions & 0 deletions Assets/Art/cannon.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
}
Binary file added Assets/Art/cannon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Assets/Art/cannonBall.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
}
Binary file added Assets/Art/cannonBall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Assets/Art/cannonLoose.json
Original file line number Diff line number Diff line change
@@ -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" }
]
}
}
Binary file added Assets/Art/cannonLoose.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/Aseprite/cannon.ase
Binary file not shown.
Binary file added Assets/Aseprite/cannonBall.ase
Binary file not shown.
Binary file added Assets/Aseprite/cannonLoose.ase
Binary file not shown.
9 changes: 9 additions & 0 deletions Components/Cannonball.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Numerics;

namespace NovemberPirates.Components
{
internal class Cannonball
{
internal Vector2 Motion;
}
}
11 changes: 11 additions & 0 deletions Components/Ship.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using NovemberPirates.Utilities;

namespace NovemberPirates.Components
{
internal class Ship
{
public BoatCondition BoatCondition = BoatCondition.Good;


}
}
27 changes: 27 additions & 0 deletions Entities/Archetypes/CannonballBuilder.cs
Original file line number Diff line number Diff line change
@@ -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<Sprite, Cannonball>();

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);

}
}
}
3 changes: 2 additions & 1 deletion Scenes/Levels/OceanScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions Scenes/Levels/Systems/CannonBallSystem.cs
Original file line number Diff line number Diff line change
@@ -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<Cannonball, Sprite>();

var allShips = new QueryDescription().WithAll<Ship, Sprite>();

world.Query(in cannonballQuery, (entity) =>
{
var cannonball = entity.Get<Cannonball>();
var sprite = entity.Get<Sprite>();

sprite.Position += cannonball.Motion * Raylib.GetFrameTime();
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,9 +10,9 @@

namespace NovemberPirates.Scenes.Levels.Systems
{
internal class BoatMovementSystem : GameSystem
internal class ShipControlSystem : GameSystem
{
public BoatMovementSystem()
public ShipControlSystem()
{
}

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

});
}
}
Expand Down
39 changes: 39 additions & 0 deletions Utilities/ShipSpriteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ internal static Sprite GenerateBoat(BoatOptions options)
baseHullSprite.Play("HullLarge1");

//Cannons
var cannons = new List<Sprite>();

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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions Utilities/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -44,5 +47,8 @@ internal enum TextureKey
Pole,
SailLarge,
SailSmall,
Cannon,
CannonLoose,
Cannonball,
}
}

0 comments on commit 74afca6

Please sign in to comment.