2
0

XNAPacMan.cs 3.6 KB

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