protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // changing the back buffer size changes the window size (when in windowed mode) graphics.PreferredBackBufferWidth = 1024; graphics.PreferredBackBufferHeight = 660; graphics.ApplyChanges(); // Loding wall, bean and bigBean objects wall = new AnimatedObject(Content.Load <Texture2D>("mur"), new Vector2(0f, 0f), new Vector2(20f, 20f)); bean = new AnimatedObject(Content.Load <Texture2D>("bean"), new Vector2(0f, 0f), new Vector2(20f, 20f)); bigBean = new AnimatedObject(Content.Load <Texture2D>("gros_bean"), new Vector2(0f, 0f), new Vector2(20f, 20f)); //loading font _font = Content.Load <SpriteFont>("SpriteFont1"); //loading sounds beanEaten1 = Content.Load <SoundEffect>("PelletEat1"); beanEaten2 = Content.Load <SoundEffect>("PelletEat2"); pacmanDead = Content.Load <SoundEffect>("PacmanEaten"); ghostEaten = Content.Load <SoundEffect>("MonsterEaten"); siren = Content.Load <SoundEffect>("Siren").CreateInstance(); invincible = Content.Load <SoundEffect>("Invincible").CreateInstance(); //Loding animated characters animatedPacMan = new AnimatedPacMan(Content.Load <Texture2D>("pacmanDroite0"), new Vector2(0f, 0f), new Vector2(20f, 20f), pacManCharacter); listAnimatedGhosts = new List <AnimatedGhost>(); for (int i = 0; i < 4; i++) { listAnimatedGhosts.Add(new AnimatedGhost(Content.Load <Texture2D>("fantome" + i), new Vector2(0f, 0f), new Vector2(20f, 20f), listGhostCharacters.ElementAt(i))); } }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); // Drawing wall and beans for (int x = 0; x < 31; x++) { for (int y = 0; y < 28; y++) { if (map[x, y] == 0) { int xpos, ypos; xpos = x * 20; ypos = y * 20; Vector2 pos = new Vector2(ypos, xpos); spriteBatch.Draw(wall.Texture, pos, Color.White); } else if (map[x, y] == 1) { int xpos, ypos; xpos = x * 20; ypos = y * 20; Vector2 pos = new Vector2(ypos, xpos); spriteBatch.Draw(bean.Texture, pos, Color.White); } else if (map[x, y] == 3) { int xpos, ypos; xpos = x * 20; ypos = y * 20; Vector2 pos = new Vector2(ypos, xpos); spriteBatch.Draw(bigBean.Texture, pos, Color.White); } } } // Drawing ghost fence spriteBatch.Draw(Content.Load <Texture2D>("barriereFantome"), new Vector2(13 * 20, 12 * 20), Color.White); //Drawing animated objects according to the associated character spriteBatch.Draw(animatedPacMan.Texture, new Vector2(pacManCharacter.getPostion().X * 20, pacManCharacter.getPostion().Y * 20), Color.White); for (int i = 0; i < 4; i++) { if (pacManCharacter.Moving) // If the pacMan is dead, ghosts disapear before the pacman reapears { spriteBatch.Draw(listAnimatedGhosts.ElementAt(i).Texture, new Vector2(listGhostCharacters.ElementAt(i).getPostion().X * 20, listGhostCharacters.ElementAt(i).getPostion().Y * 20), Color.White); } } //If we restart the game, the "ready !" image displays if (restart) { spriteBatch.Draw(Content.Load <Texture2D>("ready"), new Vector2(5 * 20, 5 * 20), Color.White); } //If we restart the game, the "game over" and the "press enter" image display if (pacManCharacter.Dead) { //"game over" spriteBatch.Draw(Content.Load <Texture2D>("game_over"), new Vector2(7 * 20, 5 * 20), Color.White); //"press enter" spriteBatch.Draw(Content.Load <Texture2D>("enter"), new Vector2(3 * 20, 7 * 20), Color.White); KeyboardState keyboard = Keyboard.GetState(); if (keyboard.IsKeyDown(Keys.Enter)) { //We reinitialize the game on the enter key pressed pacManCharacter.Dead = false; pacManCharacter.Moving = true; pacManCharacter.Direction = Direction.Right; pacManCharacter.Position = pacManCharacter.InitialPosition; pacManCharacter.Life = 3; animatedPacMan = new AnimatedPacMan(Content.Load <Texture2D>("pacmanDroite0"), new Vector2(0f, 0f), new Vector2(20f, 20f), pacManCharacter); foreach (GhostCharacter ghostCharacter in listGhostCharacters) { ghostCharacter.Position = ghostCharacter.InitialPosition; } restart = true; beginPause = timer; } } spriteBatch.DrawString(_font, "Score: " + score, new Vector2(600, 40), Color.White); base.Draw(gameTime); spriteBatch.End(); }