Add attribute system with core stats and gameplay components
This commit is contained in:
32
GameCore/Movement/JumpSystem.cs
Normal file
32
GameCore/Movement/JumpSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using GameCore.Attributes;
|
||||
using GameCore.ECS;
|
||||
using GameCore.ECS.Interfaces;
|
||||
using GameCore.Input;
|
||||
using GameCore.Physics;
|
||||
using Attribute = GameCore.Attributes.Attribute;
|
||||
|
||||
namespace GameCore.Movement;
|
||||
|
||||
public class JumpSystem : ISystem
|
||||
{
|
||||
public void Update(World world, float deltaTime)
|
||||
{
|
||||
var entities = world.GetEntitiesWith<InputStateComponent>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
var input = world.GetComponent<InputStateComponent>(entity);
|
||||
var velocity = world.GetComponent<VelocityComponent>(entity);
|
||||
var attributes = world.GetComponent<AttributeComponent>(entity);
|
||||
var characterState = world.GetComponent<CharacterStateComponent>(entity);
|
||||
|
||||
if (input == null || velocity == null || attributes == null || characterState == null)
|
||||
continue;
|
||||
|
||||
if (input.IsJumping && characterState.IsOnFloor)
|
||||
{
|
||||
var jumpHeight = attributes.GetValue(Attribute.JumpHeight);
|
||||
velocity.DesiredVelocity.Y = (float)System.Math.Sqrt(2f * world.Config.GravityStrength * jumpHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user