diff --git a/Components/Singleton.cs b/Components/Singleton.cs index 6804a79..2b53b59 100644 --- a/Components/Singleton.cs +++ b/Components/Singleton.cs @@ -11,6 +11,7 @@ internal class Singleton internal Map Map; public AudioKey Music; + internal bool InventoryOpen; } public enum DebugLevel diff --git a/NovemberPiratesEngine.cs b/NovemberPiratesEngine.cs index 20ce74b..bcb5e5d 100644 --- a/NovemberPiratesEngine.cs +++ b/NovemberPiratesEngine.cs @@ -39,8 +39,6 @@ public void StartGame() ActiveScene = new MainMenuScene(); - var data = ShipData.Instance; - while (!Raylib.WindowShouldClose()) { GameLoop(); diff --git a/Scenes/Levels/OceanScene.cs b/Scenes/Levels/OceanScene.cs index bcb5415..d68d246 100644 --- a/Scenes/Levels/OceanScene.cs +++ b/Scenes/Levels/OceanScene.cs @@ -50,6 +50,7 @@ internal OceanScene() Systems.Add(new CannonBallSystem()); Systems.Add(new EnemyControlSystem()); Systems.Add(new EffectsSystem()); + Systems.Add(new InventorySystem()); Systems.Add(new SpawningSystem()); Systems.Add(new PickupSystem()); Systems.Add(new AudioSystem()); diff --git a/Scenes/Levels/Systems/InventorySystem.cs b/Scenes/Levels/Systems/InventorySystem.cs new file mode 100644 index 0000000..340448b --- /dev/null +++ b/Scenes/Levels/Systems/InventorySystem.cs @@ -0,0 +1,27 @@ +using Arch.Core; +using Arch.Core.Extensions; +using NovemberPirates.Components; +using NovemberPirates.Extensions; +using NovemberPirates.Systems; +using Raylib_CsLo; + +namespace NovemberPirates.Scenes.Levels.Systems +{ + internal class InventorySystem : GameSystem + { + internal override void Update(World world) { } + + internal override void UpdateNoCamera(World world) + { + var singletonEntity = world.QueryFirst(); + var singleton = singletonEntity.Get(); + + if (singleton.InventoryOpen) + { + Console.WriteLine("Inventory Open"); + 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)); + } + } + } +} diff --git a/Scenes/Levels/Systems/PlayerControlSystem.cs b/Scenes/Levels/Systems/PlayerControlSystem.cs index f468155..8f713c3 100644 --- a/Scenes/Levels/Systems/PlayerControlSystem.cs +++ b/Scenes/Levels/Systems/PlayerControlSystem.cs @@ -12,52 +12,159 @@ namespace NovemberPirates.Scenes.Levels.Systems { internal class PlayerControlSystem : GameSystem { + private Dictionary> Controls = new(); internal override void Update(World world) { + if (Controls.Count == 0) + { + LoadControls(world); + } + var singletonEntity = world.QueryFirst(); var singleton = singletonEntity.Get(); + var controlMode = singleton.InventoryOpen ? ControlModes.Inventory : ControlModes.Standard; + var playerEntity = world.QueryFirst(); - //var player = playerEntity.Get(); var sprite = playerEntity.Get(); var playerShip = playerEntity.Get(); var boatChanged = false; - if (Raylib.IsKeyPressed(KeyboardKey.KEY_W)) + foreach (var control in Controls[controlMode]) { - var priorSail = playerShip.Sail; - playerShip.Sail = (SailStatus)Math.Min(Enum.GetValues().Length - 1, (int)playerShip.Sail + 1); + if (control.RepeatPress) + { + if (Raylib.IsKeyDown(control.Key)) + { + boatChanged = control.Action() || boatChanged; + } + } + else + { + if (Raylib.IsKeyPressed(control.Key)) + { + boatChanged = control.Action() || boatChanged; + } + } + } - if (priorSail != playerShip.Sail && playerShip.Sail >= SailStatus.Half) - world.Create().Set(new AudioEvent() { Key = AudioKey.SailOpen, Position = sprite.Position }); + if (singleton.Debug > DebugLevel.None) + { + if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_UP)) + { + playerShip.BoatType = (HullType)Math.Min(Enum.GetValues().Length - 1, (int)playerShip.BoatType + 1); + boatChanged = true; - boatChanged = true; + } + if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_DOWN)) + { + playerShip.BoatType = (HullType)Math.Max(0, (int)playerShip.BoatType - 1); + boatChanged = true; + } } - if (Raylib.IsKeyPressed(KeyboardKey.KEY_S)) - { - var priorSail = playerShip.Sail; - playerShip.Sail = (SailStatus)Math.Max(0, (int)playerShip.Sail - 1); - if (priorSail != playerShip.Sail && playerShip.Sail >= SailStatus.Rowing) - world.Create().Set(new AudioEvent() { Key = AudioKey.SailClose, Position = sprite.Position }); + if (boatChanged) + { + var newboat = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip)); + newboat.Position = sprite.Position; + newboat.Rotation = sprite.Rotation; + playerEntity.Set(newboat); - boatChanged = true; + //sprite.Texture = newboat.Texture; } - if (Raylib.IsKeyDown(KeyboardKey.KEY_A)) + } + public void LoadControls(World world) + { + var singletonEntity = world.QueryFirst(); + var singleton = singletonEntity.Get(); + + Controls.Add(ControlModes.Standard, new List()); + Controls.Add(ControlModes.Inventory, new List()); + + Controls[ControlModes.Standard].Add(new Control() { - sprite.Rotation -= playerShip.RotationSpeed * Raylib.GetFrameTime(); - } - if (Raylib.IsKeyDown(KeyboardKey.KEY_D)) + Key = KeyboardKey.KEY_W, + RepeatPress = false, + Action = () => + { + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); + + var priorSail = playerShip.Sail; + playerShip.Sail = (SailStatus)Math.Min(Enum.GetValues().Length - 1, (int)playerShip.Sail + 1); + + if (priorSail != playerShip.Sail && playerShip.Sail >= SailStatus.Half) + { + world.Create().Set(new AudioEvent() { Key = AudioKey.SailOpen, Position = sprite.Position }); + return true; + } + + return false; + } + }); + + Controls[ControlModes.Standard].Add(new Control() { - sprite.Rotation += playerShip.RotationSpeed * Raylib.GetFrameTime(); - } + Key = KeyboardKey.KEY_S, + RepeatPress = false, + Action = () => + { + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); + + var priorSail = playerShip.Sail; + playerShip.Sail = (SailStatus)Math.Max(0, (int)playerShip.Sail - 1); + + if (priorSail != playerShip.Sail && playerShip.Sail >= SailStatus.Rowing) + { + world.Create().Set(new AudioEvent() { Key = AudioKey.SailClose, Position = sprite.Position }); + return true; + } + return false; + } + }); + Controls[ControlModes.Standard].Add(new Control() + { + Key = KeyboardKey.KEY_A, + RepeatPress = true, + Action = () => + { + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); + + sprite.Rotation -= playerShip.RotationSpeed * Raylib.GetFrameTime(); + return false; + } + }); + + Controls[ControlModes.Standard].Add(new Control() + { + Key = KeyboardKey.KEY_D, + RepeatPress = true, + Action = () => + { + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); + + sprite.Rotation += playerShip.RotationSpeed * Raylib.GetFrameTime(); + return false; + } + }); - if (Raylib.IsKeyPressed(KeyboardKey.KEY_Q) || Raylib.IsKeyDown(KeyboardKey.KEY_LEFT)) + var fireLeftCannon = () => { + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); + // fire cannon Port var nextCannon = playerShip.Cannons.FirstOrDefault(x => x.ReloadElapsed >= x.ReloadTime && x.Placement == BoatSide.Port); @@ -72,10 +179,14 @@ internal override void Update(World world) var sound = world.Create(); sound.Set(new AudioEvent() { Position = cannonPos, Key = AudioKey.CannonFire }); } - } - if (Raylib.IsKeyPressed(KeyboardKey.KEY_E) || Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT)) + return false; + }; + + var fireRightCannon = () => { - // fire cannon Starboard + var playerEntity = world.QueryFirst(); + var sprite = playerEntity.Get(); + var playerShip = playerEntity.Get(); var nextCannon = playerShip.Cannons.FirstOrDefault(x => x.ReloadElapsed >= x.ReloadTime && x.Placement == BoatSide.Starboard); @@ -90,32 +201,70 @@ internal override void Update(World world) var sound = world.Create(); sound.Set(new AudioEvent() { Position = cannonPos, Key = AudioKey.CannonFire }); } - } + return false; + }; - if (singleton.Debug > DebugLevel.None) + Controls[ControlModes.Standard].Add(new Control() { - if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_UP)) - { - playerShip.BoatType = (HullType)Math.Min(Enum.GetValues().Length - 1, (int)playerShip.BoatType + 1); - boatChanged = true; + Key = KeyboardKey.KEY_Q, + RepeatPress = false, + Action = fireLeftCannon + }); - } - if (Raylib.IsKeyPressed(KeyboardKey.KEY_PAGE_DOWN)) - { - playerShip.BoatType = (HullType)Math.Max(0, (int)playerShip.BoatType - 1); - boatChanged = true; + Controls[ControlModes.Standard].Add(new Control() + { + Key = KeyboardKey.KEY_LEFT, + RepeatPress = true, + Action = fireLeftCannon + }); - } - } - if (boatChanged) + + Controls[ControlModes.Standard].Add(new Control() { - var newboat = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip)); - newboat.Position = sprite.Position; - newboat.Rotation = sprite.Rotation; - playerEntity.Set(newboat); + Key = KeyboardKey.KEY_E, + RepeatPress = false, + Action = fireRightCannon + }); - //sprite.Texture = newboat.Texture; - } + Controls[ControlModes.Standard].Add(new Control() + { + Key = KeyboardKey.KEY_RIGHT, + RepeatPress = true, + Action = fireRightCannon + }); + + var openInventory = () => + { + singleton.InventoryOpen = !singleton.InventoryOpen; + return false; + }; + + Controls[ControlModes.Standard].Add(new Control() + { + Key = KeyboardKey.KEY_TAB, + RepeatPress = false, + Action = openInventory + }); + + Controls[ControlModes.Inventory].Add(new Control() + { + Key = KeyboardKey.KEY_TAB, + RepeatPress = false, + Action = openInventory + }); } } + + public class Control + { + public KeyboardKey Key; + public Func Action = () => { return false; }; + public bool RepeatPress; + } + + public enum ControlModes + { + Standard, + Inventory, + } } diff --git a/Scenes/Menus/MainMenu/PauseScene.cs b/Scenes/Menus/MainMenu/PauseScene.cs index 7855f2d..6e92f75 100644 --- a/Scenes/Menus/MainMenu/PauseScene.cs +++ b/Scenes/Menus/MainMenu/PauseScene.cs @@ -3,7 +3,6 @@ using NovemberPirates.Extensions; using NovemberPirates.Scenes.Menus.Components; using NovemberPirates.Scenes.Menus.Systems; -using System.ComponentModel.Design; namespace NovemberPirates.Scenes.Menus.MainMenu { diff --git a/Scenes/Menus/MainMenu/SettingsScene.cs b/Scenes/Menus/MainMenu/SettingsScene.cs index 3ef239f..dde5996 100644 --- a/Scenes/Menus/MainMenu/SettingsScene.cs +++ b/Scenes/Menus/MainMenu/SettingsScene.cs @@ -50,6 +50,17 @@ public SettingsScene(Singleton singleton, BaseScene lastscene) SettingKey = SettingsManager.SettingKeys.SfxVolume, }); + World.Create(new UiButton + { + Text = "Full Screen", + Action = () => + { + Raylib.ToggleFullscreen(); + SettingsManager.Instance.Settings[SettingsManager.SettingKeys.Fullscreen] = Raylib.IsWindowFullscreen() ? 1 : 0; + }, + Order = index++ + }); + World.Create(new UiButton { Text = "Save", diff --git a/Utilities/SettingsManager.cs b/Utilities/SettingsManager.cs index 6f79e10..24abae5 100644 --- a/Utilities/SettingsManager.cs +++ b/Utilities/SettingsManager.cs @@ -30,7 +30,7 @@ internal void LoadSettings() Settings.Add(SettingKeys.MainVolume, 50f); Settings.Add(SettingKeys.MusicVolume, 50f); Settings.Add(SettingKeys.SfxVolume, 50f); - + Settings.Add(SettingKeys.Fullscreen, 0); } } @@ -51,7 +51,8 @@ internal enum SettingKeys MainVolume, MusicVolume, SfxVolume, - Language + Language, + Fullscreen } } }