//Loading All Content protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); backgroundTxr = Content.Load <Texture2D>("nightBackground"); //Loading background Texture for level 1 backgroundTxr1 = Content.Load <Texture2D>("background1"); //Loading background Texture for level 2 backgroundTxr2 = Content.Load <Texture2D>("background2"); //Loading background Texture for level 3 winScreen = Content.Load <Texture2D>("winScreen"); //Loading the win screen Texture gameOver = Content.Load <Texture2D>("gameOver"); //Loading the game over screen Texture playersheetTxr = Content.Load <Texture2D>("charSprite"); //Loading the player character sprite sheet platformTxr = Content.Load <Texture2D>("spriteSheet2"); //Loading the platform Texture wallTxr = Content.Load <Texture2D>("spriteSheet2.1"); //Loading the rotated platform Texture kiBlastTxr = Content.Load <Texture2D>("KiBlastSprite"); //Loading the Blast sprite sheet enemysheetTxr = Content.Load <Texture2D>("CharSprite2"); //Loading the enemy character sprite sheet backingTrack = Content.Load <Song>("backingTrack"); //Loading the backing track .MP3 jumpSound = Content.Load <SoundEffect>("jump"); //Loading the jump sound .WAV hitSound = Content.Load <SoundEffect>("hitSound"); //Loading the hit sound .WAV deathSound = Content.Load <SoundEffect>("deathSound"); //Loading the death sound .WAV advanceSound = Content.Load <SoundEffect>("advanceSound"); //Loading the level advance sound .WAV blastSound = Content.Load <SoundEffect>("kiBlastSound"); //Loading the blast sound .WAV newFont = Content.Load <SpriteFont>("newFont"); //Loading the font style MediaPlayer.Play(backingTrack); //Starting the backing tack .MP3 whiteBox = new Texture2D(GraphicsDevice, 1, 1); whiteBox.SetData(new[] { Color.White }); playerSprite = new PlayerSprite(playersheetTxr, whiteBox, new Vector2(50, 430), hitSound, jumpSound); //giving player sprite variable a value BuildLevels(); //Building the Platforms EnemySpawn(); //Building the Enemies BuildWalls(); //Building the Rotated Platform }
public void Update(GameTime gameTime, List <EnemySprite> enemySprites, PlayerSprite playerSprite) { spritePos += spriteVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds; //Movement of the blast //Decaliring the collision on an enemy and declairing the blast as dead to be removed foreach (EnemySprite enemySprite in enemySprites) { if (!enemySprite.dead && checkCollisionBelow(enemySprite)) { hasCollided = true; spriteVelocity.Y = 0; dead = true; } else if (!enemySprite.dead && checkCollisionAbove(enemySprite)) { hasCollided = true; spriteVelocity.Y = 0; dead = true; } if (!enemySprite.dead && checkCollisionLeft(enemySprite)) { hasCollided = true; spriteVelocity.X = 0; dead = true; } else if (!enemySprite.dead && checkCollisionRight(enemySprite)) { hasCollided = true; spriteVelocity.X = 0; dead = true; } } }
public void Update(GameTime gameTime, List <KiBlastSprite> blastSprites, PlayerSprite playerSprite) { if (spritePos.Y > 120) { spriteScale = new Vector2(1.5f, 1.5f); //controlling sprite size of enemies that are on the lower part of the screen } foreach (KiBlastSprite blastSprite in blastSprites) { if (!dead && checkCollision(blastSprite)) //checking for collision from another sprite { hasCollided = true; //declaring collision dead = true; //declaring death deathSound.Play(); //playing the death sound effect } if (dead && spritePos.Y < 110f) //if death has been declared and the sprite is less than 110 frames down { levelAdvance = true; //declaring the level has advanced advanceSound.Play(); //playing the level advance sound effect } } }
protected override void Update(GameTime gameTime) { playerSprite.spritePos = Vector2.Clamp(playerSprite.spritePos, new Vector2(50, 0), new Vector2(780, 1500)); //Stopping the Character sprite from being able to go off the screen if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); // when ESC is pressed the game will close } KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); if (levelNumber == 4 && keyboardState.IsKeyDown(Keys.Enter)) { levelNumber = 0; lives = 3; playerSprite = new PlayerSprite(playersheetTxr, whiteBox, new Vector2(50, 430), hitSound, jumpSound); //giving player sprite variable a value foreach (EnemySprite enemySprite in enemySprites[levelNumber]) { enemySprite.dead = false; enemySprite.levelAdvance = false; } MediaPlayer.Play(backingTrack); } if (levelNumber == 3 && keyboardState.IsKeyDown(Keys.Enter)) { levelNumber = 0; lives = 3; playerSprite = new PlayerSprite(playersheetTxr, whiteBox, new Vector2(50, 430), hitSound, jumpSound); //giving player sprite variable a value foreach (EnemySprite enemySprite in enemySprites[levelNumber]) { enemySprite.dead = false; enemySprite.levelAdvance = false; } MediaPlayer.Play(backingTrack); } // if you are on any screen other than the game over screen then pressing space will create a blast corresponding to where the player character is positioned and whether or not the sprite is flipped if (levelNumber < 4) { if (keyboardState.IsKeyDown(Keys.Space) && !kiBlast && playerSprite.currentState != PlayerSprite.playerStates.kiBlast) { if (playerSprite.flipped) { blasts.Add(new KiBlastSprite(kiBlastTxr, whiteBox, new Vector2(playerSprite.spritePos.X - 25, playerSprite.spritePos.Y - 25), new Vector2(-300, 0))); } else { blasts.Add(new KiBlastSprite(kiBlastTxr, whiteBox, new Vector2(playerSprite.spritePos.X + 25, playerSprite.spritePos.Y - 25), new Vector2(300, 0))); } kiBlast = true; blastSound.Play(); //Playing the sound of the blast } else if (!keyboardState.IsKeyDown(Keys.Space) && kiBlast) { kiBlast = false; //declairing the value of the blast false when space bar is no longer pressed after using a blast } //Updating the blasts foreach (KiBlastSprite kiBlast in blasts) { kiBlast.Update(gameTime, enemySprites[levelNumber], playerSprite); } } foreach (EnemySprite enemySprite in enemySprites[levelNumber]) { if (!enemySprite.dead) { enemySprite.Update(gameTime, blasts, playerSprite); //if the enemy sprite is not dead then the enemy sprites update } if (enemySprite.levelAdvance) { levelNumber++; playerSprite = new PlayerSprite(playersheetTxr, whiteBox, new Vector2(50, 430), hitSound, jumpSound); break; } //Controlling the movement of the enemies on the 1st level if (levelNumber == 0) { if (enemySprite.spritePos.Y < 110f && enemySprite.spritePos.X > 748f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X++; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y < 110f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y < 110f && enemySprite.flipped && enemySprite.spritePos.X > 750f) { enemySprite.spritePos.X--; } else if (enemySprite.spritePos.Y < 110f && enemySprite.flipped && enemySprite.spritePos.X <= 750f) { enemySprite.flipped = false; } if (enemySprite.spritePos.Y > 216f && enemySprite.spritePos.X > 200f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X += 2; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y > 216f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y > 216f && enemySprite.flipped && enemySprite.spritePos.X > 202f) { enemySprite.spritePos.X -= 2; } else if (enemySprite.spritePos.Y > 216f && enemySprite.flipped && enemySprite.spritePos.X <= 202f) { enemySprite.flipped = false; } } //Controlling the enemies movement on the 2nd level if (levelNumber == 1) { if (enemySprite.spritePos.Y < 200f && enemySprite.spritePos.X > 748f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X++; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y < 200f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y < 200f && enemySprite.flipped && enemySprite.spritePos.X > 750f) { enemySprite.spritePos.X--; } else if (enemySprite.spritePos.Y < 200f && enemySprite.flipped && enemySprite.spritePos.X <= 750f) { enemySprite.flipped = false; } if (enemySprite.spritePos.Y > 301f && enemySprite.spritePos.X > 200f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X += 2; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y > 301f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y > 301f && enemySprite.flipped && enemySprite.spritePos.X > 499) { enemySprite.spritePos.X -= 2; } else if (enemySprite.spritePos.Y > 301f && enemySprite.flipped && enemySprite.spritePos.X <= 500f) { enemySprite.flipped = false; } } //Controlling the enemies on the 3rd level if (levelNumber == 2) { if (enemySprite.spritePos.Y < 200f && enemySprite.spritePos.X > 748f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X++; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y < 200f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y < 200f && enemySprite.flipped && enemySprite.spritePos.X > 750f) { enemySprite.spritePos.X--; } else if (enemySprite.spritePos.Y < 200f && enemySprite.flipped && enemySprite.spritePos.X <= 750f) { enemySprite.flipped = false; } if (enemySprite.spritePos.Y > 350f && enemySprite.spritePos.X > 200f && enemySprite.spritePos.X < 790f && !enemySprite.flipped) { enemySprite.spritePos.X += 2; enemySprite.flipped = false; } else if (enemySprite.spritePos.Y > 350f && !enemySprite.flipped && enemySprite.spritePos.X == 790f) { enemySprite.flipped = true; } if (enemySprite.spritePos.Y > 350f && enemySprite.flipped && enemySprite.spritePos.X > 600) { enemySprite.spritePos.X -= 2; } else if (enemySprite.spritePos.Y > 350f && enemySprite.flipped && enemySprite.spritePos.X <= 600f) { enemySprite.flipped = false; } } } if (!playerSprite.dead) { playerSprite.Update(gameTime, levels[levelNumber], enemySprites[levelNumber], walls[levelNumber]); //Updating the PlayerSprite Class } blasts.RemoveAll(kiBlast => kiBlast.dead); //Removing the blasts when they are declared dead //Resetting the players position on death as long as the lives are greater than 0 if (playerSprite.dead && lives > 0) { playerSprite = new PlayerSprite(playersheetTxr, whiteBox, new Vector2(50, 430), hitSound, jumpSound); lives--; } //If your lives reach 0 it loads the gameover screen and stops the music if (lives <= 0) { levelNumber = 4; MediaPlayer.Stop(); } base.Update(gameTime); }