public static void initLevel() { bool dead = (player != null) ? player.removed : false; int powerupssize = powerups.Count; clear(); StreamReader sr = new StreamReader(File.OpenRead("/Application/res/maps/definitions/" + level + "/" + level + "_" + levelmap + ".txt")); map = new Map(sr.ReadLine(), Map.TILESIZE, scales, graphics); // obstacles = new GenerateObstacles(map, true); PowerUps powerup = null; if (levelmap != 8) { obstacles = new GenerateObstacles(map, true, graphics); powerup = new PowerUps(Convert.ToInt32(sr.ReadLine()), obstacles.getList(), graphics, scales); } else { obstacles = new GenerateObstacles(map, false, graphics); } if (levelmap != 8) { if (level == 4 || level == 7) { keymusic = "bgm_03"; } else if (level == 6 || level == 8) { keymusic = "bgm_02"; } else { keymusic = "bgm_01"; } } else { keymusic = "bgm_boss"; } while (sr.Peek() >= 0) { String[] line = sr.ReadLine().Split(); int type = Convert.ToInt32(line[0]); int count = Convert.ToInt32(line[1]); switch (type) { case 6: // blue snake // for (int x = 0; x < count; x++) { // // SnakeHead head = new SnakeHead(obstacles, map, player); // SnakeBody body = new SnakeBody(obstacles, map, player, head); // // for (int i = 0; i < 4; i++) { // head.setChild(body); // enemies.Add(head); // enemies.Add(body); // head = body; // body = new SnakeBody(obstacles, map, player, head); // } // } break; default: for (int i = 0; i < count; i++) { enemies.Add(Enemy.createEnemy(type, obstacles, map, player, graphics, scales)); } break; } } // in.close(); if (powerup != null && levelmap != 8 && !dead) { powerups.Add(powerup); } else if (powerup != null && levelmap != 8 && dead && powerupssize > 0) { powerups.Add(powerup); } if (levelmap != 8) { do { exit = new Exit(obstacles.getList(), enemies, graphics, scales); } while (exit.intersects(powerup)); } else { exit = new Exit(null, enemies, graphics, scales); } sr.Dispose(); }
public static void Update() { // Query gamepad for current state var gamePadData = GamePad.GetData(0); input.tick(gamePadData); if (time.ElapsedMilliseconds > 240 * 1000 && playing) { // Tiempo acabado, Game Over //if (player.isInvincible()) invincible.close(); //else music[keymusic].stop(); player.setLives(player.getLives() - 1); setMenu(new GameOverMenu(player.getLives(), level, levelmap, graphics, scales)); time.Reset(); time.Start(); } if (menu != null) { menu.tick(input); playing = false; } else { // Si se han matado a todos los enemigos y no se ha cogido el powerup // el obstaculo sobre el que esta el powerup parpadea if (((Exit)exit).isActive() && powerups.Count > 0) { foreach (Obstacle obs in obstacles.getList()) { if (obs.intersects(powerups[0])) { obs.blink(); break; } } } // Tecla ESC, salir al menu principal if (input.exit.clicked) { //if (player.isInvincible()) invincible.close(); //else music[keymusic].stop(); playing = false; pause = false; //initLevel(); level = 1; levelmap = 1; offsetX = 0; offsetY = 0; setMenu(new TitleMenu(graphics, scales)); } // Tecla P, pausa if (input.pause.clicked) { //if (player.isInvincible()) invincible.pause(); //else music[keymusic].pause(); pause = !pause; } if (!pause) { // Si bomberman no es invencible, musica normal if (!player.isInvincible()) { //if (playing) music[keymusic].play(); //invincible.close(); } // Si no, musica de invencibilidad else { //if (playing) invincible.play(); //music[keymusic].pause(); } // Primer frame en el que se ha acabado el nivel if (player.endLvlFirst()) { //music[keymusic].stop(); //if (!playing) invincible.close(); //level_clear.play(); } playing = true; player.tick(input); // Si el jugador se ha muerto parar la musica de fondo // if (player.isDyingFirst()) { // music.get(keymusic).stop(); // } // Si se ha acabado el nivel if (player.endLvl()) { //level_clear.stop(); levelmap++; if (levelmap > 8) { levelmap = 1; level++; if (level > 8) { setMenu(new CreditsMenu(graphics, scales)); return; } else { setMenu(new LevelMenu(level, graphics, scales)); } } else { setMenu(new MapMenu(level, levelmap, graphics, scales)); } initLevel(); return; } // Detonacion remota de las bombas if (player.hasRemoteDetonator() && input.remote.clicked && bombs.Count > 0) { bombs[0].removed = true; Sounds.bomb.play(); } // Detonacion normal de las bombas if (input.fire.clicked && bombs.Count < player.getBombs()) { Bomb bomb = new Bomb(player, graphics, scales); bool found = false; foreach (Bomb b in bombs) { if (bomb.intersects(b)) { found = true; break; } } if (!found) { foreach (Obstacle obs in obstacles.getList()) { if (obs != null && obs.intersects(bomb)) { found = true; break; } } } if (!found && !player.isTeleporting() && !player.isDying()) { bombs.Add(bomb); } } // Tick de las salida exit.tick(); // Comprobar si el jugador ha muerto if (player.removed) { //music[keymusic].stop(); player.setLives(player.getLives() - 1); if (player.getLives() < 0) { initLevel(); player.setLives(2); setMenu(new GameOverMenu(continues, level, levelmap, graphics, scales)); continues--; } else { initLevel(); setMenu(new MapMenu(level, levelmap, graphics, scales)); } } // Comprobar si los enemigos han muerto y hacer tick for (int i = 0; i < enemies.Count; i++) { if (enemies[i] != null) { if (enemies[i].removed) { player.setScore(player.getScore() + enemies[i].getScore()); enemies.Remove(enemies[i]); break; } enemies[i].tick(); } } // Tick de los powerups foreach (Entity e in powerups) { e.tick(); } // Tick de las bombas for (int i = 0; i < bombs.Count; i++) { bombs[i].tick(); if (bombs[i].removed) { addFlares(bombs[i]); bombs.Remove(bombs[i]); //t.join(); } } // Tick de las llamas for (int i = 0; i < flares.Count; i++) { if (flares[i].removed) { flares.Remove(flares[i]); } else { flares[i].tick(); } } // Tick de los obstaculos for (int i = 0; i < obstacles.getList().Count; i++) { obstacles.getList()[i].tick(); if (obstacles.getList()[i].removed) { obstacles.getList().Remove(obstacles.getList()[i]); } } // Comprobar colisiones checkCollisions(); } } hud.UpdateFPS(timeDelta); hud.UpdatePosition(timeDelta + "ms"); hud.UpdateEnemyCount(enemies.Count); }