Multiple fixes and HUD upgrade
This commit is contained in:
		
							parent
							
								
									06f99c1801
								
							
						
					
					
						commit
						5653c137f8
					
				@ -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(){
 | 
				
			||||||
 | 
					        if(player.lives==0){
 | 
				
			||||||
 | 
					            handleGameEnded("You lost the game.\nYour score: "+player.score);
 | 
				
			||||||
 | 
					        }else {
 | 
				
			||||||
            player.lives--;
 | 
					            player.lives--;
 | 
				
			||||||
            gameObjectManager.getLivesLabel().setLifeCount(player.lives);
 | 
					            gameObjectManager.getLivesLabel().setLifeCount(player.lives);
 | 
				
			||||||
            gameObjectManager.getBubbles().clear();
 | 
					            gameObjectManager.getBubbles().clear();
 | 
				
			||||||
            specialBubblePresent = false;
 | 
					            specialBubblePresent = false;
 | 
				
			||||||
            spawnBubbles = true;
 | 
					            spawnBubbles = true;
 | 
				
			||||||
        gameObjectManager.getGameOverlay().flashScreen(Color.red,100);
 | 
					            gameObjectManager.getGameOverlay().flashScreen(Color.red, 100);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -115,13 +115,22 @@ public class GamePlayManager {
 | 
				
			|||||||
            level = levelManager.getNextLevel();
 | 
					            level = levelManager.getNextLevel();
 | 
				
			||||||
            initializeLevel();
 | 
					            initializeLevel();
 | 
				
			||||||
        } catch (LevelManager.NoMoreLevelsAvailableException e) {
 | 
					        } 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.stopAllSounds();
 | 
				
			||||||
            gameView.showEndScreen("You won!");
 | 
					        gameView.showEndScreen(text);
 | 
				
			||||||
        boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
 | 
					        boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
 | 
				
			||||||
        initializeGame(easyDifficulty);
 | 
					        initializeGame(easyDifficulty);
 | 
				
			||||||
        initializeLevel();
 | 
					        initializeLevel();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Update all HUD elements
 | 
					     * Update all HUD elements
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user