Praktikum 5

This commit is contained in:
Andreas Greiner 2021-04-26 19:52:51 +02:00
parent 70d431a32d
commit 973a4e9710
59 changed files with 172 additions and 40 deletions

View File

@ -1,3 +1,3 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Main-Class: de.thdeg.greiner.superpangworld.game.Start Main-Class: de.thdeg.greiner.superpangworld.game.bin.Start

View File

@ -1,6 +1,6 @@
package de.thdeg.greiner.superpangworld.game; package de.thdeg.greiner.superpangworld.game.bin;
import de.thdeg.greiner.superpangworld.managers.GameLoopManager; import de.thdeg.greiner.superpangworld.game.managers.GameLoopManager;
/** /**
* Die Startklasse für das Spiel. * Die Startklasse für das Spiel.

View File

@ -1,9 +1,6 @@
package de.thdeg.greiner.superpangworld.managers; package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.managers.GameObjectManager;
import de.thdeg.greiner.superpangworld.managers.GamePlayManager;
import de.thdeg.greiner.superpangworld.managers.InputManager;
/** This class manages the main game loop of the game. */ /** This class manages the main game loop of the game. */
public class GameLoopManager { public class GameLoopManager {

View File

@ -1,4 +1,4 @@
package de.thdeg.greiner.superpangworld.managers; package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.immovable.*; import de.thdeg.greiner.superpangworld.graphics.immovable.*;
@ -9,7 +9,7 @@ import java.awt.*;
/** /**
* The manager handling the display and passive movement of the game objects. * The manager handling the display and passive movement of the game objects.
*/ */
public class GameObjectManager { class GameObjectManager {
/** The GameView to display the objects */ /** The GameView to display the objects */
private GameView gameView; private GameView gameView;

View File

@ -1,4 +1,4 @@
package de.thdeg.greiner.superpangworld.managers; package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;

View File

@ -1,4 +1,4 @@
package de.thdeg.greiner.superpangworld.managers; package de.thdeg.greiner.superpangworld.game.managers;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.moveable.Player; import de.thdeg.greiner.superpangworld.graphics.moveable.Player;
@ -9,7 +9,7 @@ import java.util.Arrays;
/** /**
* The manager which handles the user input and controls the player object. * The manager which handles the user input and controls the player object.
*/ */
public class InputManager { class InputManager {
/** The gameView, which displays the player object */ /** The gameView, which displays the player object */
private GameView gameView; private GameView gameView;

View File

@ -1,12 +1,12 @@
package de.thdeg.greiner.superpangworld.graphics.base; package de.thdeg.greiner.superpangworld.graphics.base;
import de.thdeg.greiner.superpangworld.managers.GamePlayManager; import de.thdeg.greiner.superpangworld.game.managers.GamePlayManager;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
/** /**
* A basic game object. * A basic game object.
*/ */
class GameObject { public abstract class GameObject {
/** The game view to display the game object on. */ /** The game view to display the game object on. */
protected final GameView gameView; protected final GameView gameView;

View File

@ -1,19 +1,46 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.immovable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import java.util.Random;
/** /**
* The background for the game. * The background for the game.
*/ */
public class Background extends GameObject{ public class Background extends GameObject {
private final String pixelArt;
/** /**
* Create a background object. * Create a background object.
* *
* @param gameView the gameView * @param gameView the gameView
*/ */
protected Background(GameView gameView) { public Background(GameView gameView) {
super(gameView); super(gameView);
this.position.setTo(0,0);
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);
} }
} }

View File

@ -1,13 +1,14 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.immovable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import java.awt.*; import java.awt.*;
/** /**
* The label to display the current level. * The label to display the current level.
*/ */
public class LevelLabel extends GameObject{ public class LevelLabel extends GameObject {
/** The level to display */ /** The level to display */
private int level; private int level;

View File

@ -1,11 +1,12 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.immovable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
/** /**
* The progress bar of a level. * The progress bar of a level.
*/ */
public class LevelProgressBar extends GameObject{ public class LevelProgressBar extends GameObject {
/** The progress of the level ranging from <code>0</code> to <code>100</code> */ /** The progress of the level ranging from <code>0</code> to <code>100</code> */
private int levelProgress; private int levelProgress;

View File

@ -1,17 +1,41 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.immovable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
/** /**
* The icon to display the remaining lives. * The icon to display the remaining lives.
*/ */
public class LivesIcon extends GameObject{ public class LivesIcon extends GameObject {
private final static String ICON =
" RR RR \n"+
" RRRR RRRR \n"+
"RRRRRRRRRRR\n"+
"RRRRRRRRRRR\n"+
" RRRRRRRRR \n"+
" RRRRRRR \n"+
" RRRRR \n"+
" RRR \n"+
" R \n";
/** /**
* Create a game object with default values. * Create lives icon.
* *
* @param gameView the gameView * @param gameView the gameView
*/ */
protected LivesIcon(GameView gameView) { public LivesIcon(GameView gameView) {
super(gameView); super(gameView);
rotation = 0;
size = 5;
width = 12;
height = 12;
position.setTo(50,GameView.HEIGHT-50);
}
@Override
public void addToCanvas() {
gameView.addBlockImageToCanvas(ICON,position.x,position.y,size,rotation);
} }
} }

View File

@ -1,13 +1,14 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.immovable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import java.awt.*; import java.awt.*;
/** /**
* The label to display the score. * The label to display the score.
*/ */
public class ScoreLabel extends GameObject{ public class ScoreLabel extends GameObject {
/** The score to display */ /** The score to display */
private int score; private int score;

View File

@ -1,11 +1,13 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
/** /**
* A harpoon which can be fired upwards by the player. * A harpoon which can be fired upwards by the player.
*/ */
public class Harpoon extends GameObject{ public class Harpoon extends GameObject {
private final static String HARPOON = private final static String HARPOON =
" B \n"+ " B \n"+
@ -20,7 +22,7 @@ public class Harpoon extends GameObject{
*/ */
public Harpoon(GameView gameView){ public Harpoon(GameView gameView){
super(gameView); super(gameView);
speedInPixel = 10; speedInPixel = 1;
size = 3; size = 3;
width = 11; width = 11;
height = 11; height = 11;
@ -47,5 +49,8 @@ public class Harpoon extends GameObject{
@Override @Override
public void updatePosition(){ public void updatePosition(){
getPosition().up(speedInPixel); getPosition().up(speedInPixel);
if(getPosition().y < 0){
getPosition().setTo(300,300);
}
} }
} }

View File

@ -1,11 +1,12 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
/** /**
* The rare hexagonal bubble. * The rare hexagonal bubble.
*/ */
public class HexagonalBubble extends Bubble{ public class HexagonalBubble extends Bubble {
/** /**
* Create a hexagonal bubble with default values. * Create a hexagonal bubble with default values.
@ -14,5 +15,19 @@ public class HexagonalBubble extends Bubble{
*/ */
public HexagonalBubble(GameView gameView) { public HexagonalBubble(GameView gameView) {
super(gameView); super(gameView);
position.setTo(100,200);
size=0.6;
speedInPixel = 2;
}
@Override
public void addToCanvas() {
gameView.addImageToCanvas("hexagon.png",position.x,position.y,size,rotation);
}
@Override
public void updatePosition() {
super.updatePosition();
rotation = (rotation + 1) % 360;
} }
} }

View File

@ -1,13 +1,14 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import java.awt.*; import java.awt.*;
/** /**
* The game character controlled by the player. * The game character controlled by the player.
*/ */
public class Player extends GameObject{ public class Player extends GameObject {
/** Flag, if the player is shooting */ /** Flag, if the player is shooting */
private boolean shooting; private boolean shooting;
@ -39,7 +40,7 @@ public class Player extends GameObject{
*/ */
public Player(GameView gameView){ public Player(GameView gameView){
super(gameView); super(gameView);
position.setTo(GameView.WIDTH/2, GameView.HEIGHT/2); position.setTo(GameView.WIDTH/2, GameView.HEIGHT/1.5);
shooting = false; shooting = false;
size = 3; size = 3;
width = (int) size * 12; width = (int) size * 12;

View File

@ -1,12 +1,28 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
/** /**
* The classic red, round bubble. * The classic red, round bubble.
*/ */
public class RoundBubble extends Bubble{ public class RoundBubble extends Bubble {
/** The pixel art for the bubble */
private final static String RED_BUBBLE =
" RRRR \n"+
" RWRRRR \n"+
" RWRRRRRR \n"+
" RWRRRRRRRR \n"+
"RWRRRRRRRRRR\n"+
"RWRRRRRRRRRR\n"+
"RWRRRRRRRRWR\n"+
"RRRRRRRRRWWR\n"+
" RRRRRRRWWR \n"+
" RRRRRWWR \n"+
" RRRWWR \n"+
" RRRR \n";
/** /**
* Create a round bubble with default values. * Create a round bubble with default values.
@ -16,4 +32,12 @@ public class RoundBubble extends Bubble{
public RoundBubble(GameView gameView) { public RoundBubble(GameView gameView) {
super(gameView); super(gameView);
} }
/**
* Draws the bubble onto the canvas of the {@link GameView}.
*/
@Override
public void addToCanvas(){
gameView.addBlockImageToCanvas(RED_BUBBLE, getPosition().x, getPosition().y,size, rotation);
}
} }

View File

@ -1,11 +1,27 @@
package de.thdeg.greiner.superpangworld.graphics; package de.thdeg.greiner.superpangworld.graphics.moveable;
import de.thdeg.greiner.superpangworld.gameview.GameView; import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.Bubble;
/** /**
* The green bubble with special abilities. * The green bubble with special abilities.
*/ */
public class SpecialBubble extends Bubble{ public class SpecialBubble extends Bubble {
/** The pixel art for the bubble */
private final static String GREEN_BUBBLE =
" GGGG \n"+
" GWGGGG \n"+
" GWGGGGGG \n"+
" GWGGGGGGGG \n"+
"GWGGGGGGGGGG\n"+
"GWGGGGGGGGGG\n"+
"GWGGGGGGGGWG\n"+
"GGGGGGGGGWWG\n"+
" GGGGGGGWWG \n"+
" GGGGGWWG \n"+
" GGGWWG \n"+
" GGGG \n";
/** /**
* Create a special bubble with default values. * Create a special bubble with default values.
@ -14,5 +30,25 @@ public class SpecialBubble extends Bubble{
*/ */
public SpecialBubble(GameView gameView) { public SpecialBubble(GameView gameView) {
super(gameView); super(gameView);
position.setTo(100, 100);
}
@Override
public void addToCanvas() {
gameView.addBlockImageToCanvas(GREEN_BUBBLE,position.x,position.y,size, rotation);
}
/**
* Switches the active effect.
*/
private void switchEffect(){
}
/**
* Activates the current effect.
*/
private void activateEffect(){
} }
} }

View File

@ -1,3 +1,3 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Main-Class: de.thdeg.greiner.superpangworld.game.Start Main-Class: de.thdeg.greiner.superpangworld.game.bin.Start

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 641 B