feat: camera following player

This commit is contained in:
2024-04-18 22:54:09 +07:00
parent 36af656e0d
commit bcd0650aed
10 changed files with 216 additions and 97 deletions

View File

@@ -28,19 +28,7 @@ public class BlockFactory
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;
}

View File

@@ -1,6 +1,7 @@
using System.Numerics;
using BakeryGame.Components.Common;
using BakeryGame.Components.Player;
using BakeryGame.Models;
using Raylib_cs;
using Scellecs.Morpeh;
@@ -23,7 +24,7 @@ public class PlayerFactory
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)
Camera = new CameraRef(new(0.0f, 20.0f, 10.0f), new(0.0f, 0.0f, 0.0f), new(0.0f, 1.0f, 0.0f), 60.0f)
};
player.SetComponent(camera);

20
Entities/RoomBuilder.cs Normal file
View File

@@ -0,0 +1,20 @@
using Scellecs.Morpeh;
namespace BakeryGame.Entities;
public class RoomBuilder
{
public static int RoomSize = 16;
public static IEnumerable<Entity> GenerateMapOfBlocks(BlockFactory blockFactory)
{
for (int x = -RoomSize / 2; x <= RoomSize / 2; x++) {
for (int z = -RoomSize / 2; z <= RoomSize / 2; z++) {
if (x == -RoomSize / 2 || x == RoomSize / 2 || z == -RoomSize / 2 || z == RoomSize / 2)
{
yield return blockFactory.CreateBlock(x, z);
}
}
}
}
}