BrickBuster/core/src/com/me/brickbuster/BrickBuster.java
Matt Low 1f9c2e6db0 Decrease chance of glue powerup dropping from 50% to 8%
Increase default ball speed to 350px/sec
Change paddle speed control to time-based, 375px/sec
2018-11-12 09:54:07 +04:00

118 lines
2.4 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.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.me.brickbuster.entity.*;
import java.util.ArrayList;
import java.util.Iterator;
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 ArrayList<PowerUp> powerUps;
private boolean playing = false;
@Override
public void create () {
ball = new Ball(this);
paddle = new Paddle(this);
powerUps = new ArrayList<PowerUp>();
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));
Class<? extends PowerUp> powerUpType = null;
if (MathUtils.randomBoolean(0.08f)) {
powerUpType = GluePowerUp.class;
}
bricks.add(new Brick(this, powerUpType, 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();
}
for (PowerUp powerUp : powerUps) {
powerUp.render();
}
ball.render();
paddle.render();
}
public void update(float dt) {
if (Gdx.input.justTouched() && (!isPlaying() || ball.isStuck())) {
playing = true;
ball.launch();
}
ball.update(dt);
paddle.update(dt);
for (Iterator<PowerUp> it = powerUps.iterator(); it.hasNext();) {
PowerUp powerUp = it.next();
powerUp.update(dt);
if(powerUp.isCaught()) {
it.remove();
}
}
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;
}
public void addPowerUp(PowerUp powerUp) {
this.powerUps.add(powerUp);
}
}