Example #1
0
  public void draw(Graphics2D g) {

    /*
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, GamePanel.WIDTH, GamePanel.HEIGHT);
    g.setColor(Color.white);
    */
    // bgManager.draw(g);
    /*
                mAlimentos.drawAlimentos(g);
        mAlimentos.drawPoderes(g);
    */
    // draw the backgrounds
    /*
    bgSky.draw(g);
    bgSoil.draw(g);
    */
    bgKitchen.draw(g);

    // draw the rails
    /*
    g.setColor(Color.blue);
    g.fillRect(0, 484, GamePanel.WIDTH, 3);
    g.fillRect(0, 592, GamePanel.WIDTH, 3);
    g.fillRect(0, 700, GamePanel.WIDTH, 3);
    */

    // draw the dishes
    for (int i = 0; i < dishes.size(); i++) {
      dishes.get(i).draw(g);
    }

    // draw the player
    player.draw(g);

    // draw the npc
    npc.draw(g);

    // draw the hud
    hud.draw(g);

    // drawing rails
    // {444, 552, 660}

    // draw the dish values
    for (int i = 0; i < numbers.size(); i++) {
      numbers.get(i).draw(g);
    }

    // draw the explosion
    for (int i = 0; i < explosions.size(); i++) {
      explosions.get(i).draw(g);
    }

    // draw the heart bg animation
    if (player.getCholesterol() >= 85) {
      g.drawImage(
          ImagesLoader.getImage("heartattackbg"),
          GamePanel.WIDTH / 2 - ImagesLoader.getImage("heartattackbg").getWidth() / 2,
          GamePanel.HEIGHT / 2 - ImagesLoader.getImage("heartattackbg").getHeight() / 2,
          null);
      heartAttack.draw(g);
    }
    if (player.getCholesterol() <= 25) {
      warning.draw(g);
    }

    // end of heart bg animation
    // Text.drawString(g, "Testing Colesterage", 200, 400, "leishoFont", null);
    // Text.drawString(g, "Font testing", 600, 200, "leishoFont", txtAnimation);
    if (eventIntro) {
      if (titleIntroA != null) titleIntroA.draw(g);
      if (titleIntroB != null) titleIntroB.draw(g);
    }

    if (eventCaught) {
      if (titleCaught != null) titleCaught.draw(g);
    }

    if (eventClear) {
      if (titleClear != null) if (!showResults) titleClear.draw(g);
      if (showResults) {
        g.setColor(new Color(0, 0, 0, 226));
        g.fillRect(
            GamePanel.WIDTH / 2 - squarewidth / 2,
            GamePanel.HEIGHT / 2 - squareheight / 2,
            squarewidth,
            squareheight);
        if (ticksResults > 35) {
          g.setStroke(new BasicStroke(6));
          g.setColor(Color.white);
          g.drawRect(
              GamePanel.WIDTH / 2 - squarewidth / 2,
              GamePanel.HEIGHT / 2 - squareheight / 2,
              squarewidth,
              squareheight);
        }
        if (ticksResults > 40)
          Text.drawString(g, "Resultados", Text.CENTERED, 150, "leishoFont", null);
        if (ticksResults > 50)
          Text.drawString(
              g, "Puntos adquiridos: " + player.getScoreLevel(), 250, 250, "leishoFont", null);
        if (ticksResults > 55)
          Text.drawString(
              g, "Alimentos consumidos: " + player.getEatenDishes(), 250, 300, "leishoFont", null);
        if (ticksResults > 60)
          Text.drawString(
              g,
              "Ocasiones en Paro Cardiaco: " + hud.getTimesHeartAttack(),
              250,
              350,
              "leishoFont",
              null);
        if (ticksResults > 60)
          Text.drawString(
              g, "Ocasiones en Débil: " + hud.getTimesWeak(), 250, 400, "leishoFont", null);
        if (ticksResults > 65 && ticksResults < 80)
          Text.drawString(
              g, "Presiona Enter para continuar", Text.CENTERED, 500, "leishoFont", null);
      }
    }

    if (eventDead) {
      if (titleDead != null) titleDead.draw(g);
    }

    if (eventPoints) eventPoints();
  }
Example #2
0
  public void update() {

    // keyboard input
    input();

    // check the events flags
    eventClear = player.clearedLevel();
    eventDead = player.isDead();
    eventCaught = player.isCaught();

    if (eventIntro) {
      // title update
      player.setPlaying(false);
      if (titleIntroA != null) {
        titleIntroA.update();
        if (titleIntroA.shouldRemove()) {
          titleIntroA = null;
          titleIntroB.start();
        }
      }
      if (titleIntroB != null) {
        titleIntroB.update();
        if (titleIntroB.shouldRemove()) {
          titleIntroB = null;
          eventIntro = false;
          player.setPlaying(true);
        }
      }
    }

    if (eventClear || eventDead || eventCaught) player.stop();

    if (eventClear) {
      if (!playFlag) {
        AudioPlayer.stop(musicFnm);
        AudioPlayer.playAndLoop("levelclear");
        playFlag = true;
      }
      PlayerData.setScore(player.getScore());
      PlayerData.addEatenDishes(player.getEatenDishes());
      if (showResults) showResults();
      if (!titleClear.hasStarted()) titleClear.start();
    }

    if (eventCaught) {
      if (!playFlag) {
        AudioPlayer.stop(musicFnm);
        AudioPlayer.play("levelfailcaught");
        playFlag = true;
      }
      if (!titleCaught.hasStarted()) titleCaught.start();
      if (titleCaught.shouldRemove()) titleCaught = null;
    }

    if (eventDead) {
      if (!playFlag) {
        AudioPlayer.stop(musicFnm);
        AudioPlayer.play("levelfaildead");
        playFlag = true;
      }
      if (!titleDead.hasStarted()) titleDead.start();
      if (titleDead.shouldRemove()) titleDead = null;
    }

    camera.setPosition(playerxscreen - player.getx(), 0);

    player.update();

    /*
    bgSky.setPosition(camera.getx() * 0.6, camera.gety() + bgSky.gety());
    bgSoil.setPosition(camera.getx(), camera.gety() + bgSoil.gety());

    bgSky.update();
    bgSoil.update();
    */

    bgKitchen.setPosition(camera.getx(), camera.gety());
    bgKitchen.update();

    for (int i = 0; i < numbers.size(); i++) {
      numbers.get(i).update();
      if (numbers.get(i).isOver()) {
        numbers.remove(i);
        i--;
      }
    }

    for (int i = 0; i < explosions.size(); i++) {
      SpriteAnimation explosion = explosions.get(i);
      explosion.update();
      if (explosion.hasPlayedOnce()) {
        explosions.remove(i);
        i--;
      }
    }
    for (int i = 0; i < powerup.size(); i++) {
      SpriteAnimation pup = powerup.get(i);
      pup.update();
      if (pup.hasPlayedOnce()) {
        powerup.remove(i);
        i--;
      }
    }

    // collisionDetection();
    for (int i = 0; i < dishes.size(); i++) {
      // dishes.get(i).setPosition(400 - player.getx(), dishes.get(i).gety());
      dishes.get(i).update();
      if (dishes.get(i).shouldRemove()) {
        dishes.remove(i);
        i--;
      }
    }
    hud.update();
    npc.update();

    if (player.getCholesterol() >= 85) {
      heartAttack.update();
      if (heartAttack.shouldPlaySound()) if (player.isPlaying()) AudioPlayer.play("heartbeat");
    }
    if (player.getCholesterol() <= 25) {
      warning.update();
      if (warning.shouldPlaySound()) if (player.isPlaying()) AudioPlayer.play("redalert");
    }

    levelIntroTimerDiff = (System.nanoTime() - levelIntroTimer) / 1000000;
    if (levelIntroTimerDiff > levelIntroDelay) levelStart = true;

    if (eventIntro || eventClear || eventDead || eventCaught) return;
    addDish();
  }