feat: refactoring && walls

This commit is contained in:
2024-04-18 16:04:53 +07:00
parent 6333d80fd4
commit 36af656e0d
20 changed files with 202 additions and 93 deletions

46
Entities/BlockFactory.cs Normal file
View File

@@ -0,0 +1,46 @@
using System.Numerics;
using BakeryGame.Components.Common;
using BakeryGame.Components.Environment;
using Raylib_cs;
using Scellecs.Morpeh;
namespace BakeryGame.Entities;
public class BlockFactory
{
private readonly World _world;
public BlockFactory(World world)
{
_world = world;
}
public Entity CreateBlock(float x, float z)
{
var position = new Vector3(x, 1.0f, z);
var size = new Vector3(BlockSize, BlockSize, BlockSize);
var block = _world.CreateEntity();
block.SetComponent(new BlockComponent { Size = size });
block.SetComponent(new ColorComponent { Color = Color.Gray });
block.SetComponent(new PositionComponent(){ Position = position });
return block;
}
public IEnumerable<Entity> GenerateMapOfBlocks()
{
for (int x = -16 / 2; x <= 16 / 2; x++) {
for (int z = -16 / 2; z <= 16 / 2; z++) {
if (x == -16 / 2 || x == 16 / 2 || z == -16 / 2 || z == 16 / 2)
{
yield return CreateBlock(x, z);
}
}
}
}
public const float BlockSize = 1;
}

38
Entities/PlayerFactory.cs Normal file
View File

@@ -0,0 +1,38 @@
using System.Numerics;
using BakeryGame.Components.Common;
using BakeryGame.Components.Player;
using Raylib_cs;
using Scellecs.Morpeh;
namespace BakeryGame.Entities;
public class PlayerFactory
{
private readonly World _world;
public PlayerFactory(World world)
{
_world = world;
}
public Entity CreatePlayer(out CameraComponent camera)
{
var player = _world.CreateEntity();
player.SetComponent(new HealthComponent { HealthPoints = 100 });
player.SetComponent(new PositionComponent { Position = new Vector3(0.0f, 1.0f, 2.0f) });
player.SetComponent(new MovementComponent() { Speed = 0.1f });
camera = new CameraComponent()
{
Camera = new Camera3D(new(0.0f, 10.0f, 10.0f), new(0.0f, 0.0f, 0.0f), new(0.0f, 1.0f, 0.0f), 45.0f, 0)
};
player.SetComponent(camera);
player.SetComponent(new PlayerComponent
{
Size = new Vector3(1.0f, 2.0f, 1.0f ),
});
return player;
}
}