Guest User

Untitled

a guest
Dec 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. internal struct Position : IComponent
  2. {
  3. public int X { get; set; }
  4. public int Y { get; set; }
  5. }
  6.  
  7. internal struct MovementSpeed : IComponent
  8. {
  9. public int Value { get; set; }
  10. }
  11.  
  12. internal class Movement : ISystem
  13. {
  14. public void Update()
  15. {
  16. foreach (Entity entity in EntityPool.activeEntities.Values) // Loop through all entities
  17. {
  18. Dictionary<Type, IComponent> components = entity.Components;
  19.  
  20. if (components.TryGetValue(typeof(Position), out Position positionComponent))
  21. {
  22. if (components.TryGetValue(typeof(MovementSpeed), out MovementSpeed movementSpeedComponent))
  23. {
  24. // TEST: move (1 * movementspeed) units
  25. positionComponent.X += movementSpeedComponent.Value;
  26. positionComponent.Y += movementSpeedComponent.Value;
  27. }
  28. }
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment