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 */
public boolean movementFroze;
private int backgroundMusic;
private int harpoonSound;
/**
* Create the manager handling the gameplay.
*
@ -66,7 +63,7 @@ public class GamePlayManager {
* @param easyDifficulty the game difficulty
*/
private void initializeGame(boolean easyDifficulty){
//backgroundMusic = gameView.playSound("backgroundMusic.wav", true);
gameView.playSound("backgroundMusic.wav", true);
gameObjectManager.clearAll();
levelManager = new LevelManager(easyDifficulty);
try {
@ -76,7 +73,6 @@ public class GamePlayManager {
System.exit(-1);
}
player = new Player(level);
player.score = 1000000;
gameObjectManager.getPlayerObject().setGamePlayManager(this);
}
@ -99,12 +95,16 @@ public class GamePlayManager {
* Loose a life and remove all bubbles
*/
public void looseLife(){
if(player.lives==0){
handleGameEnded("You lost the game.\nYour score: "+player.score);
}else {
player.lives--;
gameObjectManager.getLivesLabel().setLifeCount(player.lives);
gameObjectManager.getBubbles().clear();
specialBubblePresent = false;
spawnBubbles = true;
gameObjectManager.getGameOverlay().flashScreen(Color.red,100);
gameObjectManager.getGameOverlay().flashScreen(Color.red, 100);
}
}
/**
@ -115,13 +115,22 @@ public class GamePlayManager {
level = levelManager.getNextLevel();
initializeLevel();
} catch (LevelManager.NoMoreLevelsAvailableException e) {
handleGameEnded("You won the game.\nYour score: "+player.score);
}
}
/**
* End the game and show exit/restart screen.
*
* @param text text to display
*/
private void handleGameEnded(String text){
gameView.stopAllSounds();
gameView.showEndScreen("You won!");
gameView.showEndScreen(text);
boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
initializeGame(easyDifficulty);
initializeLevel();
}
}
/**
* 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";
private final String harpoonRope;
private int sound;
/**
@ -35,14 +37,39 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
height = (int) (5 * size);
rotation = 0;
getPosition().setTo(300,300);
this.hitBox.width = width;
this.hitBox.width = width - 2;
this.hitBox.height = (int) (440 - position.y);
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
protected void updateHitBoxPosition() {
hitBox.x = (int) (position.x);
hitBox.x = (int) (position.x) + 1;
hitBox.y = (int) (position.y);
hitBox.height = (int) (440 - position.y);
}
@ -58,7 +85,7 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
@Override
public void addToCanvas(){
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
public void addToCanvas() {
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