From 409735d94ee8864d7ae32c01be5197d802dc1dea Mon Sep 17 00:00:00 2001 From: Matt Low Date: Tue, 13 Nov 2018 17:17:19 +0400 Subject: [PATCH] Scale entity units to new board units. Rename Brick.BLOCK_ to Brick.BRICK_ --- core/src/com/me/brickbuster/entity/Ball.java | 10 ++++++---- core/src/com/me/brickbuster/entity/Brick.java | 12 ++++++------ core/src/com/me/brickbuster/entity/Paddle.java | 8 ++++---- .../entity/powerup/LongerPaddlePowerUp.java | 4 ++-- .../me/brickbuster/entity/powerup/PowerUp.java | 6 +++--- .../com/me/brickbuster/state/PlayState.java | 18 ++++++++++++------ 6 files changed, 33 insertions(+), 25 deletions(-) diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index c48a6dd..61e2fe1 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -15,10 +15,10 @@ import java.util.Iterator; public class Ball extends Entity { - public static final int RADIUS = 12; + public static final int RADIUS = 45; public static final Color BALL_COLOR = Color.CHARTREUSE; - public static final float DEFAULT_SPEED = 350; - public static final float BOOST_SPEED = 450; + public static final float DEFAULT_SPEED = 1400; + public static final float BOOST_SPEED = 1800; public static final int BLOCKS_FOR_BOOST = 39; public Vector2 direction; @@ -101,7 +101,9 @@ public class Ball extends Entity { } public Vector2 paddleReflectAngle() { - float rel = MathUtils.clamp((pos.x - state.paddle.getX()) + (state.paddle.getWidth()/2), 5, state.paddle.getWidth()-5); + int trim = (int) (state.paddle.getWidth() * 0.10); + float rel = MathUtils.clamp((pos.x - state.paddle.getX()) + (state.paddle.getWidth()/2), + trim, state.paddle.getWidth()-trim); float newAngle = MathUtils.PI - (MathUtils.PI * (rel / state.paddle.getWidth())); return new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle)); } diff --git a/core/src/com/me/brickbuster/entity/Brick.java b/core/src/com/me/brickbuster/entity/Brick.java index 53ed380..d48ffb0 100644 --- a/core/src/com/me/brickbuster/entity/Brick.java +++ b/core/src/com/me/brickbuster/entity/Brick.java @@ -10,8 +10,8 @@ import com.me.brickbuster.state.PlayState; public class Brick extends Entity { public static final Color BLOCK_COLOR = Color.FOREST; - public static final int BLOCK_WIDTH = 50; - public static final int BLOCK_HEIGHT = 20; + public static final int BRICK_WIDTH = 200; + public static final int BRICK_HEIGHT = 100; private Class powerUpType; @@ -23,9 +23,9 @@ public class Brick extends Entity { this.vertices = new Vector2[] { new Vector2(x, y), - new Vector2(x + BLOCK_WIDTH, y), - new Vector2(x + BLOCK_WIDTH, y + BLOCK_HEIGHT), - new Vector2(x, y + BLOCK_HEIGHT) + new Vector2(x + BRICK_WIDTH, y), + new Vector2(x + BRICK_WIDTH, y + BRICK_HEIGHT), + new Vector2(x, y + BRICK_HEIGHT) }; } @@ -33,7 +33,7 @@ public class Brick extends Entity { public void render(ShapeRenderer sr) { sr.begin(ShapeType.Filled); sr.setColor(BLOCK_COLOR); - sr.rect(getX(), getY(), BLOCK_WIDTH, BLOCK_HEIGHT); + sr.rect(getX(), getY(), BRICK_WIDTH, BRICK_HEIGHT); sr.end(); } diff --git a/core/src/com/me/brickbuster/entity/Paddle.java b/core/src/com/me/brickbuster/entity/Paddle.java index 510e86b..1ae44f2 100644 --- a/core/src/com/me/brickbuster/entity/Paddle.java +++ b/core/src/com/me/brickbuster/entity/Paddle.java @@ -13,10 +13,10 @@ import net.dermetfan.utils.Pair; public class Paddle extends Entity { public static final Color PADDLE_COLOR = Color.BLACK; - public static final int DEFAULT_WIDTH = 100; - public static final int PADDLE_HEIGHT = 10; - public static final int PADDLE_Y = 15; - public static final int PADDLE_SPEED = 375; + public static final int DEFAULT_WIDTH = 300; + public static final int PADDLE_HEIGHT = 30; + public static final int PADDLE_Y = 50; + public static final int PADDLE_SPEED = 1500; private int width = DEFAULT_WIDTH; private boolean sticky = false; diff --git a/core/src/com/me/brickbuster/entity/powerup/LongerPaddlePowerUp.java b/core/src/com/me/brickbuster/entity/powerup/LongerPaddlePowerUp.java index 9463d0f..fbe53bf 100644 --- a/core/src/com/me/brickbuster/entity/powerup/LongerPaddlePowerUp.java +++ b/core/src/com/me/brickbuster/entity/powerup/LongerPaddlePowerUp.java @@ -13,8 +13,8 @@ public class LongerPaddlePowerUp extends PowerUp { @Override public void activate() { - if (state.paddle.getWidth() < 250) { - state.paddle.setWidth(state.paddle.getWidth() + 50); + if (state.paddle.getWidth() < Paddle.DEFAULT_WIDTH*2.5) { + state.paddle.setWidth(state.paddle.getWidth() + Paddle.DEFAULT_WIDTH/2); } } } diff --git a/core/src/com/me/brickbuster/entity/powerup/PowerUp.java b/core/src/com/me/brickbuster/entity/powerup/PowerUp.java index 6915b43..baa0d17 100644 --- a/core/src/com/me/brickbuster/entity/powerup/PowerUp.java +++ b/core/src/com/me/brickbuster/entity/powerup/PowerUp.java @@ -12,14 +12,14 @@ import net.dermetfan.utils.Pair; public abstract class PowerUp extends Entity { - public static final int RADIUS = 10; - public static final int FALL_SPEED = 100; + public static final int RADIUS = 45; + public static final int FALL_SPEED = 600; private Color color; private boolean isCaught; public PowerUp(PlayState state, Brick brick, Color color) { - super(state, brick.getX() + Brick.BLOCK_WIDTH/2, brick.getY() + Brick.BLOCK_HEIGHT/2); + super(state, brick.getX() + Brick.BRICK_WIDTH/2, brick.getY() + Brick.BRICK_HEIGHT/2); this.color = color; } diff --git a/core/src/com/me/brickbuster/state/PlayState.java b/core/src/com/me/brickbuster/state/PlayState.java index 0dcf030..813935c 100644 --- a/core/src/com/me/brickbuster/state/PlayState.java +++ b/core/src/com/me/brickbuster/state/PlayState.java @@ -14,9 +14,12 @@ import java.util.*; public class PlayState extends State { - public static final int SHIELD_HEIGHT = 5; + public static final int SHIELD_HEIGHT = 30; public static final float POWERUP_CHANCE = 0.15f; + public static final int COLUMNS = 9; + public static final int ROWS = 8; + public static final Map, Integer> powerUpWeights; private static final int weightSum; @@ -38,15 +41,18 @@ public class PlayState extends State { powerUps = new ArrayList(); paddle = new Paddle(this); + int brick_padding = (BrickBuster.BOARD_WIDTH - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1); bricks = new ArrayList(); - for (int col = 0; col < 13; col++) { - for (int row = 0; row < 7; row++) { - int x = 15 + (col * (Brick.BLOCK_WIDTH + 10)); - int y = 15 + Brick.BLOCK_HEIGHT + (row * (Brick.BLOCK_HEIGHT + 10)); + for (int col = 0; col < COLUMNS; col++) { + for (int row = 0; row < ROWS; row++) { + int x = brick_padding + (col * (Brick.BRICK_WIDTH + brick_padding)); + int y = brick_padding + Brick.BRICK_HEIGHT + (row * (Brick.BRICK_HEIGHT + brick_padding)); + Class powerUpType = null; if (MathUtils.randomBoolean(POWERUP_CHANCE)) { powerUpType = getWeightedPowerUp(); } + bricks.add(new Brick(this, powerUpType, x, BrickBuster.BOARD_HEIGHT - y)); } } @@ -80,7 +86,7 @@ public class PlayState extends State { game.sb.begin(); game.font.setColor(Color.GRAY); game.font.draw(game.sb, String.format("FPS: %d Update: %.2f ms Render: %.2f ms", - Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 0, 13); + Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 10, BrickBuster.BOARD_HEIGHT-10); game.sb.end(); }