initial commit
This commit is contained in:
26
Systems/BallRenderSystem.cs
Normal file
26
Systems/BallRenderSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Numerics;
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
public class BallRenderSystem : 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Systems/BlockRenderSystem.cs
Normal file
36
Systems/BlockRenderSystem.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
public class BlockRenderSystem : ISystem
|
||||
{
|
||||
private Filter _filter;
|
||||
|
||||
public BlockRenderSystem(World world)
|
||||
{
|
||||
World = world;
|
||||
}
|
||||
|
||||
public World World { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAwake()
|
||||
{
|
||||
_filter = World.Filter.With<BlockComponent>().Build();
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
foreach (var item in _filter)
|
||||
{
|
||||
var size = item.GetComponent<BlockComponent>().Size;
|
||||
var positionComponent = item.GetComponent<PositionComponent>();
|
||||
var itemColorComponent = item.GetComponent<ColorComponent>();
|
||||
|
||||
// Draw enemy-box
|
||||
Raylib.DrawCube(positionComponent.Position, size.X, size.Y, size.Z, itemColorComponent.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Systems/CameraSystem.cs
Normal file
59
Systems/CameraSystem.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Numerics;
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
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 = new Vector2(position.X + 20, position.Y + 20);
|
||||
|
||||
// // 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
80
Systems/CollisionSystem.cs
Normal file
80
Systems/CollisionSystem.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Numerics;
|
||||
using BakeryGame.Models;
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
namespace BakeryGame.Systems;
|
||||
|
||||
public class CollisionSystem: ISystem
|
||||
{
|
||||
private Filter _playerFilter;
|
||||
private Filter _blockFilter;
|
||||
public World World { get; set; }
|
||||
|
||||
public CollisionSystem(World world)
|
||||
{
|
||||
World = world;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnAwake()
|
||||
{
|
||||
_playerFilter = World.Filter.With<PlayerComponent>().Build();
|
||||
_blockFilter = World.Filter.With<BlockComponent>().Build();
|
||||
}
|
||||
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
var player = _playerFilter.First();
|
||||
ref var playerPosition = ref player.GetComponent<PositionComponent>();
|
||||
var playerSize = player.GetComponent<PlayerComponent>().Size;
|
||||
var playerMovement = player.GetComponent<MovementComponent>();
|
||||
foreach (var block in _blockFilter)
|
||||
{
|
||||
var blockPosition = block.GetComponent<PositionComponent>().Position;
|
||||
var blockSize = block.GetComponent<BlockComponent>().Size;
|
||||
var blockBounds = new BoundingBox(
|
||||
new Vector3(blockPosition.X - blockSize.X / 2, blockPosition.Y - blockSize.Y / 2,
|
||||
blockPosition.Z - blockSize.Z / 2),
|
||||
new Vector3(blockPosition.X + blockSize.X / 2, blockPosition.Y + blockSize.Y / 2,
|
||||
blockPosition.Z + blockSize.Z / 2));
|
||||
|
||||
|
||||
var collided = false;
|
||||
do
|
||||
{
|
||||
var playerBounds = new BoundingBox(
|
||||
new Vector3(playerPosition.Position.X - playerSize.X / 2, playerPosition.Position.Y - playerSize.Y / 2,
|
||||
playerPosition.Position.Z - playerSize.Z / 2),
|
||||
new Vector3(playerPosition.Position.X + playerSize.X / 2, playerPosition.Position.Y + playerSize.Y / 2,
|
||||
playerPosition.Position.Z + playerSize.Z / 2));
|
||||
|
||||
collided = Raylib.CheckCollisionBoxes(playerBounds, blockBounds);
|
||||
if (collided)
|
||||
{
|
||||
var delta = playerMovement.Speed / 2;
|
||||
switch (playerMovement.Direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
playerPosition.Position.X += delta;
|
||||
break;
|
||||
case Direction.Right:
|
||||
playerPosition.Position.X -= delta;
|
||||
break;
|
||||
case Direction.Up:
|
||||
playerPosition.Position.Z += delta;
|
||||
break;
|
||||
case Direction.Down:
|
||||
playerPosition.Position.Z -= delta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (collided);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Systems/HPRenderSystem.cs
Normal file
26
Systems/HPRenderSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
public class HPRenderSystem : ILateSystem
|
||||
{
|
||||
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)
|
||||
{
|
||||
var healthComponent = entity.GetComponent<HealthComponent>();
|
||||
Raylib.DrawText($"HP: {healthComponent.HealthPoints}", 12, 12, 20, Color.Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Systems/HealthSystem.cs
Normal file
28
Systems/HealthSystem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Systems/MovementSystem.cs
Normal file
50
Systems/MovementSystem.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using BakeryGame.Models;
|
||||
using Raylib_cs;
|
||||
using Scellecs.Morpeh;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user