コード例 #1
0
  public SpriteAnimation(String name) {
    this.name = name;

    animation = new Animation();
    animation.setFrames(ImagesLoader.getFrames(name));

    width = ImagesLoader.getImageAt(name, animation.getFrame()).getWidth();
    height = ImagesLoader.getImageAt(name, animation.getFrame()).getHeight();
  }
コード例 #2
0
  public SpriteAnimation(double x, double y, String name, long delay) {
    this.x = x;
    this.y = y;
    this.name = name;

    animation = new Animation();
    animation.setFrames(ImagesLoader.getFrames(name));
    animation.setDelay(delay);

    width = ImagesLoader.getImageAt(name, animation.getFrame()).getWidth();
    height = ImagesLoader.getImageAt(name, animation.getFrame()).getHeight();
  }
コード例 #3
0
 public void draw(Graphics2D g) {
   g.drawImage(
       ImagesLoader.getImageAt(name, animation.getFrame()),
       (int) (x - width / 2),
       (int) (y - height / 2),
       null);
 }
コード例 #4
0
ファイル: Level3State.java プロジェクト: IvanAli/ColesteRage
 public void clearAll() {
   ImagesLoader.clearImages();
   AudioPlayer.clearAudio();
 }
コード例 #5
0
ファイル: Level3State.java プロジェクト: IvanAli/ColesteRage
  public void input() {
    if (player.isPlaying())
      if (Keys.isPressed(Keys.ESCAPE) || Keys.isPressed(Keys.ENTER)) gsm.setPaused(true);
    if (!eventCaught && !eventDead && !eventClear) {
      if (Keys.isPressed(Keys.UP)) {
        player.setUp();
        npc.setUp();
      }
      if (Keys.isPressed(Keys.DOWN)) {
        player.setDown();
        npc.setDown();
      }
      if (Keys.isPressed(Keys.SPACE)) player.setJumping();
      if (Keys.isPressed(Keys.RIGHT)) player.setAccelerating();
    }

    if (eventCaught) {
      if (Keys.isPressed(Keys.ENTER)) {
        AudioPlayer.stop("levelfailcaught");
        gsm.setState(GameStateManager.MENU);
        ImagesLoader.removeImages("nivel3_imagenes.txt");
        ImagesLoader.removeImages("player_imagenes.txt");
        ImagesLoader.removeImages("npc_imagenes.txt");
        ImagesLoader.removeImages("hud_imagenes.txt");
        ImagesLoader.removeImages("nivel_efectosvisuales_imagenes.txt");
        AudioLoader.removeAudio("nivel3_sonido.txt");
      }
    }
    if (eventDead) {
      if (Keys.isPressed(Keys.ENTER)) {
        AudioPlayer.stop("levelfaildead");
        gsm.setState(GameStateManager.MENU);
        ImagesLoader.removeImages("nivel3_imagenes.txt");
        ImagesLoader.removeImages("player_imagenes.txt");
        ImagesLoader.removeImages("npc_imagenes.txt");
        ImagesLoader.removeImages("hud_imagenes.txt");
        ImagesLoader.removeImages("nivel_efectosvisuales_imagenes.txt");
        AudioLoader.removeAudio("nivel3_sonido.txt");
      }
    }
    if (eventClear) {
      if (Keys.isPressed(Keys.ENTER)) {
        if (!showResults) {
          showResults = true;
          resultsStartTime = System.nanoTime();
          return;
        }
        if (ticksResults > 65) {
          eventPoints = true;
          if (nextLevel) {
            AudioPlayer.play("menu_skip");
            AudioPlayer.stop("levelclear");
            ImagesLoader.removeImages("nivel3_imagenes.txt");
            AudioLoader.removeAudio("nivel3_sonido.txt");
            gsm.setState(nextState);
          }
        }
      }

      /*
      if(Keys.isPressed(Keys.ENTER)) {
             AudioPlayer.stop("levelclear");
             gsm.setState(GameStateManager.Level3);
         }
         */
    }
  }
コード例 #6
0
ファイル: Level3State.java プロジェクト: IvanAli/ColesteRage
  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();
  }
コード例 #7
0
ファイル: Level3State.java プロジェクト: IvanAli/ColesteRage
  public void init() {

    // LEVEL SPEED
    levelSpeed = 8;

    // AudioPlayer init
    AudioLoader.loadFromFile("nivel3_sonido.txt");

    // images loading
    ImagesLoader.loadFromFile("nivel3_imagenes.txt");
    ImagesLoader.loadFromFile("nivel_efectosvisuales_imagenes.txt");
    ImagesLoader.loadFromFile("food_imagenes.txt");

    // food appearance probability
    if (difficulty == OptionsState.EASY) foodprobability = 0.8;
    if (difficulty == OptionsState.NORMAL) foodprobability = 0.88;
    if (difficulty == OptionsState.HARD) foodprobability = 0.94;

    fooddelays = new int[6];
    fooddelays[0] = 100;
    fooddelays[1] = 600;
    fooddelays[2] = 100;
    fooddelays[3] = 500;
    fooddelays[4] = 100;
    fooddelays[5] = 400;

    // Events init
    eventIntro = true;
    eventClear = eventDead = eventCaught = false;

    txtAnimation = new TextAnimation();

    camera = new Camera();
    cameraPoint = new Camera();

    levelStart = false;
    levelIntroTimer = System.nanoTime();
    levelIntroDelay = 10000;

    foodTimer = System.nanoTime();
    foodDelay = 3000;

    // load fonts
    Text.loadFont("yummyFont.png");
    Text.loadFont("leishoFont.png");

    player = new Player();
    npc = new NPC(player);
    dishes = new ArrayList<>();
    hud = new HUD(player);

    // difficulty
    difficulty = OptionsData.getDifficulty();

    // rails init
    rails = new Rail[3];

    // title init
    titleIntroA = new Title(levelName, Title.INTROANIMATIONA);
    titleIntroB = new Title("EMPIEZA", Title.INTROANIMATIONB);
    titleClear = new Title("GANASTE", Title.CLEARANIMATION);
    titleDead = new Title("MORISTE", Title.CAUGHTANIMATION);
    titleCaught = new Title("ATRAPADO", Title.CAUGHTANIMATION);

    titleIntroA.start();

    // background creation
    // individual creation

    bgKitchen = new Background(0, 0, ImagesLoader.getImage("3_background"), Background.MOVELEFT);
    heartAttack =
        new BackgroundAnimation(
            ImagesLoader.getImage("heartsolo"), BackgroundAnimation.HEARTATTACK);
    warning =
        new BackgroundAnimation(ImagesLoader.getImage("warning"), BackgroundAnimation.WARNING);
    /*
    bgSky = new Background(0, 0, ImagesLoader.getImage("nivel1_clouds"));
    bgSoil = new Background(0, GamePanel.HEIGHT - (ImagesLoader.getHeight("nivel1_soil")),
            ImagesLoader.getImage("nivel1_soil"));
    */
    numbers = new ArrayList<>();
    explosions = new ArrayList<>();
    powerup = new ArrayList<>();
    player.init(dishes, numbers, explosions, powerup);

    // setting the score for the player
    player.setScore(PlayerData.getScore());

    foodValues = new HashMap<>();
    foodList = new ArrayList<>();
    powerList = new ArrayList<>();

    loadFoodFile("archivoComida.txt");

    powerList.add("FREEZEPOWER");
    powerList.add("DOUBLESCOREPOWER");
    powerList.add("DOUBLESPEEDPOWER");
    powerList.add("HALFSPEEDPOWER");

    // set position
    // debugging
    player.setPositionInRail(playerxscreen, player.getCurrentRail());
    cameraPoint.setPosition(playerxscreen, 0);

    // player.setVector(levelSpeed, 0);
    // parameters to be given: dx, dy, moveSpeed, jumpStart, fallSpeed
    player.setSpeed(levelSpeed, 0, 3.6, -28.8, 1.8);
    cameraPoint.setVector(levelSpeed, 0);

    npc.setPositionInRail(-npc.getWidth() / 2, npc.getCurrentRail());
    // npc.setVector(levelSpeed, 0);
    // parameters to be given: dx, dy, moveSpeed
    npc.setSpeed(levelSpeed, 0, 3.6);

    player.setCamera(camera);
    npc.setCamera(camera);

    // results stuff init
    squarewidth = 5;
    squareheight = 1;
    resultsDelay = 600;
    ticksResults = 0;

    // AudioPlayer volume setting
    // AudioPlayer.setVolume("musicFnm", -5.0f);
    AudioPlayer.setVolume("increasescore", -25.0f);

    // AudioPlayer bg play
    AudioPlayer.playAndLoop(musicFnm);
  }