Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal struct Position : IComponent
- {
- public int X { get; set; }
- public int Y { get; set; }
- }
- internal struct MovementSpeed : IComponent
- {
- public int Value { get; set; }
- }
- internal class Movement : ISystem
- {
- public void Update()
- {
- foreach (Entity entity in EntityPool.activeEntities.Values) // Loop through all entities
- {
- Dictionary<Type, IComponent> components = entity.Components;
- if (components.TryGetValue(typeof(Position), out Position positionComponent))
- {
- if (components.TryGetValue(typeof(MovementSpeed), out MovementSpeed movementSpeedComponent))
- {
- // TEST: move (1 * movementspeed) units
- positionComponent.X += movementSpeedComponent.Value;
- positionComponent.Y += movementSpeedComponent.Value;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment