PacMan.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. // using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. // using Microsoft.Xna.Framework.Net;
  12. // using Microsoft.Xna.Framework.Storage;
  13. namespace PacMan
  14. {
  15. /// <summary>
  16. /// This is the main type for your game
  17. /// </summary>
  18. public class PacManGame : Game
  19. {
  20. GraphicsDeviceManager graphics_;
  21. SpriteBatch spriteBatch_;
  22. AudioEngine audioEngine_;
  23. WaveBank waveBank_;
  24. SoundBank soundBank_;
  25. public PacManGame()
  26. {
  27. // Pac Man 2 is somewhat resolution-independent, but runs best at 720x640.
  28. graphics_ = new GraphicsDeviceManager(this);
  29. graphics_.PreferredBackBufferHeight = 720;
  30. graphics_.PreferredBackBufferWidth = 640;
  31. // Pac Man 2 always updates 1000 times per second. Framerate may vary.
  32. IsFixedTimeStep = true;
  33. TargetElapsedTime = TimeSpan.FromMilliseconds(1);
  34. // The menu needs to be added in the Components list in the constructor.
  35. // Otherwise its Initialize() method is not called and everything blows up.
  36. Components.Add(new Menu(this, null));
  37. Content.RootDirectory = "Content";
  38. }
  39. /// <summary>
  40. /// Allows the game to perform any initialization it needs to before starting to run.
  41. /// This is where it can query for any required services and load any non-graphic
  42. /// related content. Calling base.Initialize will enumerate through any components
  43. /// and initialize them as well.
  44. /// </summary>
  45. protected override void Initialize()
  46. {
  47. // This will be called before the Initialize() method of any component, which
  48. // all rely on these Services being available.
  49. audioEngine_ = new AudioEngine("Content/Audio/YEPAudio.xgs");
  50. waveBank_ = new WaveBank(audioEngine_, "Content/Audio/Wave Bank.xwb");
  51. soundBank_ = new SoundBank(audioEngine_, "Content/Audio/Sound Bank.xsb");
  52. Services.AddService(typeof(AudioEngine), audioEngine_);
  53. Services.AddService(typeof(SoundBank), soundBank_);
  54. spriteBatch_ = new SpriteBatch(GraphicsDevice);
  55. Services.AddService(typeof(SpriteBatch), spriteBatch_);
  56. Services.AddService(typeof(GraphicsDeviceManager), graphics_);
  57. base.Initialize();
  58. }
  59. /// <summary>
  60. /// Allows the game to run logic such as updating the world,
  61. /// checking for collisions, gathering input, and playing audio.
  62. /// </summary>
  63. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  64. protected override void Update(GameTime gameTime)
  65. {
  66. // The components are automatically updated by XNA. The only relevant
  67. // task here is to update the AudioEngine.
  68. audioEngine_.Update();
  69. base.Update(gameTime);
  70. }
  71. /// <summary>
  72. /// This is called when the game should draw itself.
  73. /// </summary>
  74. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  75. protected override void Draw(GameTime gameTime)
  76. {
  77. // We _always_ clear to black, so we do this here.
  78. GraphicsDevice.Clear(Color.Black);
  79. base.Draw(gameTime);
  80. }
  81. }
  82. }