Add PowerUp logic + GluePowerUp
This commit is contained in:
@ -3,12 +3,12 @@ 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.Ball;
|
||||
import com.me.brickbuster.entity.Brick;
|
||||
import com.me.brickbuster.entity.Paddle;
|
||||
import com.me.brickbuster.entity.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class BrickBuster extends ApplicationAdapter {
|
||||
|
||||
@ -22,18 +22,24 @@ public class BrickBuster extends ApplicationAdapter {
|
||||
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));
|
||||
bricks.add(new Brick(this, x, HEIGHT - y));
|
||||
Class<? extends PowerUp> powerUpType = null;
|
||||
if (MathUtils.randomBoolean(0.5f)) {
|
||||
powerUpType = GluePowerUp.class;
|
||||
}
|
||||
bricks.add(new Brick(this, powerUpType, x, HEIGHT - y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,17 +55,31 @@ public class BrickBuster extends ApplicationAdapter {
|
||||
block.render();
|
||||
}
|
||||
|
||||
for (PowerUp powerUp : powerUps) {
|
||||
powerUp.render();
|
||||
}
|
||||
|
||||
ball.render();
|
||||
paddle.render();
|
||||
}
|
||||
|
||||
public void update(float dt) {
|
||||
if (Gdx.input.justTouched() && !isPlaying()) {
|
||||
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;
|
||||
@ -89,4 +109,9 @@ public class BrickBuster extends ApplicationAdapter {
|
||||
public ArrayList<Brick> getBricks() {
|
||||
return bricks;
|
||||
}
|
||||
|
||||
public void addPowerUp(PowerUp powerUp) {
|
||||
this.powerUps.add(powerUp);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user