FunGame.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using fun.Client.Components;
  2. using fun.Core;
  3. using OpenTK;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using Environment = fun.Core.Environment;
  8. namespace fun.Client
  9. {
  10. internal sealed class FunGame : GameWindow
  11. {
  12. private List<GameComponent> components;
  13. private InputComponent input;
  14. private SceneComponent scene;
  15. private CameraComponent camera;
  16. private SimulationComponent simulation;
  17. public FunGame()
  18. : base(1280, 720)
  19. {
  20. components = new List<GameComponent>();
  21. input = new InputComponent(this);
  22. components.Add(input);
  23. simulation = new SimulationComponent(this, input);
  24. components.Add(simulation);
  25. camera = new CameraComponent(this, input, simulation);
  26. components.Add(camera);
  27. scene = new SceneComponent(this, simulation, camera);
  28. components.Add(scene);
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. base.OnLoad(e);
  33. foreach (var component in components)
  34. component.Initialize();
  35. }
  36. protected override void OnUpdateFrame(FrameEventArgs e)
  37. {
  38. base.OnUpdateFrame(e);
  39. foreach (var component in components)
  40. component.Update(e);
  41. }
  42. protected override void OnRenderFrame(FrameEventArgs e)
  43. {
  44. base.OnRenderFrame(e);
  45. foreach (var component in components)
  46. component.Draw(e);
  47. SwapBuffers();
  48. }
  49. }
  50. }