/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // We don't want XNA calling this method each time we resume from the menu, // unfortunately, it'll call it whatever we try. So the only thing // we can do is check if it has been called already and return. Yes, it's ugly. if (spriteBatch_ != null) { GhostSoundsManager.ResumeLoops(); return; } // Otherwise, this is the first time this component is Initialized, so proceed. GhostSoundsManager.Init(Game); Grid.Reset(); Constants.Level = 1; spriteBatch_ = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch)); graphics_ = (GraphicsDeviceManager)Game.Services.GetService(typeof(GraphicsDeviceManager)); soundBank_ = (SoundBank)Game.Services.GetService(typeof(SoundBank)); scoreFont_ = Game.Content.Load <SpriteFont>("Score"); scoreEventFont_ = Game.Content.Load <SpriteFont>("ScoreEvent"); xlife_ = Game.Content.Load <Texture2D>("sprites/ExtraLife"); ppill_ = Game.Content.Load <Texture2D>("sprites/PowerPill"); crump_ = Game.Content.Load <Texture2D>("sprites/Crump"); board_ = Game.Content.Load <Texture2D>("sprites/Board"); boardFlash_ = Game.Content.Load <Texture2D>("sprites/BoardFlash"); bonusEaten_ = new Dictionary <string, int>(); bonus_ = new Dictionary <string, Texture2D>(9); bonus_.Add("Apple", Game.Content.Load <Texture2D>("bonus/Apple")); bonus_.Add("Banana", Game.Content.Load <Texture2D>("bonus/Banana")); bonus_.Add("Bell", Game.Content.Load <Texture2D>("bonus/Bell")); bonus_.Add("Cherry", Game.Content.Load <Texture2D>("bonus/Cherry")); bonus_.Add("Key", Game.Content.Load <Texture2D>("bonus/Key")); bonus_.Add("Orange", Game.Content.Load <Texture2D>("bonus/Orange")); bonus_.Add("Pear", Game.Content.Load <Texture2D>("bonus/Pear")); bonus_.Add("Pretzel", Game.Content.Load <Texture2D>("bonus/Pretzel")); bonus_.Add("Strawberry", Game.Content.Load <Texture2D>("bonus/Strawberry")); scoreEvents_ = new List <ScoreEvent>(5); bonusPresent_ = false; bonusSpawned_ = 0; eatenGhosts_ = 0; Score = 0; xlives_ = 2; paChomp_ = true; playerDied_ = false; player_ = new Player(Game); ghosts_ = new List <Ghost> { new Ghost(Game, player_, Ghosts.Blinky), new Ghost(Game, player_, Ghosts.Clyde), new Ghost(Game, player_, Ghosts.Inky), new Ghost(Game, player_, Ghosts.Pinky) }; ghosts_[2].SetBlinky(ghosts_[0]); // Oh, dirty hack. Inky needs this for his AI. soundBank_.PlayCue("Intro"); LockTimer = TimeSpan.FromMilliseconds(4500); base.Initialize(); }
public override void Initialize() { if (spriteBatch_ != null) { GhostSoundsManager.ResumeLoops(); return; } GhostSoundsManager.Init(Game); Grid.Reset(); Constants.Level = 1; spriteBatch_ = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch)); graphics_ = (GraphicsDeviceManager)Game.Services.GetService(typeof(GraphicsDeviceManager)); soundBank_ = (SoundBank)Game.Services.GetService(typeof(SoundBank)); scoreFont_ = Game.Content.Load <SpriteFont>("Score"); scoreEventFont_ = Game.Content.Load <SpriteFont>("ScoreEvent"); xlife_ = Game.Content.Load <Texture2D>("sprites/ExtraLife"); ppill_ = Game.Content.Load <Texture2D>("sprites/PowerPill"); crump_ = Game.Content.Load <Texture2D>("sprites/Crump"); board_ = Game.Content.Load <Texture2D>("sprites/Board"); boardFlash_ = Game.Content.Load <Texture2D>("sprites/BoardFlash"); bonusEaten_ = new Dictionary <string, int>(); bonus_ = new Dictionary <string, Texture2D>(9); bonus_.Add("Apple", Game.Content.Load <Texture2D>("bonus/Apple")); bonus_.Add("Banana", Game.Content.Load <Texture2D>("bonus/Banana")); bonus_.Add("Bell", Game.Content.Load <Texture2D>("bonus/Bell")); bonus_.Add("Cherry", Game.Content.Load <Texture2D>("bonus/Cherry")); bonus_.Add("Key", Game.Content.Load <Texture2D>("bonus/Key")); bonus_.Add("Orange", Game.Content.Load <Texture2D>("bonus/Orange")); bonus_.Add("Pear", Game.Content.Load <Texture2D>("bonus/Pear")); bonus_.Add("Pretzel", Game.Content.Load <Texture2D>("bonus/Pretzel")); bonus_.Add("Strawberry", Game.Content.Load <Texture2D>("bonus/Strawberry")); scoreEvents_ = new List <ScoreEvent>(5); bonusPresent_ = false; bonusSpawned_ = 0; eatenGhosts_ = 0; Score = 0; xlives_ = 2; paChomp_ = true; playerDied_ = false; player_ = new Player(Game); ghosts_ = new List <Ghost> { new Ghost(Game, player_, Ghosts.Blinky), new Ghost(Game, player_, Ghosts.Clyde), new Ghost(Game, player_, Ghosts.Inky), new Ghost(Game, player_, Ghosts.Pinky) }; ghosts_[2].SetBlinky(ghosts_[0]); soundBank_.PlayCue("Intro"); LockTimer = TimeSpan.FromMilliseconds(4500); base.Initialize(); }