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 d91c1e7..b9d1c8c 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.java @@ -31,6 +31,7 @@ public class GamePlayManager { /** Der Spieler */ private final Player player; + /** * Create the manager handling the gameplay. * @@ -58,7 +59,7 @@ public class GamePlayManager { RoundBubble roundBubble = new RoundBubble(gameView, new ArrayList<>(Collections.singletonList(gameObjectManager.getPlayerObject()))); roundBubble.setGamePlayManager(this); gameObjectManager.getBubbles().add(roundBubble); - gameView.setTimer("SpawnBubble","GamePlayManager",3000); + gameView.setTimer("SpawnBubble","GamePlayManager",30000000); } } 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 69e7771..0f95753 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,11 @@ package de.thdeg.greiner.superpangworld.graphics.base; import de.thdeg.greiner.superpangworld.gameview.GameView; +import de.thdeg.greiner.superpangworld.graphics.helper.HelperValues; import de.thdeg.greiner.superpangworld.graphics.moveable.Harpoon; import de.thdeg.greiner.superpangworld.graphics.moveable.PlayerObject; +import java.awt.geom.Point2D; import java.util.*; /** @@ -11,6 +13,9 @@ import java.util.*; */ public abstract class Bubble extends CollidingGameObject implements MovingGameObject{ + private static final Point2D VELOCITY_RIGHT = new Point2D.Double(3,1); + private static final Point2D VELOCITY_LEFT = new Point2D.Double(-3,1); + /** Random generator */ private final Random random; /** Flag, if the bubble is in the spawning phase */ @@ -22,6 +27,8 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb /** Temporary movement action */ private Position nextPosition; + private Point2D velocity; + /** * Create a bubble with default values. * @@ -43,7 +50,8 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb spawnSpeed = 500; gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); - nextPosition = new Position(random.nextInt(GameView.WIDTH-width),random.nextInt(GameView.HEIGHT-width)); + velocity = new Point2D.Double(-3.5,1.4); + } /** @@ -55,8 +63,9 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb * @param speedInPixel the speed in pixel per tick * @param position the position * @param spawning flag, if the bubble is in the spawning phase + * @param moveLeftToRight flag, if the bubble is moving left to right */ - public Bubble(GameView gameView, ArrayList objectsToCollideWith, double size, double speedInPixel, Position position, boolean spawning){ + public Bubble(GameView gameView, ArrayList objectsToCollideWith, double size, double speedInPixel, Position position, boolean spawning, boolean moveLeftToRight){ super(gameView,objectsToCollideWith); rotation = 90; this.size = size; @@ -72,7 +81,7 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); } - nextPosition = new Position(random.nextInt(GameView.WIDTH-width),random.nextInt(GameView.HEIGHT-width)); + velocity = new Point2D.Double(3.5,1.4); } /** @@ -81,23 +90,34 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb @Override public void updatePosition(){ if(spawning){ - if(position.y >= 0){ + if(position.y >= HelperValues.FRAME_BORDER_WIDTH){ spawning = false; } else if(gameView.timerExpired("spawn"+spawnID,"bubble"+spawnID)){ - position.down(width/4.0); + position.down((width + HelperValues.FRAME_BORDER_WIDTH)/4.0); gameView.setTimer("spawn"+spawnID,"bubble"+spawnID,spawnSpeed); } }else{ - 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)); + + Point2D newLocation = new Point2D.Double(position.x,position.y); + double speedFactor = 0.2; + + newLocation = new Point2D.Double(newLocation.getX() + (velocity.getX() * speedFactor), newLocation.getY() + (velocity.getY() * speedFactor)); + velocity = new Point2D.Double(velocity.getX() + HelperValues.BUBBLE_GRAVITY.getX(), velocity.getY() + HelperValues.BUBBLE_GRAVITY.getY()); + + // Wall bounce + 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()); } + + // Bottom bounce + if(newLocation.getY() >= HelperValues.FRAME_WINDOW_HEIGHT + HelperValues.FRAME_BORDER_WIDTH - width){ + 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); + } + + position.setTo(newLocation.getX(), newLocation.getY()); + } - - } /** @@ -127,11 +147,20 @@ public abstract class Bubble extends CollidingGameObject implements MovingGameOb return speedInPixel; } + /** + * Get the flag if the bubble is in its spawning phase. + * + * @return true if in spawning phase, else false + */ + public boolean isSpawning(){ + return spawning; + } + @Override public void reactToCollision(CollidableGameObject otherObject) { if(otherObject instanceof PlayerObject){ gamePlayManager.looseLife(); - }else if(otherObject instanceof Harpoon){ + }else if(otherObject instanceof Harpoon && !spawning){ gamePlayManager.destroy((Harpoon) otherObject); gamePlayManager.destroy(this); } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.java index b525df6..31110b2 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.java @@ -1,2 +1,12 @@ -package de.thdeg.greiner.superpangworld.graphics.helper;public class HelperValues { +package de.thdeg.greiner.superpangworld.graphics.helper; + +import java.awt.geom.Point2D; + +public class HelperValues { + + public static final int FRAME_BORDER_WIDTH = 8; + public static final int FRAME_WINDOW_HEIGHT = 432; + + public static Point2D BUBBLE_GRAVITY = new Point2D.Double(0,0.2); + } diff --git a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.java b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.java index f622399..a8e35fc 100644 --- a/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.java +++ b/SuperPangWorld/src/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.java @@ -18,8 +18,6 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject { " kkkkk \n"+ "k kkk k\n"+ "k kkk k\n"; - private boolean stuckAtRoof; - private final long harpoonID; /** * Create a harpoon with default values. @@ -37,8 +35,6 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject { getPosition().setTo(300,300); this.hitBox.width = width; this.hitBox.height = (int) (440 - position.y); - stuckAtRoof = false; - harpoonID = UUID.randomUUID().getLeastSignificantBits(); } @Override @@ -50,9 +46,12 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject { @Override public void reactToCollision(CollidableGameObject otherObject) { - gamePlayManager.destroy(this); if(Bubble.class.isAssignableFrom(otherObject.getClass())){ - gamePlayManager.destroy((Bubble)otherObject); + Bubble bubble = (Bubble) otherObject; + if(!bubble.isSpawning()){ + gamePlayManager.destroy((Bubble)otherObject); + gamePlayManager.destroy(this); + } } } @@ -72,9 +71,8 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject { public void updatePosition(){ if(position.y > 8){ getPosition().up(Math.min(speedInPixel, position.y-8)); - }else if(!stuckAtRoof){ - stuckAtRoof = true; - gameView.setTimer("stuckAtRoof"+harpoonID,"harpoon"+harpoonID,1000); + }else{ + gamePlayManager.destroy(this); } } @@ -83,8 +81,5 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject { */ @Override public void updateStatus() { - if(stuckAtRoof && gameView.timerExpired("stuckAtRoof"+harpoonID,"harpoon"+harpoonID)){ - gamePlayManager.destroy(this); - } } } diff --git a/out/artifacts/Programmieren_2_jar/Programmieren 2.jar b/out/artifacts/Programmieren_2_jar/Programmieren 2.jar index 175bd2b..23239a8 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/GamePlayManager.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/game/managers/GamePlayManager.class index f09a974..a846c8d 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/graphics/base/Bubble.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/base/Bubble.class index 7c31dc8..61e6fc1 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/helper/HelperValues.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.class new file mode 100644 index 0000000..cbbe268 Binary files /dev/null and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/helper/HelperValues.class differ diff --git a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.class b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.class index a2bf3a6..ecee511 100644 Binary files a/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.class and b/out/production/SuperPangWorld/de/thdeg/greiner/superpangworld/graphics/moveable/Harpoon.class differ