Added blocks and paddle and part of ball movement.

This commit is contained in:
2018-11-11 11:40:03 +04:00
parent 6c6d5b34bf
commit 74b96990c5
5 changed files with 107 additions and 11 deletions

View File

@ -4,8 +4,11 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.me.brickbuster.entity.Ball;
import com.me.brickbuster.entity.Block;
import com.me.brickbuster.entity.Paddle;
import java.util.ArrayList;
public class BrickBuster extends ApplicationAdapter {
public static final int WIDTH = 800;
@ -14,11 +17,21 @@ public class BrickBuster extends ApplicationAdapter {
Ball ball;
Paddle paddle;
ArrayList<Block> blocks;
boolean playing = false;
@Override
public void create () {
ball = new Ball();
paddle = new Paddle();
ball = new Ball(this);
paddle = new Paddle(this);
blocks = new ArrayList<Block>();
for (int col = 0; col < 13; col++) {
for (int row = 0; row < 10; row++) {
int x = 15 + (col * (Block.BLOCK_WIDTH + 10));
int y = 15 + Block.BLOCK_HEIGHT + (row * (Block.BLOCK_HEIGHT + 5));
blocks.add(new Block(this, x, HEIGHT - y));
}
}
}
@Override
@ -30,9 +43,17 @@ public class BrickBuster extends ApplicationAdapter {
ball.render();
paddle.render();
for (Block block : blocks) {
block.render();
}
}
public void update(float dt) {
if (Gdx.input.justTouched()) {
playing = true;
ball.launch();
}
ball.update(dt);
paddle.update(dt);
}
@ -41,4 +62,16 @@ public class BrickBuster extends ApplicationAdapter {
public void dispose () {
}
public boolean isPlaying() {
return playing;
}
public Ball getBall() {
return ball;
}
public Paddle getPaddle() {
return paddle;
}
}