From ca16e6e5cdbda8f7776114929e5cdae5e0071e3e Mon Sep 17 00:00:00 2001 From: John Pavek Date: Sun, 4 Feb 2024 01:47:36 -0600 Subject: [PATCH] WIP Inventory step 1 --- NovemberPiratesEngine.cs | 11 ++++-- .../Levels/DataManagers/InventoryManager.cs | 14 ++++++++ Scenes/Levels/Systems/EnemyAISystem.cs | 23 ++++++++++++ Scenes/Levels/Systems/InventorySystem.cs | 35 +++++++++++++++++-- Scenes/Levels/Systems/PickupSystem.cs | 5 ++- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 Scenes/Levels/DataManagers/InventoryManager.cs create mode 100644 Scenes/Levels/Systems/EnemyAISystem.cs diff --git a/NovemberPiratesEngine.cs b/NovemberPiratesEngine.cs index bcb5e5d..3fb6373 100644 --- a/NovemberPiratesEngine.cs +++ b/NovemberPiratesEngine.cs @@ -1,5 +1,6 @@ using NovemberPirates.Scenes; using NovemberPirates.Scenes.Menus.MainMenu; +using NovemberPirates.Utilities; using NovemberPirates.Utilities.Data; using Raylib_CsLo; @@ -19,8 +20,8 @@ public void StartGame() //Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_TOPMOST); //Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_MAXIMIZED); //Raylib.SetConfigFlags(ConfigFlags.FLAG_WINDOW_UNDECORATED); - - Raylib.InitWindow(0,0, "November Pirates"); + + Raylib.InitWindow(0, 0, "November Pirates"); var monitor = Raylib.GetCurrentMonitor(); var width = Raylib.GetMonitorWidth(monitor); @@ -31,6 +32,12 @@ public void StartGame() Raylib.SetTargetFPS(60); Raylib.InitAudioDevice(); Raylib.SetExitKey(0); + + if (SettingsManager.Instance.Settings[SettingsManager.SettingKeys.Fullscreen] == 1) + { + Raylib.ToggleFullscreen(); + } + Camera = new Camera2D { zoom = 1.0f, diff --git a/Scenes/Levels/DataManagers/InventoryManager.cs b/Scenes/Levels/DataManagers/InventoryManager.cs new file mode 100644 index 0000000..412796e --- /dev/null +++ b/Scenes/Levels/DataManagers/InventoryManager.cs @@ -0,0 +1,14 @@ +namespace NovemberPirates.Scenes.Levels.DataManagers +{ + internal class InventoryManager + { + private InventoryManager() { } + + public static InventoryManager Instance = new(); + + public long Gold = 0; + public long Food = 0; + public long Lumber = 0; + + } +} diff --git a/Scenes/Levels/Systems/EnemyAISystem.cs b/Scenes/Levels/Systems/EnemyAISystem.cs new file mode 100644 index 0000000..aa0d13c --- /dev/null +++ b/Scenes/Levels/Systems/EnemyAISystem.cs @@ -0,0 +1,23 @@ +using Arch.Core; +using NovemberPirates.Systems; + +namespace NovemberPirates.Scenes.Levels.Systems +{ + internal class EnemyAISystem : GameSystem + { + internal override void Update(World world) + { + + } + } + + public enum EnemyGoals + { + Sailing, + Trading, + Repairing, + Escaping, + GetReinforcements, + Fighting + } +} diff --git a/Scenes/Levels/Systems/InventorySystem.cs b/Scenes/Levels/Systems/InventorySystem.cs index 340448b..ab19143 100644 --- a/Scenes/Levels/Systems/InventorySystem.cs +++ b/Scenes/Levels/Systems/InventorySystem.cs @@ -2,8 +2,12 @@ using Arch.Core.Extensions; using NovemberPirates.Components; using NovemberPirates.Extensions; +using NovemberPirates.Scenes.Levels.Components; +using NovemberPirates.Scenes.Levels.DataManagers; using NovemberPirates.Systems; +using NovemberPirates.Utilities; using Raylib_CsLo; +using System.Numerics; namespace NovemberPirates.Scenes.Levels.Systems { @@ -16,11 +20,38 @@ internal override void UpdateNoCamera(World world) var singletonEntity = world.QueryFirst(); var singleton = singletonEntity.Get(); + var playerEntity = world.QueryFirst(); + var player = playerEntity.Get(); + + if (singleton.InventoryOpen) { - Console.WriteLine("Inventory Open"); + var inventoryFrame = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2); + Raylib.DrawText("Inventory", 0, 0, 24, Raylib.BLUE); - Raylib.DrawRectangle(Raylib.GetScreenWidth() / 2 - 200, Raylib.GetScreenHeight() / 2 - 200, 400, 400, Raylib.Fade(Raylib.BLACK, 0.8f)); + Raylib.DrawRectangle( + (int)(Raylib.GetScreenWidth() / 2 - inventoryFrame.X / 2), + (int)(Raylib.GetScreenHeight() / 2 - inventoryFrame.Y / 2), + (int)inventoryFrame.X, + (int)inventoryFrame.Y, + Raylib.Fade(Raylib.BLACK, 0.8f)); + + var rightAlignment = Raylib.GetScreenWidth() / 2 + 100; + var leftAlignment = inventoryFrame.X + 10; + + Raylib.DrawText($"Gold: {InventoryManager.Instance.Gold} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 180, 24, Raylib.WHITE); + Raylib.DrawText($"Lumber: {InventoryManager.Instance.Lumber} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 150, 24, Raylib.WHITE); + Raylib.DrawText($"Food: {InventoryManager.Instance.Food} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 120, 24, Raylib.WHITE); + + var playerShip = playerEntity.Get(); + + 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); + } } } diff --git a/Scenes/Levels/Systems/PickupSystem.cs b/Scenes/Levels/Systems/PickupSystem.cs index 7b89b5e..9b3e6a3 100644 --- a/Scenes/Levels/Systems/PickupSystem.cs +++ b/Scenes/Levels/Systems/PickupSystem.cs @@ -3,6 +3,7 @@ using NovemberPirates.Components; using NovemberPirates.Extensions; using NovemberPirates.Scenes.Levels.Components; +using NovemberPirates.Scenes.Levels.DataManagers; using NovemberPirates.Systems; using Raylib_CsLo; using System.Numerics; @@ -54,11 +55,9 @@ internal override void Update(World world) if (playerSprite.Position.DistanceTo(sprite.Position) < 50) { world.Destroy(entity); - var playerShip = player.Get(); - playerShip.Wood += 1; + InventoryManager.Instance.Lumber += 1; world.Create().Set(new AudioEvent() { Key = Utilities.AudioKey.CollectWood, Position = sprite.Position }); } - }); } }