wip: floor texture
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -12,4 +13,13 @@
|
||||
<PackageReference Include="Scellecs.Morpeh" Version="2023.1.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="461223108.jpg">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="plasma.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
9
Components/Environment/FloorComponent.cs
Normal file
9
Components/Environment/FloorComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Numerics;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
namespace BakeryGame.Components.Environment;
|
||||
|
||||
public struct FloorComponent: IComponent
|
||||
{
|
||||
public Vector3 Size;
|
||||
}
|
||||
30
Entities/FloorFactory.cs
Normal file
30
Entities/FloorFactory.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ public class RoomBuilder
|
||||
{
|
||||
public static int RoomSize = 16;
|
||||
|
||||
public static IEnumerable<Entity> GenerateMapOfBlocks(BlockFactory blockFactory)
|
||||
public static IEnumerable<Entity> 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);
|
||||
}
|
||||
}
|
||||
29
Program.cs
29
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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
44
Systems/Rendering/FloorRenderSystem.cs
Normal file
44
Systems/Rendering/FloorRenderSystem.cs
Normal file
@@ -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<FloorComponent>().Build();
|
||||
_camera = World.Filter.With<CameraComponent>().Build();
|
||||
}
|
||||
|
||||
public World World { get; set; }
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
foreach (var item in _floor)
|
||||
{
|
||||
var size = item.GetComponent<FloorComponent>().Size;
|
||||
var positionComponent = item.GetComponent<PositionComponent>();
|
||||
var itemColorComponent = item.GetComponent<ColorComponent>();
|
||||
|
||||
//var position = Raylib.GetWorldToScreen(positionComponent.Position, _camera.First().GetComponent<CameraComponent>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
plasma.png
Normal file
BIN
plasma.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 568 KiB |
Reference in New Issue
Block a user