Files
brick-framework/GameCore/Movement/JumpSystem.cs

32 lines
1.1 KiB
C#

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);
}
}
}
}