Skip to content

Commit

Permalink
Sounds and menu clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Jan 30, 2024
1 parent 306a069 commit 30b3bc6
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 24 deletions.
8 changes: 8 additions & 0 deletions Extensions/ArchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public static Entity QueryFirst<T0>(this World world)

return result.Value;
}
public static Entity? QueryFirstOrNull<T0>(this World world)
{
try { return world.QueryFirst<T0>(); }
catch
{
return null;
}
}

public static T0 QueryUnique<T0>(this World world) where T0 : struct
{
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A Game for [Game of the Month 29 (November 2023)](https://itch.io/jam/one-game-a

# How to play

Download the latest release from [the Releases](https://github.com/Nhawdge/November-Pirates/releases].
Download the latest release from [itch](https://nhawdge.itch.io/november-pirates).

Extract the zip file and run the executable.

Expand Down
1 change: 1 addition & 0 deletions Scenes/Levels/Components/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Ship(HullType hull, BoatColor color, Team team)
internal float Currency;
internal Port? TargetPort;
internal List<Route> SailingRoute;
internal int Wood;

public Task<List<Vector2>> NavTask { get; set; }
}
Expand Down
26 changes: 25 additions & 1 deletion Scenes/Levels/Systems/PickupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NovemberPirates.Extensions;
using NovemberPirates.Scenes.Levels.Components;
using NovemberPirates.Systems;
using NovemberPirates.Utilities.Data;
using Raylib_CsLo;
using System.Numerics;

Expand All @@ -17,14 +16,26 @@ internal override void Update(World world)
var singletonEntity = world.QueryFirst<Singleton>();
var singleton = singletonEntity.Get<Singleton>();

var player = world.QueryFirst<Player>();
var playerSprite = player.Get<Sprite>();

var crewQuery = new QueryDescription().WithAll<Sprite, CrewMember>();
var woodQuery = new QueryDescription().WithAll<Sprite, Wood>();

world.Query(crewQuery, (entity) =>
{
var sprite = entity.Get<Sprite>();
var crewMember = entity.Get<CrewMember>();
crewMember.Elapsed += Raylib.GetFrameTime();

if (playerSprite.Position.DistanceTo(sprite.Position) < 50)
{
world.Destroy(entity);
var playerShip = player.Get<Ship>();
playerShip.Crew += 1;
world.Create<AudioEvent>().Set(new AudioEvent() { Key = Utilities.AudioKey.Yarr, Position = sprite.Position });
}

if (crewMember.Elapsed > crewMember.Duration)
{
world.Destroy(entity);
Expand All @@ -34,6 +45,19 @@ internal override void Update(World world)
{
sprite.Position += Vector2.Normalize(crewMember.Target - sprite.Position) * Raylib.GetFrameTime() * crewMember.Speed;
}
});

world.Query(woodQuery, (entity) =>
{
var sprite = entity.Get<Sprite>();

if (playerSprite.Position.DistanceTo(sprite.Position) < 50)
{
world.Destroy(entity);
var playerShip = player.Get<Ship>();
playerShip.Wood += 1;
world.Create<AudioEvent>().Set(new AudioEvent() { Key = Utilities.AudioKey.CollectWood, Position = sprite.Position });
}

});
}
Expand Down
9 changes: 9 additions & 0 deletions Scenes/Menus/Components/UiContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Raylib_CsLo;

namespace NovemberPirates.Scenes.Menus.Components
{
internal class UiContainer
{
internal Rectangle Rectangle = new();
}
}
21 changes: 13 additions & 8 deletions Scenes/Menus/MainMenu/CreditsScene.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NovemberPirates.Scenes.Menus.Components;
using NovemberPirates.Scenes.Menus.Systems;
using Raylib_CsLo;

namespace NovemberPirates.Scenes.Menus.MainMenu
{
Expand All @@ -8,14 +9,18 @@ internal class CreditsScene : BaseScene
public CreditsScene()
{
Systems.Add(new MenuSystem());
Systems.Add(new MenuMusicSystem());

World.Create(new UiTitle { Text = @"Credits", Order = 1 });
World.Create(new UiTitle { Text = @"Nhawdge - Code", Order = 2 });
World.Create(new UiTitle { Text = @"Kaitlyn Schmidt - Game Design", Order = 3 });
World.Create(new UiTitle { Text = @"Game Design and Project Management?", Order = 4 });
World.Create(new UiTitle { Text = @"Barun Sinha - Sounds", Order = 5 });
World.Create(new UiTitle { Text = @"UnicornGirlie - Art ", Order = 6 });
World.Create(new UiTitle { Text = @"Kenney.nl - Pirate Asset Pack", Order = 7 });
var index = 5;
World.Create(new UiContainer { Rectangle = new Rectangle() });

World.Create(new UiTitle { Text = @"Credits", Order = index++ });
World.Create(new UiTitle { Text = @"Nhawdge - Code", Order = index++ });
World.Create(new UiTitle { Text = @"Kaitlyn Schmidt - Game Design", Order = index++ });
World.Create(new UiTitle { Text = @"Barun Sinha - Sounds", Order = index++ });
World.Create(new UiTitle { Text = @"UnicornGirlie - Title Art ", Order = index++ });
World.Create(new UiTitle { Text = @"CFHM - Yarrs", Order = index++ });
World.Create(new UiTitle { Text = @"Kenney.nl - Pirate Asset Pack", Order = index++ });

World.Create(new UiButton
{
Expand All @@ -24,7 +29,7 @@ public CreditsScene()
{
NovemberPiratesEngine.Instance.ActiveScene = new MainMenuScene();
},
Order = 9
Order = index++
});
}
}
Expand Down
14 changes: 10 additions & 4 deletions Scenes/Menus/MainMenu/HowToPlayScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Arch.Core.Extensions;
using NovemberPirates.Scenes.Menus.Components;
using NovemberPirates.Scenes.Menus.Systems;
using Raylib_CsLo;

namespace NovemberPirates.Scenes.Menus.MainMenu
{
Expand All @@ -10,13 +11,18 @@ internal class HowToPlayScene : BaseScene
public HowToPlayScene()
{
Systems.Add(new MenuSystem());
Systems.Add(new MenuMusicSystem());

var index = 5;

World.Create(new UiContainer { Rectangle = new Rectangle() });

var instructions = World.Create<UiTitle>();
instructions.Set(new UiTitle { Text = @"WASD to move Q/E or Arrow keys to shoot", Order = 1 });
instructions.Set(new UiTitle { Text = @"WASD to move Q/E or Arrow keys to shoot", Order = index++ });
var instructions2 = World.Create<UiTitle>();
instructions2.Set(new UiTitle { Text = @"f3 to change the wind", Order = 2 });
instructions2.Set(new UiTitle { Text = @"f3 to change the wind", Order = index++ });
var instructions3 = World.Create<UiTitle>();
instructions3.Set(new UiTitle { Text = @"F2 for the debugger I'm proud of", Order = 3 });
instructions3.Set(new UiTitle { Text = @"F2 for the debugger I'm proud of", Order = index++ });

World.Create(new UiButton
{
Expand All @@ -25,7 +31,7 @@ public HowToPlayScene()
{
NovemberPiratesEngine.Instance.ActiveScene = new MainMenuScene();
},
Order = 5
Order = index++
});
}

Expand Down
1 change: 1 addition & 0 deletions Scenes/Menus/MainMenu/PauseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class PauseScene : BaseScene
public PauseScene(BaseScene lastScene)
{
Systems.Add(new MenuSystem());
Systems.Add(new MenuMusicSystem());

World.Create(new UiButton
{
Expand Down
38 changes: 32 additions & 6 deletions Scenes/Menus/MainMenu/SettingsScene.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Arch.Core.Extensions;
using NovemberPirates.Scenes.Menus.Components;
using NovemberPirates.Scenes.Menus.Systems;
using Raylib_CsLo;

namespace NovemberPirates.Scenes.Menus.MainMenu
{
internal class SettingsScene
internal class SettingsScene : BaseScene
{
public SettingsScene()
{
Systems.Add(new MenuSystem());
Systems.Add(new MenuMusicSystem());

var index = 5;

World.Create(new UiContainer { Rectangle = new Rectangle() });

var instructions = World.Create<UiTitle>();
instructions.Set(new UiTitle { Text = @"WASD to move Q/E or Arrow keys to shoot", Order = index++ });
var instructions2 = World.Create<UiTitle>();
instructions2.Set(new UiTitle { Text = @"f3 to change the wind", Order = index++ });
var instructions3 = World.Create<UiTitle>();
instructions3.Set(new UiTitle { Text = @"F2 for the debugger I'm proud of", Order = index++ });

World.Create(new UiButton
{
Text = "Back",
Action = () =>
{
NovemberPiratesEngine.Instance.ActiveScene = new MainMenuScene();
},
Order = index++
});
}

}
}
28 changes: 25 additions & 3 deletions Scenes/Menus/Systems/MenuSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,27 @@ internal override void UpdateNoCamera(World world)
new Rectangle(0, 0, Raylib.GetScreenWidth(), Raylib.GetScreenHeight()),
Vector2.Zero, 0f, Raylib.WHITE);
var query = new QueryDescription().WithAny<UiTitle, UiButton, SpriteButton>();
var uiElementCount = world.CountEntities(in query);

var centerPoint = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);

var dummyrect = new Rectangle(centerPoint.X - 200, centerPoint.Y - 300, 400, 500);
//RayGui.GuiDummyRec(dummyrect, "");
var placementContainer = new Rectangle(centerPoint.X - 300, centerPoint.Y - 300, 600, 500);

var container = world.QueryFirstOrNull<UiContainer>();
if (container.HasValue)
{
var uiContainer = container.Value.Get<UiContainer>();

//Raylib.DrawRectangleRec(container.Rectangle, Color.BLACK);
RayGui.GuiDummyRec(uiContainer.Rectangle with
{
X = placementContainer.x,
y = placementContainer.y,
width = placementContainer.width,
height = 55 * uiElementCount
}, "");
}

var index = 0;

//RayGui.GuiSetFont(CreditsFont);
Expand All @@ -52,7 +68,13 @@ internal override void UpdateNoCamera(World world)
if (entity.Has<UiButton>())
{
var button = entity.Get<UiButton>();
var rect = dummyrect with { x = dummyrect.x + 100, y = dummyrect.y + (60 * button.Order), width = 200, height = 50 };
var rect = placementContainer with
{
x = placementContainer.x + placementContainer.width / 2 - 200 / 2,
y = placementContainer.y + (60 * button.Order),
width = 200,
height = 50
};

if (RayGui.GuiButton(rect, button.Text))
{
Expand Down
11 changes: 10 additions & 1 deletion Utilities/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ private AudioManager() { }
public Dictionary<AudioKey, Sound[]> AudioStore = new();
public Dictionary<AudioKey, Music> MusicStore = new();


internal void LoadAllAudio()
{
AudioStore.Add(AudioKey.CannonFire, new[] {
Expand Down Expand Up @@ -63,6 +62,15 @@ internal void LoadAllAudio()
Raylib.LoadSound("Assets/Audio/sfx_WindinSail.ogg"),
});

AudioStore.Add(AudioKey.Yarr, new[]
{
Raylib.LoadSound("Assets/Audio/yarrs01.wav"),
Raylib.LoadSound("Assets/Audio/yarrs02.wav"),
Raylib.LoadSound("Assets/Audio/yarrs03.wav"),
});

// M U S I C

MusicStore.Add(AudioKey.Charge, Raylib.LoadMusicStream("Assets/Audio/Charge.wav"));
MusicStore.Add(AudioKey.Drifting, Raylib.LoadMusicStream("Assets/Audio/Drifting.wav"));
MusicStore.Add(AudioKey.TheBleedingOcean, Raylib.LoadMusicStream("Assets/Audio/The-Bleeding-Ocean.wav"));
Expand Down Expand Up @@ -118,5 +126,6 @@ internal enum AudioKey
Drifting,
TheWarriorsOfTheWater,
TheBleedingOcean,
Yarr,
}
}
46 changes: 46 additions & 0 deletions Utilities/SettingsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;

namespace NovemberPirates.Utilities
{
internal class SettingsManager
{
private SettingsManager() { }

internal static SettingsManager Instance = new();

internal Dictionary<SettingKeys, float> Settings = new();

internal void LoadSettings()
{
if (File.Exists("settings.json"))
{
try
{
var settings = File.ReadAllText("settings.json");
Settings = JsonSerializer.Deserialize<Dictionary<SettingKeys, float>>(settings);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
else
{
Settings.Add(SettingKeys.MainVolume, 0.5f);
Settings.Add(SettingKeys.MusicVolume, 0.5f);
Settings.Add(SettingKeys.SfxVolume, 0.5f);

File.WriteAllText("settings.json", JsonSerializer.Serialize(Settings));
}
}

internal enum SettingKeys
{
MainVolume,
MusicVolume,
SfxVolume,
Language
}
}
}

0 comments on commit 30b3bc6

Please sign in to comment.