/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); if (subMenu) { drawSubMenu(spriteBatch); } else if (displayMenu) { drawMenu(spriteBatch); } else if(!win) { // correct clock only if offset is not set if (offset == null) { offset = (float)gameTime.TotalGameTime.Seconds; } time = (float)gameTime.TotalGameTime.Seconds - offset; //Draw background spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, 800, 600), Color.White); //draw enemies // if gameover, draw to screen if (gameOver) { human.xPos = -200; human.yPos = -200; spriteBatch.DrawString(titleFont, "GAME OVER", new Vector2(150, 150), Color.White); } foreach (EnemyShot shot in shotList) { if (shot != null) { shot.draw(spriteBatch); } } // if (boss.appearTime <= time) { boss.yPos = 400; boss.draw(spriteBatch); } foreach (Enemy enemy in activeList) { if (enemy != null) { if (time >= enemy.appearTime) { enemy.start = true; enemy.draw(spriteBatch); } } } //handle player movement if (!human.respawn) { Vector2 humanPos = human.updateState(gameTime, activeList, boss); human.drawShots(spriteBatch); human.sprite.draw(spriteBatch, humanPos); // handle player explosions if (human.hit) { Expolsion exp = new Expolsion(explosionTexture, 128, 128, 20); explosionList.Add(exp); human.die(exp, spriteBatch); } } else { human.respawnUpdate(); human.drawShots(spriteBatch); Vector2 humanPos = human.updateState(gameTime, activeList, boss); human.sprite.drawInvincible(spriteBatch, humanPos); } //draw effects and remove players/enemies updateEffects(spriteBatch); removeEnemies(spriteBatch); /* //hit box for debugging spriteBatch.Draw(singlePix, human.hitBox, Color.Red); // hit box for enemies foreach (Enemy enemy in activeList) { if (enemy != null) { spriteBatch.Draw(singlePix, enemy.hitBox, Color.Yellow); } } spriteBatch.Draw(singlePix, boss.hitBox, Color.Green); */ } spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Creates an explosion at the player's position /// </summary> /// <param name="explosion"></param> /// <param name="batch"></param> public void die(Expolsion explosion, SpriteBatch batch) { explosion.xPos = xPos; explosion.yPos = yPos; }
/// <summary> /// Removes all defeated enemies from active lists /// </summary> /// <param name="batch">current sprite batch</param> protected void removeEnemies(SpriteBatch batch) { Expolsion exp = new Expolsion(explosionTexture, 128, 128, 20); //remove each enemy in the remove list from the main enemy list foreach (Enemy enemy in removeList) { //create a new explosion and add it to the explosion list explosionList.Add(exp); enemy.die(exp, batch); // re-open slot in active list for (int i = 0; i < activeList.Length; i++) { if (activeList[i] == enemy) { activeList[i] = null; } } } if (!boss.alive) { boss.die(exp, batch); } removeList.Clear(); }
public override void die(Expolsion explosion, SpriteBatch batch) { base.die(explosion, batch); xPos = -100; yPos = -100; }