Added sounds and backgrounds

This commit is contained in:
Andreas Greiner 2021-06-25 21:29:48 +02:00
parent 3d389fd180
commit 64b8d620e4
50 changed files with 81 additions and 6 deletions

View File

@ -152,4 +152,13 @@ class GameObjectManager {
public GameOverlay getGameOverlay(){ public GameOverlay getGameOverlay(){
return gameOverlay; return gameOverlay;
} }
/**
* Get the background object.
*
* @return the background object
*/
public Background getBackground() {
return background;
}
} }

View File

@ -41,6 +41,9 @@ 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.
* *
@ -63,6 +66,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);
gameObjectManager.clearAll(); gameObjectManager.clearAll();
levelManager = new LevelManager(easyDifficulty); levelManager = new LevelManager(easyDifficulty);
try { try {
@ -86,6 +90,8 @@ public class GamePlayManager {
movementFroze = false; movementFroze = false;
// Update HUD // Update HUD
updateHUD(); updateHUD();
// Update background
gameObjectManager.getBackground().setBackgroundImage(level.backgroundImage);
} }
/** /**
@ -108,6 +114,7 @@ public class GamePlayManager {
level = levelManager.getNextLevel(); level = levelManager.getNextLevel();
initializeLevel(); initializeLevel();
} catch (LevelManager.NoMoreLevelsAvailableException e) { } catch (LevelManager.NoMoreLevelsAvailableException e) {
gameView.stopAllSounds();
gameView.showEndScreen("You won!"); gameView.showEndScreen("You won!");
boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game"); boolean easyDifficulty = gameView.showSimpleStartScreen("Super Pang World","Start the game");
initializeGame(easyDifficulty); initializeGame(easyDifficulty);
@ -171,6 +178,7 @@ public class GamePlayManager {
*/ */
public void freezeMovement(int freezeTime){ public void freezeMovement(int freezeTime){
movementFroze = true; movementFroze = true;
gameView.playSound("freeze.wav",false);
gameView.setTimer("MovementFroze","GamePlayManager",freezeTime); gameView.setTimer("MovementFroze","GamePlayManager",freezeTime);
} }
@ -180,6 +188,7 @@ public class GamePlayManager {
* @param harpoon the harpoon to remove * @param harpoon the harpoon to remove
*/ */
public void destroy(Harpoon harpoon){ public void destroy(Harpoon harpoon){
harpoon.stopSound();
gameObjectManager.getHarpoons().remove(harpoon); gameObjectManager.getHarpoons().remove(harpoon);
} }

View File

@ -2,7 +2,10 @@ package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.graphics.helper.Level; import de.thdeg.greiner.superpangworld.graphics.helper.Level;
import java.sql.Array;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue; import java.util.Queue;
/** /**
@ -10,9 +13,13 @@ import java.util.Queue;
*/ */
public class LevelManager { public class LevelManager {
private static final int BACKGROUND_IMAGE_COUNT = 9;
/** The queue to store the generated levels */ /** The queue to store the generated levels */
private final Queue<Level> levels; private final Queue<Level> levels;
private List<String> backgroundImages;
/** /**
* Create a level manager. * Create a level manager.
* *
@ -20,6 +27,7 @@ public class LevelManager {
*/ */
public LevelManager(boolean easyDifficulty){ public LevelManager(boolean easyDifficulty){
levels = new ArrayDeque<>(); levels = new ArrayDeque<>();
backgroundImages = loadBackgroundImages();
generateLevels(easyDifficulty); generateLevels(easyDifficulty);
} }
@ -44,13 +52,28 @@ public class LevelManager {
*/ */
private void generateLevels(boolean easyDifficulty){ private void generateLevels(boolean easyDifficulty){
int overallScoreNeeded = 0; int overallScoreNeeded = 0;
for(int i=0;i<3;i++){ int imageIndex = 0;
for(int i=0;i<99;i++){
int scoreNeeded = easyDifficulty ? 1000 + (100*i) : 10000 + (1000*i); int scoreNeeded = easyDifficulty ? 1000 + (100*i) : 10000 + (1000*i);
overallScoreNeeded += scoreNeeded; overallScoreNeeded += scoreNeeded;
levels.add(new Level(i+1, scoreNeeded,overallScoreNeeded)); levels.add(new Level(i+1, scoreNeeded,overallScoreNeeded,backgroundImages.get(imageIndex)));
if((i+1)%4==0){
imageIndex++;
if(imageIndex==BACKGROUND_IMAGE_COUNT){
imageIndex = 0;
}
}
} }
} }
private List<String> loadBackgroundImages(){
List<String> images = new ArrayList<>();
for(int i=1;i<=BACKGROUND_IMAGE_COUNT;i++){
images.add("backgrounds/background_"+i+".png");
}
return images;
}
/** /**
* The exception in case no next level is remaining. * The exception in case no next level is remaining.
*/ */

View File

@ -111,20 +111,27 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb
if((newLocation.getX() >= GameView.WIDTH - width - HelperValues.FRAME_BORDER_WIDTH) || newLocation.getX() <= HelperValues.FRAME_BORDER_WIDTH){ if((newLocation.getX() >= GameView.WIDTH - width - HelperValues.FRAME_BORDER_WIDTH) || newLocation.getX() <= HelperValues.FRAME_BORDER_WIDTH){
velocity = new Point2D.Double(velocity.getX() * -1.0, velocity.getY()); velocity = new Point2D.Double(velocity.getX() * -1.0, velocity.getY());
if(this instanceof SpecialBubble){ if(this instanceof SpecialBubble){
SpecialBubble specialBubble = (SpecialBubble) this; switchSpecialBubbleState((SpecialBubble) this);
specialBubble.freezeState = !specialBubble.freezeState;
} }
} }
// Floor bounce // Floor bounce
if(newLocation.getY() >= HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width){ if(newLocation.getY() >= HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width){
velocity = new Point2D.Double(velocity.getX(), velocity.getY() * -0.95); velocity = new Point2D.Double(velocity.getX(), velocity.getY() * -0.95);
newLocation = new Point2D.Double(newLocation.getX(), HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width); newLocation = new Point2D.Double(newLocation.getX(), HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width);
if(this instanceof SpecialBubble){
switchSpecialBubbleState((SpecialBubble) this);
}
} }
position.setTo(newLocation.getX(), newLocation.getY()); position.setTo(newLocation.getX(), newLocation.getY());
} }
} }
private void switchSpecialBubbleState(SpecialBubble specialBubble){
specialBubble.freezeState = !specialBubble.freezeState;
gameView.playSound("specialBounce.wav",false);
}
/** /**
* Get the score to add when bursting the bubble. * Get the score to add when bursting the bubble.
* *

View File

@ -12,6 +12,8 @@ public class Level {
/** The overall needed score to surpass this level */ /** The overall needed score to surpass this level */
public int neededOverallScore; public int neededOverallScore;
public String backgroundImage;
/** /**
* Create a level with a number, a needed score to surpass the level and a needed overall score to surpass the level. * Create a level with a number, a needed score to surpass the level and a needed overall score to surpass the level.
* *
@ -19,9 +21,10 @@ public class Level {
* @param neededLevelScore the needed score to surpass this level * @param neededLevelScore the needed score to surpass this level
* @param neededOverallScore the overall needed score to surpass this level * @param neededOverallScore the overall needed score to surpass this level
*/ */
public Level(int number, int neededLevelScore, int neededOverallScore){ public Level(int number, int neededLevelScore, int neededOverallScore, String backgroundImage){
this.number = number; this.number = number;
this.neededLevelScore = neededLevelScore; this.neededLevelScore = neededLevelScore;
this.neededOverallScore = neededOverallScore; this.neededOverallScore = neededOverallScore;
this.backgroundImage = backgroundImage;
} }
} }

View File

@ -8,6 +8,8 @@ import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
*/ */
public class Background extends GameObject { public class Background extends GameObject {
private String backgroundImage;
/** /**
* Create a background object. * Create a background object.
* *
@ -18,11 +20,24 @@ public class Background extends GameObject {
this.position.setTo(0,0); this.position.setTo(0,0);
size = 1; size = 1;
rotation = 0; rotation = 0;
backgroundImage = "backgrounds/background_1.png";
} }
@Override @Override
public void addToCanvas() { public void addToCanvas() {
gameView.addImageToCanvas("background.png",position.x,position.y,size,rotation); gameView.addImageToCanvas(backgroundImage,position.x,position.y,size,rotation);
}
/**
* Set the background image. If it differs from the previous one a sound is played.
*
* @param backgroundImage the background image
*/
public void setBackgroundImage(String backgroundImage){
if(!this.backgroundImage.equals(backgroundImage)){
this.backgroundImage = backgroundImage;
gameView.playSound("levelSwitch.wav",false);
}
} }
@Override @Override

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 int sound;
/** /**
* Create a harpoon with default values. * Create a harpoon with default values.
* *
@ -35,6 +37,7 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
getPosition().setTo(300,300); getPosition().setTo(300,300);
this.hitBox.width = width; this.hitBox.width = width;
this.hitBox.height = (int) (440 - position.y); this.hitBox.height = (int) (440 - position.y);
sound = gameView.playSound("harpoon.wav",true);
} }
@Override @Override
@ -76,4 +79,8 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
@Override @Override
public void updateStatus() { public void updateStatus() {
} }
public void stopSound(){
gameView.stopSound(sound);
}
} }

View File

@ -68,6 +68,7 @@ public class HexagonalBubble extends Bubble {
@Override @Override
public void destroy() { public void destroy() {
gameView.playSound("burst.wav",false);
if (size > 0.125) { if (size > 0.125) {
Position positionLeft = new Position(position.x - (width/2.0/2.0), position.y); Position positionLeft = new Position(position.x - (width/2.0/2.0), position.y);
Position positionRight = new Position(position.x + width - (width/2.0/2.0), position.y); Position positionRight = new Position(position.x + width - (width/2.0/2.0), position.y);

View File

@ -87,6 +87,7 @@ public class RoundBubble extends Bubble {
@Override @Override
public void destroy() { public void destroy() {
gameView.playSound("burst.wav",false);
if (size > 1.25) { if (size > 1.25) {
Position positionLeft = new Position(position.x - (width/2.0/2.0), position.y); Position positionLeft = new Position(position.x - (width/2.0/2.0), position.y);
Position positionRight = new Position(position.x + width - (width/2.0/2.0), position.y); Position positionRight = new Position(position.x + width - (width/2.0/2.0), position.y);

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.