Пример #1
0
        //private Animation animation;

        public Bomb(Bomberman player, GraphicsContext g, Vector2 scale) : base(scale)
        {
            //super(obs, map, player);

            this.position.X = 2 - (w * scale.X) / 2 + (int)Math.Round(((float)(player.position.X + (float)w * scale.X / 2) / (w * scale.X))) * (w * scale.X);
            this.position.Y = -(h * scale.Y) / 2 + (int)Math.Round(((float)(player.position.Y + (float)h * scale.Y / 2) / (h * scale.Y))) * (h * scale.Y);

            this.position.Width  = 12 * scale.X;
            this.position.Height = 14 * scale.Y;

            explode = !player.hasRemoteDetonator();

            this.potency = player.getPotency();

            this.sl = new SpriteLoader();
            this.sl.cargarImagen(ANIMATION);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scale.X),
                                                                (int)(sl.getImage().Size.Height *scale.Y))));
            this.ss = new SpriteSheet(this.sl.getImage());

            Sprite[] anim = { ss.obtenerSprite((int)(1 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(0 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(2 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(0 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(1 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(0 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(2 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(0 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(1 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(0 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g),
                              ss.obtenerSprite((int)(2 * w * scale.X), 0, (int)(w * scale.X), (int)(h * scale.Y), g) };

            // Animacion inicial
            animation = new Animation(anim, 10, Animation.Direction.DOWN);
            animation.start();
        }
Пример #2
0
        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);
        }