Compare commits
No commits in common. "adebc42c16a431f5966be1953d45e3db788429fe" and "e4000998cc4d99201779467ba457a6239aa45a41" have entirely different histories.
adebc42c16
...
e4000998cc
@ -6,9 +6,11 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import com.badlogic.gdx.physics.box2d.Body;
|
||||
import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||
import com.badlogic.gdx.physics.box2d.CircleShape;
|
||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.me.brickbuster.physics.CollisionListener;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
import com.me.brickbuster.physics.PhysicsBody;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
|
||||
@ -28,7 +30,7 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
|
||||
|
||||
public Ball(PlayState state) {
|
||||
super(state, state.paddle.getX(), state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
||||
this.speed = state.bricks.size > BLOCKS_FOR_BOOST? DEFAULT_SPEED : BOOST_SPEED;
|
||||
this.speed = state.bricks.size() > BLOCKS_FOR_BOOST? DEFAULT_SPEED : BOOST_SPEED;
|
||||
createBody();
|
||||
}
|
||||
|
||||
@ -81,10 +83,6 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
|
||||
ballFixture.shape = ballShape;
|
||||
ballFixture.restitution = 1f;
|
||||
ballFixture.friction = 0f;
|
||||
ballFixture.density = 1f;
|
||||
|
||||
ballFixture.filter.categoryBits = EntityType.BALL;
|
||||
ballFixture.filter.maskBits = EntityType.BOUNDARY | EntityType.BRICK | EntityType.PADDLE | EntityType.POWER_UP;
|
||||
|
||||
body = state.world.createBody(ballBody);
|
||||
body.createFixture(ballFixture);
|
||||
|
@ -3,8 +3,6 @@ package com.me.brickbuster.entity;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.Body;
|
||||
import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||
@ -12,7 +10,6 @@ import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.badlogic.gdx.physics.box2d.PolygonShape;
|
||||
import com.me.brickbuster.entity.powerup.PowerUpType;
|
||||
import com.me.brickbuster.physics.CollisionListener;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
import com.me.brickbuster.physics.PhysicsBody;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
|
||||
@ -47,11 +44,10 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
|
||||
public void render(ShapeRenderer sr) {
|
||||
sr.begin(ShapeType.Filled);
|
||||
sr.setColor(color);
|
||||
sr.rect(pos.x * PlayState.PIXEL_PER_METER, pos.y * PlayState.PIXEL_PER_METER,
|
||||
0f, 0f,
|
||||
BRICK_WIDTH * PlayState.PIXEL_PER_METER, BRICK_HEIGHT * PlayState.PIXEL_PER_METER,
|
||||
1f, 1f,
|
||||
body.getAngle() * MathUtils.radiansToDegrees);
|
||||
sr.rect(getX() * PlayState.PIXEL_PER_METER,
|
||||
getY() * PlayState.PIXEL_PER_METER,
|
||||
BRICK_WIDTH * PlayState.PIXEL_PER_METER,
|
||||
BRICK_HEIGHT * PlayState.PIXEL_PER_METER);
|
||||
sr.end();
|
||||
}
|
||||
|
||||
@ -82,9 +78,6 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
|
||||
brickFixture.shape = brickShape;
|
||||
brickFixture.friction = 0f;
|
||||
|
||||
brickFixture.filter.categoryBits = EntityType.BRICK;
|
||||
brickFixture.filter.maskBits = EntityType.BALL;
|
||||
|
||||
body = state.world.createBody(brickBody);
|
||||
body.createFixture(brickFixture);
|
||||
body.setUserData(this);
|
||||
@ -104,7 +97,7 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
|
||||
}
|
||||
|
||||
public boolean hit() {
|
||||
if (state.bricks.size-1 <= Ball.BLOCKS_FOR_BOOST) {
|
||||
if (state.bricks.size()-1 <= Ball.BLOCKS_FOR_BOOST) {
|
||||
for (Ball ball : state.balls) {
|
||||
ball.setSpeed(Ball.BOOST_SPEED);
|
||||
}
|
||||
|
@ -5,14 +5,12 @@ import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.Body;
|
||||
import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||
import com.badlogic.gdx.physics.box2d.EdgeShape;
|
||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.me.brickbuster.physics.CollisionListener;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
import com.me.brickbuster.physics.PhysicsBody;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
import net.dermetfan.utils.Pair;
|
||||
@ -50,27 +48,29 @@ public class Paddle extends Entity implements PhysicsBody {
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
float displacement = PADDLE_SPEED * dt;
|
||||
float adjust = 0;
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
|
||||
if (pos.x - width / 2 - displacement < PlayState.EDGE_PADDING) {
|
||||
adjust = -(pos.x - width/2 - PlayState.EDGE_PADDING);
|
||||
} else {
|
||||
adjust = -displacement;
|
||||
if (pos.x - width/2 - PADDLE_SPEED * dt < 0) {
|
||||
setX(width/2);
|
||||
return;
|
||||
}
|
||||
setX(pos.x - PADDLE_SPEED * dt);
|
||||
|
||||
for (Ball ball : state.balls) {
|
||||
if (ball.isStuck()) {
|
||||
ball.setX(ball.getX() - PADDLE_SPEED * dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
|
||||
if (pos.x + width / 2 + displacement > PlayState.BOARD_WIDTH-PlayState.EDGE_PADDING) {
|
||||
adjust = PlayState.BOARD_WIDTH - PlayState.EDGE_PADDING - width/2 - pos.x;
|
||||
} else {
|
||||
adjust = displacement;
|
||||
if (pos.x + width/2 + PADDLE_SPEED * dt > PlayState.BOARD_WIDTH) {
|
||||
setX(PlayState.BOARD_WIDTH - width/2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!MathUtils.isZero(adjust)) {
|
||||
setX(pos.x + adjust);
|
||||
setX(pos.x + PADDLE_SPEED * dt);
|
||||
|
||||
for (Ball ball : state.balls) {
|
||||
if (ball.isStuck()) {
|
||||
ball.setX(ball.getX() + adjust);
|
||||
ball.setX(ball.getX() + PADDLE_SPEED * dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,9 +88,7 @@ public class Paddle extends Entity implements PhysicsBody {
|
||||
|
||||
FixtureDef paddleFixture = new FixtureDef();
|
||||
paddleFixture.shape = paddleShape;
|
||||
|
||||
paddleFixture.filter.categoryBits = EntityType.PADDLE;
|
||||
paddleFixture.filter.maskBits = EntityType.BALL | EntityType.POWER_UP;
|
||||
//paddleFixture.isSensor = true;
|
||||
|
||||
body = state.world.createBody(paddleBody);
|
||||
body.createFixture(paddleFixture);
|
||||
|
@ -8,7 +8,6 @@ import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.badlogic.gdx.physics.box2d.PolygonShape;
|
||||
import com.me.brickbuster.entity.powerup.PowerUpType;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
import com.me.brickbuster.physics.PhysicsBody;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
|
||||
@ -54,9 +53,6 @@ public class Shield extends Entity implements PhysicsBody {
|
||||
brickFixture.shape = brickShape;
|
||||
brickFixture.friction = 0f;
|
||||
|
||||
brickFixture.filter.categoryBits = EntityType.SHIELD;
|
||||
brickFixture.filter.maskBits = EntityType.BALL;
|
||||
|
||||
body = state.world.createBody(brickBody);
|
||||
body.createFixture(brickFixture);
|
||||
body.setUserData(this);
|
||||
|
@ -9,11 +9,9 @@ import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||
import com.badlogic.gdx.physics.box2d.CircleShape;
|
||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.me.brickbuster.Utils;
|
||||
import com.me.brickbuster.entity.Ball;
|
||||
import com.me.brickbuster.entity.Entity;
|
||||
import com.me.brickbuster.entity.Paddle;
|
||||
import com.me.brickbuster.physics.CollisionListener;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
import com.me.brickbuster.physics.PhysicsBody;
|
||||
import com.me.brickbuster.state.PlayState;
|
||||
import net.dermetfan.utils.Pair;
|
||||
@ -74,9 +72,6 @@ public abstract class PowerUp extends Entity implements PhysicsBody, CollisionLi
|
||||
ballFixture.shape = ballShape;
|
||||
ballFixture.isSensor = true;
|
||||
|
||||
ballFixture.filter.categoryBits = EntityType.POWER_UP;
|
||||
ballFixture.filter.maskBits = EntityType.PADDLE | EntityType.BALL;
|
||||
|
||||
body = state.world.createBody(ballBody);
|
||||
body.createFixture(ballFixture);
|
||||
body.setUserData(this);
|
||||
@ -88,7 +83,7 @@ public abstract class PowerUp extends Entity implements PhysicsBody, CollisionLi
|
||||
|
||||
@Override
|
||||
public void beginContact(Entity contacted) {
|
||||
if (contacted instanceof Paddle || contacted instanceof Ball) {
|
||||
if (contacted instanceof Paddle) {
|
||||
isCaught = true;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.me.brickbuster.physics;
|
||||
|
||||
public final class EntityType {
|
||||
|
||||
public static final short BOUNDARY = 0x1;
|
||||
public static final short BALL = 0x1 << 1;
|
||||
public static final short BRICK = 0x1 << 2;
|
||||
public static final short PADDLE = 0x1 << 3;
|
||||
public static final short POWER_UP = 0x1 << 4;
|
||||
public static final short SHIELD = 0x1 << 5;
|
||||
|
||||
}
|
@ -11,9 +11,10 @@ import com.me.brickbuster.entity.*;
|
||||
import com.me.brickbuster.entity.powerup.PowerUp;
|
||||
import com.me.brickbuster.entity.powerup.PowerUpType;
|
||||
import com.me.brickbuster.physics.Box2dContactListener;
|
||||
import com.me.brickbuster.physics.EntityType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayState extends State {
|
||||
|
||||
@ -41,11 +42,11 @@ public class PlayState extends State {
|
||||
public Body playArea;
|
||||
public Array<Body> bodies;
|
||||
|
||||
public Array<PowerUp> powerUps;
|
||||
public List<PowerUp> powerUps;
|
||||
public Paddle paddle;
|
||||
public Array<Ball> balls;
|
||||
public Array<Brick> bricks;
|
||||
public Array<Shield> shields;
|
||||
public List<Ball> balls;
|
||||
public List<Brick> bricks;
|
||||
public List<Shield> shields;
|
||||
|
||||
private float updateTime = 0f;
|
||||
|
||||
@ -69,32 +70,26 @@ public class PlayState extends State {
|
||||
|
||||
EdgeShape screenEdge = new EdgeShape();
|
||||
|
||||
FixtureDef playAreaFixture = new FixtureDef();
|
||||
playAreaFixture.shape = screenEdge;
|
||||
|
||||
playAreaFixture.filter.categoryBits = EntityType.BOUNDARY;
|
||||
playAreaFixture.filter.maskBits = EntityType.BALL | EntityType.BRICK;
|
||||
|
||||
playArea = world.createBody(playAreaDef);
|
||||
// Right edge
|
||||
screenEdge.set(lowerRightCorner, upperRightCorner);
|
||||
playArea.createFixture(playAreaFixture);
|
||||
playArea.createFixture(screenEdge, 0f);
|
||||
// Top edge
|
||||
screenEdge.set(upperRightCorner, upperLeftCorner);
|
||||
playArea.createFixture(playAreaFixture);
|
||||
playArea.createFixture(screenEdge, 0f);
|
||||
// Left edge
|
||||
screenEdge.set(upperLeftCorner, lowerLeftCorner);
|
||||
playArea.createFixture(playAreaFixture);
|
||||
playArea.createFixture(screenEdge, 0f);
|
||||
// Bottom edge
|
||||
//screenEdge.set(lowerLeftCorner, lowerRightCorner);
|
||||
//playArea.createFixture(playAreaFixture);
|
||||
//playArea.createFixture(screenEdge, 0f);
|
||||
screenEdge.dispose();
|
||||
|
||||
powerUps = new Array<PowerUp>();
|
||||
powerUps = new ArrayList<PowerUp>();
|
||||
paddle = new Paddle(this);
|
||||
|
||||
float brick_padding = ((BrickBuster.BOARD_WIDTH/PIXEL_PER_METER) - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1);
|
||||
bricks = new Array<Brick>();
|
||||
bricks = new ArrayList<Brick>();
|
||||
for (int col = 0; col < COLUMNS; col++) {
|
||||
for (int row = 0; row < ROWS; row++) {
|
||||
float x = brick_padding + (col * (Brick.BRICK_WIDTH + brick_padding));
|
||||
@ -109,10 +104,10 @@ public class PlayState extends State {
|
||||
}
|
||||
}
|
||||
|
||||
balls = new Array<Ball>();
|
||||
balls = new ArrayList<Ball>();
|
||||
balls.add(new Ball(this));
|
||||
|
||||
shields = new Array<Shield>();
|
||||
shields = new ArrayList<Shield>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,7 +116,7 @@ public class PlayState extends State {
|
||||
world.getBodies(bodies);
|
||||
for (Body b : bodies) {
|
||||
Entity e = (Entity) b.getUserData();
|
||||
if (e instanceof Ball || e instanceof PowerUp || e instanceof Brick) {
|
||||
if (e instanceof Ball || e instanceof PowerUp) {
|
||||
e.setPos(b.getPosition());
|
||||
}
|
||||
}
|
||||
@ -164,7 +159,7 @@ public class PlayState extends State {
|
||||
world.destroyBody(ball.getBody());
|
||||
}
|
||||
}
|
||||
if (balls.size == 0) {
|
||||
if (balls.isEmpty()) {
|
||||
ballReset();
|
||||
}
|
||||
|
||||
@ -194,7 +189,7 @@ public class PlayState extends State {
|
||||
world.destroyBody(brick.getBody());
|
||||
}
|
||||
}
|
||||
if (bricks.size == 0) {
|
||||
if (bricks.isEmpty()) {
|
||||
game.setScreen(new MenuState(game));
|
||||
dispose();
|
||||
return;
|
||||
@ -220,7 +215,7 @@ public class PlayState extends State {
|
||||
}
|
||||
|
||||
public int getShieldCount() {
|
||||
return shields.size;
|
||||
return shields.size();
|
||||
}
|
||||
|
||||
public void addShield() {
|
||||
|
Loading…
Reference in New Issue
Block a user