Compare commits
No commits in common. "0abae880d3d987e12bd22c4cd9ebf6d4d63931da" and "1c7e20f8e94a9399d5106019ed9b1150d30a56e9" have entirely different histories.
0abae880d3
...
1c7e20f8e9
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB |
@ -3,24 +3,16 @@ package com.me.brickbuster;
|
|||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
import com.me.brickbuster.state.PlayState;
|
||||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
|
||||||
import com.me.brickbuster.state.MenuState;
|
|
||||||
|
|
||||||
public class BrickBuster extends Game {
|
public class BrickBuster extends Game {
|
||||||
|
|
||||||
|
public static final int WIDTH = 800;
|
||||||
|
public static final int HEIGHT = 600;
|
||||||
public static final String TITLE = "Brick Buster";
|
public static final String TITLE = "Brick Buster";
|
||||||
// 9*16 board area
|
|
||||||
public static final int BOARD_WIDTH = 2160;
|
|
||||||
public static final int BOARD_HEIGHT = 3840;
|
|
||||||
|
|
||||||
public OrthographicCamera cam;
|
|
||||||
public Viewport viewport;
|
|
||||||
|
|
||||||
public BitmapFont font;
|
public BitmapFont font;
|
||||||
public SpriteBatch sb;
|
public SpriteBatch sb;
|
||||||
@ -28,18 +20,11 @@ public class BrickBuster extends Game {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
cam = new OrthographicCamera();
|
|
||||||
viewport = new FitViewport(BOARD_WIDTH, BOARD_HEIGHT, cam);
|
|
||||||
viewport.apply(true);
|
|
||||||
|
|
||||||
font = new BitmapFont();
|
font = new BitmapFont();
|
||||||
font.getData().setScale(4);
|
|
||||||
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
|
||||||
|
|
||||||
sb = new SpriteBatch();
|
sb = new SpriteBatch();
|
||||||
sr = new ShapeRenderer();
|
sr = new ShapeRenderer();
|
||||||
|
|
||||||
setScreen(new MenuState(this));
|
setScreen(new PlayState(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,14 +35,4 @@ public class BrickBuster extends Game {
|
|||||||
super.render();
|
super.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resize(int width, int height) {
|
|
||||||
viewport.update(width, height);
|
|
||||||
|
|
||||||
sb.setProjectionMatrix(cam.combined);
|
|
||||||
sr.setProjectionMatrix(cam.combined);
|
|
||||||
|
|
||||||
super.resize(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
public class Ball extends Entity {
|
public class Ball extends Entity {
|
||||||
|
|
||||||
public static final int RADIUS = 45;
|
public static final int RADIUS = 12;
|
||||||
public static final Color BALL_COLOR = Color.CHARTREUSE;
|
public static final Color BALL_COLOR = Color.CHARTREUSE;
|
||||||
public static final float DEFAULT_SPEED = 1800;
|
public static final float DEFAULT_SPEED = 350;
|
||||||
public static final float BOOST_SPEED = 2200;
|
public static final float BOOST_SPEED = 450;
|
||||||
public static final int BLOCKS_FOR_BOOST = 39;
|
public static final int BLOCKS_FOR_BOOST = 39;
|
||||||
|
|
||||||
public Vector2 direction;
|
public Vector2 direction;
|
||||||
@ -27,7 +27,7 @@ public class Ball extends Entity {
|
|||||||
private boolean isDead = false;
|
private boolean isDead = false;
|
||||||
|
|
||||||
public Ball(PlayState state) {
|
public Ball(PlayState state) {
|
||||||
super(state,BrickBuster.BOARD_WIDTH /2, state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
super(state,BrickBuster.WIDTH/2, state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||||
this.speed = state.bricks.size() > BLOCKS_FOR_BOOST? DEFAULT_SPEED : BOOST_SPEED;
|
this.speed = state.bricks.size() > BLOCKS_FOR_BOOST? DEFAULT_SPEED : BOOST_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ public class Ball extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_pos.x + RADIUS > BrickBuster.BOARD_WIDTH || new_pos.x - RADIUS < 0) {
|
if (new_pos.x + RADIUS > BrickBuster.WIDTH || new_pos.x - RADIUS < 0) {
|
||||||
Utils.reflect(direction, Utils.VERTICAL_EDGE);
|
Utils.reflect(direction, Utils.VERTICAL_EDGE);
|
||||||
} else if (new_pos.y + RADIUS > BrickBuster.BOARD_HEIGHT) {
|
} else if (new_pos.y + RADIUS > BrickBuster.HEIGHT) {
|
||||||
Utils.reflect(direction, Utils.HORIZONTAL_EDGE);
|
Utils.reflect(direction, Utils.HORIZONTAL_EDGE);
|
||||||
} else if (state.getShieldCount() > 0
|
} else if (state.getShieldCount() > 0
|
||||||
&& new_pos.y - RADIUS < PlayState.SHIELD_HEIGHT * state.getShieldCount()) {
|
&& new_pos.y - RADIUS < PlayState.SHIELD_HEIGHT * state.getShieldCount()) {
|
||||||
@ -101,9 +101,7 @@ public class Ball extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 paddleReflectAngle() {
|
public Vector2 paddleReflectAngle() {
|
||||||
int trim = (int) (state.paddle.getWidth() * 0.10);
|
float rel = MathUtils.clamp((pos.x - state.paddle.getX()) + (state.paddle.getWidth()/2), 5, state.paddle.getWidth()-5);
|
||||||
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()));
|
float newAngle = MathUtils.PI - (MathUtils.PI * (rel / state.paddle.getWidth()));
|
||||||
return new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle));
|
return new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle));
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import com.me.brickbuster.state.PlayState;
|
|||||||
public class Brick extends Entity {
|
public class Brick extends Entity {
|
||||||
|
|
||||||
public static final Color BLOCK_COLOR = Color.FOREST;
|
public static final Color BLOCK_COLOR = Color.FOREST;
|
||||||
public static final int BRICK_WIDTH = 200;
|
public static final int BLOCK_WIDTH = 50;
|
||||||
public static final int BRICK_HEIGHT = 100;
|
public static final int BLOCK_HEIGHT = 20;
|
||||||
|
|
||||||
private Class<? extends PowerUp> powerUpType;
|
private Class<? extends PowerUp> powerUpType;
|
||||||
|
|
||||||
@ -23,9 +23,9 @@ public class Brick extends Entity {
|
|||||||
|
|
||||||
this.vertices = new Vector2[] {
|
this.vertices = new Vector2[] {
|
||||||
new Vector2(x, y),
|
new Vector2(x, y),
|
||||||
new Vector2(x + BRICK_WIDTH, y),
|
new Vector2(x + BLOCK_WIDTH, y),
|
||||||
new Vector2(x + BRICK_WIDTH, y + BRICK_HEIGHT),
|
new Vector2(x + BLOCK_WIDTH, y + BLOCK_HEIGHT),
|
||||||
new Vector2(x, y + BRICK_HEIGHT)
|
new Vector2(x, y + BLOCK_HEIGHT)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class Brick extends Entity {
|
|||||||
public void render(ShapeRenderer sr) {
|
public void render(ShapeRenderer sr) {
|
||||||
sr.begin(ShapeType.Filled);
|
sr.begin(ShapeType.Filled);
|
||||||
sr.setColor(BLOCK_COLOR);
|
sr.setColor(BLOCK_COLOR);
|
||||||
sr.rect(getX(), getY(), BRICK_WIDTH, BRICK_HEIGHT);
|
sr.rect(getX(), getY(), BLOCK_WIDTH, BLOCK_HEIGHT);
|
||||||
sr.end();
|
sr.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,16 +13,16 @@ import net.dermetfan.utils.Pair;
|
|||||||
public class Paddle extends Entity {
|
public class Paddle extends Entity {
|
||||||
|
|
||||||
public static final Color PADDLE_COLOR = Color.BLACK;
|
public static final Color PADDLE_COLOR = Color.BLACK;
|
||||||
public static final int DEFAULT_WIDTH = 300;
|
public static final int DEFAULT_WIDTH = 100;
|
||||||
public static final int PADDLE_HEIGHT = 30;
|
public static final int PADDLE_HEIGHT = 10;
|
||||||
public static final int PADDLE_Y = 50;
|
public static final int PADDLE_Y = 15;
|
||||||
public static final int PADDLE_SPEED = 1500;
|
public static final int PADDLE_SPEED = 375;
|
||||||
|
|
||||||
private int width = DEFAULT_WIDTH;
|
private int width = DEFAULT_WIDTH;
|
||||||
private boolean sticky = false;
|
private boolean sticky = false;
|
||||||
|
|
||||||
public Paddle(PlayState brickBuster) {
|
public Paddle(PlayState brickBuster) {
|
||||||
super(brickBuster, BrickBuster.BOARD_WIDTH / 2, PADDLE_Y);
|
super(brickBuster, BrickBuster.WIDTH / 2, PADDLE_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,8 +49,8 @@ public class Paddle extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
||||||
if (pos.x + width/2 + PADDLE_SPEED * dt > BrickBuster.BOARD_WIDTH) {
|
if (pos.x + width/2 + PADDLE_SPEED * dt > BrickBuster.WIDTH) {
|
||||||
setX(BrickBuster.BOARD_WIDTH - width/2);
|
setX(BrickBuster.WIDTH - width/2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pos.x = pos.x + PADDLE_SPEED * dt;
|
pos.x = pos.x + PADDLE_SPEED * dt;
|
||||||
|
@ -13,8 +13,8 @@ public class LongerPaddlePowerUp extends PowerUp {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate() {
|
public void activate() {
|
||||||
if (state.paddle.getWidth() < Paddle.DEFAULT_WIDTH*2.5) {
|
if (state.paddle.getWidth() < 250) {
|
||||||
state.paddle.setWidth(state.paddle.getWidth() + Paddle.DEFAULT_WIDTH/2);
|
state.paddle.setWidth(state.paddle.getWidth() + 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,14 @@ import net.dermetfan.utils.Pair;
|
|||||||
|
|
||||||
public abstract class PowerUp extends Entity {
|
public abstract class PowerUp extends Entity {
|
||||||
|
|
||||||
public static final int RADIUS = 45;
|
public static final int RADIUS = 10;
|
||||||
public static final int FALL_SPEED = 600;
|
public static final int FALL_SPEED = 100;
|
||||||
|
|
||||||
private Color color;
|
private Color color;
|
||||||
private boolean isCaught;
|
private boolean isCaught;
|
||||||
|
|
||||||
public PowerUp(PlayState state, Brick brick, Color color) {
|
public PowerUp(PlayState state, Brick brick, Color color) {
|
||||||
super(state, brick.getX() + Brick.BRICK_WIDTH/2, brick.getY() + Brick.BRICK_HEIGHT/2);
|
super(state, brick.getX() + Brick.BLOCK_WIDTH/2, brick.getY() + Brick.BLOCK_HEIGHT/2);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
package com.me.brickbuster.state;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.math.Vector3;
|
|
||||||
import com.me.brickbuster.BrickBuster;
|
|
||||||
|
|
||||||
public class MenuState extends State {
|
|
||||||
|
|
||||||
private Texture playButton;
|
|
||||||
|
|
||||||
public MenuState(BrickBuster game) {
|
|
||||||
super(game);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setup() {
|
|
||||||
this.playButton = new Texture(Gdx.files.internal("playBtn.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render() {
|
|
||||||
game.sb.begin();
|
|
||||||
game.sb.draw(playButton,
|
|
||||||
BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2,
|
|
||||||
BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2);
|
|
||||||
game.sb.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(float dt) {
|
|
||||||
if (Gdx.input.justTouched()) {
|
|
||||||
Vector3 clickLoc = game.cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
|
|
||||||
if (clickLoc.x >= BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2
|
|
||||||
&& clickLoc.x <= BrickBuster.BOARD_WIDTH/2+playButton.getWidth()/2
|
|
||||||
&& clickLoc.y >= BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2
|
|
||||||
&& clickLoc.y <= BrickBuster.BOARD_HEIGHT/2+playButton.getHeight()/2) {
|
|
||||||
game.setScreen(new PlayState(game));
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
playButton.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,12 +14,9 @@ import java.util.*;
|
|||||||
|
|
||||||
public class PlayState extends State {
|
public class PlayState extends State {
|
||||||
|
|
||||||
public static final int SHIELD_HEIGHT = 30;
|
public static final int SHIELD_HEIGHT = 5;
|
||||||
public static final float POWERUP_CHANCE = 0.15f;
|
public static final float POWERUP_CHANCE = 0.15f;
|
||||||
|
|
||||||
public static final int COLUMNS = 9;
|
|
||||||
public static final int ROWS = 8;
|
|
||||||
|
|
||||||
public static final Map<Class<? extends PowerUp>, Integer> powerUpWeights;
|
public static final Map<Class<? extends PowerUp>, Integer> powerUpWeights;
|
||||||
private static final int weightSum;
|
private static final int weightSum;
|
||||||
|
|
||||||
@ -41,19 +38,16 @@ public class PlayState extends State {
|
|||||||
powerUps = new ArrayList<PowerUp>();
|
powerUps = new ArrayList<PowerUp>();
|
||||||
paddle = new Paddle(this);
|
paddle = new Paddle(this);
|
||||||
|
|
||||||
int brick_padding = (BrickBuster.BOARD_WIDTH - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1);
|
|
||||||
bricks = new ArrayList<Brick>();
|
bricks = new ArrayList<Brick>();
|
||||||
for (int col = 0; col < COLUMNS; col++) {
|
for (int col = 0; col < 13; col++) {
|
||||||
for (int row = 0; row < ROWS; row++) {
|
for (int row = 0; row < 7; row++) {
|
||||||
int x = brick_padding + (col * (Brick.BRICK_WIDTH + brick_padding));
|
int x = 15 + (col * (Brick.BLOCK_WIDTH + 10));
|
||||||
int y = brick_padding + Brick.BRICK_HEIGHT + (row * (Brick.BRICK_HEIGHT + brick_padding));
|
int y = 15 + Brick.BLOCK_HEIGHT + (row * (Brick.BLOCK_HEIGHT + 10));
|
||||||
|
|
||||||
Class<? extends PowerUp> powerUpType = null;
|
Class<? extends PowerUp> powerUpType = null;
|
||||||
if (MathUtils.randomBoolean(POWERUP_CHANCE)) {
|
if (MathUtils.randomBoolean(POWERUP_CHANCE)) {
|
||||||
powerUpType = getWeightedPowerUp();
|
powerUpType = getWeightedPowerUp();
|
||||||
}
|
}
|
||||||
|
bricks.add(new Brick(this, powerUpType, x, BrickBuster.HEIGHT - y));
|
||||||
bricks.add(new Brick(this, powerUpType, x, BrickBuster.BOARD_HEIGHT - y));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +72,7 @@ public class PlayState extends State {
|
|||||||
if (getShieldCount() > 0) {
|
if (getShieldCount() > 0) {
|
||||||
game.sr.begin(ShapeType.Filled);
|
game.sr.begin(ShapeType.Filled);
|
||||||
game.sr.setColor(Color.SALMON);
|
game.sr.setColor(Color.SALMON);
|
||||||
game.sr.rect(0, 0, BrickBuster.BOARD_WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
game.sr.rect(0, 0, BrickBuster.WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
||||||
game.sr.end();
|
game.sr.end();
|
||||||
}
|
}
|
||||||
long renderTime = System.nanoTime() - start;
|
long renderTime = System.nanoTime() - start;
|
||||||
@ -86,7 +80,7 @@ public class PlayState extends State {
|
|||||||
game.sb.begin();
|
game.sb.begin();
|
||||||
game.font.setColor(Color.GRAY);
|
game.font.setColor(Color.GRAY);
|
||||||
game.font.draw(game.sb, String.format("FPS: %d Update: %.2f ms Render: %.2f ms",
|
game.font.draw(game.sb, String.format("FPS: %d Update: %.2f ms Render: %.2f ms",
|
||||||
Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 10, BrickBuster.BOARD_HEIGHT-10);
|
Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 0, 13);
|
||||||
game.sb.end();
|
game.sb.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,25 +109,12 @@ public class PlayState extends State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bricks.isEmpty()) {
|
if (bricks.isEmpty()) {
|
||||||
game.setScreen(new MenuState(game));
|
// TODO: Fix this - go to an after-game menu
|
||||||
dispose();
|
//create();
|
||||||
}
|
}
|
||||||
updateTime = System.nanoTime() - start;
|
updateTime = System.nanoTime() - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
|
|
||||||
powerUps.clear();
|
|
||||||
powerUps = null;
|
|
||||||
balls.clear();
|
|
||||||
balls = null;
|
|
||||||
bricks.clear();
|
|
||||||
bricks = null;
|
|
||||||
paddle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getShieldCount() {
|
public int getShieldCount() {
|
||||||
return shieldCount;
|
return shieldCount;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.me.brickbuster.BrickBuster;
|
|||||||
public abstract class State extends ScreenAdapter {
|
public abstract class State extends ScreenAdapter {
|
||||||
|
|
||||||
protected final BrickBuster game;
|
protected final BrickBuster game;
|
||||||
private boolean disposed;
|
|
||||||
|
|
||||||
public State(BrickBuster game) {
|
public State(BrickBuster game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
@ -16,15 +15,8 @@ public abstract class State extends ScreenAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public final void render(float delta) {
|
public final void render(float delta) {
|
||||||
update(delta);
|
update(delta);
|
||||||
if (!disposed) {
|
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
this.disposed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void setup();
|
public abstract void setup();
|
||||||
|
|
||||||
|
@ -7,10 +7,9 @@ import com.me.brickbuster.BrickBuster;
|
|||||||
public class DesktopLauncher {
|
public class DesktopLauncher {
|
||||||
public static void main (String[] arg) {
|
public static void main (String[] arg) {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
config.width = 450;
|
config.width = BrickBuster.WIDTH;
|
||||||
config.height = 800;
|
config.height = BrickBuster.HEIGHT;
|
||||||
config.title = BrickBuster.TITLE;
|
config.title = BrickBuster.TITLE;
|
||||||
new LwjglApplication(new BrickBuster(), config);
|
new LwjglApplication(new BrickBuster(), config);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user