Praktikum 7
This commit is contained in:
parent
f0d73b7cf0
commit
937d74a0db
@ -94,4 +94,21 @@ class GameObjectManager {
|
||||
public LinkedList<Harpoon> getHarpoons() {
|
||||
return harpoons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts the position of all game objects.
|
||||
*
|
||||
* @param adaptX Adaption to the right.
|
||||
* @param adaptY Adaption downwards.
|
||||
*/
|
||||
public void moveWorld(double adaptX, double adaptY) {
|
||||
for (GameObject gameObject : gameObjects) {
|
||||
if (gameObject.getClass() != LevelLabel.class
|
||||
&& gameObject.getClass() != LevelProgressBar.class
|
||||
&& gameObject.getClass() != LivesIcon.class
|
||||
&& gameObject.getClass() != ScoreLabel.class){
|
||||
gameObject.adaptPosition(adaptX, adaptY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,4 +104,22 @@ public class GamePlayManager {
|
||||
public void destroy(Harpoon harpoon){
|
||||
gameObjectManager.getHarpoons().remove(harpoon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the World to the left.
|
||||
*
|
||||
* @param speedInPixel Speed to move the World
|
||||
*/
|
||||
public void playerMovingRight(double speedInPixel) {
|
||||
gameObjectManager.moveWorld(-speedInPixel, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the World to the right.
|
||||
*
|
||||
* @param speedInPixel Speed to move the World
|
||||
*/
|
||||
public void playerMovingLeft(double speedInPixel) {
|
||||
gameObjectManager.moveWorld(speedInPixel, 0);
|
||||
}
|
||||
}
|
||||
|
@ -71,4 +71,15 @@ public abstract class GameObject {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts the position of this game object, in case the whole game world is moved.
|
||||
*
|
||||
* @param adaptX Adaption to the right.
|
||||
* @param adaptY Adaption downwards.
|
||||
*/
|
||||
public void adaptPosition(double adaptX, double adaptY){
|
||||
position.x += adaptX;
|
||||
position.y += adaptY;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ import java.util.Random;
|
||||
*/
|
||||
public class Background extends GameObject {
|
||||
|
||||
|
||||
private final String pixelArt;
|
||||
|
||||
/**
|
||||
* Create a background object.
|
||||
*
|
||||
@ -24,24 +21,12 @@ public class Background extends GameObject {
|
||||
size = 1;
|
||||
rotation = 0;
|
||||
|
||||
Random r = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int h=0;h<450;h++){
|
||||
for(int i=0;i<960;i++){
|
||||
if(r.nextBoolean()){
|
||||
sb.append("y");
|
||||
}else{
|
||||
sb.append("o");
|
||||
}
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
pixelArt = sb.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToCanvas() {
|
||||
gameView.addBlockImageToCanvas(pixelArt,position.x,position.y,size, rotation);
|
||||
gameView.addImageToCanvas("background.png",position.x,position.y,size,rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,11 +66,19 @@ public class Player extends GameObject {
|
||||
|
||||
/** Moves the character to the left */
|
||||
public void left(){
|
||||
if (position.x > 300) {
|
||||
position.left(speedInPixel);
|
||||
} else {
|
||||
gamePlayManager.playerMovingLeft(speedInPixel);
|
||||
}
|
||||
}
|
||||
/** Moves the character to the right */
|
||||
public void right(){
|
||||
if (position.x < GameView.WIDTH - width - 300) {
|
||||
position.right(speedInPixel);
|
||||
} else {
|
||||
gamePlayManager.playerMovingRight(speedInPixel);
|
||||
}
|
||||
}
|
||||
/** Moves the character upwards */
|
||||
public void up(){
|
||||
|
BIN
SuperPangWorld/src/resources/background.png
Normal file
BIN
SuperPangWorld/src/resources/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 305 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.
BIN
out/production/SuperPangWorld/resources/background.png
Normal file
BIN
out/production/SuperPangWorld/resources/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 305 KiB |
Loading…
Reference in New Issue
Block a user