Multiple fixes and HUD upgrade

This commit is contained in:
Andreas Greiner 2021-06-27 17:33:29 +02:00
parent 06f99c1801
commit 5653c137f8
9 changed files with 55 additions and 20 deletions

View File

@ -41,9 +41,6 @@ public class GamePlayManager {
/** Flag, if the bubble movement is froze */ /** Flag, if the bubble movement is froze */
public boolean movementFroze; public boolean movementFroze;
private int backgroundMusic;
private int harpoonSound;
/** /**
* Create the manager handling the gameplay. * Create the manager handling the gameplay.
* *
@ -66,7 +63,7 @@ public class GamePlayManager {
* @param easyDifficulty the game difficulty * @param easyDifficulty the game difficulty
*/ */
private void initializeGame(boolean easyDifficulty){ private void initializeGame(boolean easyDifficulty){
//backgroundMusic = gameView.playSound("backgroundMusic.wav", true); gameView.playSound("backgroundMusic.wav", true);
gameObjectManager.clearAll(); gameObjectManager.clearAll();
levelManager = new LevelManager(easyDifficulty); levelManager = new LevelManager(easyDifficulty);
try { try {
@ -76,7 +73,6 @@ public class GamePlayManager {
System.exit(-1); System.exit(-1);
} }
player = new Player(level); player = new Player(level);
player.score = 1000000;
gameObjectManager.getPlayerObject().setGamePlayManager(this); gameObjectManager.getPlayerObject().setGamePlayManager(this);
} }
@ -99,12 +95,16 @@ public class GamePlayManager {
* Loose a life and remove all bubbles * Loose a life and remove all bubbles
*/ */
public void looseLife(){ public void looseLife(){
player.lives--; if(player.lives==0){
gameObjectManager.getLivesLabel().setLifeCount(player.lives); handleGameEnded("You lost the game.\nYour score: "+player.score);
gameObjectManager.getBubbles().clear(); }else {
specialBubblePresent = false; player.lives--;
spawnBubbles = true; gameObjectManager.getLivesLabel().setLifeCount(player.lives);
gameObjectManager.getGameOverlay().flashScreen(Color.red,100); gameObjectManager.getBubbles().clear();
specialBubblePresent = false;
spawnBubbles = true;
gameObjectManager.getGameOverlay().flashScreen(Color.red, 100);
}
} }
/** /**
@ -115,14 +115,23 @@ public class GamePlayManager {
level = levelManager.getNextLevel(); level = levelManager.getNextLevel();
initializeLevel(); initializeLevel();
} catch (LevelManager.NoMoreLevelsAvailableException e) { } catch (LevelManager.NoMoreLevelsAvailableException e) {
gameView.stopAllSounds(); handleGameEnded("You won the game.\nYour score: "+player.score);
gameView.showEndScreen("You won!");
boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
initializeGame(easyDifficulty);
initializeLevel();
} }
} }
/**
* End the game and show exit/restart screen.
*
* @param text text to display
*/
private void handleGameEnded(String text){
gameView.stopAllSounds();
gameView.showEndScreen(text);
boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
initializeGame(easyDifficulty);
initializeLevel();
}
/** /**
* Update all HUD elements * Update all HUD elements
*/ */

View File

@ -19,6 +19,8 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
"k kkk k\n"+ "k kkk k\n"+
"k kkk k\n"; "k kkk k\n";
private final String harpoonRope;
private int sound; private int sound;
/** /**
@ -35,14 +37,39 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
height = (int) (5 * size); height = (int) (5 * size);
rotation = 0; rotation = 0;
getPosition().setTo(300,300); getPosition().setTo(300,300);
this.hitBox.width = width; this.hitBox.width = width - 2;
this.hitBox.height = (int) (440 - position.y); this.hitBox.height = (int) (440 - position.y);
sound = gameView.playSound("harpoon.wav",true); sound = gameView.playSound("harpoon.wav",true);
harpoonRope = generateRope();
}
private String generateRope(){
int pre = 3;
int post = 3;
boolean right = true;
String rope = "";
for(int i=0;i<100;i++){
rope += " ".repeat(pre) + "k" + " ".repeat(post)+"\n";
if(right){
pre++;
post--;
}else{
pre--;
post++;
}
if(post==0 || pre==0){
right = !right;
}
}
return rope;
} }
@Override @Override
protected void updateHitBoxPosition() { protected void updateHitBoxPosition() {
hitBox.x = (int) (position.x); hitBox.x = (int) (position.x) + 1;
hitBox.y = (int) (position.y); hitBox.y = (int) (position.y);
hitBox.height = (int) (440 - position.y); hitBox.height = (int) (440 - position.y);
} }
@ -58,7 +85,7 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
@Override @Override
public void addToCanvas(){ public void addToCanvas(){
gameView.addBlockImageToCanvas(HARPOON, getPosition().x, getPosition().y,size, rotation); gameView.addBlockImageToCanvas(HARPOON, getPosition().x, getPosition().y,size, rotation);
gameView.addRectangleToCanvas(position.x + (width/2.0) - 2,position.y + height, 4,440 - position.y,1,true,Color.lightGray); gameView.addBlockImageToCanvas(harpoonRope, position.x + (width/2.0) - 7,position.y + height,2,0);
} }
/** /**

View File

@ -52,7 +52,6 @@ public class HexagonalBubble extends Bubble {
@Override @Override
public void addToCanvas() { public void addToCanvas() {
gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation); gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation);
gameView.addRectangleToCanvas(hitBox.x,hitBox.y,hitBox.width,hitBox.height,1,false, Color.GREEN);
} }
@Override @Override