Aufgaben 11

This commit is contained in:
Andreas Greiner 2021-06-15 18:00:49 +02:00
parent 301c4993a7
commit 2f00876eec
42 changed files with 397 additions and 119 deletions

View File

@ -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);
}

View File

@ -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<Bubble> 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);
}

View File

@ -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<CollidableGameObject> 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();
}
}

View File

@ -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;

View File

@ -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<CollidableGameObject> 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<CollidableGameObject> 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(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);
}
if(flyFromLeftToRight){
getPosition().right(1);
}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.
*/
private void popBubble(){}
}
/**
* Freezes the time.
* Get the score to add when bursting the bubble.
*
* @return the score to add
*/
private void freezeTime(){}
public int getBurstScore(){
return (int)(size*100);
}
/**
* Get the size of the bubble.
*
* @return the size
*/
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);
}
}
}

View File

@ -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<Position> 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<Position> zero = new ArrayList<>();
zero.addAll(square);
zero.addAll(zigZag);
zero.sort(Comparator.naturalOrder());
ArrayList<Position> xFirst = new ArrayList<>(zero);
xFirst.sort(new XAxisComparator());
Comparator<Position> yAxisComparator = new Comparator<Position>() {
@Override
public int compare(Position o1, Position o2) {
return Double.compare(o1.y,o2.y);
}
};
ArrayList<Position> yFirst = new ArrayList<>(zero);
yFirst.sort(yAxisComparator);
ArrayList<Position> 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);
}
/**

View File

@ -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<Position>{
/** 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));
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<Position> {
@Override
public int compare(Position o1, Position o2) {
return (int)Math.signum(o1.x-o2.x);
}
}

View File

@ -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() {

View File

@ -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));
}

View File

@ -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<lifeCount;i++){
gameView.addBlockImageToCanvas(ICON,position.x + (i*size*width),position.y,size,rotation);
}
}
/**
* Set the current life count.
* @param lifeCount the lives
*/
public void setLifeCount(int lifeCount) {
this.lifeCount = lifeCount;
}
@Override

View File

@ -19,7 +19,7 @@ public class ScoreLabel extends GameObject {
*/
public ScoreLabel(GameView gameView) {
super(gameView);
score = 1300;
score = 0;
size = 50;
width = 100;
height = 8;
@ -32,8 +32,15 @@ public class ScoreLabel extends GameObject {
gameView.addTextToCanvas(Integer.toString(score),getPosition().x,getPosition().y,40, Color.YELLOW,0);
}
/**
* Set the game score
* @param score the score
*/
public void setScore(int score) {
this.score = score;
}
@Override
public void updateStatus() {
}
}

View File

@ -22,9 +22,6 @@ public class HexagonalBubble extends Bubble {
public HexagonalBubble(GameView gameView, ArrayList<CollidableGameObject> 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;

View File

@ -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

View File

@ -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);

View File

@ -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<CollidableGameObject> 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<CollidableGameObject> 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));
}
/**

View File

@ -39,9 +39,6 @@ public class SpecialBubble extends Bubble {
public SpecialBubble(GameView gameView, ArrayList<CollidableGameObject> 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;