diff --git a/BakeryGame.csproj b/BakeryGame.csproj
index fcfa10b..b8f5fa7 100644
--- a/BakeryGame.csproj
+++ b/BakeryGame.csproj
@@ -5,6 +5,7 @@
net7.0
enable
enable
+ true
@@ -12,4 +13,13 @@
+
+
+ Always
+
+
+ Always
+
+
+
diff --git a/Components/Environment/FloorComponent.cs b/Components/Environment/FloorComponent.cs
new file mode 100644
index 0000000..d0af780
--- /dev/null
+++ b/Components/Environment/FloorComponent.cs
@@ -0,0 +1,9 @@
+using System.Numerics;
+using Scellecs.Morpeh;
+
+namespace BakeryGame.Components.Environment;
+
+public struct FloorComponent: IComponent
+{
+ public Vector3 Size;
+}
\ No newline at end of file
diff --git a/Entities/FloorFactory.cs b/Entities/FloorFactory.cs
new file mode 100644
index 0000000..c2abb95
--- /dev/null
+++ b/Entities/FloorFactory.cs
@@ -0,0 +1,30 @@
+using System.Numerics;
+using BakeryGame.Components.Common;
+using BakeryGame.Components.Environment;
+using Raylib_cs;
+using Scellecs.Morpeh;
+
+namespace BakeryGame.Entities;
+
+public class FloorFactory
+{
+ private readonly World _world;
+
+ public FloorFactory(World world)
+ {
+ _world = world;
+ }
+
+ public Entity CreateFloorBlock(float x, float z, float width, float height)
+ {
+ var position = new Vector3(x, 0, z);
+ var size = new Vector3(width, 0, height);
+
+ var block = _world.CreateEntity();
+ block.SetComponent(new FloorComponent { Size = size });
+ block.SetComponent(new ColorComponent { Color = Color.Red });
+ block.SetComponent(new PositionComponent(){ Position = position });
+
+ return block;
+ }
+}
\ No newline at end of file
diff --git a/Entities/RoomBuilder.cs b/Entities/RoomBuilder.cs
index c13e938..729bb0a 100644
--- a/Entities/RoomBuilder.cs
+++ b/Entities/RoomBuilder.cs
@@ -6,7 +6,7 @@ public class RoomBuilder
{
public static int RoomSize = 16;
- public static IEnumerable GenerateMapOfBlocks(BlockFactory blockFactory)
+ public static IEnumerable GenerateMapOfBlocks(BlockFactory blockFactory, FloorFactory floorFactory)
{
for (int x = -RoomSize / 2; x <= RoomSize / 2; x++) {
for (int z = -RoomSize / 2; z <= RoomSize / 2; z++) {
@@ -16,5 +16,6 @@ public class RoomBuilder
}
}
}
+ yield return floorFactory.CreateFloorBlock(0, 0, RoomSize, RoomSize);
}
}
\ No newline at end of file
diff --git a/Program.cs b/Program.cs
index 76a1dc5..7baf2d8 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1,15 +1,8 @@
// See https://aka.ms/new-console-template for more information
using System.Numerics;
-using BakeryGame.Components.Common;
-using BakeryGame.Components.Environment;
using BakeryGame.Components.Player;
using BakeryGame.Entities;
-using BakeryGame.Models;
-using BakeryGame.Systems;
-using BakeryGame.Systems.Common;
-using BakeryGame.Systems.Player;
-using BakeryGame.Systems.Rendering;
using Raylib_cs;
using Scellecs.Morpeh;
@@ -21,18 +14,26 @@ internal class Program
private static int WindowWidth = 800;
private static int WindowHeight = 480;
- private static void Main(string[] args)
+ private unsafe static void Main(string[] args)
{
_world = World.Create();
var playerFactory = new PlayerFactory(_world);
var blockFactory = new BlockFactory(_world);
-
+ var floorFactory = new FloorFactory(_world);
Raylib.InitWindow(WindowWidth, WindowHeight, "Hello World");
CameraComponent camera;
var player = playerFactory.CreatePlayer(out camera);
- var block = RoomBuilder.GenerateMapOfBlocks(blockFactory).ToList();
+ var block = RoomBuilder.GenerateMapOfBlocks(blockFactory, floorFactory).ToList();
+
+ var mesh = Raylib.GenMeshPlane(RoomBuilder.RoomSize, RoomBuilder.RoomSize, 10, 10);
+ var model = Raylib.LoadModelFromMesh(mesh);
+ var texture = Raylib.LoadTexture("plasma.png");
+ Raylib.SetMaterialTexture(ref model, 0, MaterialMapIndex.Albedo, ref texture);
+ // var material = Raylib.LoadMaterialDefault();
+ // Raylib.SetMaterialTexture(ref material, MaterialMapIndex.Normal, texture);
+ //
SystemRegistrations.RegisterLogicGroup(_world);
SystemRegistrations.RegisterGraphicsGroup(_world);
@@ -40,12 +41,13 @@ internal class Program
while (!Raylib.WindowShouldClose())
{
var deltaTime = Raylib.GetFrameTime();
- //Raylib.UpdateCamera(ref camera.Camera, CameraMode.Custom);
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.White);
Raylib.BeginMode3D(camera.Camera.GetCamera3D());
_world.Update(deltaTime);
- Raylib.DrawGrid(RoomBuilder.RoomSize, 1.0f);
+
+ Raylib.DrawModel(model, new Vector3(), 1.0f, Color.White);
+ //Raylib.DrawGrid(RoomBuilder.RoomSize, 1.0f);
_world.CleanupUpdate(deltaTime);
Raylib.EndMode3D();
Raylib.DrawFPS(WindowWidth - 100, 12);
@@ -53,6 +55,9 @@ internal class Program
_world.Commit();
Raylib.EndDrawing();
}
+
+ Raylib.UnloadModel(model);
+ Raylib.UnloadTexture(texture);
Raylib.CloseWindow();
}
diff --git a/SystemRegistrations.cs b/SystemRegistrations.cs
index d7e9d21..e3fc6a3 100644
--- a/SystemRegistrations.cs
+++ b/SystemRegistrations.cs
@@ -32,16 +32,19 @@ public static class SystemRegistrations
var ballRenderSystem = new PlayerRenderSystem { World = world };
var cameraSystem = new CameraSystem() {World = world };
var blockRenderSystem = new BlockRenderSystem(world);
-
+ var floorRenderSystem = new FloorRenderSystem(world);
+
renderSystemsGroup.AddSystem(blockRenderSystem);
renderSystemsGroup.AddSystem(ballRenderSystem);
renderSystemsGroup.AddSystem(hpRenreSystem);
renderSystemsGroup.AddSystem(cameraSystem);
+ renderSystemsGroup.AddSystem(floorRenderSystem);
renderSystemsGroup.EnableSystem(blockRenderSystem);
renderSystemsGroup.EnableSystem(ballRenderSystem);
renderSystemsGroup.EnableSystem(hpRenreSystem);
renderSystemsGroup.EnableSystem(cameraSystem);
+ renderSystemsGroup.EnableSystem(floorRenderSystem);
world.AddSystemsGroup(1, renderSystemsGroup);
}
diff --git a/Systems/Rendering/FloorRenderSystem.cs b/Systems/Rendering/FloorRenderSystem.cs
new file mode 100644
index 0000000..4b25b5c
--- /dev/null
+++ b/Systems/Rendering/FloorRenderSystem.cs
@@ -0,0 +1,44 @@
+using BakeryGame.Components.Common;
+using BakeryGame.Components.Environment;
+using BakeryGame.Components.Player;
+using Raylib_cs;
+using Scellecs.Morpeh;
+
+namespace BakeryGame.Systems.Rendering;
+
+public class FloorRenderSystem:ISystem
+{
+ private Filter _floor;
+ private Filter _camera;
+
+ public FloorRenderSystem(World world)
+ {
+ World = world;
+ }
+
+ public void Dispose()
+ {
+
+ }
+
+ public void OnAwake()
+ {
+ _floor = World.Filter.With().Build();
+ _camera = World.Filter.With().Build();
+ }
+
+ public World World { get; set; }
+ public void OnUpdate(float deltaTime)
+ {
+ foreach (var item in _floor)
+ {
+ var size = item.GetComponent().Size;
+ var positionComponent = item.GetComponent();
+ var itemColorComponent = item.GetComponent();
+
+ //var position = Raylib.GetWorldToScreen(positionComponent.Position, _camera.First().GetComponent().Camera.GetCamera3D());
+ //Raylib.DrawRectangle((int)position.X, (int)position.Y, 10, 10, itemColorComponent.Color);
+ //Raylib.DrawCube(positionComponent.Position, size.X, size.Y, size.Z, itemColorComponent.Color);
+ }
+ }
+}
\ No newline at end of file
diff --git a/plasma.png b/plasma.png
new file mode 100644
index 0000000..01c2d88
Binary files /dev/null and b/plasma.png differ