Skip to content

Commit

Permalink
Some stuff I can't remember
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Nov 15, 2023
1 parent d5ad458 commit 82439ed
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 21 deletions.
53 changes: 53 additions & 0 deletions Assets/Art/wood.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ "frames": [
{
"filename": "Wood1-0",
"frame": { "x": 1, "y": 1, "w": 26, "h": 10 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 26, "h": 10 },
"sourceSize": { "w": 26, "h": 10 },
"duration": 100
},
{
"filename": "Wood2-1",
"frame": { "x": 29, "y": 1, "w": 26, "h": 10 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 26, "h": 10 },
"sourceSize": { "w": 26, "h": 10 },
"duration": 100
},
{
"filename": "Wood3-2",
"frame": { "x": 1, "y": 13, "w": 26, "h": 10 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 26, "h": 10 },
"sourceSize": { "w": 26, "h": 10 },
"duration": 100
},
{
"filename": "Wood4-3",
"frame": { "x": 29, "y": 13, "w": 26, "h": 10 },
"rotated": false,
"trimmed": false,
"spriteSourceSize": { "x": 0, "y": 0, "w": 26, "h": 10 },
"sourceSize": { "w": 26, "h": 10 },
"duration": 100
}
],
"meta": {
"app": "https://www.aseprite.org/",
"version": "1.3-rc6-x64",
"image": "wood.png",
"format": "RGBA8888",
"size": { "w": 56, "h": 24 },
"scale": "1",
"frameTags": [
{ "name": "Wood1", "from": 0, "to": 0, "direction": "forward", "color": "#000000ff" },
{ "name": "Wood2", "from": 1, "to": 1, "direction": "forward", "color": "#000000ff" },
{ "name": "Wood3", "from": 2, "to": 2, "direction": "forward", "color": "#000000ff" },
{ "name": "Wood4", "from": 3, "to": 3, "direction": "forward", "color": "#000000ff" }
]
}
}
Binary file added Assets/Art/wood.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/wood.ase
Binary file not shown.
Binary file added Assets/Audio/sfx_ShipHit_01.ogg
Binary file not shown.
Binary file added Assets/Audio/sfx_ShipHit_02.ogg
Binary file not shown.
Binary file added Assets/Audio/sfx_ShipHit_03.ogg
Binary file not shown.
Binary file added Assets/lavanda.rgs
Binary file not shown.
1 change: 1 addition & 0 deletions Components/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal class Ship

internal float MaxSpeed = 500f;
internal float HullHealth = 100f;
internal float WindInSail;

// 1 - steering only, drifts in the wind.
// 2 - Steering and rowing
Expand Down
12 changes: 12 additions & 0 deletions Components/Wood.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Numerics;

namespace NovemberPirates.Components
{
internal class Wood
{
internal float Duration;
internal float Elapsed;
internal Vector2 Target;
internal float Speed;
}
}
16 changes: 16 additions & 0 deletions Entities/Archetypes/PickupBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,21 @@ internal static void CreateCrewMember(World world, Vector2 position)
entity.Set(crewMember);
entity.Set(sprite);
}

internal static void CreateWood(World world, Vector2 position)
{
var entity = world.Create<Wood, Sprite>();
var wood = new Wood();
var spread = 100;
wood.Target = position + new Vector2(Random.Shared.Next(-spread, spread), Random.Shared.Next(-spread, spread));
wood.Duration = 25f;
wood.Speed = 10f;

var sprite = new Sprite(TextureKey.Wood, "Assets/Art/wood", 1f, true);
sprite.Position = position;

entity.Set(wood);
entity.Set(sprite);
}
}
}
2 changes: 1 addition & 1 deletion Scenes/BaseScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NovemberPirates.Scenes
{
internal class BaseScene
internal abstract class BaseScene
{
internal World World = World.Create();

Expand Down
21 changes: 13 additions & 8 deletions Scenes/Levels/Systems/CannonBallSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ internal override void Update(World world)
{
ship.HullHealth -= 5;
EffectsBuilder.CreateExplosion(world, end);
world.Create(new AudioEvent
{
Key = AudioKey.CannonHitShip,
Position = sprite.Position
});
destroyed = true;
ship.BoatCondition = ship.HullHealth switch
{
Expand All @@ -51,22 +56,22 @@ internal override void Update(World world)
< 75 => BoatCondition.Good,
_ => BoatCondition.Good
};
var shouldSpawnWood = Random.Shared.Next(0, 100) < 30;
if (shouldSpawnWood)
{
PickupBuilder.CreateWood(world, sprite.Position);
}

shipSprite.Texture = ShipSpriteBuilder.GenerateBoat(new BoatOptions(ship)).Texture;
}
});
if (destroyed)
world.Destroy(entity);
else
else if (cannonball.Elapsed > cannonball.Duration)
{
if (cannonball.Elapsed > cannonball.Duration)
{
var sound = world.Create<AudioEvent>();
sound.Set(new AudioEvent() { Key = AudioKey.CannonHitWater, Position = sprite.Position });
world.Destroy(entity);
}
world.Create(new AudioEvent() { Key = AudioKey.CannonHitWater, Position = sprite.Position });
world.Destroy(entity);
}

});
}
}
Expand Down
4 changes: 2 additions & 2 deletions Scenes/Levels/Systems/EnemyControlSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal override void Update(World world)
ship.Crew -= 1;
ship.HullHealth += 1;
var sound = world.Create<AudioEvent>();
sound.Set(new AudioEvent() { Key = AudioKey.CrewHitWater });
sound.Set(new AudioEvent() { Key = AudioKey.CrewHitWater, Position = sprite.Position });
PickupBuilder.CreateCrewMember(world, sprite.Position);
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ internal override void Update(World world)
ship.Sail = SailStatus.Closed;
sprite.Texture = ShipSpriteBuilder.GenerateBoat(new BoatOptions(ship)).Texture;
}
Console.WriteLine($"{new BoatOptions(ship).ToString()} {ship.Crew} {ship.HullHealth} ");
//Console.WriteLine($"{new BoatOptions(ship).ToString()} {ship.Crew} {ship.HullHealth} ");
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions Scenes/Levels/Systems/PlayerControlSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ internal override void Update(World world)

if (Raylib.IsKeyPressed(KeyboardKey.KEY_W))
{
var priorSail = playerShip.Sail;
playerShip.Sail = (SailStatus)Math.Min(Enum.GetValues<SailStatus>().Length - 1, (int)playerShip.Sail + 1);

if (priorSail != playerShip.Sail && playerShip.Sail >= SailStatus.Half)
world.Create<AudioEvent>().Set(new AudioEvent() { Key = AudioKey.SailOpen, Position = sprite.Position });

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<AudioEvent>().Set(new AudioEvent() { Key = AudioKey.SailClose, Position = sprite.Position });

boatChanged = true;
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_A))
Expand Down
5 changes: 5 additions & 0 deletions Scenes/Levels/Systems/ShipControlSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ internal override void Update(World world)
< 75 => 0.1f,
_ => 0f,
};

if (windInSail == 1f && windInSail != ship.WindInSail && ship.Sail >= SailStatus.Half)
world.Create(new AudioEvent() { Key = AudioKey.WindInSail, Position = sprite.Position });

ship.WindInSail = windInSail;
//singleton.DebugText += $"Boat Angle:{boatAngle.ToString("0.0")}\nWind Angle: {windAngle.ToString("0.0")}\nAngle Diff: {angleDiff.ToString("0.0")}\nWind In Sail: {windInSail.ToString("0.0")}";
var windStrength = wind.WindStrength * windInSail;

Expand Down
34 changes: 33 additions & 1 deletion Scenes/Menus/MainMenu/MainMenuScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,39 @@ public MainMenuScene()
Order = 1
});



World.Create(new UiButton
{
Text = "How to Play",
Action = () =>
{
NovemberPiratesEngine.Instance.ActiveScene = new HowToPlayScene();
},
Order = 2
});

World.Create(new UiButton
{
Text = "Credits",
Action = () =>
{
NovemberPiratesEngine.Instance.ActiveScene = new CreditsScene();
},
Order = 3
});


World.Create(new UiButton
{
Text = "Exit",
Action = () =>
{
Environment.Exit(0);
//NovemberPiratesEngine.Instance.ActiveScene = new HowToPlayScene();
},
Order = 5
});



}
Expand Down
16 changes: 11 additions & 5 deletions Scenes/Menus/Systems/MenuSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ namespace NovemberPirates.Scenes.Menus.Systems
{
internal class MenuSystem : GameSystem
{

internal override void Update(World world) { }

internal override void UpdateNoCamera(World world)
{
//RayGui.GuiLoadStyle("Assets/lavanda.rgs");
var query = new QueryDescription().WithAny<UiTitle, UiButton>();

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

var dummyrect = new Rectangle(centerPoint.X - 200, centerPoint.Y - 150, 400, 400);
RayGui.GuiDummyRec(dummyrect, "");
var index = 0;

RayGui.GuiSetStyle((int)GuiControl.DEFAULT, (int)GuiDefaultProperty.TEXT_SIZE, 48);
RayGui.GuiSetStyle((int)GuiControl.LABEL, (int)GuiControlProperty.TEXT_ALIGNMENT, 1);

RayGui.GuiSetStyle((int)GuiControl.BUTTON, (int)GuiControlProperty.TEXT_ALIGNMENT, 0);
world.Query(in query, (entity) =>
{
index++;
Expand All @@ -31,20 +38,19 @@ internal override void UpdateNoCamera(World world)
var rect = new Rectangle(centerPoint.X - 100, 200 + 50 * titleComponent.Order, 200, 100);
//RayGui.GuiTextBox(text, centerPoint.X - 200, centerPoint.Y - 200, 24, Raylib.ORANGE);

RayGui.GuiSetStyle((int)GuiControl.LABEL, (int)GuiControlProperty.TEXT_ALIGNMENT, 1);

// TODO fix font size
var font = RayGui.GuiGetFont();
font.baseSize = 48;
RayGui.GuiSetFont(font);

RayGui.GuiLabel(rect, text);
}
RayGui.GuiSetStyle((int)GuiControl.BUTTON, (int)GuiControlProperty.TEXT_ALIGNMENT, 1);

RayGui.GuiSetStyle((int)GuiControl.DEFAULT, (int)GuiDefaultProperty.TEXT_SIZE, 24);

if (entity.Has<UiButton>())
{
var button = entity.Get<UiButton>();
var rect = dummyrect with { x = dummyrect.x + 100, y = dummyrect.y + 50 * button.Order, width = 200, height = 60 };
var rect = dummyrect with { x = dummyrect.x + 100, y = dummyrect.y + (60 * button.Order), width = 200, height = 50 };

if (RayGui.GuiButton(rect, button.Text))
{
Expand Down
9 changes: 8 additions & 1 deletion Utilities/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ internal void LoadAllAudio()
Raylib.LoadSound("Assets/Audio/sfx_CannonFire_03.ogg"),
Raylib.LoadSound("Assets/Audio/sfx_CannonFire_04.ogg"),
});
AudioStore.Add(AudioKey.CannonHitShip, new[]
{
Raylib.LoadSound("Assets/Audio/sfx_ShipHit_01.ogg"),
Raylib.LoadSound("Assets/Audio/sfx_ShipHit_02.ogg"),
Raylib.LoadSound("Assets/Audio/sfx_ShipHit_03.ogg"),
});
AudioStore.Add(AudioKey.CannonHitWater, new[]
{
Raylib.LoadSound("Assets/Audio/sfx_CannonHitWater.ogg")
Expand All @@ -33,7 +39,7 @@ internal void LoadAllAudio()
{
Raylib.LoadSound("Assets/Audio/sfx_Wind.ogg")
});
AudioStore.Add(AudioKey.CollectWood, new[] {
AudioStore.Add(AudioKey.CollectWood, new[] { // TODO
Raylib.LoadSound("Assets/Audio/sfx_CollectWood_01.ogg"),
Raylib.LoadSound("Assets/Audio/sfx_CollectWood_02.ogg"),
Raylib.LoadSound("Assets/Audio/sfx_CollectWood_03.ogg"),
Expand Down Expand Up @@ -76,5 +82,6 @@ internal enum AudioKey
SailClose,
SailOpen,
WindInSail,
CannonHitShip,
}
}
4 changes: 1 addition & 3 deletions Utilities/ShipSpriteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ internal static Sprite GenerateBoat(BoatOptions options)
};
sprite.Play("idle");

//Raylib.ExportImage(Raylib.LoadImageFromTexture(sprite.Texture), options.ToKey() + ".png");

//TextureManager.Instance.TextureCache.Add(options.ToKey(), renderTexture.texture);
TextureManager.Instance.TextureCache.Add(options.ToKey(), renderTexture.texture);

return sprite;
}
Expand Down
2 changes: 2 additions & 0 deletions Utilities/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private void LoadTextures()
TextureStore.Add(TextureKey.Fire, Raylib.LoadTexture("Assets/Art/fire1.png"));
TextureStore.Add(TextureKey.WhitePixel, Raylib.LoadTexture("Assets/Art/whitepixel.png"));
TextureStore.Add(TextureKey.Crew, Raylib.LoadTexture("Assets/Art/crew.png"));
TextureStore.Add(TextureKey.Wood, Raylib.LoadTexture("Assets/Art/wood.png"));
}

internal Texture GetTexture(TextureKey key)
Expand Down Expand Up @@ -70,5 +71,6 @@ internal enum TextureKey
Crew,
HullSmall,
HullMedium,
Wood,
}
}

0 comments on commit 82439ed

Please sign in to comment.