GameRoot.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //---------------------------------------------------------------------------------
  2. // Written by Michael Hoffman
  3. // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
  4. //----------------------------------------------------------------------------------
  5. using System;
  6. using AtomicEngine;
  7. using AtomicPlayer;
  8. namespace AtomicBlaster
  9. {
  10. class GameRoot : NETScriptObject
  11. {
  12. public static Scene Scene { get; private set; }
  13. public static float ElapsedTime { get; private set; }
  14. public static Vector2 ScreenSize { get; private set; }
  15. public static IntRect ScreenBounds { get; private set; }
  16. public static Grid Grid { get; private set; }
  17. public static ParticleManager<ParticleState> ParticleManager { get; private set; }
  18. bool paused = false;
  19. public GameRoot()
  20. {
  21. Art.Load();
  22. var graphics = AtomicNET.GetSubsystem<Graphics>();
  23. ScreenSize = new Vector2(graphics.Width, graphics.Height);
  24. ScreenBounds = new IntRect(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y);
  25. ParticleManager = new ParticleManager<ParticleState>(1024 * 20, ParticleState.UpdateParticle);
  26. const int maxGridPoints = 1600;
  27. float amt = (float)Math.Sqrt(ScreenBounds.Width * ScreenBounds.Height / maxGridPoints);
  28. Vector2 gridSpacing = new Vector2(amt, amt);
  29. Grid = new Grid(ScreenBounds, gridSpacing);
  30. EntityManager.Add(PlayerShip.Instance);
  31. SubscribeToEvent("Update", HandleUpdate);
  32. Scene = AtomicNET.GetSubsystem<Player>().LoadScene("Scenes/Scene.scene");
  33. CustomRenderer.Initialize();
  34. }
  35. void HandleUpdate(uint eventType, ScriptVariantMap eventData)
  36. {
  37. float time = eventData.GetFloat("timestep");
  38. ElapsedTime += time;
  39. // Input.Update();
  40. if (!paused)
  41. {
  42. PlayerStatus.Update();
  43. EntityManager.Update();
  44. EnemySpawner.Update();
  45. ParticleManager.Update();
  46. Grid.Update();
  47. }
  48. Draw();
  49. }
  50. void Draw()
  51. {
  52. EntityManager.Draw();
  53. Grid.Draw();
  54. ParticleManager.Draw();
  55. }
  56. }
  57. }