Aufgaben 7

This commit is contained in:
Andreas Greiner 2021-05-01 14:00:26 +02:00
parent e8cfbb70ba
commit f0d73b7cf0
31 changed files with 66 additions and 27 deletions

View File

@ -3,6 +3,7 @@ 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.*;
@ -65,8 +66,7 @@ class GameObjectManager {
gameObjects.add(player);
gameObjects.forEach(gameObject ->{
gameObject.updatePosition();
gameObject.updateStatus();
gameObject.update();
gameObject.addToCanvas();
});
}

View File

@ -5,7 +5,7 @@ import de.thdeg.greiner.superpangworld.gameview.GameView;
/**
* A Bubble, which moves around on the screen and can be shot by the player.
*/
public class Bubble extends GameObject {
public abstract class Bubble extends GameObject implements MovingGameObject{
/** Flag, if the bubble flies from left to right */
private boolean flyFromLeftToRight;

View File

@ -35,25 +35,24 @@ public abstract class GameObject {
position = new Position(0,0);
}
/**
* Update the position of the game object.
*/
public void updatePosition(){
}
/**
* Add the game object to the canvas.
*/
public void addToCanvas(){
}
public abstract void addToCanvas();
/**
* Updates the game object's status.
*/
public void updateStatus(){
protected abstract void updateStatus();
/**
* Update the status and the position is applicable.
*/
public void update(){
if(this instanceof MovingGameObject){
((MovingGameObject)this).updatePosition();
}
updateStatus();
}
/**

View File

@ -0,0 +1,13 @@
package de.thdeg.greiner.superpangworld.graphics.base;
/**
* The interface for moving game objects.
*/
public interface MovingGameObject {
/**
* Update the position of a game object.
*/
public void updatePosition();
}

View File

@ -43,4 +43,9 @@ public class Background extends GameObject {
public void addToCanvas() {
gameView.addBlockImageToCanvas(pixelArt,position.x,position.y,size, rotation);
}
@Override
public void updateStatus() {
}
}

View File

@ -35,8 +35,8 @@ public class LevelLabel extends GameObject {
}
@Override
public void updatePosition() {
super.updatePosition();
public void updateStatus() {
}
@Override

View File

@ -40,8 +40,8 @@ public class LevelProgressBar extends GameObject {
}
@Override
public void updatePosition() {
super.updatePosition();
public void updateStatus() {
}
@Override

View File

@ -38,4 +38,9 @@ public class LivesIcon extends GameObject {
public void addToCanvas() {
gameView.addBlockImageToCanvas(ICON,position.x,position.y,size,rotation);
}
@Override
public void updateStatus() {
}
}

View File

@ -33,7 +33,7 @@ public class ScoreLabel extends GameObject {
}
@Override
public void updatePosition() {
super.updatePosition();
public void updateStatus() {
}
}

View File

@ -3,11 +3,12 @@ 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.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
/**
* A harpoon which can be fired upwards by the player.
*/
public class Harpoon extends GameObject {
public class Harpoon extends GameObject implements MovingGameObject {
private final static String HARPOON =
" B \n"+

View File

@ -30,6 +30,11 @@ public class HexagonalBubble extends Bubble {
gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation);
}
@Override
public void updateStatus() {
}
@Override
public void updatePosition() {
super.updatePosition();

View File

@ -2,6 +2,7 @@ package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.base.MovingGameObject;
import java.awt.*;
@ -48,11 +49,6 @@ public class Player extends GameObject {
speedInPixel = 5;
}
@Override
public void updatePosition(){
}
@Override
public void addToCanvas(){
if(SHOW_X) {
@ -63,6 +59,11 @@ public class Player extends GameObject {
shooting = false;
}
@Override
public void updateStatus() {
}
/** Moves the character to the left */
public void left(){
position.left(speedInPixel);

View File

@ -45,4 +45,9 @@ public class RoundBubble extends Bubble {
public void addToCanvas(){
gameView.addBlockImageToCanvas(RED_BUBBLE, getPosition().x, getPosition().y,size, rotation);
}
@Override
public void updateStatus() {
}
}

View File

@ -42,6 +42,11 @@ public class SpecialBubble extends Bubble {
gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation);
}
@Override
public void updateStatus() {
}
/**
* Switches the active effect.
*/