Praktikum 9 V2

This commit is contained in:
Andreas Greiner 2021-06-07 15:40:08 +02:00
parent 686f7442c8
commit 5cae1734d7
27 changed files with 29 additions and 15 deletions

View File

@ -28,6 +28,9 @@ class GameObjectManager {
private Background background;
private Player player;
private RandomBall randomBall;
private FollowerBall followerBall;
private LinkedList<GameObject> gameObjects;
/**
@ -49,6 +52,9 @@ class GameObjectManager {
this.background = new Background(gameView);
this.player = new Player(gameView);
this.randomBall = new RandomBall(gameView);
this.followerBall = new FollowerBall(gameView, randomBall);
}
/**
@ -64,6 +70,9 @@ class GameObjectManager {
gameObjects.add(scoreLabel);
gameObjects.add(livesIcon);
gameObjects.add(player);
gameObjects.add(randomBall);
gameObjects.add(followerBall);
gameObjects.forEach(gameObject ->{
gameObject.update();

View File

@ -100,6 +100,16 @@ public class Position implements Cloneable{
this.y = y;
}
/**
* Calculates the distance to any other position.
*
* @param other Position to calculate the distance to.
* @return The distance.
*/
public double distance(Position other) {
return Math.sqrt(Math.pow((x - other.x), 2) + Math.pow((y - other.y), 2));
}
@Override
public String toString() {
return "Position(" + (int) Math.round(x) + ", " + (int) Math.round(y) + ')';

View File

@ -1,9 +1,9 @@
package de.thdeg.berl.ufofight.graphics.movingobjects;
package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.berl.ufofight.gameview.GameView;
import de.thdeg.berl.ufofight.graphics.base.GameObject;
import de.thdeg.berl.ufofight.graphics.base.MovingGameObject;
import de.thdeg.berl.ufofight.graphics.base.Position;
import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
import de.thdeg.greiner.superpangworld.graphics.base.Position;
import java.awt.*;

View File

@ -56,7 +56,6 @@ public class Harpoon extends CollidingGameObject implements MovingGameObject {
@Override
public void addToCanvas(){
gameView.addBlockImageToCanvas(HARPOON, getPosition().x, getPosition().y,size, rotation);
gameView.addRectangleToCanvas(hitBox.x, hitBox.y, hitBox.width, hitBox.height,1,false, Color.red);
}
/**

View File

@ -44,7 +44,6 @@ public class HexagonalBubble extends Bubble {
@Override
public void addToCanvas() {
gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation);
gameView.addRectangleToCanvas(hitBox.x, hitBox.y, hitBox.width, hitBox.height,1,false, Color.red);
}
@Override

View File

@ -73,7 +73,6 @@ public class Player extends CollidableGameObject {
gameView.addBlockImageToCanvas(SPIELFIGUR, position.x, position.y, size, rotation);
}
shooting = false;
gameView.addRectangleToCanvas(hitBox.x, hitBox.y, hitBox.width, hitBox.height,1,false, Color.red);
}
@Override

View File

@ -1,9 +1,9 @@
package de.thdeg.berl.ufofight.graphics.movingobjects;
package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.berl.ufofight.gameview.GameView;
import de.thdeg.berl.ufofight.graphics.base.GameObject;
import de.thdeg.berl.ufofight.graphics.base.MovingGameObject;
import de.thdeg.berl.ufofight.graphics.base.Position;
import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
import de.thdeg.greiner.superpangworld.graphics.base.Position;
import java.awt.*;
import java.util.Random;

View File

@ -57,7 +57,6 @@ public class RoundBubble extends Bubble {
@Override
public void addToCanvas(){
gameView.addBlockImageToCanvas(RED_BUBBLE, getPosition().x, getPosition().y,size, rotation);
gameView.addRectangleToCanvas(hitBox.x, hitBox.y, hitBox.width, hitBox.height,1,false, Color.yellow);
}
@Override

View File

@ -57,7 +57,6 @@ public class SpecialBubble extends Bubble {
@Override
public void addToCanvas() {
gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation);
gameView.addRectangleToCanvas(hitBox.x, hitBox.y, hitBox.width, hitBox.height,1,false, Color.red);
}
@Override