예제 #1
0
 public void listenInput(GameContainer gc, StateBasedGame sbg, int delta) {
   Input input = gc.getInput();
   if (input.isKeyPressed(Input.KEY_DOWN)) {
     cursor = Math.min(cursor + 1, 2);
   } else if (input.isKeyPressed(Input.KEY_UP)) {
     cursor = Math.max(cursor - 1, 0);
   }
   if (cursor == 0 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeVolume(delta * 0.5f);
   } else if (cursor == 0 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeVolume(-delta * 0.5f);
   }
   if (cursor == 1 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.goFullScreen(true);
   } else if (cursor == 1 && input.isKeyDown(Input.KEY_LEFT)) {
     control.goFullScreen(false);
   }
   if (cursor == 2 && input.isKeyDown(Input.KEY_RIGHT)) {
     control.changeBrightness(+5);
   } else if (cursor == 2 && input.isKeyDown(Input.KEY_LEFT)) {
     control.changeBrightness(-5);
   } else if (input.isKeyDown(Input.KEY_ENTER)) {
     ((GameController) gc).changeState("pause");
     //			sbg.enterState(((Game)sbg).prevState);
     ((GameController) gc).changeState(((Game) sbg).prevState);
   }
 }
예제 #2
0
  @Override
  protected void timedEvents(GameContainer gc, StateBasedGame sbg, int delta) {
    Input input = gc.getInput();

    if (input.isKeyDown(Input.KEY_LEFT)) {
      Globals.player.moveLeft();
    }
    if (input.isKeyDown(Input.KEY_RIGHT)) {
      Globals.player.moveRight();
    }
    if ((input.isKeyPressed(Input.KEY_LCONTROL))
        || (input.isKeyPressed(Input.KEY_RCONTROL))
        || (input.isKeyPressed(Input.KEY_UP))
        || (input.isKeyPressed(Input.KEY_SPACE))) {
      Globals.player.jump();
      // soundJump2.play();
    }
    // useful to have longer jumps my maintaining CTRL
    if (!input.isKeyDown(Input.KEY_LCONTROL)
        && !input.isKeyDown(Input.KEY_UP)
        && !input.isKeyDown(Input.KEY_SPACE)) {
      if (Globals.player.jumping()) {
        Globals.player.setVelocity(Globals.player.getVelX(), Globals.player.getVelY() * 0.95f);
      }
    }
  }
예제 #3
0
 @Override
 public void update(GameContainer container, int arg1) throws SlickException {
   input = container.getInput();
   if (input.isKeyPressed(Input.KEY_ENTER)) {
     GameStart = true;
   }
   if (!player.GameOver && GameStart) {
     invul_frame -= 1;
     trap.update(v);
     for (int x = 0; x < 4; x++) {
       for (int y = 0; y < 3; y++) {
         walls[x][y].update(v);
       }
     }
     input = container.getInput();
     player.update();
     if (input.isKeyPressed(Input.KEY_SPACE)) {
       player.jump();
     }
     if (isCollide(player, trap, invul_frame)) {
       player.HIT();
       ;
       invul_frame = 30;
     }
     if (trap.getX() <= -100) {
       randomTrap();
     }
   }
   input = container.getInput();
   if (player.GameOver && input.isKeyPressed(Input.KEY_R)) {
     GameStart = false;
     container.reinit();
   }
 }
예제 #4
0
  @Override
  public void update(
      final GameContainer container, final StateBasedGame game, final int deltaInMillis)
      throws SlickException {
    final Input input = container.getInput();

    if (input.isKeyPressed(Input.KEY_F1)) {
      container.setPaused(true);
      try {
        container.setFullscreen(!container.isFullscreen());
      } catch (final SlickException e) {

      }
      container.setVSync(true);
      container.setSmoothDeltas(true);
      container.setMaximumLogicUpdateInterval(17);
      container.setPaused(false);
    }

    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      onExitKey(container, game);
    }

    final Level level = this.getLevel();

    if (level != null) {
      level.handleInput(input);
      level.update(deltaInMillis);
    }

    Player currentPlayer = level.getCurrentPlayer();
    if (currentPlayer != null) {
      PlayerState state = currentPlayer.getState();
      // change player color
      if (input.isKeyPressed(Input.KEY_C)) {
        state.color = state.color << 1;
        if (state.color > StateColor.BLUE) {
          state.color = StateColor.RED;
        }
      }

      // change weapon color
      if (input.isKeyPressed(Input.KEY_X)) {
        state.weaponColor = state.weaponColor << 1;
        if (state.weaponColor > StateColor.BLUE) {
          state.weaponColor = StateColor.RED;
        }
      }
    }

    // Sorgt dafür dass 1. Collisionnen neu berechnet werden, 2. Zeile
    // Den Objekten gesagt wird die Kollision zu behandeln.
    CollisionManager.update();
    level.handleCollisions();
  }
예제 #5
0
  @Override
  public void update(GameContainer gc, StateBasedGame sb, int delta) throws SlickException {
    background.rotate(0.05F * delta);
    Input input = gc.getInput();

    if (input.isKeyPressed(Input.KEY_ESCAPE)) sb.enterState(0);
    if (input.isKeyPressed(Input.KEY_DOWN)) {
      // Wenn ausgewählter Index + 1 kleiner als die Items auf der Seite sind, erhöre den Index
      if (currentIndex + 1 < itemsOnSide) currentIndex++;
    }
    if (input.isKeyPressed(Input.KEY_UP)) {
      // gleiches wie oben, nur andersrum
      if (currentIndex != 0) currentIndex--;
    }
    if (input.isKeyPressed(Input.KEY_RIGHT)) {
      // Seite wechseln
      if (side + 1 < sideCount) {
        currentIndex = 0;
        side++;
        start = side * 10 + 1;
        end = start + 9;
      }
    }
    if (input.isKeyPressed(Input.KEY_LEFT)) {
      // Seite wechseln
      if (side - 1 >= 0) {
        currentIndex = 0;
        side--;
        start = side * 10 + 1;
        end = start + 9;
      }
    }
    count = 0;

    // Anpassung des Selection-Rectangles
    // Muss immer auf die Breite/Position des jeweiligen MenuItems angepasst werden
    for (MenuItem item : levelNames) {
      if (count == currentIndex + start) {
        selection.setLocation(item.getPos().x - 5, item.getPos().y - 5);
      }
      count++;
    }
    count = 0;
    for (MenuItem item : times) {
      if (count == currentIndex + start) {
        selection.setWidth(
            item.getPos().x + uniNormal.getWidth(item.getName()) - selection.getX() + 5);
      }
      count++;
    }
  }
예제 #6
0
 @Override
 public void update(GameContainer container, GomokuClient game, int delta) throws SlickException {
   Input input = container.getInput();
   if (input.isKeyPressed(Input.KEY_ESCAPE)) {
     exitState();
   }
 }
 /** Nothing to update. */
 @Override
 public void update(GameContainer gc, int delta) throws SlickException {
   Input input = gc.getInput();
   if (input.isKeyPressed(Input.KEY_ESCAPE)) {
     System.exit(0);
   }
 }
예제 #8
0
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    Input input = container.getInput();

    if (input.isKeyPressed(Input.KEY_ADD) || input.isKeyPressed(Input.KEY_LEFT)) {
      segments = new Segment[segments.length + 1];
      createNoise(container.getHeight() / 2, container.getWidth() / segments.length);
    }
    if (input.isKeyPressed(Input.KEY_SUBTRACT) || input.isKeyPressed(Input.KEY_RIGHT)) {
      segments = new Segment[segments.length - 1];
      createNoise(container.getHeight() / 2, container.getWidth() / segments.length);
    }

    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      container.exit();
    }
  }
예제 #9
0
  /* ****** *
   * Events *
   * ****** */
  @Override
  protected void notTimedEvents(GameContainer gc, StateBasedGame sbg, int delta) {

    if (input.isKeyPressed(Input.KEY_R)) {
      try {
        Globals.returnState = -1;
        enter(gc, sbg);
      } catch (SlickException e) {
        System.err.println("Erreur lors du relancement du jeu");
      }
      return;
    }
    if (input.isKeyPressed(Input.KEY_B)) {
      map.showBounds();
    }
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      currentState = States.GAME_OVER;
    }
    if (input.isKeyPressed(Input.KEY_P)) {
      currentState = States.PAUSE;
    }

    /*if (input.isKeyPressed(Input.KEY_F4)) {
    	map.addEntity(new WalkingIA(Conf.IMG_SPRITES_PATH+"mariowalk_big.png", 3, 0, false, 100, 100, 40, 62, 12,new Node(1)));
    }
    if (input.isKeyPressed(Input.KEY_F5)) {
    	Enemy enemy = new Enemy(Conf.IMG_SPRITES_PATH+"mariowalk_big.png", 3, 100, 100, 40, 62, 2);
    	map.addEntity(enemy);
    	//the ennemies do not collide between each other
    	for (int i = 0; i < map.getWorld().getBodies().size(); i++) {
    		if (map.getEntityByBody(map.getWorld().getBodies().get(i)) instanceof Enemy) {
    			enemy.getBody().addExcludedBody(map.getWorld().getBodies().get(i));
    		}
    	}
    }*/
    // determines if the character moves
    Globals.player.setMoving(false);
    if (input.isKeyDown(Input.KEY_LEFT) || input.isKeyDown(Input.KEY_RIGHT)) {
      Globals.player.setMoving(true);
    }
    if (input.isKeyPressed(Input.KEY_F1)) {
      // jouer un son : l'aide
      // TODO
      helpSound.play();
    }
    if (input.isKeyPressed(Input.KEY_F2)) {
      Globals.dialogNextState = Globals.returnState;
      sbg.enterState(
          Songe.DIALOGSTATE, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
    if (input.isKeyPressed(Input.KEY_F3)) {
      voix.stop();
      voix.playShortText("Vous avez " + Globals.score + " points.");
    }
  }
예제 #10
0
  @Override
  public void update(
      final GameContainer container, final StateBasedGame game, final int deltaInMillis)
      throws SlickException {
    final Input input = container.getInput();

    if (input.isKeyPressed(Input.KEY_F1)) {
      container.setPaused(true);
      try {
        container.setFullscreen(!container.isFullscreen());
      } catch (final SlickException e) {
        Log.error(e);
      }
      //			container.setVSync(true);
      //			container.setSmoothDeltas(true);
      //			container.setMaximumLogicUpdateInterval(17);
      container.setPaused(false);
    }

    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      onExitKey(container, game);
    }

    final Level level = this.getLevel();

    if (level != null) {
      level.handleInput(input);
      level.update(deltaInMillis);

      EventManager.update();

      // Sorgt dafür dass 1. Collisionnen neu berechnet werden, 2. Zeile
      // Den Objekten gesagt wird die Kollision zu behandeln.
      CollisionManager.update();
      level.handleCollisions();
    }
  }
예제 #11
0
 @Override
 public boolean actionPerformed(Input input) {
   if (!draw) return false;
   if (input.isKeyPressed(Input.KEY_F1)) {
     menu = Menu.CM_SYS;
     cursor = Menu.SYS_S.ordinal();
   } else if (input.isKeyPressed(Input.KEY_F2)) {
     menu = Menu.CM_C;
     cursor = Menu.CHAR_C.ordinal();
   } else if (input.isKeyPressed(Input.KEY_F3)) {
     menu = Menu.CM_M1;
     cursor = 0;
   } else if (input.isKeyPressed(Input.KEY_F4)) {
     menu = Menu.CM_M2;
     cursor = 0;
   } else if (input.isKeyPressed(Input.KEY_F5)) {
     menu = Menu.CM_M3;
     cursor = 0;
   } else {
     if (menu == Menu.NONE) return false;
     if (input.isKeyPressed(Input.KEY_UP)) {
       if (menu == Menu.CM_SYS) {
         if (cursor > Menu.SYS_S.ordinal()) cursor--;
       } else if (menu == Menu.CM_C) {
         if (cursor > Menu.CHAR_C.ordinal()) cursor--;
       }
     } else if (input.isKeyPressed(Input.KEY_DOWN)) {
       if (menu == Menu.CM_SYS) {
         if (cursor < Menu.SYS_E.ordinal()) cursor++;
       } else if (menu == Menu.CM_C) {
         if (cursor < Menu.CHAR_M.ordinal()) cursor++;
       }
     } else if (input.isKeyPressed(Input.KEY_SPACE)) {
       draw = false;
       setChanged();
       notifyObservers(Menu.valueOf(cursor));
     } else if (input.isKeyPressed(Input.KEY_ESCAPE)) {
       init();
     }
   }
   return true;
 }
예제 #12
0
  @Override
  public void update(GameContainer container, StateBasedGame game, int delta)
      throws SlickException {
    final int X_DECCEL = 2;
    final int Y_ACCEL = 3;

    // Player movement
    Player p = getPlayer();
    if (!p.isAlive()) {
      Sound fx = null;
      if (playDeathSound) {
        fx = new Sound("res/audio/sounds/FallAndSplat.wav");
        fx.play();
        playDeathSound = false;
      }
      while (!fx.playing()) {
        container.exit();
      }
    }
    // Account for input
    Input i = container.getInput();
    if (i.isKeyDown(Input.KEY_D)) {
      p.accelerate(new Vector2f(4, 0));
    }
    if (i.isKeyDown(Input.KEY_A)) {
      p.accelerate(new Vector2f(-4, 0));
    }
    if (i.isKeyPressed(Input.KEY_W)) {
      p.jump();
    }

    Vector2f playerVect = p.getAccelerationVector();
    // Deccelerate X
    if (playerVect.x < 4 && playerVect.x > -4) {
      p.accelerate(new Vector2f(-1 * playerVect.x, 0));
    } else if (playerVect.x >= 4) {
      p.accelerate(new Vector2f(-1 * X_DECCEL, 0));
    } else {
      p.accelerate(new Vector2f(X_DECCEL, 0));
    }

    // Accellerate Y
    p.accelerate(new Vector2f(0, Y_ACCEL));
    p.move();
    this.manageCollision(true, true, true);
  }
예제 #13
0
  public void update(GameContainer container, StateBasedGame game, int delta)
      throws SlickException {
    Input input = container.getInput();

    for (int i = 0; i < allMapTab.length; i++) {
      levelB[i].update(container);
    }
    for (int i = 0; i < allMapTab.length; i++) {
      if (levelB[i].isClicked() && (i + 1) <= Fenetre.profilActif.getNiveaux_debloque()) {
        Fenetre.profilActif.setCurrent_Level(i + 1);
        Fenetre.profilActif.setLevel(Fenetre.profilActif.getCurrent_Level());
        game.enterState(PlayLevel.ID);
      }
    }
    if (input.isKeyPressed(Keyboard.KEY_ESCAPE)) {
      game.enterState(MenuGame.ID);
    }
  }
예제 #14
0
  @Override
  public void update(GameContainer container, int delta) {
    Input input = container.getInput();

    // move player
    if (input.isKeyDown(Input.KEY_W)) {
      //        	if(input.isKeyDown(Input.KEY_A)){
      //        		setDirection(Direction.NORTHWEST);
      //        	} else if(input.isKeyDown(Input.KEY_D)){
      //        		setDirection(Direction.NORTHEAST);
      //        	} else {
      setDirection(Direction.NORTH);
      //        	}
    } else if (input.isKeyDown(Input.KEY_S)) {
      //        	if(input.isKeyDown(Input.KEY_A)){
      //        		setDirection(Direction.SOUTHWEST);
      //        	} else if(input.isKeyDown(Input.KEY_D)){
      //        		setDirection(Direction.SOUTHEAST);
      //        	} else {
      setDirection(Direction.SOUTH);
      //        	}
    } else if (input.isKeyDown(Input.KEY_A)) {
      setDirection(Direction.WEST);
    } else if (input.isKeyDown(Input.KEY_D)) {
      setDirection(Direction.EAST);
    } else {
      setDirection(Direction.STOP);
    }

    if (input.isKeyPressed(Input.KEY_SPACE)) {
      //            float x = getPosition().x + (getImage().getWidth() / 2);
      //            float y = getPosition().y + (getImage().getHeight() / 2);
      //            currentWeapon.activate(new Vector2f(x, y));
      currentWeapon.activate(getPosition().copy());
    }

    move(delta);

    Vector2f pos = getPosition();
    pos.x = Math.max(0, pos.x);
    pos.x = Math.min(container.getWidth(), pos.x);
    pos.y = Math.max(0, pos.y);
    pos.y = Math.min(container.getHeight(), pos.y);
  }
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    Input input = gc.getInput();
    int mouseX = input.getMouseX();
    int mouseY = input.getMouseY();
    System.out.println("PAUSED");

    if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
      sbg.enterState(SimpleGame.GAMEPLAYSTATE);
      // GameplayState.currentState = STATES.START_GAME_STATE;
      // GameplayState.music.loop(1f,.3f);
      // GameplayState.needReset = true;
      // GameplayState.playing = false;
      // GameplayState.health = 100;

    }

    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      // gc.exit();
    }
  }
예제 #16
0
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    Input input = gc.getInput(); // Getting actual input

    if (menu[0]) { // When play is true
      if (input.isKeyPressed(Input.KEY_ENTER))
        sbg.enterState(
            Game.States.PLAY.ordinal(),
            new FadeOutTransition(),
            new FadeInTransition()); // When enter is pressed change state to PLAY with nice
      // transition :)
      if (input.isKeyPressed(Input.KEY_W))
        Game.level++; // When W is pressed increase game level by 1
      if (input.isKeyPressed(Input.KEY_S)) {
        if (Game.level > 1) Game.level--;
      } // When S is pressed reduce game level by 1 if is higher than 1
    } else if (menu[1]) {
      if (input.isKeyPressed(Input.KEY_ENTER)) menu[1] = false;
    } // When about is enabled and enter is pressed it returns to main menu
    else if (menu[2]) gc.exit(); // Exit when exit is enabled (cpt. Obvious)
    else { // When nothing is true show main menu
      if (input.isKeyPressed(Input.KEY_S)) {
        if (menuPos < 2) menuPos++;
      } // S pressed - pointer lower
      if (input.isKeyPressed(Input.KEY_W)) {
        if (menuPos > 0) menuPos--;
      } // W pressed - pointer higher
      if (input.isKeyPressed(Input.KEY_ENTER))
        menu[menuPos] = true; // If enter is pressed. The selected option is true
      menuPointer.setY(400 + 10 + 35 * menuPos); // Setting the position of "pointer"
      if (input.isKeyPressed(Input.KEY_P)) {
        if (!gc.isFullscreen()) gc.setFullscreen(true);
        else gc.setFullscreen(false);
      }
    }
  }
예제 #17
0
  @Override
  public void update(GameContainer gc, int delta) throws SlickException {
    NinjaJump g = (NinjaJump) game;

    Input input = gc.getInput();
    border.setX(x);
    border.setY(y);

    if (g.playerObstacleCollsion.checkCollsion()) {
      isAlive = false;
      jumpSpeed = -9F;
    }

    if (isJumping) {
      if ((isOnLeftSide && g.playerPlatformRCollsion.checkCollsion())
          || (!isOnLeftSide && g.playerPlatformLCollsion.checkCollsion())) {
        isJumping = false;
        jumpSpeed = 0F;
        isOnLeftSide = !isOnLeftSide;
        if (isOnLeftSide) {
          x = g.getLeftWallObstaclePosition();
        } else {
          x = gc.getWidth() - g.wallRight.getBorder().getWidth() - getBorder().getWidth();
        }
      }
    }

    if ((input.isKeyPressed(Input.KEY_SPACE) || input.isMousePressed(Input.MOUSE_LEFT_BUTTON))
        && !isJumping) {
      isJumping = true;
      if (x <= 33) {
        jumpSpeed = 5F; // old 0.4F
      } else {
        jumpSpeed = -5F;
      }
    }
    x += jumpSpeed;
  }
예제 #18
0
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    Input in = gc.getInput();
    float mouseX = in.getMouseX();
    float mouseY = in.getMouseY();

    if (mouseX != lastMouseX || mouseY != lastMouseY) {
      for (int i = 0; i < buttons.size(); i++) {
        buttons.get(i).checkMouseHover(new Vector2f(mouseX, mouseY));
      }
      lastMouseX = mouseX;
      lastMouseY = mouseY;
    }
    if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
      for (int i = 0; i < buttons.size(); i++) {
        boolean temp = buttons.get(i).checkMouseClick(new Vector2f(mouseX, mouseY), 0);
        if (temp && tf.getText().length() > 0) {
          int e = buttons.get(i).getButtonID();
          Vector2f point = rm.getMap("World_1.tmx").getStartLocation();
          int x = (int) point.x;
          int y = (int) point.y;
          switch (e) {
            case 0:
              p =
                  new Player(
                      Settings.PLAYER_X,
                      Settings.PLAYER_Y,
                      rm.getSprite("knight.png"),
                      tf.getText(),
                      CType.KNIGHT,
                      x,
                      y,
                      rm.getLog());
              break;
            case 1:
              p =
                  new Player(
                      Settings.PLAYER_X,
                      Settings.PLAYER_Y,
                      rm.getSprite("mage.png"),
                      tf.getText(),
                      CType.MAGE,
                      x,
                      y,
                      rm.getLog());
              break;
            case 2:
              p =
                  new Player(
                      Settings.PLAYER_X,
                      Settings.PLAYER_Y,
                      rm.getSprite("thief.png"),
                      tf.getText(),
                      CType.THIEF,
                      x,
                      y,
                      rm.getLog());
              break;
          }
          am = new AtlasMain(p, rm, 2);
          sbg.addState(am);
          am.init(gc, sbg);
          sbg.enterState(2);
        }
      }
    }
    if (in.isKeyPressed(Input.KEY_ESCAPE)) {
      System.exit(0);
    }
  }
예제 #19
0
  @Override
  public void update(GameContainer gameContainer, StateBasedGame stateBasedGame, int delta)
      throws SlickException {

    Input in = gameContainer.getInput();

    if (in.isKeyPressed(Input.KEY_C)) {
      clear();
    }

    gameContainer.setMaximumLogicUpdateInterval(updateInterval);

    if (in.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
      float x1 = in.getMouseX() / ratio;
      float y1 = in.getMouseY() / ratio;
      if (start == null) {
        start = new Cell((int) x1, (int) y1, ratio, false);
        start.start = true;
        cells[start.gridPosX][start.gridPosY].start = true;
        cellStack.add(cells[start.gridPosX][start.gridPosY]);
      } else if (goal == null) {
        goal = new Cell((int) x1, (int) y1, ratio, false);
        cells[goal.gridPosX][goal.gridPosY].goal = true;
      } else {
        changeCellAtPosition((int) x1, (int) y1);
      }

      if (start != null && goal != null) {
        this.wall = cells[(int) x1][(int) y1].wall;
      }
    }

    if (in.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
      if (start != null && goal != null) {
        mousePressing = true;
        float x1 = in.getMouseX() / ratio;
        float y1 = in.getMouseY() / ratio;
        cells[(int) x1][(int) y1].wall = this.wall;
      }
    } else {
      mousePressing = false;
    }

    if (in.isKeyPressed(Input.KEY_ENTER)) {
      if (mazeSolved && displayingMaze) {
        clear();
        createGraph();
        maze = true;
      } else if (!maze) {
        this.search = true;
      }
    }

    if (in.isKeyPressed(Input.KEY_M) && !maze) {
      createGraph();
      maze = true;
      this.logger.initWriter();
    }

    if (in.isKeyPressed(Input.KEY_S)) {
      clear();
      for (int i = 0; i < cells.length; i++) {
        for (int j = 0; j < cells.length; j++) {
          Random random = new Random();
          if (random.nextInt(3) == 0) {
            cells[i][j].wall = true;
          }
        }
      }
      setDefaultStartAndEnd(true);
    }

    if (in.isKeyPressed(Input.KEY_ADD)) {
      if (updateInterval > 1) {
        updateInterval -= 1;
      }
    }
    if (in.isKeyPressed(Input.KEY_SUBTRACT)) {
      if (updateInterval < 20) {
        updateInterval += 1;
      }
    }

    if (in.isKeyPressed(Input.KEY_P)) {
      if (!gameContainer.isPaused()) {
        gameContainer.pause();
      } else {
        gameContainer.resume();
      }
    }

    if (in.isKeyPressed(Input.KEY_D)) {
      this.diagonal = !this.diagonal;
    }

    if (in.isKeyPressed(Input.KEY_ESCAPE)) {
      stateBasedGame.enterState(1);
    }

    if (in.isKeyPressed(Input.KEY_A)) {
      AnalyzeLog.analyzeBacktracks(AnalyzeLog.FIRST);
    }

    if (in.isKeyPressed(Input.KEY_I)) {
      this.createImage();
    }

    if (this.search) {
      if (start == null || goal == null) {
        this.search = false;
      } else {
        if (ButtonStates.DFSState) {
          if (solvingVisited.size() < 1) {
            solvingVisited.add(cells[start.gridPosX][start.gridPosY]);
            cells[start.gridPosX][start.gridPosY].solvingVisited = true;
            currentDFSCell = cells[start.gridPosX][start.gridPosY];
          } else {
            for (int x = 0; x < CELLS; x++) {
              for (int y = 0; y < CELLS; y++) {
                cells[x][y].dfsCheckNeighbors();
              }
            }
            if (currentDFSCell.goal) {
              this.search = false;
              this.drawWay = true;
              this.end = currentDFSCell;
              getPath(false, null);
              if (displayingMaze) {
                mazeSolved = true;
              }
              foundSolution = true;
            } else {
              if (solvingVisited.size() != (CELLS * CELLS)) {
                ArrayList<Cell> currentNeighbors = new ArrayList<>();
                if (currentDFSCell.dfsNorth != null
                    && !currentDFSCell.dfsNorth.solvingVisited
                    && !currentDFSCell.dfsNorth.wall) {
                  currentNeighbors.add(currentDFSCell.dfsNorth);
                } else if (currentDFSCell.dfsEast != null
                    && !currentDFSCell.dfsEast.solvingVisited
                    && !currentDFSCell.dfsEast.wall) {
                  currentNeighbors.add(currentDFSCell.dfsEast);
                } else if (currentDFSCell.dfsSouth != null
                    && !currentDFSCell.dfsSouth.solvingVisited
                    && !currentDFSCell.dfsSouth.wall) {
                  currentNeighbors.add(currentDFSCell.dfsSouth);
                } else if (currentDFSCell.dfsWest != null
                    && !currentDFSCell.dfsWest.solvingVisited
                    && !currentDFSCell.dfsWest.wall) {
                  currentNeighbors.add(currentDFSCell.dfsWest);
                } else {;
                }
                if (currentNeighbors.size() > 0) {
                  Cell neighbor = currentNeighbors.get(0);
                  neighbor.solvingPrevious = currentDFSCell;
                  neighbor.solvingVisited = true;
                  currentDFSCell = neighbor;
                } else {
                  dfsBacktracked.add(currentDFSCell);
                  dfsBacktracked.add(currentDFSCell.solvingPrevious);
                  currentDFSCell = currentDFSCell.solvingPrevious;
                }
              }
            }
          }
        } else if (ButtonStates.AStarState) {

        } else if (ButtonStates.BFSState) {
          if (solvingVisited.size() < 1) {
            solvingVisited.add(cells[start.gridPosX][start.gridPosY]);
            cells[start.gridPosX][start.gridPosY].solvingVisited = true;
            cellStack.add(cells[start.gridPosX][start.gridPosY]);
          } else {
            if (!cellStack.isEmpty()) {
              Cell current = (Cell) cellStack.remove();
              Cell child;
              if (current.goal) {
                this.end = current;
                this.drawWay = true;
                this.search = false;
                getPath(false, null);
                if (displayingMaze) {
                  mazeSolved = true;
                }
                foundSolution = true;
              } else {
                while ((child = getUnvisitedChildCell(current)) != null) {
                  child.solvingVisited = true;
                  child.solvingPrevious = current;
                  solvingVisited.add(child);
                  cellStack.add(child);
                  current.solvingCheckNeighbors(diagonal);
                  getPath(true, child);
                }
              }
            }
          }
        } else {
          try {
            throw new NoSolvingAlgorithmSelectedException();
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
    if (this.maze) {
      if (this.logger.used) {
        this.logger.createNewLogFile();
        this.logger.initWriter();
        this.logger.used = false;
      }
      if (cells.length != 0) {
        logger.writeInLog("Checking neighbors");
        for (int i = 0; i < CELLS; i++) {
          for (int j = 0; j < CELLS; j++) {
            cells[i][j].genCheckNeighbors();
          }
        }

        if (genVisited.size() < 1) {
          genVisited.add(cells[1][1]);
          currentGenCell = cells[1][1];
          currentGenCell.genVisited = true;
          logger.writeInLog("Adding Cell X1 and Y1 to visited Cells");
        }
        if (genVisited.size() != totalCells) {
          ArrayList<Cell> currentNeighbors = new ArrayList<>();
          if (currentGenCell.north != null
              && !currentGenCell.north.genVisited
              && currentGenCell.north.allWallsIntact) {
            currentNeighbors.add(currentGenCell.north);
            logger.writeInLog(
                "Adding north cell to neighbors at: "
                    + currentGenCell.north.gridPosX
                    + "; "
                    + currentGenCell.north.gridPosY);
          }
          if (currentGenCell.east != null
              && !currentGenCell.east.genVisited
              && currentGenCell.east.allWallsIntact) {
            currentNeighbors.add(currentGenCell.east);
            logger.writeInLog(
                "Adding east cell to neighbors at: "
                    + currentGenCell.east.gridPosX
                    + "; "
                    + currentGenCell.east.gridPosY);
          }
          if (currentGenCell.south != null
              && !currentGenCell.south.genVisited
              && currentGenCell.south.allWallsIntact) {
            currentNeighbors.add(currentGenCell.south);
            logger.writeInLog(
                "Adding south cell to neighbors at: "
                    + currentGenCell.south.gridPosX
                    + "; "
                    + currentGenCell.south.gridPosY);
          }
          if (currentGenCell.west != null
              && !currentGenCell.west.genVisited
              && currentGenCell.west.allWallsIntact) {
            currentNeighbors.add(currentGenCell.west);
            logger.writeInLog(
                "Adding west cell to neighbors at: "
                    + currentGenCell.west.gridPosX
                    + "; "
                    + currentGenCell.west.gridPosY);
          }

          if (currentNeighbors.size() > 0) {
            Random random = new Random();
            int randomValue = random.nextInt(currentNeighbors.size());
            logger.writeInLog("Generated random number: " + randomValue);
            Cell neighbor = currentNeighbors.get(randomValue);
            logger.writeInLog("Picked neighbor: " + neighbor.gridPosX + "; " + neighbor.gridPosY);
            neighbor.genVisited = true;

            int wallX = 0;
            int wallY = 0;

            // break wall
            if (neighbor.gridPosX > currentGenCell.gridPosX) {
              wallX = currentGenCell.gridPosX + 1;
            } else if (neighbor.gridPosX < currentGenCell.gridPosX) {
              wallX = currentGenCell.gridPosX - 1;
            } else {
              wallX = currentGenCell.gridPosX;
            }

            if (neighbor.gridPosY > currentGenCell.gridPosY) {
              wallY = currentGenCell.gridPosY + 1;
            } else if (neighbor.gridPosY < currentGenCell.gridPosY) {
              wallY = currentGenCell.gridPosY - 1;
            } else {
              wallY = currentGenCell.gridPosY;
            }

            cells[wallX][wallY].wall = false;
            cells[wallX][wallY].genVisited = true;
            logger.writeInLog("Breaking wall at: " + wallX + "; " + wallY);
            genVisited.add(cells[wallX][wallY]);
            neighbor.genBacktrack = currentGenCell;
            logger.writeInLog(
                "Set current cell to backtrack cell at: "
                    + currentGenCell.gridPosX
                    + "; "
                    + currentGenCell.gridPosY);
            currentGenCell = neighbor;

          } else {
            currentGenCell = currentGenCell.genBacktrack;
            logger.writeInLog(
                "Backtracking at: "
                    + currentGenCell.genBacktrack.gridPosX
                    + "; "
                    + currentGenCell.genBacktrack.gridPosY);
          }
        } else {
          currentGenCell = null;
          this.maze = false;
          setDefaultStartAndEnd(true);
          displayingMaze = true;
          if ((this.search = !this.search) == true) {
            if (this.startSearch == false) {
              this.search = false;
              createImage();
            }
          }
          logger.writeInLog("Done Maze, closing logger.");
          logger.closeWriter();
          if (this.automaticallyGenerateMazes && (generatedMazes < mazesToGenerate)) {
            generatedMazes += 1;
            clear();
            createGraph();
            this.maze = true;
          } else if (this.logger.stepList.size() != 0) {
            this.logger.printStepList();
          } else {;
          }
        }
      }
    }
    char[][] copyOfLevel = new char[CELLS][CELLS];
    for (int x = 0; x < cells.length; x++) {
      for (int y = 0; y < cells.length; y++) {
        if (cells[x][y].wall) {
          copyOfLevel[x][y] = 'W';
        } else if (!cells[x][y].wall) {
          copyOfLevel[x][y] = 'D';
        } else if (cells[x][y].start) {
          copyOfLevel[x][y] = 'S';
        } else if (cells[x][y].goal) {
          copyOfLevel[x][y] = 'G';
        } else {
          copyOfLevel[x][y] = 'D';
        }
      }
    }
    Level.update(copyOfLevel);
  }
예제 #20
0
  /** Actualiza el juego, uso interno */
  @Override
  public void update(GameContainer gc, int fps) throws SlickException {
    Input i = gc.getInput();
    if (guardado && progreso) {
      if (i.isMouseButtonDown(0)) {
        double y =
            1 - (double) (Math.max(20, Math.min(i.getMouseY(), sy - 20)) - 20) / (double) (sy - 40);
        PartidoGuardado pguardado = (PartidoGuardado) partido;
        pguardado.setTiempo((int) (y * (double) pguardado.getIterciones()));
      }
    }
    if (i.isKeyDown(Input.KEY_SUBTRACT)) {
      escala = escala * 0.970;
    } else if (i.isKeyDown(Input.KEY_ADD)) {
      escala = escala / 0.970;
    }
    if (i.isKeyPressed(Input.KEY_F1)) {
      estadio = !estadio;
    }
    if (i.isKeyPressed(Input.KEY_F2)) {
      entorno = !entorno;
    }
    if (i.isKeyPressed(Input.KEY_F3)) {
      showfps = !showfps;
      gc.setShowFPS(showfps);
    }
    if (i.isKeyPressed(Input.KEY_F4)) {
      tipoTexto = (tipoTexto + 1) % 5;
    }
    if (i.isKeyPressed(Input.KEY_F5)) {
      marcador = !marcador;
    }
    if (i.isKeyDown(Input.KEY_ESCAPE)) {
      gc.setSoundVolume(0);
      gc.setSoundOn(false);
      stop();
      gc.exit();
    }
    if (i.isKeyDown(Input.KEY_P)) {
      pause = !pause;
      if (pause) {
        gc.pause();
      } else {
        gc.resume();
      }
    }
    if (guardado && i.isKeyPressed(Input.KEY_LEFT)) {
      if (incremento == 0) {
        incremento = -1;
      } else if (incremento == -1) {
        incremento = -2;
      } else if (incremento == -2) {
        incremento = -4;
      } else if (incremento == -4) {
        incremento = -4;
      } else if (incremento == 1) {
        incremento = 0;
      } else if (incremento == 2) {
        incremento = 1;
      } else if (incremento == 4) {
        incremento = 2;
      }
      iteracionControl = 30;
    }
    if (guardado && i.isKeyPressed(Input.KEY_RIGHT)) {
      if (incremento == 0) {
        incremento = 1;
      } else if (incremento == 1) {
        incremento = 2;
      } else if (incremento == 2) {
        incremento = 4;
      } else if (incremento == 4) {
        incremento = 4;
      } else if (incremento == -1) {
        incremento = 0;
      } else if (incremento == -2) {
        incremento = -1;
      } else if (incremento == -4) {
        incremento = -2;
      }
      iteracionControl = 30;
    }
    paso = 0;
    if (guardado && i.isKeyPressed(Input.KEY_UP)) {
      incremento = 0;
      paso = 1;
    }
    if (guardado && i.isKeyPressed(Input.KEY_DOWN)) {
      incremento = 0;
      paso = -1;
    }
    if (guardado && i.isKeyPressed(Input.KEY_HOME)) {
      inicio = pg.getTiempo();
    }
    if (guardado && i.isKeyPressed(Input.KEY_END)) {
      fin = pg.getTiempo();
    }
    if (guardado && i.isKeyPressed(Input.KEY_DELETE)) {
      if (JOptionPane.showConfirmDialog(
              null,
              "Desea eliminar los frames seleccionados?",
              "Eliminar Frames",
              JOptionPane.YES_NO_OPTION)
          == 0) {
        if (inicio < fin) {
          pg.delete(inicio, fin);
          fin = inicio;
        } else {
          pg.delete(inicio, pg.getIterciones() - 1);
          pg.delete(0, fin);
          inicio = 0;
          fin = pg.getIterciones() - 1;
          pg.setTiempo(0);
        }
      }
    }
    if (guardado && i.isKeyPressed(Input.KEY_S)) {
      if (JOptionPane.showConfirmDialog(
              null, "Desea gardar el partido?", "Guardar Partido", JOptionPane.YES_NO_OPTION)
          == 0) {
        // System.out.println(pg.getURL().getProtocol());
        if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
          try {
            pg.save(jfc.getSelectedFile());
          } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al guardar partido...");
            if (principal != null) {
              try {
                principal.addGuardadoLocal(new File[] {jfc.getSelectedFile()});
              } catch (Exception ex) {
              }
            }
          }
        }
      }
    }
    if (iteracionControl > 0) {
      iteracionControl--;
    }

    vx = (partido.getPosiciones()[2][0].getX() - px) / Constants.SEGUIMIENTO_CAMARA;
    vy = (partido.getPosiciones()[2][0].getY() - py) / Constants.SEGUIMIENTO_CAMARA;

    px = px + vx;
    py = py + vy;

    for (int j = 0; j < 11; j++) {
      posPrev[j][0] = posActu[0][j];
      posPrev[j][1] = posActu[1][j];
    }

    if (partido != null) {
      if (guardado) {
        try {
          pg.setTiempo(pg.getTiempo() + incremento + paso);
        } catch (Exception ex) {
          logger.error("Error al establecer tiempo de partido guardo", ex);
          throw new SlickException(ex.getLocalizedMessage());
        }
      } else {
        try {
          partido.iterar();
        } catch (Exception ex) {
          logger.error("Error al iterar partido", ex);
          throw new SlickException(ex.getLocalizedMessage());
        }
      }

      boolean oldSound = sonidos;
      if (guardado && incremento == 0) {
        sonidos = false;
      }

      if (audioAmbiente == audioAmbienteIdx) {
        if (sonidos) {
          ambiente[audioIdx].play(pinch(), volumenAmbiente);
        }
        audioAmbiente = 50 + rand.nextInt(20);
        audioAmbienteIdx = 0;
        audioIdx = rand.nextInt(ambiente.length);
      }
      audioAmbienteIdx++;

      if (partido.estanSilbando()) {
        if (sonidos) {
          silbato.play(pinch(), volumenCancha);
        }
      }
      if (partido.estanRematando()) {
        if (sonidos) {
          remate[rand.nextInt(2)].play(pinch(), volumenCancha);
        }
      }
      if (partido.estanOvacionando()) {
        if (sonidos) {
          ovacion[rand.nextInt(2)].play(pinch(), volumenAmbiente);
        }
      }
      if (partido.esGol()) {
        if (sonidos) {
          gol.play(pinch(), volumenAmbiente);
        }
        golIter = 1;
      }

      if (golIter > 0) {
        golIter++;
        if (golIter == 50) {
          golIter = 0;
        }
      }

      if (partido.isLibreIndirecto()) {
        if (sonidos) {
          silbato.play(pinch(), volumenAmbiente);
        }
      }

      if (partido.isOffSide()) offSideIter = 1;

      if (offSideIter > 0) {
        offSideIter += dxsaque;
        if (offSideIter > 800) {
          offSideIter = 0;
        }
      }

      if (partido.cambioDeSaque()) {
        if (sonidos) {
          silbato.play(pinch(), volumenAmbiente);
        }
        saqueIter = 1;
      }

      if (saqueIter > 0) {
        saqueIter = saqueIter + dxsaque;
        if (saqueIter > sx + 2 * 177) {
          saqueIter = 0;
        }
      }
      if (partido.estaRebotando()) {
        if (sonidos) {
          rebote.play(pinch(), volumenCancha);
        }
      }
      if (partido.esPoste()) {
        if (sonidos) {
          poste[rand.nextInt(2)].play(pinch(), volumenCancha);
          ovacion[rand.nextInt(2)].play(pinch(), volumenAmbiente);
        }
      }
      sonidos = oldSound;
      if (partido.estanSacando()) {
        iterSaca = (iterSaca + 1) % 6;
      }
    }

    posActu = partido.getPosiciones();
    for (int j = 0; j < 11; j++) {
      dx = posPrev[j][0].getX() - posActu[0][j].getX();
      dy = posPrev[j][0].getY() - posActu[0][j].getY();
      if (dy != 0 || dx != 0) {
        iteraciones[j][0] = iteraciones[j][0] + 1;
        angulos[j][0] = posPrev[j][0].angle(posActu[0][j]) * 180 / Math.PI + 90;
        if (incremento < 0) {
          angulos[j][0] = angulos[j][0] + 180;
        }
      } else {
        iteraciones[j][0] = 3;
      }

      dx = posPrev[j][1].getX() - posActu[1][j].getX();
      dy = posPrev[j][1].getY() - posActu[1][j].getY();
      if (dy != 0 || dx != 0) {
        iteraciones[j][1] = iteraciones[j][1] + 1;
        angulos[j][1] = posPrev[j][1].angle(posActu[1][j]) * 180 / Math.PI + 90;
        if (incremento < 0) {
          angulos[j][1] = angulos[j][1] + 180;
        }
      } else {
        iteraciones[j][1] = 3;
      }
    }

    for (int j = 1; j < angulosAnteriores[0][0].length; j++) {
      for (int x = 0; x < 11; x++) {
        for (int y = 0; y < 2; y++) {
          angulosAnteriores[x][y][j - 1] = angulosAnteriores[x][y][j];
        }
      }
    }
    for (int x = 0; x < 11; x++) {
      for (int y = 0; y < 2; y++) {
        angulosAnteriores[x][y][angulosAnteriores[0][0].length - 1] = angulos[x][y];
      }
    }
    boolean ok = true;
    for (int x = 0; x < 11; x++) {
      for (int y = 0; y < 2; y++) {
        angVisible[x][y] = 0;
        for (int j = 0; j < angulosAnteriores[0][0].length; j++) {
          angVisible[x][y] = angVisible[x][y] + angulosAnteriores[x][y][j];
        }
        angVisible[x][y] = angVisible[x][y] / (double) angulosAnteriores[0][0].length;
      }
    }

    if (autoescala) {
      int[] escalas =
          (Transforma.transform(
              partido.getPosVisibleBalon(),
              Constants.centroCampoJuego,
              -Transforma.transform(px, escala),
              -Transforma.transform(py, escala),
              escala));
      escalaAjustada =
          escala
              * Math.min(
                  0.7d * sx2 / (double) Math.abs(escalas[0]),
                  0.7d * sy2 / (double) Math.abs(escalas[1]));
    }
    if (!noAutoEscalar && partido.esGol()) {
      noAutoEscalar = true;
    }
    if (noAutoEscalar && partido.estanRematando()) {
      noAutoEscalar = false;
    }
  }
  @Override
  public void update(GameContainer container, StateBasedGame state, int delta)
      throws SlickException {
    frog.update(container, delta);
    allOtherObjects.update(container, delta);

    // Musik loopen
    if (sound_music.playing() == false) {
      if (isMusicPaused == true) sound_music.resume();
      else sound_music.loop();
    }

    // Testobjekte
    woman.update(container, delta);
    timerBar.update(container, delta);

    // Rupees einsammeln
    for (Rupee obj : allOtherObjects.getRupees()) {
      if (frog.checkCollisionWith(obj) == true) {
        if (obj.getCollected() == false) {
          obj.setCollected(true);
          obj.getSound().play();
          frog.incrRupeesInBag(obj.getWert());
          frog.getRupeeStringHover().activate(frog.getPosX(), frog.getPosY(), obj.getWert());
        }
      }
    }

    // und bei der Frau abgeben!
    /*
     * Nur wenn die Rupees bei der Frau abgegegeben werden
     * dann wird die Zeit vollends aufgefüllt
     */
    /*
     * Berechnung des Highscores:
     * Rupees * verbliebende Zeit = Highscore
     */
    if (frog.checkCollisionWith(woman) == true && frog.getRupeesInBag() != 0) {

      // Highscore Berechnung!
      highscore += (long) ((timerBar.getWidth() / 1) * frog.getRupeeaInBag());

      rupeeCounter += frog.getRupeesInBag();
      frog.setRupeesInBag(0);
      woman.setWithBag(true);
      woman.setCollisionOn(false);
      woman.setAnimation(true);
      woman.getSound().play();
      timerBar.restoreWidth();
      for (Rupee obj : allOtherObjects.getRupees()) {
        obj.randomize();
      }
    }

    // beim Tod/Gameover
    if (frog.getLifeCount() <= 0) {
      frog.getSound_gameover().play();
      sound_music.stop();

      frog.reset();
      frog.setRupeesInBag(0);
      frog.setLifeCount(2);
      timerBar.setTimerOn(false);

      state.enterState(GameStates.GameOver);
    }

    // wenn die Zeit abgelaufen wird: ein Leben nehmen!
    // außerdem die Rupees wieder neu druchwürfeln
    if (timerBar.getEvent() == true) {
      frog.reduceLifeCount();
      frog.incrLifeCount();
      timerBar.setEvent(false);
      frog.reset();
      timerBar.setTimerOn(false);

      for (Rupee obj : allOtherObjects.getRupees()) {
        obj.randomize();
      }
    }

    // Kollisionsabfrage
    // Frosch mit Autos
    for (GameObj obj : allOtherObjects.getCars()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.reset();
        timerBar.setTimerOn(false);

        for (Rupee obj2 : allOtherObjects.getRupees()) {
          obj2.randomize();
        }
      }
    }

    // mit den LOGS oder dem WASSER
    frog.setOnBoat(false);

    for (GameObj obj : allOtherObjects.getLogs()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.setOnBoat(true);
      }
    }

    for (GameObj obj : allOtherObjects.getLogs()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.setPosX(frog.getPosX() + (obj.getSpdX() * (delta / 1000.0f)));
      }
    }

    for (GameObj obj2 : allOtherObjects.getRiver()) {
      if (frog.checkCollisionWith(obj2) == true && frog.getOnBoat() == false) {
        frog.reset();
        timerBar.setTimerOn(false);

        for (Rupee obj : allOtherObjects.getRupees()) {
          obj.randomize();
        }
      }
    }

    // Falls man den Frosch wegen eines resettes nicht mehr steuern kann
    // sollen so und so viele Sekunden passieren bis man ihn wieder
    // kontrollieren kann!
    if (frog.getEingabe() == false) {
      resetTimer--;
    }
    if (resetTimer <= 0) {
      frog.setEingabe(true);
      frog.setCollisionOn(true);
      timerBar.setTimerOn(true);
      resetTimer = RESETTIMER;
      timerBar.restoreWidth();
    }

    // Der Frosch soll nicht durch die Wände können!
    for (GameObj obj : allOtherObjects.getWall()) {
      if (frog.checkCollisionWith(obj) == true) {
        // von rechts
        if (frog.getSpdX() > 0) frog.setPosX(frog.getPrevPosX());
        // von links
        else if (frog.getSpdX() < 0) frog.setPosX(frog.getPrevPosX());
        // von unten
        if (frog.getSpdY() < 0 && frog.getPosY() >= 82) frog.setPosY(frog.getPrevPosY());
      }
    }

    // Pause game
    Input input = container.getInput();
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      sound_pause.play();
      sound_music.pause();
      isMusicPaused = true;
      state.enterState(GameStates.Paused);
    }

    /*
     * Der Guide wird nur ganz am Anfang oben als kleiner Text eingeblendet.
     * Sobald einmal die Rupees bei der Frau abgegeben worden sind,
     * verschwindet der Text bzw ein motivierender Text steht dort.
     */

    if (guideString.equals(Constants.GUIDE5) == false) {
      // erster Tipp
      guideString = Constants.GUIDE1;

      // zweiter Tipp
      if (frog.getRupeesInBag() >= 2) guideString = Constants.GUIDE2;

      // dritter Tipp
      if (rupeeCounter >= 1) guideString = Constants.GUIDE3;

      // vierter Tipp
      if (guideString.equals(Constants.GUIDE3) && frog.getRupeesInBag() >= 1)
        guideString = Constants.GUIDE4;

      // Ende
      if (guideString.equals(Constants.GUIDE4) && frog.getRupeesInBag() == 0)
        guideString = Constants.GUIDE5;
    }
  }
예제 #22
0
파일: HoverCave.java 프로젝트: nam0r/Devint
  @Override
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
    Input input = gc.getInput();
    // If the beginning explanation is finished
    if (playTheGame) {
      // if the player is not dead
      if (!dead) {
        if (movingUp) {
          dudeHeight -= ((double) delta) / 10.0;
        } else {
          dudeHeight += ((double) delta) / 10.0;
        }
        float coeff = (wallOffset - dudeSize.width / 2) / WALL_RES;
        actualUpperWall =
            (int)
                (upperWall.get(currentWallNo - 1)
                    - coeff * (upperWall.get(currentWallNo) - upperWall.get(currentWallNo - 1)));
        actualLowerWall =
            (int)
                (lowerWall.get(currentWallNo - 1)
                    - coeff * (lowerWall.get(currentWallNo) - lowerWall.get(currentWallNo - 1)));

        // TODO The speed can be adjusted here
        wallOffset -= (float) delta * speed;
        speed += ((double) delta / 1000000000.0) * 2000;
        if (wallOffset <= -WALL_RES) {
          wallOffset += WALL_RES;
          popWall();
          addToWall();
        }
        distance += delta;
        // detect collisions
        // TODO Improve collision detection to find the edge of the box
        // against the edge of the cave.
        if ((dudeHeight + SENSITIVITY) > actualLowerWall
            || (dudeHeight - SENSITIVITY) < actualUpperWall) {
          dead = true;
          // voix.playText("Le je est terminé, votre score est de "+ distance/1000);
        }
        // the start explosion
        explosion.update(delta * 2);
        // the smoke trail
        trail.update(delta);
      }

      // If we are dead
      else {
        sonD.stop(1);
        sonG.stop();

        // if we are in main game
        if (Globals.returnState != Songe.MAINMENUSTATE) {
          // The score is set
          Globals.score += distance / 1000;
          Globals.nextEvent(sbg);
        }
        // if playing from the stand-alone version
        else {
          sbg.enterState(
              Globals.returnState,
              new FadeOutTransition(Color.black),
              new FadeInTransition(Color.black));
        }
      }
    }
    // if not yet started to play
    else {
      sonG.setVolume(0f, 0);
      sonD.setVolume(0f, 1);
      if (input.isKeyPressed(Input.KEY_UP)) {
        playTheGame = true;
        sonG.setVolume(600f, 0);
        sonD.setVolume(600f, 1);

        // sonG.setPitch(0.8f, 0);
        // sonD.setPitch(0.8f, 1);
        enterSound.stop();
      } else if (input.isKeyPressed(Input.KEY_F1)) {
        enterSound.stop();
        enterSound.play();
      }
    }
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      sbg.enterState(
          Globals.returnState,
          new FadeOutTransition(Color.black),
          new FadeInTransition(Color.black));
    }
    spX -= delta * 4.0f * speed;
  }
예제 #23
0
 @Override
 public void respondToUserInput(Input in) {
   if (in.isKeyPressed(Options.OPEN_MINIMAP.key())) visible = !visible;
 }
예제 #24
0
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    // throw new UnsupportedOperationException("Not supported yet.");
    Input input = container.getInput();

    // rotate quad
    double x1 = jugador1.getPosicion().getX();
    double y1 = jugador1.getPosicion().getY();

    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
      plane1.rotate(-0.2f * delta);
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
      plane1.rotate(0.2f * delta);
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
      float hip = 0.4f * delta;
      float rotation = plane1.getRotation();
      x1 -= hip * Math.sin(Math.toRadians(rotation));
      y1 += hip * Math.cos(Math.toRadians(rotation));
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
      float hip = 0.4f * delta;
      float rotation = plane1.getRotation();
      x1 += hip * Math.sin(Math.toRadians(rotation));
      y1 -= hip * Math.cos(Math.toRadians(rotation));
    }

    // keep quad on the screen
    if (x1 < 10) {
      x1 = 10;
    }
    if (x1 > 790) {
      x1 = 790;
    }
    if (y1 < 10) {
      y1 = 10;
    }
    if (y1 > 590) {
      y1 = 590;
    }

    Vector posicion = jugador1.getPosicion();
    posicion.setX(x1);
    posicion.setY(y1);
    jugador1.setPosicion(posicion);

    // jugador 2
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) lastSteering = 1;
    if (Keyboard.isKeyDown(Keyboard.KEY_A)) lastSteering = 2;
    if (Keyboard.isKeyDown(Keyboard.KEY_F)) lastSteering = 3;
    if (Keyboard.isKeyDown(Keyboard.KEY_S)) lastSteering = 4;
    /*
    switch(lastSteering) {
        case 1: jugador2.update(steeringW.getSteering(), delta);
            break;
        case 2: jugador2.update(steeringA.getSteering(), delta);
            break;
        case 3: jugador2.update(steeringF.getSteering(), delta);
            break;
        case 4: jugador2.update(steeringS.getSteering(), delta);
            break;
        default:
    }*/

    // plane2.rotate((float) jugador2.getOrientacion());

    if (input.isKeyPressed(Input.KEY_F1)) {
      Image target = new Image(container.getWidth(), container.getHeight());
      container.getGraphics().copyArea(target, 0, 0);
      ImageOut.write(target.getFlippedCopy(false, true), "screenshot.png", false);
      target.destroy();
    }
  }