Compare commits
20 Commits
Author | SHA1 | Date |
---|---|---|
rxbn_ | 2a27f74846 | |
rxbn_ | 5a5d661719 | |
rxbn_ | 05a4463ba8 | |
rxbn_ | 59c2f83f49 | |
rxbn_ | 59fdc12e4f | |
rxbn_ | 90afe2d72e | |
rxbn_ | 21a7b951d6 | |
rxbn_ | 5ea292bbae | |
rxbn_ | b51c1c4f62 | |
rxbn_ | f6e8e6fcc5 | |
rxbn_ | 87048abd6f | |
rxbn_ | 49f431c236 | |
rxbn_ | 041092f121 | |
rxbn_ | 8668f6e2b5 | |
rxbn_ | 9210e43b6a | |
rxbn_ | 2102f5c27b | |
rxbn_ | 0fdd579b41 | |
rxbn_ | 669c37029a | |
rxbn_ | 2870a5fc9a | |
rxbn_ | 1b829fba1e |
|
@ -3,8 +3,13 @@
|
||||||
- Einführung in die Programmierung WS19/20
|
- Einführung in die Programmierung WS19/20
|
||||||
- Programmieren des Spieles "Breakout" basierend auf dem Framework des Instituts
|
- Programmieren des Spieles "Breakout" basierend auf dem Framework des Instituts
|
||||||
|
|
||||||
# Gruppe
|
# alte Gruppe (bis inkl. 3.)
|
||||||
Gruppennummer: 175
|
Gruppennummer: 175
|
||||||
Gruppenmitglieder
|
Gruppenmitglieder
|
||||||
- [Ruben Meyer](mailto:ruben.meyer@student.uni-luebeck.de)
|
- [Ruben Meyer](mailto:ruben.meyer@student.uni-luebeck.de)
|
||||||
- [Moritz Henseleit](mailto:moritz.henseleit@student.uni-luebeck.de)
|
- [Moritz Henseleit](mailto:moritz.henseleit@student.uni-luebeck.de)
|
||||||
|
|
||||||
|
# neue Gruppe (ab inkl. 4.)
|
||||||
|
Gruppennummer: 262
|
||||||
|
Gruppenmitglieder:
|
||||||
|
- [Ruben Meyer](mailto:ruben.meyer@student.uni-luebeck.de)
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
# project prefix
|
# project prefix
|
||||||
PREFIX="175-BreakOutA"
|
PREFIX="262-BreakOutA"
|
||||||
|
|
||||||
# get versioning
|
# get versioning
|
||||||
echo -n "Type your tag version for '$PREFIX' (like (2.1) followed by [ENTER] for ${PREFIX}2.1): "
|
echo -n "Type your tag version for '$PREFIX' (like (2.1) followed by [ENTER] for ${PREFIX}2.1): "
|
||||||
|
|
|
@ -1,33 +1,35 @@
|
||||||
{
|
{
|
||||||
"field" : [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
"field" : [
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 3, 3, 3, 3, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
|
||||||
|
"maxLives" : 5
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package break_out;
|
package break_out;
|
||||||
|
|
||||||
|
import break_out.model.Position;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +49,7 @@ public class Constants {
|
||||||
/**
|
/**
|
||||||
* The paddle width in pixels
|
* The paddle width in pixels
|
||||||
*/
|
*/
|
||||||
public static final Integer PADDLE_WIDTH = 70;
|
public static final Integer PADDLE_WIDTH = 90;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The paddle height in pixels
|
* The paddle height in pixels
|
||||||
|
@ -77,21 +79,51 @@ public class Constants {
|
||||||
/**
|
/**
|
||||||
* The background color for the field
|
* The background color for the field
|
||||||
*/
|
*/
|
||||||
public static final Color COLOR_GAME_BACKGROUND = new Color(33, 97, 138);
|
public static final Color COLOR_GAME_BACKGROUND = new Color(64, 45, 61);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default component color
|
* The default component color
|
||||||
*/
|
*/
|
||||||
public static final Color COLOR_COMPONENT = new Color(200, 200, 200);
|
public static final Color COLOR_COMPONENT = new Color(191, 105, 145);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The component color for the bottom paddle
|
* The component color for the bottom paddle
|
||||||
*/
|
*/
|
||||||
public static final Color COLOR_PADDLE_BOTTOM = new Color(226, 215, 73);
|
public static final Color COLOR_PADDLE_BOTTOM = new Color(242, 173, 148);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The component color for the top paddle
|
* The component color for the top paddle
|
||||||
*/
|
*/
|
||||||
public static final Color COLOR_PADDLE_TOP = new Color(140, 226, 165);
|
public static final Color COLOR_PADDLE_TOP = new Color(242, 196, 141);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component color for the text
|
||||||
|
*/
|
||||||
|
public static final Color COLOR_TEXT = new Color(0, 0, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component color for the scoreboard
|
||||||
|
*/
|
||||||
|
public static final Color COLOR_SCOREBOARD = new Color(140, 140, 140, 144);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The padding / offset of the scoreboard to the inner text elements
|
||||||
|
*/
|
||||||
|
public static final int SCOREBOARD_OFFSET = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The string for the score on the scoreboard
|
||||||
|
*/
|
||||||
|
public static final String SCOREBOARD_SCORE = "Score: ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The string for the lives on the scoreboard
|
||||||
|
*/
|
||||||
|
public static final String SCOREBOARD_LIVES = "Lives: ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The position for the scoreboards midpoint (bottom center)
|
||||||
|
*/
|
||||||
|
public static final Position SCOREBOARD_MIDPOINT = new Position(SCREEN_WIDTH*5/6, SCREEN_HEIGHT);
|
||||||
|
|
||||||
}
|
}
|
|
@ -136,7 +136,7 @@ public class Controller implements ActionListener, KeyListener {
|
||||||
case KeyEvent.VK_ESCAPE:
|
case KeyEvent.VK_ESCAPE:
|
||||||
// exit current level
|
// exit current level
|
||||||
game.getLevel().setFinished(true);
|
game.getLevel().setFinished(true);
|
||||||
toStartScreen();
|
toStartScreen(game.getLevel().getScore());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,10 +161,14 @@ public class Controller implements ActionListener, KeyListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method switches the view to the StartScreen view.
|
* This method switches the view to the StartScreen view.
|
||||||
|
* @param score The player score
|
||||||
*/
|
*/
|
||||||
public void toStartScreen() {
|
public void toStartScreen(int score) {
|
||||||
view.showScreen(StartScreen.class.getName());
|
view.showScreen(StartScreen.class.getName());
|
||||||
view.getStartScreen().requestFocusInWindow();
|
view.getStartScreen().requestFocusInWindow();
|
||||||
|
|
||||||
|
view.getStartScreen().addScore(score);
|
||||||
|
view.getStartScreen().repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package break_out.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import break_out.Constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The <code>JSONReader</code> reads the content of an json file.
|
||||||
|
*
|
||||||
|
* @author dmlux, modified by I.Schumacher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class JSONReader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The project path to the JSON file
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stones stored as List<List<Long>>
|
||||||
|
*/
|
||||||
|
private List<List<Long>> rects = new ArrayList<List<Long>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stones stored as 2D-int-array
|
||||||
|
*/
|
||||||
|
private int[][] stones = new int[Constants.SQUARES_Y][Constants.SQUARES_X];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The counter with the number of trials that are allowed to break out the stones of the level
|
||||||
|
*/
|
||||||
|
private Long lifecount = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor needs an path to create the JSONReader
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* The absolute path to the JSON file
|
||||||
|
*/
|
||||||
|
public JSONReader(String path) {
|
||||||
|
this.path = path;
|
||||||
|
loadJsonValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the stones of the JSON file
|
||||||
|
*
|
||||||
|
* @return The List<List<Long>> of stones
|
||||||
|
*/
|
||||||
|
public List<List<Long>> getStonesListOfLists() {
|
||||||
|
return rects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the stones of the JSON file
|
||||||
|
*
|
||||||
|
* @return The stones as 2D-Array
|
||||||
|
*/
|
||||||
|
public int[][] getStones2DArray() {
|
||||||
|
for (int i = 0; i < rects.size(); i++) {
|
||||||
|
for (int j = 0; j < rects.get(i).size(); j++) {
|
||||||
|
stones[i][j] = (int)rects.get(i).get(j).longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stones;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the lifeCounter of the JSON file
|
||||||
|
*
|
||||||
|
* @return The lifeCounter
|
||||||
|
*/
|
||||||
|
public int getLifeCounter() {
|
||||||
|
return (int)lifecount.longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader for the both values "fields" and "maxDrops" of the JSON file
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void loadJsonValues() {
|
||||||
|
JSONParser parser = new JSONParser();
|
||||||
|
try {
|
||||||
|
Object obj = parser.parse(new FileReader(path));
|
||||||
|
|
||||||
|
String jsonStr = obj.toString();
|
||||||
|
JSONObject json = (JSONObject) JSONValue.parse(jsonStr);
|
||||||
|
rects = (List<List<Long>>) json.get("field");
|
||||||
|
lifecount = (Long)json.get("maxLives");
|
||||||
|
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,8 @@ package break_out.model;
|
||||||
|
|
||||||
import break_out.Constants;
|
import break_out.Constants;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,23 +28,33 @@ public class Ball implements IBall {
|
||||||
*/
|
*/
|
||||||
private boolean hitsPaddle;
|
private boolean hitsPaddle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The balls lost state for upper and lower borders
|
||||||
|
*/
|
||||||
|
private boolean isLost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The balls color with default component color
|
* The balls color with default component color
|
||||||
*/
|
*/
|
||||||
private Color color = Constants.COLOR_COMPONENT;
|
private Color color = Constants.COLOR_COMPONENT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stone which has been hit by the ball
|
||||||
|
*/
|
||||||
|
private Stone hitStone = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor of a ball
|
* The constructor of a ball
|
||||||
* The balls position and direction are initialized here.
|
* The balls position and direction are initialized here.
|
||||||
*/
|
*/
|
||||||
public Ball() {
|
public Ball() {
|
||||||
this.position = new Position(0, 0);
|
this.position = new Position(0, 0);
|
||||||
this.direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
|
|
||||||
this.direction.rescale();
|
|
||||||
|
|
||||||
// start at bottom-center
|
// reset direction
|
||||||
this.position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) / 2.0);
|
resetDirection();
|
||||||
this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT);
|
|
||||||
|
// reset position to bottom-center
|
||||||
|
resetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,8 +98,7 @@ public class Ball implements IBall {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
// random hue without blue colors to prevent ghosting
|
// random hue without blue colors to prevent ghosting
|
||||||
// 65 <~ 170/255
|
float hue = (random.nextInt(200)+50) / 360f;
|
||||||
float hue = (random.nextInt(65)) / 100f;
|
|
||||||
|
|
||||||
// saturation between 0.5 and 0.7
|
// saturation between 0.5 and 0.7
|
||||||
float saturation = (random.nextInt(2000) + 5000) / 10000f;
|
float saturation = (random.nextInt(2000) + 5000) / 10000f;
|
||||||
|
@ -141,14 +151,12 @@ public class Ball implements IBall {
|
||||||
|
|
||||||
// reacts on top border
|
// reacts on top border
|
||||||
if (this.position.getY() <= 0) {
|
if (this.position.getY() <= 0) {
|
||||||
this.position.setY(0);
|
isLost = true;
|
||||||
this.direction.setDy(-(this.direction.getDy()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reacts on bottom border (+Diameter because of hitbox)
|
// reacts on bottom border (+Diameter because of hitbox)
|
||||||
if (this.position.getY() >= Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER) {
|
if (this.position.getY() >= Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER) {
|
||||||
this.position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER);
|
isLost = true;
|
||||||
this.direction.setDy(-(this.direction.getDy()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +222,7 @@ public class Ball implements IBall {
|
||||||
// only two paddles defined in the game design, therefore greater or smaller than middle of screen
|
// only two paddles defined in the game design, therefore greater or smaller than middle of screen
|
||||||
|
|
||||||
//deciding if the paddle is at the top or bottom to adjust if its +or- y direction
|
//deciding if the paddle is at the top or bottom to adjust if its +or- y direction
|
||||||
if (paddle.getPosition().getY() <= Constants.SCREEN_HEIGHT/2) {
|
if (paddle.getPosition().getY() <= Constants.SCREEN_HEIGHT/2.0) {
|
||||||
// top paddle
|
// top paddle
|
||||||
reflectionPoint.setY(reflectionPoint.getY() - Constants.REFLECTION_OFFSET);
|
reflectionPoint.setY(reflectionPoint.getY() - Constants.REFLECTION_OFFSET);
|
||||||
} else {
|
} else {
|
||||||
|
@ -237,6 +245,163 @@ public class Ball implements IBall {
|
||||||
// replace direction vector
|
// replace direction vector
|
||||||
this.direction.setDx(reflectionVector.getDx());
|
this.direction.setDx(reflectionVector.getDx());
|
||||||
this.direction.setDy(reflectionVector.getDy());
|
this.direction.setDy(reflectionVector.getDy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tests whether the ball touches any stone's hit box
|
||||||
|
* @param stones list of stones on the playground
|
||||||
|
* @return true if the ball touches a stone
|
||||||
|
*/
|
||||||
|
public boolean hitsStone(ArrayList<Stone> stones) {
|
||||||
|
// ball as a Rectangle
|
||||||
|
Rectangle rectBall = new Rectangle((int) getPosition().getX(), (int) getPosition().getY(), Constants.BALL_DIAMETER, Constants.BALL_DIAMETER);
|
||||||
|
|
||||||
|
// size of grid blocks
|
||||||
|
int blockWidth = Constants.SCREEN_WIDTH / Constants.SQUARES_X;
|
||||||
|
int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y;
|
||||||
|
|
||||||
|
// foreach stone in stones
|
||||||
|
for(Stone stone : stones) {
|
||||||
|
if(stone != null) {
|
||||||
|
// stone as a Rectangle based on view.Field
|
||||||
|
Rectangle rectStone = new Rectangle((int) stone.getPosition().getX()+1, (int) stone.getPosition().getY()+1, blockWidth-1, blockHeight-1);
|
||||||
|
|
||||||
|
// if ball intersects with stone which is existent and visible
|
||||||
|
if(rectBall.intersects(rectStone) && stone.getColor() != null) {
|
||||||
|
// set stone and return true
|
||||||
|
hitStone = stone;
|
||||||
|
|
||||||
|
// reflect ball
|
||||||
|
reflectOnStone(hitStone);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the stone which got hit, can be null
|
||||||
|
* @return the stone which got hit
|
||||||
|
*/
|
||||||
|
public Stone getHitStone() {
|
||||||
|
return hitStone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ball got hit by Stone stone
|
||||||
|
* @param stone hitbox mechanism of stone
|
||||||
|
*/
|
||||||
|
public void reflectOnStone(Stone stone) {
|
||||||
|
// reflection model based on view.Field rendering model
|
||||||
|
|
||||||
|
// size of grid blocks
|
||||||
|
int blockWidth = Constants.SCREEN_WIDTH / Constants.SQUARES_X;
|
||||||
|
int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y;
|
||||||
|
|
||||||
|
// ball as a Rectangle
|
||||||
|
Rectangle rectBall = new Rectangle((int) getPosition().getX(), (int) getPosition().getY(), Constants.BALL_DIAMETER, Constants.BALL_DIAMETER);
|
||||||
|
|
||||||
|
// stone as a Rectangle
|
||||||
|
Rectangle rectStone = new Rectangle((int) stone.getPosition().getX()+1, (int) stone.getPosition().getY()+1, blockWidth-1, blockHeight-1);
|
||||||
|
|
||||||
|
// stones borders as Rectangle's
|
||||||
|
Rectangle topBorder = new Rectangle((int) stone.getPosition().getX(), (int) stone.getPosition().getY(), blockWidth, 1);
|
||||||
|
Rectangle bottomBorder = new Rectangle((int) stone.getPosition().getX(), (int) stone.getPosition().getY()+blockHeight, blockWidth, 1);
|
||||||
|
Rectangle leftBorder = new Rectangle((int) stone.getPosition().getX(), (int) stone.getPosition().getY(), 1, blockHeight);
|
||||||
|
Rectangle rightBorder = new Rectangle((int) stone.getPosition().getX()+blockWidth, (int) stone.getPosition().getY(), 1, blockHeight);
|
||||||
|
|
||||||
|
//System.out.println(String.format("ball (%s, %s) stone (%s, %s)", getPosition().getX(), getPosition().getY(), stone.getPosition().getX(), stone.getPosition().getY()));
|
||||||
|
|
||||||
|
// if stone intersects with any bounds
|
||||||
|
if(rectBall.intersects(rectStone.getBounds())) {
|
||||||
|
|
||||||
|
// corner intersections
|
||||||
|
if((rectBall.intersects(leftBorder) || rectBall.intersects(rightBorder)) && (rectBall.intersects(topBorder) || rectBall.intersects(bottomBorder))) {
|
||||||
|
// intersections as Rectangle's
|
||||||
|
Rectangle intersTop = rectBall.intersection(topBorder);
|
||||||
|
Rectangle intersBottom = rectBall.intersection(bottomBorder);
|
||||||
|
Rectangle intersLeft = rectBall.intersection(leftBorder);
|
||||||
|
Rectangle intersRight = rectBall.intersection(rightBorder);
|
||||||
|
|
||||||
|
// rectangles as area to determine corner
|
||||||
|
double areaIntersTop = intersTop.getHeight() * intersTop.getWidth();
|
||||||
|
double areaIntersBottom = intersBottom.getHeight() * intersBottom.getWidth();
|
||||||
|
double areaIntersLeft = intersLeft.getHeight() * intersLeft.getWidth();
|
||||||
|
double areaIntersRight = intersRight.getHeight() * intersRight.getWidth();
|
||||||
|
|
||||||
|
//System.out.printf("ut, ub, ul, ur: %s %s %s %s\r\n", areaIntersTop, areaIntersBottom, areaIntersLeft, areaIntersRight);
|
||||||
|
|
||||||
|
// top side
|
||||||
|
if(areaIntersTop > 0) {
|
||||||
|
// left|right border
|
||||||
|
if(areaIntersLeft > areaIntersTop || areaIntersRight > areaIntersTop) direction.setDx(-getDirection().getDx());
|
||||||
|
|
||||||
|
// top border
|
||||||
|
else direction.setDy(-getDirection().getDy());
|
||||||
|
}
|
||||||
|
|
||||||
|
// bottom side
|
||||||
|
if(areaIntersBottom > 0) {
|
||||||
|
// left|right border
|
||||||
|
if(areaIntersLeft > areaIntersBottom || areaIntersRight > areaIntersBottom) direction.setDx(-getDirection().getDx());
|
||||||
|
|
||||||
|
// bottom border
|
||||||
|
else direction.setDy(-getDirection().getDy());
|
||||||
|
}
|
||||||
|
|
||||||
|
// return; intersection already handled
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertical bounds
|
||||||
|
if(rectBall.intersects(leftBorder) || rectBall.intersects(rightBorder)) {
|
||||||
|
//System.out.println("left|right border");
|
||||||
|
direction.setDx(-getDirection().getDx());
|
||||||
|
}
|
||||||
|
|
||||||
|
// horizontal bounds
|
||||||
|
if(rectBall.intersects(topBorder) || rectBall.intersects(bottomBorder)) {
|
||||||
|
//System.out.println("top|bottom border");
|
||||||
|
direction.setDy(-getDirection().getDy());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The getter for balls lost state
|
||||||
|
* @return balls lost state
|
||||||
|
*/
|
||||||
|
public boolean isLost() {
|
||||||
|
return isLost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setter for balls lost state
|
||||||
|
* @param lost balls lost state
|
||||||
|
*/
|
||||||
|
public void setLost(boolean lost) {
|
||||||
|
isLost = lost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets balls position
|
||||||
|
*/
|
||||||
|
public void resetPosition() {
|
||||||
|
// start at bottom-center
|
||||||
|
position.setX((Constants.SCREEN_WIDTH - Constants.BALL_DIAMETER) / 2.0);
|
||||||
|
position.setY(Constants.SCREEN_HEIGHT - Constants.BALL_DIAMETER - Constants.PADDLE_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets balls direction
|
||||||
|
*/
|
||||||
|
public void resetDirection() {
|
||||||
|
direction = new Vector2D(Constants.BALL_SPEED, Constants.BALL_SPEED);
|
||||||
|
direction.rescale();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class Game {
|
||||||
/**
|
/**
|
||||||
* The last levelnumber
|
* The last levelnumber
|
||||||
*/
|
*/
|
||||||
private int maxLevel = 1;
|
private int maxLevel = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total score of the game
|
* The total score of the game
|
||||||
|
@ -114,7 +114,7 @@ public class Game {
|
||||||
controller.toPlayground();
|
controller.toPlayground();
|
||||||
} else {
|
} else {
|
||||||
// tells the controller to switch to the startScreen of the game
|
// tells the controller to switch to the startScreen of the game
|
||||||
controller.toStartScreen();
|
controller.toStartScreen(level.getScore());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package break_out.model;
|
package break_out.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface IBall {
|
public interface IBall {
|
||||||
|
|
||||||
// Exercise 1
|
// Exercise 1
|
||||||
|
@ -11,4 +13,11 @@ public interface IBall {
|
||||||
// Exercise 2
|
// Exercise 2
|
||||||
public boolean hitsPaddle(Paddle paddle);
|
public boolean hitsPaddle(Paddle paddle);
|
||||||
public void reflectOnPaddle(Paddle paddle);
|
public void reflectOnPaddle(Paddle paddle);
|
||||||
|
|
||||||
|
// Exercise 4
|
||||||
|
public boolean hitsStone(ArrayList<Stone> stones);
|
||||||
|
public Stone getHitStone();
|
||||||
|
|
||||||
|
// Exercise 5
|
||||||
|
public boolean isLost();
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package break_out.model;
|
package break_out.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface ILevel {
|
public interface ILevel {
|
||||||
// Exercise 1
|
// Exercise 1
|
||||||
public Ball getBall();
|
public Ball getBall();
|
||||||
|
@ -10,4 +12,7 @@ public interface ILevel {
|
||||||
|
|
||||||
// Exercise 3
|
// Exercise 3
|
||||||
public void setFinished(boolean finished);
|
public void setFinished(boolean finished);
|
||||||
|
|
||||||
|
// Exercise 4
|
||||||
|
public ArrayList<Stone> getStones();
|
||||||
}
|
}
|
|
@ -2,6 +2,9 @@ package break_out.model;
|
||||||
|
|
||||||
|
|
||||||
import break_out.Constants;
|
import break_out.Constants;
|
||||||
|
import break_out.controller.JSONReader;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains information about the running game
|
* This class contains information about the running game
|
||||||
|
@ -39,13 +42,23 @@ public class Level extends Thread implements ILevel {
|
||||||
/**
|
/**
|
||||||
* Flag that shows if the level was finished
|
* Flag that shows if the level was finished
|
||||||
*/
|
*/
|
||||||
private boolean levelFinished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The paddles of the level
|
* The paddles of the level
|
||||||
*/
|
*/
|
||||||
private Paddle paddleTop, paddleBottom;
|
private Paddle paddleTop, paddleBottom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stones of the level
|
||||||
|
*/
|
||||||
|
private ArrayList<Stone> stones = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The life counter of the level
|
||||||
|
*/
|
||||||
|
private int lifeCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor creates a new level object and needs the current game object,
|
* The constructor creates a new level object and needs the current game object,
|
||||||
* the number of the level to be created and the current score
|
* the number of the level to be created and the current score
|
||||||
|
@ -60,13 +73,7 @@ public class Level extends Thread implements ILevel {
|
||||||
this.score = score;
|
this.score = score;
|
||||||
this.ball = new Ball();
|
this.ball = new Ball();
|
||||||
|
|
||||||
// calc paddle positions
|
resetPaddles();
|
||||||
Position posPaddleTop = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, 0);
|
|
||||||
Position posPaddleBottom = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, Constants.SCREEN_HEIGHT - Constants.PADDLE_HEIGHT);
|
|
||||||
|
|
||||||
// set paddles
|
|
||||||
this.paddleTop = new Paddle(posPaddleTop);
|
|
||||||
this.paddleBottom = new Paddle(posPaddleBottom);
|
|
||||||
|
|
||||||
// set paddles color
|
// set paddles color
|
||||||
this.paddleTop.setColor(Constants.COLOR_PADDLE_TOP);
|
this.paddleTop.setColor(Constants.COLOR_PADDLE_TOP);
|
||||||
|
@ -114,7 +121,7 @@ public class Level extends Thread implements ILevel {
|
||||||
game.notifyObservers();
|
game.notifyObservers();
|
||||||
|
|
||||||
// endless loop
|
// endless loop
|
||||||
while (!levelFinished) {
|
while (!finished) {
|
||||||
// if ballWasStarted is true, the ball is moving
|
// if ballWasStarted is true, the ball is moving
|
||||||
if (ballWasStarted()) {
|
if (ballWasStarted()) {
|
||||||
|
|
||||||
|
@ -124,6 +131,11 @@ public class Level extends Thread implements ILevel {
|
||||||
// Call here the balls method for reacting on the borders of the playground
|
// Call here the balls method for reacting on the borders of the playground
|
||||||
getBall().reactOnBorder();
|
getBall().reactOnBorder();
|
||||||
|
|
||||||
|
// Call here the balls method for reacting on lost ball state
|
||||||
|
if(getBall().isLost()) {
|
||||||
|
decreaseLives();
|
||||||
|
}
|
||||||
|
|
||||||
// if ball hits paddle (top|bottom), reflect ball
|
// if ball hits paddle (top|bottom), reflect ball
|
||||||
if(getBall().hitsPaddle(paddleTop)) getBall().reflectOnPaddle(paddleTop);
|
if(getBall().hitsPaddle(paddleTop)) getBall().reflectOnPaddle(paddleTop);
|
||||||
if(getBall().hitsPaddle(paddleBottom)) getBall().reflectOnPaddle(paddleBottom);
|
if(getBall().hitsPaddle(paddleBottom)) getBall().reflectOnPaddle(paddleBottom);
|
||||||
|
@ -139,6 +151,18 @@ public class Level extends Thread implements ILevel {
|
||||||
getBall().newRandomColor();
|
getBall().newRandomColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call here the balls method for reacting on stones of the playground
|
||||||
|
if(getBall().hitsStone(getStones())) {
|
||||||
|
updateStonesAndScore();
|
||||||
|
//System.out.println("count: "+stones.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// if all stones are broken, go to next level
|
||||||
|
if(allStonesBroken()) {
|
||||||
|
// next level
|
||||||
|
//System.out.println("next level");
|
||||||
|
}
|
||||||
|
|
||||||
// update paddles position
|
// update paddles position
|
||||||
getPaddleTop().updatePosition(getBall());
|
getPaddleTop().updatePosition(getBall());
|
||||||
getPaddleBottom().updatePosition(getBall());
|
getPaddleBottom().updatePosition(getBall());
|
||||||
|
@ -163,7 +187,35 @@ public class Level extends Thread implements ILevel {
|
||||||
* @param levelnr The number X for the LevelX.json file
|
* @param levelnr The number X for the LevelX.json file
|
||||||
*/
|
*/
|
||||||
private void loadLevelData(int levelnr) {
|
private void loadLevelData(int levelnr) {
|
||||||
|
JSONReader reader = new JSONReader(String.format("res/Level%s.json", levelnr));
|
||||||
|
int[][] stoneTypes = reader.getStones2DArray();
|
||||||
|
|
||||||
|
// life counter
|
||||||
|
lifeCounter = reader.getLifeCounter();
|
||||||
|
|
||||||
|
// clear stones list, not needed but could cause problems when not done
|
||||||
|
stones.clear();
|
||||||
|
|
||||||
|
// foreach column
|
||||||
|
for(int y = 0; y < stoneTypes.length; y++) {
|
||||||
|
// foreach element in column x
|
||||||
|
for(int x = 0; x < stoneTypes[y].length; x++) {
|
||||||
|
Position tempPos = new Position(-1, -1);
|
||||||
|
// position calculation, equivalent to grid calculation in "view.Field"
|
||||||
|
|
||||||
|
// size of grid blocks
|
||||||
|
int blockWidth = Constants.SCREEN_WIDTH / Constants.SQUARES_X;
|
||||||
|
int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y;
|
||||||
|
|
||||||
|
tempPos.setX(blockWidth * x);
|
||||||
|
tempPos.setY(blockHeight * y);
|
||||||
|
Stone tempStone = new Stone(stoneTypes[y][x], tempPos);
|
||||||
|
|
||||||
|
// add stone to list
|
||||||
|
if(tempStone.getType() != 0)
|
||||||
|
stones.add(tempStone);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,9 +241,110 @@ public class Level extends Thread implements ILevel {
|
||||||
* @param finished game state
|
* @param finished game state
|
||||||
*/
|
*/
|
||||||
public void setFinished(boolean finished) {
|
public void setFinished(boolean finished) {
|
||||||
this.levelFinished = finished;
|
this.finished = finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The getter for the levels stones
|
||||||
|
* @return stones The stones of the level
|
||||||
|
*/
|
||||||
|
public ArrayList<Stone> getStones() {
|
||||||
|
// hacky workaround for ConcurrentModificationExceptions
|
||||||
|
ArrayList<Stone> copy = new ArrayList<>();
|
||||||
|
copy.addAll(stones);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The updater for the levels stones and the player score
|
||||||
|
*/
|
||||||
|
private void updateStonesAndScore() {
|
||||||
|
// hit stone
|
||||||
|
Stone stone = getBall().getHitStone();
|
||||||
|
|
||||||
|
// add value to score
|
||||||
|
score += stone.getValue();
|
||||||
|
|
||||||
|
// set new type
|
||||||
|
stone.setType(stone.getType()-1);
|
||||||
|
|
||||||
|
// stones type is 0? remove it!
|
||||||
|
if(stone.getType() == 0) {
|
||||||
|
stones.remove(stone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(allStonesBroken()) {
|
||||||
|
setFinished(true);
|
||||||
|
nextLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks whether all stones are broken
|
||||||
|
* @return true when all stones are broken
|
||||||
|
*/
|
||||||
|
private boolean allStonesBroken() {
|
||||||
|
return stones.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* decreases the lives and interact to the new count
|
||||||
|
*/
|
||||||
|
private void decreaseLives() {
|
||||||
|
lifeCounter--;
|
||||||
|
// reset paddles to center pos
|
||||||
|
if(lifeCounter > 0) {
|
||||||
|
resetPaddles();
|
||||||
|
getBall().resetPosition();
|
||||||
|
getBall().resetDirection();
|
||||||
|
getBall().setLost(false);
|
||||||
|
stopBall();
|
||||||
|
// level failed
|
||||||
|
} else {
|
||||||
|
setFinished(true);
|
||||||
|
game.getController().toStartScreen(getScore());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets paddles position and or init them
|
||||||
|
*/
|
||||||
|
private void resetPaddles() {
|
||||||
|
// calc paddle positions
|
||||||
|
Position posPaddleTop = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, 0);
|
||||||
|
Position posPaddleBottom = new Position((Constants.SCREEN_WIDTH - Constants.PADDLE_WIDTH) / 2.0, Constants.SCREEN_HEIGHT - Constants.PADDLE_HEIGHT);
|
||||||
|
|
||||||
|
// resets top paddle
|
||||||
|
if(paddleTop == null) paddleTop = new Paddle(posPaddleTop);
|
||||||
|
else paddleTop.setPosition(posPaddleTop);
|
||||||
|
|
||||||
|
// resets bottom paddle
|
||||||
|
if(paddleBottom == null) paddleBottom = new Paddle(posPaddleBottom);
|
||||||
|
else paddleBottom.setPosition(posPaddleBottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The getter for levels score
|
||||||
|
* @return the score
|
||||||
|
*/
|
||||||
|
public int getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The getter for levels lives
|
||||||
|
* @return the life counter
|
||||||
|
*/
|
||||||
|
public int getLives() {
|
||||||
|
return lifeCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* switch to next level
|
||||||
|
*/
|
||||||
|
public void nextLevel() {
|
||||||
|
game.createLevel(++levelnr, score);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,9 +136,10 @@ public class Paddle implements IPaddle {
|
||||||
* @param direction The paddles new direction
|
* @param direction The paddles new direction
|
||||||
*/
|
*/
|
||||||
public void setDirection(int direction) {
|
public void setDirection(int direction) {
|
||||||
|
// normalization not needed
|
||||||
// normalize to valid values
|
// normalize to valid values
|
||||||
if(direction > 0) direction = 1;
|
//if(direction > 0) direction = 1;
|
||||||
if(direction < 0) direction = -1;
|
//if(direction < 0) direction = -1;
|
||||||
|
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,14 +112,14 @@ public class Stone implements IStone {
|
||||||
* @param type The stones new type
|
* @param type The stones new type
|
||||||
*/
|
*/
|
||||||
public void setType(int type) {
|
public void setType(int type) {
|
||||||
// type not in range
|
|
||||||
if(type > 3) { type = 0; }
|
// set the type; no verification needed;
|
||||||
setValue(type);
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
// multi-case, hacky, but dont care
|
// multi-case, hacky, but dont care
|
||||||
case 0:
|
case 0:
|
||||||
// naah, isnt a stone
|
// nah, isn't a stone
|
||||||
default:
|
default:
|
||||||
// default case, not in range
|
// default case, not in range
|
||||||
// setting to not a stone
|
// setting to not a stone
|
||||||
|
@ -127,15 +127,18 @@ public class Stone implements IStone {
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// stone type one
|
// stone type one
|
||||||
setColor(Color.CYAN);
|
setColor(new Color(77, 80, 140));
|
||||||
|
setValue(1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// stone type two
|
// stone type two
|
||||||
setColor(Color.WHITE);
|
setColor(new Color(242, 191, 94));
|
||||||
|
setValue(2);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// stone type three
|
// stone type three
|
||||||
setColor(Color.BLUE);
|
setColor(new Color(242, 80, 65));
|
||||||
|
setValue(3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package break_out.view;
|
package break_out.view;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.font.TextAttribute;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import break_out.Constants;
|
import break_out.Constants;
|
||||||
|
import break_out.model.Position;
|
||||||
|
import break_out.model.Stone;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +106,9 @@ public class Field extends JPanel {
|
||||||
// Calls the method for drawing the grid
|
// Calls the method for drawing the grid
|
||||||
drawGrid(g2);
|
drawGrid(g2);
|
||||||
|
|
||||||
|
// Calls the method for drawing the stones
|
||||||
|
drawStones(g2);
|
||||||
|
|
||||||
// Calls the method for drawing the ball
|
// Calls the method for drawing the ball
|
||||||
drawBall(g2);
|
drawBall(g2);
|
||||||
|
|
||||||
|
@ -108,6 +118,9 @@ public class Field extends JPanel {
|
||||||
// Calls the method for drawing the top paddle
|
// Calls the method for drawing the top paddle
|
||||||
drawPaddleTop(g2);
|
drawPaddleTop(g2);
|
||||||
|
|
||||||
|
// Calls the method for drawing the scoreboard
|
||||||
|
drawScoreboard(g2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,4 +218,134 @@ public class Field extends JPanel {
|
||||||
g2.setColor(temp);
|
g2.setColor(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the stones
|
||||||
|
*
|
||||||
|
* @param g2 The graphics object
|
||||||
|
*/
|
||||||
|
private void drawStones(Graphics2D g2) {
|
||||||
|
// query stones
|
||||||
|
ArrayList<Stone> stones = view.getGame().getLevel().getStones();
|
||||||
|
|
||||||
|
// foreach stone
|
||||||
|
for(Stone stone : stones) {
|
||||||
|
Position pos = stone.getPosition();
|
||||||
|
|
||||||
|
// size of grid blocks
|
||||||
|
int blockWidth = Constants.SCREEN_WIDTH / Constants.SQUARES_X;
|
||||||
|
int blockHeight = Constants.SCREEN_HEIGHT / Constants.SQUARES_Y;
|
||||||
|
|
||||||
|
// if stone has a color, draw it
|
||||||
|
if(stone.getColor() != null) {
|
||||||
|
|
||||||
|
// temporarily save default component color to draw stone in specific color
|
||||||
|
Color temp = g2.getColor();
|
||||||
|
g2.setColor(stone.getColor());
|
||||||
|
|
||||||
|
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
|
||||||
|
g2.fillRoundRect((int) pos.getX()+1,
|
||||||
|
(int) pos.getY()+1,
|
||||||
|
(int) blockWidth-1,
|
||||||
|
(int) blockHeight-1,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
|
||||||
|
// reset color to default
|
||||||
|
g2.setColor(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the scoreboard with score and lives
|
||||||
|
* @param g2
|
||||||
|
*/
|
||||||
|
private void drawScoreboard(Graphics2D g2) {
|
||||||
|
Font currentFont = g2.getFont();
|
||||||
|
|
||||||
|
// source: <a href="https://stackoverflow.com/questions/18249592/"> Stackoverflow Question - 18249592 </a>
|
||||||
|
Map<TextAttribute, Object> attributes = new HashMap<>();
|
||||||
|
attributes.put(TextAttribute.FAMILY, currentFont.getFamily());
|
||||||
|
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||||
|
attributes.put(TextAttribute.SIZE, (int) (currentFont.getSize() * 1.8));
|
||||||
|
Font myFont = Font.getFont(attributes);
|
||||||
|
g2.setFont(myFont);
|
||||||
|
|
||||||
|
// temporarily save default component color to draw text and background in specific color
|
||||||
|
Color temp = g2.getColor();
|
||||||
|
|
||||||
|
// draw background in specific color
|
||||||
|
g2.setColor(Constants.COLOR_SCOREBOARD);
|
||||||
|
|
||||||
|
// bottom centered mid-point
|
||||||
|
int midX = (int) Constants.SCOREBOARD_MIDPOINT.getX();
|
||||||
|
int midY = (int) Constants.SCOREBOARD_MIDPOINT.getY();
|
||||||
|
|
||||||
|
int offset = Constants.SCOREBOARD_OFFSET;
|
||||||
|
|
||||||
|
// calculate rendered string width
|
||||||
|
int scoreWidth = g2.getFontMetrics().stringWidth(Constants.SCOREBOARD_SCORE + view.getGame().getLevel().getScore());
|
||||||
|
int lifeWidth = g2.getFontMetrics().stringWidth(Constants.SCOREBOARD_LIVES + view.getGame().getLevel().getLives());
|
||||||
|
int maxWidth = Math.max(scoreWidth, lifeWidth); // max width
|
||||||
|
int fontSize = g2.getFontMetrics().getHeight(); // font size
|
||||||
|
|
||||||
|
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
|
||||||
|
g2.fillRoundRect((midX)-offset-maxWidth/2, midY-2*offset-3*fontSize, maxWidth+2*offset, 2*(fontSize+offset), 5, 5);
|
||||||
|
|
||||||
|
// draw text in specific color (sharing g2 object and therefore also color)
|
||||||
|
g2.setColor(Constants.COLOR_TEXT);
|
||||||
|
|
||||||
|
// draw score and lives
|
||||||
|
drawScore(g2);
|
||||||
|
drawLives(g2);
|
||||||
|
|
||||||
|
// reset color and font
|
||||||
|
g2.setColor(temp);
|
||||||
|
g2.setFont(currentFont);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the score
|
||||||
|
*
|
||||||
|
* @param g2 The graphics object
|
||||||
|
*/
|
||||||
|
private void drawScore(Graphics2D g2) {
|
||||||
|
int score = view.getGame().getLevel().getScore();
|
||||||
|
|
||||||
|
int fontSize = g2.getFontMetrics().getHeight(); // font size
|
||||||
|
|
||||||
|
// bottom centered mid-point
|
||||||
|
int x = (int) Constants.SCOREBOARD_MIDPOINT.getX();
|
||||||
|
int y = (int) Constants.SCOREBOARD_MIDPOINT.getY()-(int)((3.0/2.0)*fontSize);
|
||||||
|
|
||||||
|
String str = Constants.SCOREBOARD_SCORE+score;
|
||||||
|
|
||||||
|
x -= g2.getFontMetrics().stringWidth(str)/2; // because x is middle position on x axis
|
||||||
|
|
||||||
|
// draw string
|
||||||
|
g2.drawString(str, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the life counter
|
||||||
|
*
|
||||||
|
* @param g2 The graphics object
|
||||||
|
*/
|
||||||
|
private void drawLives(Graphics2D g2) {
|
||||||
|
int lives = view.getGame().getLevel().getLives();
|
||||||
|
|
||||||
|
int fontSize = g2.getFontMetrics().getHeight(); // font size
|
||||||
|
|
||||||
|
// bottom centered mid-point
|
||||||
|
int x = (int) Constants.SCOREBOARD_MIDPOINT.getX();
|
||||||
|
int y = (int) Constants.SCOREBOARD_MIDPOINT.getY()-3*fontSize;
|
||||||
|
|
||||||
|
String str = Constants.SCOREBOARD_LIVES+lives;
|
||||||
|
|
||||||
|
x -= g2.getFontMetrics().stringWidth(str)/2; // because x is middle position on x axis
|
||||||
|
|
||||||
|
// draw string
|
||||||
|
g2.drawString(str, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,11 @@ public class StartScreen extends JPanel {
|
||||||
*/
|
*/
|
||||||
private JLabel error;
|
private JLabel error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scoreMenu
|
||||||
|
*/
|
||||||
|
private SectionPanel scoreMenu;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor needs a view
|
* The constructor needs a view
|
||||||
|
@ -125,16 +130,16 @@ public class StartScreen extends JPanel {
|
||||||
*/
|
*/
|
||||||
private void initializeScoreMenu() {
|
private void initializeScoreMenu() {
|
||||||
// The layout
|
// The layout
|
||||||
SectionPanel scoreMenu = new SectionPanel(Color.WHITE);
|
scoreMenu = new SectionPanel(Color.WHITE);
|
||||||
scoreMenu.shady = false;
|
scoreMenu.shady = false;
|
||||||
scoreMenu.setLayout(new MigLayout("", "10[center, grow, fill]10",
|
scoreMenu.setLayout(new MigLayout("", "10[center, grow, fill]10",
|
||||||
"5[center]5"));
|
"5[center]5"));
|
||||||
|
|
||||||
// adding the compoenents to the layout
|
// adding the components to the layout
|
||||||
JLabel headline = new JLabel("Scores");
|
JLabel headline = new JLabel("Scores");
|
||||||
headline.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
headline.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||||
headline.setHorizontalAlignment(SwingConstants.CENTER);
|
headline.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
scoreMenu.add(headline, "cell 0 0, gaptop 5");
|
scoreMenu.add(headline, "cell 0 0, gaptop 5, wrap");
|
||||||
|
|
||||||
add(scoreMenu, "cell 1 0, gapleft 5");
|
add(scoreMenu, "cell 1 0, gapleft 5");
|
||||||
}
|
}
|
||||||
|
@ -200,4 +205,28 @@ public class StartScreen extends JPanel {
|
||||||
error.setText("");
|
error.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a score to the scoreboard
|
||||||
|
* @param score
|
||||||
|
*/
|
||||||
|
public void addScore(int score) {
|
||||||
|
// adding the components to the layout
|
||||||
|
|
||||||
|
// name
|
||||||
|
JLabel lName = new JLabel(getPlayersName());
|
||||||
|
lName.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||||
|
lName.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
scoreMenu.add(lName, "gaptop 5");
|
||||||
|
|
||||||
|
// spacing
|
||||||
|
JLabel space = new JLabel();
|
||||||
|
scoreMenu.add(space);
|
||||||
|
|
||||||
|
// score
|
||||||
|
JLabel lScore = new JLabel(String.valueOf(score));
|
||||||
|
lScore.setFont(new Font("Sans-serif", Font.PLAIN, 16));
|
||||||
|
lScore.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
scoreMenu.add(lScore, "gaptop 5, wrap");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue