SimulationComponent.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using fun.Communication;
  2. using fun.Core;
  3. using fun.IO;
  4. using OpenTK;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using Environment = fun.Core.Environment;
  10. namespace fun.Client.Components
  11. {
  12. internal sealed class SimulationComponent : GameComponent
  13. {
  14. private InputComponent input;
  15. private Environment environment;
  16. public Entity Player { get; private set; }
  17. public IEnumerable<IPerceived> Perceiveder { get; set; }
  18. public SimulationComponent(GameWindow game, InputComponent input)
  19. : base(game)
  20. {
  21. this.input = input;
  22. var loader = new EnvironmentLoader();
  23. environment = loader.Load(new FileStream("environment.xml", FileMode.Open, FileAccess.Read, FileShare.None))[0];
  24. Player = environment.GetEntity("player");
  25. Perceiveder = environment.Entities.Where(e => e.ContainsElement<IPerceived>()).Select(e => e.GetElement<IPerceived>() as IPerceived);
  26. }
  27. public override void Initialize()
  28. {
  29. environment.Initialize();
  30. }
  31. public override void Update(FrameEventArgs e)
  32. {
  33. foreach (var input in environment.Entities
  34. .Where(en => en.ContainsElement<IInput>())
  35. .Select(en => en.GetElement<IInput>() as IInput))
  36. {
  37. input.Keys = this.input.Keyboard.DownKeys;
  38. //input.MouseDelta = this.input.Mouse.Delta;
  39. }
  40. environment.Update(e.Time);
  41. }
  42. }
  43. }