Beispiel #1
0
  public void stopGame() {

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

    Sound.stopAllMusic();
    Sound.stopAllSounds();
  }
Beispiel #2
0
 public static void update() {
   if (update) {
     Sound.random("random", 1f, "OGG", "res/sound/music", 11);
     GUI.Background.draw("dirt");
     Text.draw("SETTINGS", GUI.Coordinates.x / 2 - 94, GUI.Coordinates.y / 4 * 3, 6, Color.white);
     GUI.Button.draw(
         "Music",
         GUIScale.toUpperCase(),
         GUI.Coordinates.x / 2 - 94,
         GUI.Coordinates.y / 2,
         1,
         1,
         "planks_oak",
         2,
         128);
     if (Button.isButtonClicked("Music")) {
       if (GUIScale.length() == 6) {
         GUIScale = "Auto";
         Create.createFile("Settings/GUIScale");
         Create.write("Auto");
         Create.closeFile();
       } else {
         GUIScale = "Normal";
         Create.createFile("Settings/GUIScale");
         Create.write("Normal");
         Create.closeFile();
         game.Main.Sleep(256);
       }
     }
   }
 }
Beispiel #3
0
  /** Starts a new thread and begins the game */
  public void startGame() {

    Score.resetScore();

    Sound.playMusic(R.sound.music.getRandom());

    currentLevel = 0;
    loadLevel(currentLevel);
  }
Beispiel #4
0
  private void gameWon() {

    // We have met, so stop the game and change level.

    // Pause for a second
    if (gameStatus == Game.GAMESTATUS_PLAYING) {
      gameStatus = GAMESTATUS_WON;
      lasttime = System.currentTimeMillis();

      GUIGame.WinStrings.change();

      Score.addScore(100000);

      if (!Physics.hearts) {
        Physics.spawnHeart(this.getRule().getPosition().x, this.getRule().getPosition().y, 50);
        Physics.spawnHeart(
            this.getRulette().getPosition().x, this.getRulette().getPosition().y, 50);
      }

      rule.setDead(true);
      Physics.world.destroyBody(rule.getBody());

      rulette.setDead(true);
      Physics.world.destroyBody(rulette.getBody());

      Physics.hearts = true;

      Sound.playSound(R.sound.effects.win);
    }

    long timetaken = System.currentTimeMillis() - lasttime;
    if (timetaken < levelTransitionTime) {
      return;
    }

    // Change level
    loadLevel(++currentLevel);

    // Reset time
    lasttime = 0l;

    Physics.hearts = false;
  }
Beispiel #5
0
  private void gameLost() {
    Physics.hearts = false;

    // Pause for a second
    if (gameStatus == Game.GAMESTATUS_PLAYING) {

      gameStatus = GAMESTATUS_FAILED;
      lasttime = System.currentTimeMillis();

      // We have met, so stop the game and change level.
      Sound.playSound(R.sound.effects.lose);

      Score.subtractScore(Score.getScore() / 2);

      if (rule.isDead()) {
        Physics.spawnBrokenHeart(
            this.getRule().getPosition().x, this.getRule().getPosition().y, 50);
        Physics.world.destroyBody(rule.getBody());
      } else if (rulette.isDead()) {
        Physics.world.destroyBody(rulette.getBody());
      }
    }

    long timetaken = System.currentTimeMillis() - lasttime;
    if (timetaken < levelTransitionTime) {
      return;
    }

    // Change level
    loadLevel(currentLevel);

    // Reset time
    lasttime = 0l;

    Physics.hearts = false;
  }
Beispiel #6
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();
    }
  }