diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.java index 8cb87d3..9650cbf 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.java @@ -18,7 +18,7 @@ public class GameLoopManager { this.gameView.setStatusText("Andreas Greiner - Java Programmierung SS 2021"); this.gameView.setWindowIcon("Target.png"); this.gameObjectManager = new GameObjectManager(gameView); - this.inputManager = new InputManager(gameView, gameObjectManager.getPlayer()); + this.inputManager = new InputManager(gameView, gameObjectManager.getPlayerObject()); this.gamePlayManager = new GamePlayManager(gameView, gameObjectManager); } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.java index 4cc6338..2b4ef85 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.java @@ -3,7 +3,6 @@ package de.thdeg.greiner.superpangworld.game.managers; import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.graphics.base.Bubble; import de.thdeg.greiner.superpangworld.graphics.base.GameObject; -import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject; import de.thdeg.greiner.superpangworld.graphics.immovable.*; import de.thdeg.greiner.superpangworld.graphics.moveable.*; @@ -15,7 +14,6 @@ import java.util.LinkedList; */ class GameObjectManager { - /** The GameView to display the objects */ private GameView gameView; private LinkedList bubbles; @@ -24,9 +22,9 @@ class GameObjectManager { private LevelProgressBar levelProgressBar; private LevelLabel levelLabel; private ScoreLabel scoreLabel; - private LivesIcon livesIcon; + private LivesLabel livesLabel; private Background background; - private Player player; + private PlayerObject playerObject; private RandomBall randomBall; private FollowerBall followerBall; @@ -48,10 +46,10 @@ class GameObjectManager { this.levelProgressBar = new LevelProgressBar(gameView); this.levelLabel = new LevelLabel(gameView); this.scoreLabel = new ScoreLabel(gameView); - this.livesIcon = new LivesIcon(gameView); + this.livesLabel = new LivesLabel(gameView); this.background = new Background(gameView); - this.player = new Player(gameView); + this.playerObject = new PlayerObject(gameView); this.randomBall = new RandomBall(gameView); this.followerBall = new FollowerBall(gameView, randomBall); @@ -68,11 +66,10 @@ class GameObjectManager { gameObjects.add(levelProgressBar); gameObjects.add(levelLabel); gameObjects.add(scoreLabel); - gameObjects.add(livesIcon); - gameObjects.add(player); + gameObjects.add(livesLabel); + gameObjects.add(playerObject); gameObjects.add(randomBall); - gameObjects.add(followerBall); - + //gameObjects.add(followerBall); gameObjects.forEach(gameObject ->{ gameObject.update(); @@ -84,8 +81,8 @@ class GameObjectManager { * Get the player object. * @return the player */ - public Player getPlayer(){ - return player; + public PlayerObject getPlayerObject(){ + return playerObject; } /** @@ -96,6 +93,38 @@ class GameObjectManager { return bubbles; } + /** + * Get the level label. + * @return the level label + */ + public LevelLabel getLevelLabel(){ + return this.levelLabel; + } + + /** + * Get the lives label. + * @return the lives label + */ + public LivesLabel getLivesLabel() { + return livesLabel; + } + + /** + * Get the score label. + * @return the score label + */ + public ScoreLabel getScoreLabel() { + return scoreLabel; + } + + /** + * Get the level progress bar. + * @return the level progress bar + */ + public LevelProgressBar getLevelProgressBar(){ + return levelProgressBar; + } + /** * Get the harpoons. * @return the harpoons @@ -114,7 +143,7 @@ class GameObjectManager { for (GameObject gameObject : gameObjects) { if (gameObject.getClass() != LevelLabel.class && gameObject.getClass() != LevelProgressBar.class - && gameObject.getClass() != LivesIcon.class + && gameObject.getClass() != LivesLabel.class && gameObject.getClass() != ScoreLabel.class){ gameObject.adaptPosition(adaptX, adaptY); } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java index 9d5f8f2..241f39f 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java @@ -4,6 +4,8 @@ import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.graphics.base.Bubble; import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject; import de.thdeg.greiner.superpangworld.graphics.base.Position; +import de.thdeg.greiner.superpangworld.graphics.helper.Level; +import de.thdeg.greiner.superpangworld.graphics.helper.Player; import de.thdeg.greiner.superpangworld.graphics.moveable.Harpoon; import de.thdeg.greiner.superpangworld.graphics.moveable.HexagonalBubble; import de.thdeg.greiner.superpangworld.graphics.moveable.RoundBubble; @@ -11,7 +13,6 @@ import de.thdeg.greiner.superpangworld.graphics.moveable.SpecialBubble; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Random; /** @@ -27,6 +28,10 @@ public class GamePlayManager { private boolean listHasBeenDeleted; /** Generator for random values */ private Random random; + /** Das erste Level */ + private Level level; + /** Der Spieler */ + private Player player; /** * Create the manager handling the gameplay. @@ -37,61 +42,26 @@ public class GamePlayManager { listHasBeenDeleted = false; this.gameView = gameView; this.gameObjectManager = gameObjectManager; + this.level = new Level(1,10000,10000); + player = new Player(this.level); this.random = new Random(); - gameObjectManager.getPlayer().setGamePlayManager(this); + gameObjectManager.getPlayerObject().setGamePlayManager(this); + gameObjectManager.getLevelLabel().setLevel(level.number); + gameObjectManager.getLivesLabel().setLifeCount(player.lives); + gameObjectManager.getScoreLabel().setScore(player.score); } /** * Handle the gameplay. */ public void updateGamePlay(){ - spawnAndDestroyBubbles(); - } - - /** - * Spawn and destory bubbles. - */ - private void spawnAndDestroyBubbles(){ - // Spawn a bubble every second if(gameView.timerExpired("SpawnBubble","GamePlayManager")){ - addRandomBubble(); - gameView.setTimer("SpawnBubble","GamePlayManager",1000); - } - // Remove a bubble every 5 seconds - if(!gameObjectManager.getBubbles().isEmpty() && gameView.timerExpired("DestroyBubble","GamePlayManager")){ - gameObjectManager.getBubbles().remove(random.nextInt(gameObjectManager.getBubbles().size())); - gameView.setTimer("DestroyBubble","GamePlayManager",5000); - } - // Delete all bubbles after 10 seconds of playing - if(!listHasBeenDeleted && gameView.getGameTimeInMilliseconds()>=10000){ - gameObjectManager.getBubbles().clear(); - listHasBeenDeleted = true; - } - - - } - - /** - * Adds a random bubble to the game. Percentages: - * - 60% normal bubble - * - 30% hexagonal bubble - * - 10% special bubble - */ - private void addRandomBubble(){ - int randomNumber = random.nextInt(100); - if(randomNumber<60){ - RoundBubble roundBubble = new RoundBubble(gameView, new ArrayList<>(Arrays.asList(gameObjectManager.getPlayer()))); + RoundBubble roundBubble = new RoundBubble(gameView, new ArrayList<>(Arrays.asList(gameObjectManager.getPlayerObject()))); roundBubble.setGamePlayManager(this); gameObjectManager.getBubbles().add(roundBubble); - }else if(randomNumber<90){ - HexagonalBubble hexagonalBubble = new HexagonalBubble(gameView, new ArrayList<>(Arrays.asList(gameObjectManager.getPlayer()))); - hexagonalBubble.setGamePlayManager(this); - gameObjectManager.getBubbles().add(hexagonalBubble); - }else{ - SpecialBubble specialBubble = new SpecialBubble(gameView, new ArrayList<>(Arrays.asList(gameObjectManager.getPlayer()))); - specialBubble.setGamePlayManager(this); - gameObjectManager.getBubbles().add(specialBubble); + gameView.setTimer("SpawnBubble","GamePlayManager",3000); } + } /** @@ -122,7 +92,71 @@ public class GamePlayManager { * @param bubble the bubble to remove */ public void destroy(Bubble bubble){ - gameObjectManager.getBubbles().remove(bubble); + if(gameObjectManager.getBubbles().contains(bubble)) { + if (bubble.getSize() > 1.25) { + addRandomBubble(bubble.getSize() / 2, bubble.getSpeedInPixel(), bubble.getPosition(), false); + addRandomBubble(bubble.getSize() / 2, bubble.getSpeedInPixel(), bubble.getPosition(), false); + } + + gameObjectManager.getBubbles().remove(bubble); + player.score += bubble.getBurstScore(); + updateHud(); + if(player.score>=level.neededOverallScore){ + switchLevel(); + } + } } + private void updateHud(){ + gameObjectManager.getScoreLabel().setScore(player.score); + double progress = (player.score- level.neededOverallScore+ level.neededLevelScore * 1.0) / level.neededLevelScore; + System.out.println(progress); + gameObjectManager.getLevelProgressBar().setLevelProgress(Math.min((int)(progress*100),100)); + gameObjectManager.getLevelLabel().setLevel(level.number); + } + + private void switchLevel(){ + if(level.number==99){ + System.out.println("You won!"); + }else{ + Level newLevel = new Level(level.number+1,10000,(level.number+1)*10000); + level = newLevel; + updateHud(); + } + } + + /** + * Add a random bubble with given values to the game. Percentages: + * - 60% normal bubble + * - 30% hexagonal bubble + * - 10% special bubble + */ + private void addRandomBubble(double size, double speedInPixel, Position position, boolean spawning){ + int randomNumber = random.nextInt(59); + ArrayList collidableGameObjects = new ArrayList<>(); + collidableGameObjects.add(gameObjectManager.getPlayerObject()); + collidableGameObjects.addAll(gameObjectManager.getHarpoons()); + if(randomNumber<60){ + RoundBubble roundBubble = new RoundBubble(gameView, collidableGameObjects,size,speedInPixel,position,spawning); + roundBubble.setGamePlayManager(this); + gameObjectManager.getBubbles().add(roundBubble); + }else if(randomNumber<90){ + HexagonalBubble hexagonalBubble = new HexagonalBubble(gameView, collidableGameObjects); + hexagonalBubble.setGamePlayManager(this); + gameObjectManager.getBubbles().add(hexagonalBubble); + }else{ + SpecialBubble specialBubble = new SpecialBubble(gameView, collidableGameObjects); + specialBubble.setGamePlayManager(this); + gameObjectManager.getBubbles().add(specialBubble); + } + } + + /** + * Loose a life and remove all bubbles + */ + public void looseLife(){ + player.lives--; + gameObjectManager.getLivesLabel().setLifeCount(player.lives); + gameObjectManager.getBubbles().clear(); + } } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/InputManager.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/InputManager.java index 21c7eaa..70b188c 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/InputManager.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/InputManager.java @@ -1,7 +1,7 @@ package de.thdeg.greiner.superpangworld.game.managers; import de.thdeg.greiner.superpangworld.gameview.GameView; -import de.thdeg.greiner.superpangworld.graphics.moveable.Player; +import de.thdeg.greiner.superpangworld.graphics.moveable.PlayerObject; import java.awt.event.KeyEvent; import java.util.Arrays; @@ -14,18 +14,18 @@ class InputManager { /** The gameView, which displays the player object */ private GameView gameView; /** The player object */ - private Player player; + private PlayerObject playerObject; /** Flag, if diagonal movement is allowed */ private static final boolean DIAGONAL_MOVEMENT_ALLOWED = false; /** * Create a manager handling the user input * @param gameView the GameView - * @param player the player object + * @param playerObject the player object */ - public InputManager(GameView gameView, Player player){ + public InputManager(GameView gameView, PlayerObject playerObject){ this.gameView = gameView; - this.player = player; + this.playerObject = playerObject; } /** @@ -34,15 +34,15 @@ class InputManager { public void updateUserInputs() { Integer[] gedruekteTasten = gameView.getKeyCodesOfCurrentlyPressedKeys(); if(Arrays.stream(gedruekteTasten).anyMatch(k -> k == KeyEvent.VK_SPACE)){ - player.shoot(); + playerObject.shoot(); } for (int keyCode : gedruekteTasten) { switch(keyCode) { case KeyEvent.VK_LEFT: - player.left(); + playerObject.left(); break; case KeyEvent.VK_RIGHT: - player.right(); + playerObject.right(); break; default: continue; diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Bubble.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Bubble.java index 364cff6..4633833 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Bubble.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Bubble.java @@ -1,9 +1,10 @@ package de.thdeg.greiner.superpangworld.graphics.base; import de.thdeg.greiner.superpangworld.gameview.GameView; -import de.thdeg.greiner.superpangworld.graphics.moveable.Player; +import de.thdeg.greiner.superpangworld.graphics.moveable.Harpoon; +import de.thdeg.greiner.superpangworld.graphics.moveable.PlayerObject; -import java.util.ArrayList; +import java.util.*; /** * A Bubble, which moves around on the screen and can be shot by the player. @@ -12,6 +13,16 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb /** Flag, if the bubble flies from left to right */ private boolean flyFromLeftToRight; + /** Random generator */ + private Random random; + /** Flag, if the bubble is in the spawning phase */ + private boolean spawning; + /** Spawning speed */ + private int spawnSpeed; + /** Unique id for the spawn event timer */ + private long spawnID; + /** Temporary movement action */ + private Position nextPosition; /** * Create a bubble with default values. @@ -22,11 +33,49 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb public Bubble(GameView gameView, ArrayList objectsToCollideWith){ super(gameView,objectsToCollideWith); rotation = 90; - size = 5; + size = 10; width = (int) (12 * size); height = (int) (12 * size); - speedInPixel = 5; + speedInPixel = 1; flyFromLeftToRight = true; + + spawnID = UUID.randomUUID().getLeastSignificantBits(); + random = new Random(); + position.setTo(random.nextInt(GameView.WIDTH-width),-width); + spawning = true; + spawnSpeed = 500; + gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); + + nextPosition = new Position(random.nextInt(GameView.WIDTH-width),random.nextInt(GameView.HEIGHT-width)); + } + + /** + * Create a bubble. + * @param gameView the {@link GameView} to display the bubble + * @param objectsToCollideWith the list of {@link CollidableGameObject} the bubble can collide with + * @param size the object size + * @param speedInPixel the speed in pixel per tick + * @param position the position + * @param spawning flag, if the bubble is in the spawning phase + */ + public Bubble(GameView gameView, ArrayList objectsToCollideWith, double size, double speedInPixel, Position position, boolean spawning){ + super(gameView,objectsToCollideWith); + rotation = 90; + this.size = size; + width = (int) (12 * size); + height = (int) (12 * size); + this.speedInPixel = speedInPixel; + flyFromLeftToRight = true; + this.position.setTo(position.x,position.y); + spawnID = UUID.randomUUID().getLeastSignificantBits(); + random = new Random(); + this.spawning = spawning; + if(spawning){ + spawnSpeed = 500; + gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); + } + + nextPosition = new Position(random.nextInt(GameView.WIDTH-width),random.nextInt(GameView.HEIGHT-width)); } /** @@ -34,32 +83,59 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb */ @Override public void updatePosition(){ - if(flyFromLeftToRight && getPosition().x + (width*size) >= GameView.WIDTH){ - flyFromLeftToRight = false; - }else if (!flyFromLeftToRight && getPosition().x <= 0){ - flyFromLeftToRight = true; - } - if(flyFromLeftToRight){ - getPosition().right(1); + if(spawning){ + if(position.y >= 0){ + spawning = false; + } else if(gameView.timerExpired("spawn"+spawnID,"bubble"+spawnID)){ + position.down(width/4); + gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); + } }else{ - getPosition().left(1); + double distance = position.distance(nextPosition); + if (distance >= speedInPixel) { + position.right((nextPosition.x - position.x) / distance * speedInPixel); + position.down((nextPosition.y - position.y) / distance * speedInPixel); + } else { + nextPosition = new Position(random.nextInt(GameView.WIDTH-width),random.nextInt(GameView.HEIGHT-width)); + } } + + } /** - * Pop the bubble. + * Get the score to add when bursting the bubble. + * + * @return the score to add */ - private void popBubble(){} + public int getBurstScore(){ + return (int)(size*100); + } /** - * Freezes the time. + * Get the size of the bubble. + * + * @return the size */ - private void freezeTime(){} + public double getSize(){ + return this.size; + } + + /** + * Get the speed in pixel per tick + * @return the speed in pixel per tick + */ + public double getSpeedInPixel(){ + return speedInPixel; + } @Override public void reactToCollision(CollidableGameObject otherObject) { - if(otherObject instanceof Player){ - System.out.println("You died!"); + if(otherObject instanceof PlayerObject){ + gamePlayManager.looseLife(); + }else if(otherObject instanceof Harpoon){ + gamePlayManager.destroy((Harpoon) otherObject); + gamePlayManager.destroy(this); } } } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.java index 9aab45f..3d40629 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.java @@ -1,5 +1,8 @@ package de.thdeg.greiner.superpangworld.graphics.base; +import de.thdeg.greiner.superpangworld.gameview.GameView; +import de.thdeg.greiner.superpangworld.graphics.helper.XAxisComparator; + import java.util.*; /** @@ -22,9 +25,35 @@ public class MovementPatterns { new Position(930,510),new Position(30,510)))); ArrayList zigZag = new ArrayList<>((Arrays.asList( new Position(300,200),new Position(400,340),new Position(500,200), new Position(600,340),new Position(700,200),new Position(800,340)))); + ArrayList zero = new ArrayList<>(); + zero.addAll(square); + zero.addAll(zigZag); + zero.sort(Comparator.naturalOrder()); + ArrayList xFirst = new ArrayList<>(zero); + xFirst.sort(new XAxisComparator()); + + Comparator yAxisComparator = new Comparator() { + @Override + public int compare(Position o1, Position o2) { + return Double.compare(o1.y,o2.y); + } + }; + ArrayList yFirst = new ArrayList<>(zero); + yFirst.sort(yAxisComparator); + + + ArrayList centered = new ArrayList<>(zero); + centered.sort((p1,p2)->{ + Position pMid = new Position(GameView.WIDTH/2,GameView.HEIGHT/2); + return Double.compare(p1.distance(pMid),p2.distance(pMid)); + }); patterns.put("square",square); patterns.put("zigzag",zigZag); + patterns.put("zero",zero); + patterns.put("XFirst",xFirst); + patterns.put("YFirst",yFirst); + patterns.put("Centered",centered); } /** diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Position.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Position.java index 0beea02..fe061a3 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Position.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/base/Position.java @@ -5,7 +5,7 @@ import java.util.Objects; /** * Die Position eines Objekts auf einem Fenster anhand zweidimensionaler Koordinaten. */ -public class Position implements Cloneable{ +public class Position implements Cloneable, Comparable{ /** Die x-Koordinate */ public double x; @@ -137,4 +137,10 @@ public class Position implements Cloneable{ public int hashCode() { return Objects.hash(x, y); } + + @Override + public int compareTo(Position o) { + Position p0 = new Position(0,0); + return (int)Math.signum(this.distance(p0)-o.distance(p0)); + } } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Level.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Level.java new file mode 100644 index 0000000..967b63c --- /dev/null +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Level.java @@ -0,0 +1,27 @@ +package de.thdeg.greiner.superpangworld.graphics.helper; + +/** + * A Level representing a level in the game. + */ +public class Level { + + /** The number of the level */ + public int number; + /** The needed score to surpass this level */ + public int neededLevelScore; + /** The overall needed score to surpass this level */ + public int neededOverallScore; + + /** + * Create a level with a number, a needed score to surpass the level and a needed overall score to surpass the level. + * + * @param number the level number + * @param neededLevelScore the needed score to surpass this level + * @param neededOverallScore the overall needed score to surpass this level + */ + public Level(int number, int neededLevelScore, int neededOverallScore){ + this.number = number; + this.neededLevelScore = neededLevelScore; + this.neededOverallScore = neededOverallScore; + } +} diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Player.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Player.java new file mode 100644 index 0000000..7328103 --- /dev/null +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/Player.java @@ -0,0 +1,26 @@ +package de.thdeg.greiner.superpangworld.graphics.helper; + +/** + * A player representing the main player in the game. + */ +public class Player { + + /** The max amount of lives a single player has */ + private static final int MAX_LIVES = 3; + /** The current amount of lives the player has */ + public int lives; + /** The current score the player has */ + public int score; + /** The current level the play is on */ + public Level level; + + /** + * Create a player. + * @param level the level the player is on + */ + public Player(Level level){ + lives = MAX_LIVES; + score = 0; + } + +} diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.java new file mode 100644 index 0000000..adf2cb0 --- /dev/null +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.java @@ -0,0 +1,17 @@ +package de.thdeg.greiner.superpangworld.graphics.helper; + +import de.thdeg.greiner.superpangworld.graphics.base.Position; + +import java.util.Comparator; + +/** + * Compare two Positions regarding their x values + */ +public class XAxisComparator implements Comparator { + + @Override + public int compare(Position o1, Position o2) { + return (int)Math.signum(o1.x-o2.x); + } + +} diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.java index 1e46d39..15650ba 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.java @@ -22,7 +22,7 @@ public class LevelLabel extends GameObject { size = 3; width = 101; height = 8; - level = 8; + level = 1; getPosition().setTo(GameView.WIDTH/2 - (width/2),GameView.HEIGHT-height-60); } @@ -34,6 +34,14 @@ public class LevelLabel extends GameObject { gameView.addTextToCanvas("Level "+level,getPosition().x,getPosition().y,40,Color.YELLOW,0); } + /** + * Set the current level number + * @param level the level number + */ + public void setLevel(int level) { + this.level = level; + } + @Override public void updateStatus() { diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.java index 0b4edc9..0d47cfd 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.java @@ -22,7 +22,7 @@ public class LevelProgressBar extends GameObject { size = 3; width = 101; height = 8; - levelProgress = 30; + levelProgress = 0; getPosition().setTo(GameView.WIDTH/2 - (width/2),GameView.HEIGHT-(height*size)); } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.java similarity index 59% rename from SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.java rename to SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.java index a3b176e..d9ad24b 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.java @@ -4,9 +4,9 @@ import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.graphics.base.GameObject; /** - * The icon to display the remaining lives. + * The label to display the remaining lives. */ -public class LivesIcon extends GameObject { +public class LivesLabel extends GameObject { private final static String ICON = " RR RR \n"+ @@ -19,24 +19,38 @@ public class LivesIcon extends GameObject { " RRR \n"+ " R \n"; + private int lifeCount; + /** - * Create lives icon. + * Create lives label. * * @param gameView the gameView */ - public LivesIcon(GameView gameView) { + public LivesLabel(GameView gameView) { super(gameView); rotation = 0; size = 5; width = 12; height = 12; - position.setTo(50,GameView.HEIGHT-50); + this.lifeCount = 0; + + position.setTo(0,GameView.HEIGHT-50); } @Override public void addToCanvas() { - gameView.addBlockImageToCanvas(ICON,position.x,position.y,size,rotation); + for(int i=0;i objectsToCollideWith) { super(gameView,objectsToCollideWith); - Random rand = new Random(); - position.setTo(rand.nextInt(GameView.WIDTH/2),rand.nextInt(GameView.HEIGHT/2)); - size=0.6; speedInPixel = 2; diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Player.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.java similarity index 89% rename from SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Player.java rename to SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.java index fa874a0..e16d699 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Player.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.java @@ -2,8 +2,6 @@ package de.thdeg.greiner.superpangworld.graphics.moveable; import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject; -import de.thdeg.greiner.superpangworld.graphics.base.GameObject; -import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject; import java.awt.*; import java.util.Objects; @@ -11,7 +9,7 @@ import java.util.Objects; /** * The game character controlled by the player. */ -public class Player extends CollidableGameObject { +public class PlayerObject extends CollidableGameObject { /** Flag, if the player is shooting */ private boolean shooting; @@ -41,7 +39,7 @@ public class Player extends CollidableGameObject { * Create the game character with default values * @param gameView the {@link GameView} to display the character */ - public Player(GameView gameView){ + public PlayerObject(GameView gameView){ super(gameView); position.setTo(GameView.WIDTH/2, GameView.HEIGHT/1.5); shooting = false; @@ -103,8 +101,8 @@ public class Player extends CollidableGameObject { } @Override - public Player clone() { - return (Player) super.clone(); + public PlayerObject clone() { + return (PlayerObject) super.clone(); } @Override @@ -112,8 +110,8 @@ public class Player extends CollidableGameObject { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - Player player = (Player) o; - return shooting == player.shooting; + PlayerObject playerObject = (PlayerObject) o; + return shooting == playerObject.shooting; } @Override diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.java index a5bbe2e..2763dd1 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.java @@ -32,7 +32,7 @@ public class RandomBall extends GameObject implements MovingGameObject { movementPatterns = new MovementPatterns(); - movementPattern = movementPatterns.getRandomPattern(); + movementPattern = movementPatterns.getPattern("Centered"); movementPatternIndex = 0; targetPosition = movementPattern.get(0); } @@ -47,7 +47,7 @@ public class RandomBall extends GameObject implements MovingGameObject { if(movementPatternIndex < movementPattern.size()-1){ movementPatternIndex++; }else{ - movementPattern = movementPatterns.getRandomPattern(); + movementPattern = movementPatterns.getPattern("Centered"); movementPatternIndex = 0; } targetPosition = movementPattern.get(movementPatternIndex); diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.java index 1cff0f7..3df5c76 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.java @@ -3,6 +3,7 @@ package de.thdeg.greiner.superpangworld.graphics.moveable; import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.graphics.base.Bubble; import de.thdeg.greiner.superpangworld.graphics.base.CollidableGameObject; +import de.thdeg.greiner.superpangworld.graphics.base.Position; import java.awt.*; import java.util.ArrayList; @@ -37,18 +38,30 @@ public class RoundBubble extends Bubble { */ public RoundBubble(GameView gameView, ArrayList objectsToCollideWith) { super(gameView,objectsToCollideWith); - - Random rand = new Random(); - position.setTo(rand.nextInt(GameView.WIDTH),rand.nextInt(GameView.HEIGHT)); - this.hitBox.width = width-20; this.hitBox.height = height-20; } + /** + * Create a round bubble with set values. + * + * @param gameView the {@link GameView} to display the bubble + * @param objectsToCollideWith the list of {@link CollidableGameObject} the bubble can collide with + * @param size the object size + * @param speedInPixel the speed in Pixel per tick + * @param position the Position + * @param spawning flag, if the bubble is spawning or not + */ + public RoundBubble(GameView gameView, ArrayList objectsToCollideWith, double size, double speedInPixel, Position position, boolean spawning){ + super(gameView, objectsToCollideWith, size, speedInPixel, position, spawning); + this.hitBox.width = (int) (width*0.8); + this.hitBox.height = (int) (height*0.8); + } + @Override protected void updateHitBoxPosition() { - hitBox.x = (int) (position.x+10); - hitBox.y = (int) (position.y+10); + hitBox.x = (int) (position.x + (width*0.1)); + hitBox.y = (int) (position.y + (width*0.1)); } /** diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.java index 57e726d..28dc425 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.java @@ -39,9 +39,6 @@ public class SpecialBubble extends Bubble { public SpecialBubble(GameView gameView, ArrayList objectsToCollideWith) { super(gameView,objectsToCollideWith); - Random rand = new Random(); - position.setTo(rand.nextInt(GameView.WIDTH),rand.nextInt(GameView.HEIGHT)); - status = Status.FREEZE; this.hitBox.width = width-20; diff --git a/out/artifacts/Programmieren_2_jar/Programmieren 2.jar b/out/artifacts/Programmieren_2_jar/Programmieren 2.jar index ad67651..34c2ca4 100644 Binary files a/out/artifacts/Programmieren_2_jar/Programmieren 2.jar and b/out/artifacts/Programmieren_2_jar/Programmieren 2.jar differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.class index 5263f7b..da31a6c 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameLoopManager.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.class index 89bce7b..e0eb6e1 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GameObjectManager.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.class index b2a35aa..4be6472 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/InputManager.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/InputManager.class index 0381933..c3f277f 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/InputManager.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/InputManager.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Bubble.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Bubble.class index fb98b0b..4f4c3d6 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Bubble.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Bubble.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns$1.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns$1.class new file mode 100644 index 0000000..9f0d8dd Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns$1.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.class index b0cfa0a..54f5e9b 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/MovementPatterns.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Position.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Position.class index d6da8bc..4fd40da 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Position.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Position.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Level.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Level.class new file mode 100644 index 0000000..b2ea548 Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Level.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Player.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Player.class new file mode 100644 index 0000000..16f6178 Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/Player.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.class new file mode 100644 index 0000000..cec5568 Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/XAxisComparator.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.class index 32141a2..3545624 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelLabel.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.class index b5e4994..3ba7157 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LevelProgressBar.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.class deleted file mode 100644 index 0f4a170..0000000 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesIcon.class and /dev/null differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.class new file mode 100644 index 0000000..71e16e0 Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/LivesLabel.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/ScoreLabel.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/ScoreLabel.class index b96068d..0d6d2bd 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/ScoreLabel.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/immovable/ScoreLabel.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/HexagonalBubble.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/HexagonalBubble.class index 82fc16d..b2a54dd 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/HexagonalBubble.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/HexagonalBubble.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Player.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.class similarity index 53% rename from out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Player.class rename to out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.class index 82c534c..9451239 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Player.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/PlayerObject.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.class index e64ef2a..f1239a5 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RandomBall.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.class index f2dc6c7..81b4562 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/RoundBubble.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble$Status.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble$Status.class index 7753b9f..113eda3 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble$Status.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble$Status.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.class index fb555f4..d721213 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/SpecialBubble.class differ