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

View File

@@ -0,0 +1,62 @@
using BakeryGame.Components.Common;
using BakeryGame.Components.Player;
using Scellecs.Morpeh;
namespace BakeryGame.Systems.Player;
public class CameraSystem : ISystem
{
private Filter _filter;
public CameraSystem(World world)
{
World = world;
}
public World World { get; set; }
public void OnAwake()
{
_filter = World.Filter.With<CameraComponent>().Build();
}
public void OnUpdate(float deltaTime)
{
foreach (var entity in _filter)
{
var position = entity.GetComponent<PositionComponent>().Position;
ref var cameraComponent = ref entity.GetComponent<CameraComponent>();
ref var camera = ref cameraComponent.Camera;
// Camera target follows player
//camera.Target.X = position.X;
//camera.Target.Z = position.Z;
// // Camera rotation controls
// if (IsKeyDown(KEY_A)) camera.rotation--;
// else if (IsKeyDown(KEY_S)) camera.rotation++;
// Limit camera rotation to 80 degrees (-40 to 40)
// if (camera.Rotation > 40) camera.Rotation = 40;
// else if (camera.Rotation < -40) camera.Rotation = -40;
// Camera zoom controls
// camera.Zoom += Raylib.GetMouseWheelMove() * 0.05f;
//
// if (camera.Zoom > 3.0f) camera.Zoom = 3.0f;
// else if (camera.Zoom < 0.1f) camera.Zoom = 0.1f;
// // Camera reset (zoom and rotation)
// if (IsKeyPressed(KEY_R))
// {
// camera.zoom = 1.0f;
// camera.rotation = 0.0f;
// }
}
}
public void Dispose()
{
}
}

View File

@@ -0,0 +1,31 @@
using BakeryGame.Components.Player;
using Raylib_cs;
using Scellecs.Morpeh;
namespace BakeryGame.Systems.Player;
public sealed class HealthSystem : ISystem
{
private Filter filter;
public World World { get; set; }
public void Dispose()
{
}
public void OnAwake()
{
filter = World.Filter.With<HealthComponent>().Build();
}
public void OnUpdate(float deltaTime)
{
foreach (var entity in filter)
{
ref var healthComponent = ref entity.GetComponent<HealthComponent>();
if (Raylib.IsKeyDown(KeyboardKey.Enter))
healthComponent.HealthPoints++;
}
}
}

View File

@@ -0,0 +1,54 @@
using BakeryGame.Components.Common;
using BakeryGame.Components.Player;
using BakeryGame.Models;
using Raylib_cs;
using Scellecs.Morpeh;
namespace BakeryGame.Systems.Player;
public sealed class MovementSystem : ISystem
{
private Filter _filter;
public World World { get; set; }
public void Dispose()
{
}
public void OnAwake()
{
_filter = World.Filter.With<PlayerComponent>().Build();
}
public void OnUpdate(float deltaTime)
{
foreach (var entity in _filter)
{
ref var positionComponent = ref entity.GetComponent<PositionComponent>();
ref var directionComponent = ref entity.GetComponent<MovementComponent>();
if (Raylib.IsKeyDown(KeyboardKey.Right))
{
positionComponent.Position.X += directionComponent.Speed;
directionComponent.Direction = Direction.Right;
}
if (Raylib.IsKeyDown(KeyboardKey.Left))
{
positionComponent.Position.X -= directionComponent.Speed;
directionComponent.Direction = Direction.Left;
}
if (Raylib.IsKeyDown(KeyboardKey.Up))
{
positionComponent.Position.Z -= directionComponent.Speed;
directionComponent.Direction = Direction.Up;
}
if (Raylib.IsKeyDown(KeyboardKey.Down))
{
positionComponent.Position.Z += directionComponent.Speed;
directionComponent.Direction = Direction.Down;
}
}
}
}

View File

@@ -0,0 +1,29 @@
using BakeryGame.Components.Common;
using BakeryGame.Components.Player;
using Raylib_cs;
using Scellecs.Morpeh;
namespace BakeryGame.Systems.Player;
public class PlayerRenderSystem : ISystem
{
private Filter _filter;
public World World { get; set; }
public void Dispose()
{
}
public void OnAwake()
{
_filter = World.Filter.With<PlayerComponent>().Build();
}
public void OnUpdate(float deltaTime)
{
foreach (var entity in _filter)
{
Raylib.DrawCubeV(entity.GetComponent<PositionComponent>().Position, entity.GetComponent<PlayerComponent>().Size, Color.Green);
}
}
}