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; }
/** * 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(); } }