Skip to content

Commit

Permalink
Cannons can be placed into the inventory!
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Feb 5, 2024
1 parent 691bfe1 commit bab652c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Entities/Archetypes/PlayerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ internal static void Create(World world, Vector2 startPos)
var playerComponent = new Player();
player.Set(playerComponent);

var ship = new Ship(HullType.Small, BoatColor.Dead, Team.November);
var ship = new Ship(HullType.Large, BoatColor.Dead, Team.November);
ship.Sail = SailStatus.Closed;

ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Starboard, 1));
ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Port, 1));
ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Starboard, 2));
ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Port, 2));
ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Starboard, 3));
ship.Cannons.Add(CannonBuilder.Create(Utilities.Data.CannonType.TrustyRusty, BoatSide.Port, 3));

player.Set(ship);

Expand Down
53 changes: 43 additions & 10 deletions Scenes/Levels/Systems/InventoryManagementSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NovemberPirates.Scenes.Levels.DataManagers;
using NovemberPirates.Systems;
using NovemberPirates.Utilities;
using NovemberPirates.Utilities.ContentData;
using NovemberPirates.Utilities.Data;
using Raylib_CsLo;
using System.Numerics;
Expand All @@ -27,9 +28,11 @@ internal override void UpdateNoCamera(World world)
if (singleton.InventoryOpen)
{
var playerShip = playerEntity.Get<Ship>();
var realShipSprite = playerEntity.Get<Sprite>();
var inventoryFrame = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);

Raylib.DrawText("Inventory", 0, 0, 24, Raylib.BLUE);

Raylib.DrawRectangle(
(int)(Raylib.GetScreenWidth() / 2 - inventoryFrame.X / 2),
(int)(Raylib.GetScreenHeight() / 2 - inventoryFrame.Y / 2),
Expand All @@ -42,13 +45,52 @@ internal override void UpdateNoCamera(World world)
var heightOffset = 180;
var lineOffset = 30;

// Left Side

var shipSprite = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip));
shipSprite.RotationOffset = 180;

var leftCenter = new Vector2(leftAlignment - inventoryFrame.X / 4, inventoryFrame.Y);
shipSprite.Position = leftCenter;
shipSprite.Scale = 4f;
shipSprite.Draw();

var shipChanged = false;

for (int i = 0; i < playerShip.Cannons.Count; i++)
{
var cannon = playerShip.Cannons[i];

var rect = new Rectangle(
(int)(leftCenter.X + (cannon.Placement == BoatSide.Port ? 40 : -120)),
(int)(leftCenter.Y + (cannon.Position.Y * 4) - 130),
70, 60);

Raylib.DrawRectangleLines((int)rect.X, (int)rect.Y, (int)rect.width, (int)rect.height, Raylib.BLACK);

if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_BUTTON_LEFT) && Raylib.CheckCollisionPointRec(Raylib.GetMousePosition(), rect))
{
playerShip.Cannons.Remove(cannon);
InventoryManager.Instance.Inventory.Add(TradeableGoodsData.GetGood((TradeableGoodsNames)cannon.CannonType));
shipChanged = true || shipChanged;
}
}
if (shipChanged)
{
Console.WriteLine("Ship Changed");
var newboat = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip));
newboat.Position = realShipSprite.Position;
newboat.Rotation = realShipSprite.Rotation;
playerEntity.Set(newboat);
}

Raylib.DrawText($"Crew: {playerShip.Crew} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.InitialCrew}"]}", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
heightOffset -= lineOffset;

Raylib.DrawText($"Hull: {playerShip.HullHealth} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.HullHealth}"]} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
heightOffset -= lineOffset;

Raylib.DrawText($"Hull: {playerShip.SailHealth} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.SailHealth}"]} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
Raylib.DrawText($"Sails: {playerShip.SailHealth} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.SailHealth}"]} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
heightOffset -= lineOffset;

Raylib.DrawText($"Gold: {InventoryManager.Instance.Gold} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
Expand All @@ -60,15 +102,6 @@ internal override void UpdateNoCamera(World world)
Raylib.DrawText($"{invGroup.Key}: {invGroup.Count()}", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE);
heightOffset -= lineOffset;
}


var texture = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip));

Raylib.DrawTexturePro(texture.Texture,
new Rectangle(0, 0, texture.Texture.width, texture.Texture.height),
new Rectangle(inventoryFrame.X / 2 + 50, inventoryFrame.Y / 2 + 50, (inventoryFrame.X / 2) - 100, inventoryFrame.Y - 100),
new Vector2(0, 0), 0, Raylib.WHITE);

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities/ContentData/ShipData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal void SaveToJson()
{ $"{HullType.Medium}{ShipAbilities.FullSail}", 10 },
{ $"{HullType.Medium}{ShipAbilities.OneCannon}", 5 },
{ $"{HullType.Medium}{ShipAbilities.TwoCannon}", 7 },


{ $"{HullType.Medium}{Stats.RowingSpeed}", 100},
{ $"{HullType.Medium}{Stats.TurningSpeed}", 100},
Expand Down
20 changes: 19 additions & 1 deletion Utilities/ContentData/TradeableGoodsData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace NovemberPirates.Utilities.ContentData
using NovemberPirates.Utilities.Data;

namespace NovemberPirates.Utilities.ContentData
{
internal class TradeableGoodsData
{
Expand All @@ -19,6 +21,11 @@ private void LoadPrices()
Goods.Add(TradeableGoodsNames.Weapons, new TradeableGood { Name = "Weapons", Price = 20 });
Goods.Add(TradeableGoodsNames.FineGoods, new TradeableGood { Name = "Fine Goods", Price = 40 });
Goods.Add(TradeableGoodsNames.Gems, new TradeableGood { Name = "Gems", Price = 80 });

//Cannon Prices
Goods.Add(TradeableGoodsNames.TrustyRusty, new TradeableGood { Name = "Trusty Rusty", Price = 100 });
Goods.Add(TradeableGoodsNames.PvtPepper, new TradeableGood { Name = "Pvt Pepper", Price = 200 });
Goods.Add(TradeableGoodsNames.BFC1700, new TradeableGood { Name = "BFC 1700", Price = 400 });
}

static internal TradeableGood GetGood(TradeableGoodsNames name)
Expand All @@ -32,13 +39,24 @@ internal class TradeableGood
internal string Name;
internal int Price;
}

internal enum TradeableGoodsNames
{
TrustyRusty = CannonType.TrustyRusty,
PvtPepper = CannonType.PvtPepper,
BFC1700 = CannonType.BFC1700,
Lumber,
Food,
Material,
Weapons,
FineGoods,
Gems,
}

internal enum UpgradeOptions
{
HullArmor, // HP Increase
SailDurability, // Sail HP Increase
RudderStrength, // Turn Speed
}
}
9 changes: 8 additions & 1 deletion Utilities/ShipSpriteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ internal BoatOptions(Ship ship) : this(ship.BoatType, ship.BoatColor, ship.Sail,

internal string ToKey()
{
return $"{Hull}-{Color}-{Sails}-{Condition}";
Cannons.Sort(delegate (Cannon x, Cannon y)
{
return (int)x.Placement * x.Row - (int)y.Placement * y.Row;
});
var cannonKey = string.Join("", Cannons.Select(x => $"{(int)x.Placement}{x.Row}"));

var key = $"{Hull}-{Color}-{Sails}-{Condition}-{cannonKey}";
return key;
}
}

Expand Down

0 comments on commit bab652c

Please sign in to comment.