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.Block; 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 blocks; private boolean playing = false; @Override public void create () { ball = new Ball(this); paddle = new Paddle(this); blocks = new ArrayList(); 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 public void render () { update(Gdx.graphics.getDeltaTime()); Gdx.gl.glClearColor(0.5f,1,1,1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); for (Block block : blocks) { 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); } @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 getBlocks() { return blocks; } }