RetroScreen.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // RetroScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. #endregion
  16. namespace Spacewar
  17. {
  18. public class RetroScreen : SpacewarScreen
  19. {
  20. /// <summary>
  21. /// Creates a new SpacewarScreen
  22. /// </summary>
  23. public RetroScreen(Game game)
  24. : base(game)
  25. {
  26. //Retro
  27. backdrop = new SceneItem(game, new RetroStarfield(game));
  28. scene.Add(backdrop);
  29. bullets = new RetroProjectiles(game);
  30. ship1 = new Ship(game, PlayerIndex.One, new Vector3(-250, 0, 0), bullets);
  31. ship1.Radius = 10f;
  32. scene.Add(ship1);
  33. ship2 = new Ship(game, PlayerIndex.Two, new Vector3(250, 0, 0), bullets);
  34. ship2.Radius = 10f;
  35. scene.Add(ship2);
  36. sun = new Sun(game, new RetroSun(game), new Vector3(SpacewarGame.Settings.SunPosition, 0.0f));
  37. scene.Add(sun);
  38. scene.Add(bullets);
  39. paused = false;
  40. }
  41. public override void Render()
  42. {
  43. Texture2D background = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\retro_backdrop");
  44. IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)GameInstance.Services.GetService(typeof(IGraphicsDeviceService));
  45. GraphicsDevice device = graphicsService.GraphicsDevice;
  46. //Backdrop
  47. SpriteBatch.Begin();
  48. SpriteBatch.Draw(background, new Vector2(0, 0), null, Color.White);
  49. SpriteBatch.End();
  50. //Always at the back so no need for zbuffer.
  51. device.DepthStencilState = DepthStencilState.None;
  52. base.Render();
  53. Font.Begin();
  54. Font.Draw(FontStyle.WeaponLarge, 300, 15, player1Score);
  55. Font.Draw(FontStyle.WeaponLarge, 940, 15, player2Score);
  56. Font.End();
  57. }
  58. public override GameState Update(TimeSpan time, TimeSpan elapsedTime)
  59. {
  60. handleCollisions(time);
  61. return base.Update(time, elapsedTime);
  62. }
  63. public override void OnCreateDevice()
  64. {
  65. base.OnCreateDevice();
  66. bullets.OnCreateDevice();
  67. }
  68. }
  69. }