1
0
Fork 0

custom color for paddles

This commit is contained in:
rxbn_ 2019-12-12 19:20:52 +01:00
parent e782ad2017
commit 75ee56adce
3 changed files with 28 additions and 0 deletions

View File

@ -74,4 +74,14 @@ public class Constants {
*/
public static final Double BALL_SPEED = 1.20;
/**
* The component color for the bottom paddle
*/
public static final Color COLOR_PADDLE_BOTTOM = new Color(226, 215, 73);
/**
* The component color for the top paddle
*/
public static final Color COLOR_PADDLE_TOP = new Color(140, 226, 165);
}

View File

@ -63,6 +63,10 @@ public class Level extends Thread implements ILevel {
this.paddleTop = new Paddle(posPaddleTop);
this.paddleBottom = new Paddle(posPaddleBottom);
// set paddles color
this.paddleTop.setColor(Constants.COLOR_PADDLE_TOP);
this.paddleBottom.setColor(Constants.COLOR_PADDLE_BOTTOM);
loadLevelData(levelnr);
}

View File

@ -150,6 +150,10 @@ public class Field extends JPanel {
* @param g2 The graphics object
*/
private void drawPaddleBottom(Graphics2D g2) {
// temporarily save default component color to draw paddle in specific color
Color temp = g2.getColor();
g2.setColor(view.getGame().getLevel().getPaddleBottom().getColor());
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
g2.fillRoundRect((int) view.getGame().getLevel().getPaddleBottom().getPosition().getX(),
(int) view.getGame().getLevel().getPaddleBottom().getPosition().getY(),
@ -157,6 +161,9 @@ public class Field extends JPanel {
(int) view.getGame().getLevel().getPaddleBottom().getHeight(),
10,
10);
// reset color to default
g2.setColor(temp);
}
/**
@ -165,6 +172,10 @@ public class Field extends JPanel {
* @param g2 The graphics object
*/
private void drawPaddleTop(Graphics2D g2) {
// temporarily save default component color to draw paddle in specific color
Color temp = g2.getColor();
g2.setColor(view.getGame().getLevel().getPaddleTop().getColor());
// fillRoundRect(x, y, width, height, arcWidth, arcHeight)
g2.fillRoundRect((int) view.getGame().getLevel().getPaddleTop().getPosition().getX(),
(int) view.getGame().getLevel().getPaddleTop().getPosition().getY(),
@ -172,6 +183,9 @@ public class Field extends JPanel {
(int) view.getGame().getLevel().getPaddleTop().getHeight(),
10,
10);
// reset color to default
g2.setColor(temp);
}
}