Move away from using pixel coordinates to "board coordinates"
Changed aspect ratio from 4:3 to 9:16
This commit is contained in:
parent
1c7e20f8e9
commit
a56d721050
@ -3,16 +3,23 @@ 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.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.StretchViewport;
|
||||||
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
import com.me.brickbuster.state.PlayState;
|
import com.me.brickbuster.state.PlayState;
|
||||||
|
|
||||||
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 = 2250;
|
||||||
|
public static final int BOARD_HEIGHT = 4000;
|
||||||
|
|
||||||
|
public OrthographicCamera cam;
|
||||||
|
public Viewport viewport;
|
||||||
|
|
||||||
public BitmapFont font;
|
public BitmapFont font;
|
||||||
public SpriteBatch sb;
|
public SpriteBatch sb;
|
||||||
@ -20,6 +27,10 @@ public class BrickBuster extends Game {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
|
cam = new OrthographicCamera();
|
||||||
|
viewport = new StretchViewport(BOARD_WIDTH, BOARD_HEIGHT, cam);
|
||||||
|
viewport.apply(true);
|
||||||
|
|
||||||
font = new BitmapFont();
|
font = new BitmapFont();
|
||||||
sb = new SpriteBatch();
|
sb = new SpriteBatch();
|
||||||
sr = new ShapeRenderer();
|
sr = new ShapeRenderer();
|
||||||
@ -35,4 +46,14 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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.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;
|
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);
|
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);
|
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()) {
|
||||||
|
@ -22,7 +22,7 @@ public class Paddle extends Entity {
|
|||||||
private boolean sticky = false;
|
private boolean sticky = false;
|
||||||
|
|
||||||
public Paddle(PlayState brickBuster) {
|
public Paddle(PlayState brickBuster) {
|
||||||
super(brickBuster, BrickBuster.WIDTH / 2, PADDLE_Y);
|
super(brickBuster, BrickBuster.BOARD_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.WIDTH) {
|
if (pos.x + width/2 + PADDLE_SPEED * dt > BrickBuster.BOARD_WIDTH) {
|
||||||
setX(BrickBuster.WIDTH - width/2);
|
setX(BrickBuster.BOARD_WIDTH - width/2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pos.x = pos.x + PADDLE_SPEED * dt;
|
pos.x = pos.x + PADDLE_SPEED * dt;
|
||||||
|
@ -47,7 +47,7 @@ public class PlayState extends State {
|
|||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,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.WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
game.sr.rect(0, 0, BrickBuster.BOARD_WIDTH, getShieldCount() * SHIELD_HEIGHT);
|
||||||
game.sr.end();
|
game.sr.end();
|
||||||
}
|
}
|
||||||
long renderTime = System.nanoTime() - start;
|
long renderTime = System.nanoTime() - start;
|
||||||
|
@ -7,9 +7,10 @@ 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 = BrickBuster.WIDTH;
|
config.width = 450;
|
||||||
config.height = BrickBuster.HEIGHT;
|
config.height = 800;
|
||||||
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