Compare commits
5 Commits
1c7e20f8e9
...
0abae880d3
Author | SHA1 | Date | |
---|---|---|---|
0abae880d3 | |||
fa7e93953b | |||
409735d94e | |||
1fe82cb5b2 | |||
a56d721050 |
BIN
core/assets/playBtn.png
Normal file
BIN
core/assets/playBtn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
@ -3,16 +3,24 @@ package com.me.brickbuster;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
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.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import com.me.brickbuster.state.MenuState;
|
||||
|
||||
public class BrickBuster extends Game {
|
||||
|
||||
public static final int WIDTH = 800;
|
||||
public static final int HEIGHT = 600;
|
||||
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 SpriteBatch sb;
|
||||
@ -20,11 +28,18 @@ public class BrickBuster extends Game {
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
cam = new OrthographicCamera();
|
||||
viewport = new FitViewport(BOARD_WIDTH, BOARD_HEIGHT, cam);
|
||||
viewport.apply(true);
|
||||
|
||||
font = new BitmapFont();
|
||||
font.getData().setScale(4);
|
||||
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
|
||||
sb = new SpriteBatch();
|
||||
sr = new ShapeRenderer();
|
||||
|
||||
setScreen(new PlayState(this));
|
||||
setScreen(new MenuState(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,4 +50,14 @@ public class BrickBuster extends Game {
|
||||
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 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 = 1800;
|
||||
public static final float BOOST_SPEED = 2200;
|
||||
public static final int BLOCKS_FOR_BOOST = 39;
|
||||
|
||||
public Vector2 direction;
|
||||
@ -27,7 +27,7 @@ public class Ball extends Entity {
|
||||
private boolean isDead = false;
|
||||
|
||||
public Ball(PlayState state) {
|
||||
super(state,BrickBuster.WIDTH/2, state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||
super(state,BrickBuster.BOARD_WIDTH /2, state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||
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.WIDTH || new_pos.x - RADIUS < 0) {
|
||||
if (new_pos.x + RADIUS > BrickBuster.BOARD_WIDTH || new_pos.x - RADIUS < 0) {
|
||||
Utils.reflect(direction, Utils.VERTICAL_EDGE);
|
||||
} else if (new_pos.y + RADIUS > BrickBuster.HEIGHT) {
|
||||
} else if (new_pos.y + RADIUS > BrickBuster.BOARD_HEIGHT) {
|
||||
Utils.reflect(direction, Utils.HORIZONTAL_EDGE);
|
||||
} else if (state.getShieldCount() > 0
|
||||
&& new_pos.y - RADIUS < PlayState.SHIELD_HEIGHT * state.getShieldCount()) {
|
||||
@ -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));
|
||||
}
|
||||
|
@ -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<? extends PowerUp> 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();
|
||||
}
|
||||
|
||||
|
@ -13,16 +13,16 @@ 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;
|
||||
|
||||
public Paddle(PlayState brickBuster) {
|
||||
super(brickBuster, BrickBuster.WIDTH / 2, PADDLE_Y);
|
||||
super(brickBuster, BrickBuster.BOARD_WIDTH / 2, PADDLE_Y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,8 +49,8 @@ public class Paddle extends Entity {
|
||||
}
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
||||
if (pos.x + width/2 + PADDLE_SPEED * dt > BrickBuster.WIDTH) {
|
||||
setX(BrickBuster.WIDTH - width/2);
|
||||
if (pos.x + width/2 + PADDLE_SPEED * dt > BrickBuster.BOARD_WIDTH) {
|
||||
setX(BrickBuster.BOARD_WIDTH - width/2);
|
||||
return;
|
||||
}
|
||||
pos.x = pos.x + PADDLE_SPEED * dt;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
49
core/src/com/me/brickbuster/state/MenuState.java
Normal file
49
core/src/com/me/brickbuster/state/MenuState.java
Normal file
@ -0,0 +1,49 @@
|
||||
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,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<Class<? extends PowerUp>, Integer> powerUpWeights;
|
||||
private static final int weightSum;
|
||||
|
||||
@ -38,16 +41,19 @@ public class PlayState extends State {
|
||||
powerUps = new ArrayList<PowerUp>();
|
||||
paddle = new Paddle(this);
|
||||
|
||||
int brick_padding = (BrickBuster.BOARD_WIDTH - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1);
|
||||
bricks = new ArrayList<Brick>();
|
||||
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<? extends PowerUp> powerUpType = null;
|
||||
if (MathUtils.randomBoolean(POWERUP_CHANCE)) {
|
||||
powerUpType = getWeightedPowerUp();
|
||||
}
|
||||
bricks.add(new Brick(this, powerUpType, x, BrickBuster.HEIGHT - y));
|
||||
|
||||
bricks.add(new Brick(this, powerUpType, x, BrickBuster.BOARD_HEIGHT - y));
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +78,7 @@ public class PlayState extends State {
|
||||
if (getShieldCount() > 0) {
|
||||
game.sr.begin(ShapeType.Filled);
|
||||
game.sr.setColor(Color.SALMON);
|
||||
game.sr.rect(0, 0, BrickBuster.WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
||||
game.sr.rect(0, 0, BrickBuster.BOARD_WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
||||
game.sr.end();
|
||||
}
|
||||
long renderTime = System.nanoTime() - start;
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -109,12 +115,25 @@ public class PlayState extends State {
|
||||
}
|
||||
|
||||
if (bricks.isEmpty()) {
|
||||
// TODO: Fix this - go to an after-game menu
|
||||
//create();
|
||||
game.setScreen(new MenuState(game));
|
||||
dispose();
|
||||
}
|
||||
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() {
|
||||
return shieldCount;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.me.brickbuster.BrickBuster;
|
||||
public abstract class State extends ScreenAdapter {
|
||||
|
||||
protected final BrickBuster game;
|
||||
private boolean disposed;
|
||||
|
||||
public State(BrickBuster game) {
|
||||
this.game = game;
|
||||
@ -15,7 +16,14 @@ public abstract class State extends ScreenAdapter {
|
||||
@Override
|
||||
public final void render(float delta) {
|
||||
update(delta);
|
||||
render();
|
||||
if (!disposed) {
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
public abstract void setup();
|
||||
|
@ -7,9 +7,10 @@ import com.me.brickbuster.BrickBuster;
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||
config.width = BrickBuster.WIDTH;
|
||||
config.height = BrickBuster.HEIGHT;
|
||||
config.width = 450;
|
||||
config.height = 800;
|
||||
config.title = BrickBuster.TITLE;
|
||||
new LwjglApplication(new BrickBuster(), config);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user