//prevent overlap between enemies public void checkOverlap(int numEnemies, enemy[] enemies, int enemyNum) { //goes through all other enemies for (int i = 1; i <= numEnemies - 1; i++) { //prevent checking for collisions with itself if (i != enemyNum) { //creates rectangle of intersection between the enemies Rectangle collide = Rectangle.Intersect(enemies[i].Position, draw); //checks if the enemies are overlapping by more than 10 if (collide.Width - 10 > 0) { //moves enemies by amount that they are overlapping if (draw.X > enemies[i].Position.X) draw.X += collide.Width - 10; else draw.X -= collide.Width - 10; } } } }
//resets all parts of level private void Reset() { //resets player's hp and mp and changes the mp and hp bar widths hp = maxHp; mp = maxMp; hpBar.Width = 500; mpBar.Width = 500; //resets number of arrows arrows = 20; //resets player posiion pos.X = graphics.GraphicsDevice.Viewport.Width / 2; pos.Y = graphics.GraphicsDevice.Viewport.Height - draw.Height; //resets items itemDraw.Y = -100; //checks what level the player is on if (level == 1) { //sets number of onscreen enenmies and total enemies numEnemies = 4; totEnemies = 8; //changes level background background = caveBackground; backgroundDraw.Height = graphics.GraphicsDevice.Viewport.Height; backgroundDraw.Width = (int)((double)backgroundDraw.Height / caveBackground.Height * caveBackground.Width); //intializes all enemies for (int i = 1; i <= numEnemies; i++) { enemies[i] = new enemy(20, 10, 30, 400, 30, 30, 5, batL, batR, 9, 1, false, batKilled, graphics, rand); } //plays level music MediaPlayer.Play(caveMusic); } else if (level == 2) { numEnemies = 3; totEnemies = 6; background = forestBackground; backgroundDraw.Height = graphics.GraphicsDevice.Viewport.Height; backgroundDraw.Width = (int)((double)backgroundDraw.Height / forestBackground.Height * forestBackground.Width); for (int i = 1; i <= numEnemies; i++) { enemies[i] = new enemy(40, 20, 25, 800, 40, 60, 10, skeletonL, skeletonR, 1, 15, false, skeletonKilled,graphics, rand); } MediaPlayer.Play(forestMusic); } else if (level == 3) { numEnemies = 2; totEnemies = 4; background = jungleBackground; backgroundDraw.Height = graphics.GraphicsDevice.Viewport.Height; backgroundDraw.Width = (int)((double)backgroundDraw.Height / jungleBackground.Height * jungleBackground.Width); for (int i = 1; i <= numEnemies; i++) { enemies[i] = new enemy(80, 20, 20, 1000, 40, 80, 20, gorgonL, gorgonR, 9, 1, false, gorgonkilled,graphics, rand); } MediaPlayer.Play(jungleMusic); } else if (level == 4) { numEnemies = 1; totEnemies = 1; background = templeBackground; backgroundDraw.Height = graphics.GraphicsDevice.Viewport.Height; backgroundDraw.Width = (int)((double)backgroundDraw.Height / templeBackground.Height * templeBackground.Width); for (int i = 1; i <= numEnemies; i++) { enemies[i] = new enemy(100, 40, 20, 1200, 40, 120, 20, swampMonster, swampMonster, 1, 3, true, bossKilled, graphics, rand); enemies[i].Projectile = gooShot; } MediaPlayer.Play(bossMusic); } }