Example #1
0
  public void stopGame() {

    // Remove world
    if (gameObjects != null) {
      for (Entity e : gameObjects) {
        Physics.world.destroyBody(e.getBody());
      }
    }

    Sound.stopAllMusic();
    Sound.stopAllSounds();
  }
Example #2
0
  public void loadLevel(int number) {

    // Remove world
    if (gameObjects != null) {
      for (Entity e : gameObjects) {
        Physics.world.destroyBody(e.getBody());
      }
    }

    gameObjects = Level.load(number);
    rule = (Rule) gameObjects.get(gameObjects.size() - 2);
    rulette = (Rulette) gameObjects.get(gameObjects.size() - 1);
    selectedCharacter = rule;
    gameStatus = GAMESTATUS_PLAYING;
  }
Example #3
0
  /**
   * GameLoop provides the accurate delta time we need to step our entities
   *
   * @param delta
   */
  public void gameInteration(float delta) {
    // Check if Rule and Rulette have met
    if (rule.getBounds().intersects(rulette.getBounds()) || gameStatus == GAMESTATUS_WON) {

      gameWon();
      return;
    } else if (rule.isDead() || rulette.isDead() || gameStatus == GAMESTATUS_FAILED) {

      // If we have died
      gameLost();
      return;
    }

    Vec2 move = new Vec2();
    if (Input.isKeyDown(KeyEvent.VK_A)) move.x -= 1;
    if (Input.isKeyDown(KeyEvent.VK_D)) move.x += 1;
    move.mulLocal(speed);

    this.selectedCharacter.setVelocityX(move.x);

    move.x = -move.x;

    this.getNotSelectedCharacter().setVelocityX(move.x);

    if (Input.isKeyDown(KeyEvent.VK_SPACE)) {
      Input.removeKey(KeyEvent.VK_SPACE);
      if (selectedCharacter.touching > 0) {
        Sound.playSound(R.sound.effects.jump);
        selectedCharacter
            .getBody()
            .applyLinearImpulse(
                new Vec2(0, -jumpspeed), selectedCharacter.getBody().getLocalCenter());
      }
      if (getNotSelectedCharacter().touching > 0) {
        Sound.playSound(R.sound.effects.jump);
        getNotSelectedCharacter()
            .getBody()
            .applyLinearImpulse(
                new Vec2(0, -jumpspeed), selectedCharacter.getBody().getLocalCenter());
      }
    }

    // Move all the tokens
    for (int i = 0; i < gameObjects.size(); i++) {
      Entity e = gameObjects.get(i);
      e.update(delta);
    }

    // SOUND
    if (Input.isKeyDownOnce(KeyEvent.VK_PAGE_UP)) {
      Sound.increaseClipVolume();
    } else if (Input.isKeyDownOnce(KeyEvent.VK_PAGE_DOWN)) {
      Sound.decreaseClipVolume();
    } else if (Input.isKeyDownOnce(KeyEvent.VK_HOME)) {
      Sound.increaseMusicVolume();
    } else if (Input.isKeyDownOnce(KeyEvent.VK_END)) {
      Sound.decreaseMusicVolume();
    } else if (Input.isKeyDownOnce(KeyEvent.VK_INSERT)) {
      if (Sound.isMusicMuted()) Sound.unmuteMusic();
      else Sound.muteMusic();
    } else if (Input.isKeyDownOnce(KeyEvent.VK_DELETE)) {
      if (Sound.isClipsMuted()) Sound.unmuteClips();
      else Sound.muteClips();
    }

    // Reset Game
    if (Input.isKeyDownOnce(KeyEvent.VK_R)) {
      resetLevel();
    }
  }