93 lines
1.9 KiB
Java
93 lines
1.9 KiB
Java
package com.me.brickbuster;
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
import com.badlogic.gdx.Gdx;
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
import com.badlogic.gdx.math.Vector2;
|
|
import com.me.brickbuster.entity.Ball;
|
|
import com.me.brickbuster.entity.Brick;
|
|
import com.me.brickbuster.entity.Paddle;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class BrickBuster extends ApplicationAdapter {
|
|
|
|
public static final int WIDTH = 800;
|
|
public static final int HEIGHT = 600;
|
|
public static final String TITLE = "Brick Buster";
|
|
|
|
public static final Vector2 HORIZONTAL_EDGE = new Vector2(1, 0);
|
|
public static final Vector2 VERTICAL_EDGE = new Vector2(0, 1);
|
|
|
|
private Ball ball;
|
|
private Paddle paddle;
|
|
private ArrayList<Brick> bricks;
|
|
private boolean playing = false;
|
|
|
|
@Override
|
|
public void create () {
|
|
ball = new Ball(this);
|
|
paddle = new Paddle(this);
|
|
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));
|
|
bricks.add(new Brick(this, x, HEIGHT - y));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void render () {
|
|
update(Gdx.graphics.getDeltaTime());
|
|
|
|
Gdx.gl.glClearColor(0.5f,1,1,1);
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
|
|
|
for (Brick block : bricks) {
|
|
block.render();
|
|
}
|
|
|
|
ball.render();
|
|
paddle.render();
|
|
}
|
|
|
|
public void update(float dt) {
|
|
if (Gdx.input.justTouched() && !isPlaying()) {
|
|
playing = true;
|
|
ball.launch();
|
|
}
|
|
ball.update(dt);
|
|
paddle.update(dt);
|
|
if (getBricks().isEmpty()) {
|
|
create();
|
|
playing = false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void dispose () {
|
|
}
|
|
|
|
public boolean isPlaying() {
|
|
return playing;
|
|
}
|
|
|
|
public void setPlaying(boolean playing) {
|
|
this.playing = playing;
|
|
}
|
|
|
|
public Ball getBall() {
|
|
return ball;
|
|
}
|
|
|
|
public Paddle getPaddle() {
|
|
return paddle;
|
|
}
|
|
|
|
public ArrayList<Brick> getBricks() {
|
|
return bricks;
|
|
}
|
|
}
|