Compare commits

..

No commits in common. "9df81ee854ea2eb09d1c290905b80ae02615086d" and "cb90c949ff375d358352692d894d02354b02d35c" have entirely different histories.

9 changed files with 27 additions and 184 deletions

View File

@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.utils.viewport.FitViewport;
@ -26,7 +25,6 @@ public class BrickBuster extends Game {
public BitmapFont font;
public SpriteBatch sb;
public ShapeRenderer sr;
public PolygonSpriteBatch pb;
@Override
public void create () {
@ -40,7 +38,6 @@ public class BrickBuster extends Game {
sb = new SpriteBatch();
sr = new ShapeRenderer();
pb = new PolygonSpriteBatch();
setScreen(new MenuState(this));
}
@ -59,7 +56,6 @@ public class BrickBuster extends Game {
sb.setProjectionMatrix(cam.combined);
sr.setProjectionMatrix(cam.combined);
pb.setProjectionMatrix(cam.combined);
super.resize(width, height);
}

View File

@ -21,7 +21,6 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
public static final int BLOCKS_FOR_BOOST = 39;
public static final float MINIMUM_ANGLE = MathUtils.PI/16;
public static final float CORRECTION_IMPULSE = 3f;
private float speed;
private boolean isStuck = true;
@ -65,13 +64,12 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
}
Vector2 velocity = body.getLinearVelocity();
body.setLinearVelocity(velocity.nor().scl(speed));
float rad = velocity.angleRad();
if (Math.abs(rad) < MINIMUM_ANGLE || Math.abs(rad) > MathUtils.PI - MINIMUM_ANGLE) {
Vector2 impulse = new Vector2(0, rad > 0? CORRECTION_IMPULSE : -CORRECTION_IMPULSE);
body.applyLinearImpulse(impulse, pos, true);
body.applyLinearImpulse(new Vector2(0, rad > 0? 1 : -1), pos, true);
}
body.setLinearVelocity(velocity.nor().scl(speed));
}
@Override

View File

@ -1,19 +1,15 @@
package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.PolygonRegion;
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.EarClippingTriangulator;
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;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.utils.ShortArray;
import com.me.brickbuster.entity.powerup.PowerUpType;
import com.me.brickbuster.physics.CollisionListener;
import com.me.brickbuster.physics.EntityType;
@ -26,17 +22,8 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
public static final float BRICK_WIDTH = 5f;
public static final float BRICK_HEIGHT = 2.5f;
private static final EarClippingTriangulator ECT = new EarClippingTriangulator();
private static final Vector2 tmp = new Vector2();
private BrickType type;
private BrickShape shape;
private PowerUpType powerUpType;
private Color color;
private Pixmap pm;
private Texture solid;
private TextureRegion region;
private Body body;
private boolean hitByBall = false;
@ -45,46 +32,27 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
this(state, powerUpType, true, x, y);
}
public Brick(PlayState state, BrickShape shape, PowerUpType powerUpType, float x, float y) {
this(state, BrickType.STANDARD_10, shape, powerUpType, DEFAULT_COLOR, true, x, y);
}
public Brick(PlayState state, PowerUpType powerUpType, boolean hidePowerup, float x, float y) {
this(state, BrickType.STANDARD_10, BrickShape.RECTANGLE, powerUpType, DEFAULT_COLOR, hidePowerup, x, y);
this(state, powerUpType, DEFAULT_COLOR, hidePowerup, x, y);
}
public Brick(PlayState state, BrickType type, BrickShape shape, PowerUpType powerUpType, Color color, boolean hidePowerUp, float x, float y) {
public Brick(PlayState state, PowerUpType powerUpType, Color color, boolean hidePowerUp, float x, float y) {
super(state, x, y);
this.type = type;
this.shape = shape;
this.powerUpType = powerUpType;
this.color = powerUpType != null && !hidePowerUp? powerUpType.getColor() : color;
this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888);
pm.setColor(color);
pm.fill();
this.solid = new Texture(pm);
this.region = new TextureRegion(solid);
createBody();
}
@Override
public void render(ShapeRenderer sr) {
PolygonShape shape = (PolygonShape) body.getFixtureList().get(0).getShape();
float[] vertices = new float[shape.getVertexCount()*2];
for (int i = 0; i < vertices.length/2; i++) {
shape.getVertex(i, tmp);
Vector2 vertex = body.getWorldPoint(tmp);
vertices[i*2] = vertex.x * PlayState.PIXEL_PER_METER;
vertices[i*2 + 1] = vertex.y * PlayState.PIXEL_PER_METER;
}
ShortArray triangleIndices = ECT.computeTriangles(vertices);
PolygonRegion polyRegion = new PolygonRegion(region, vertices, triangleIndices.toArray());
PolygonSpriteBatch pb = state.getGame().pb;
pb.begin();
pb.draw(polyRegion, 0, 0);
pb.end();
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.end();
}
@Override
@ -107,88 +75,15 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
brickBody.position.set(pos.cpy());
PolygonShape brickShape = new PolygonShape();
switch (shape) {
case DIAMOND:
brickShape.set(new float[] {
-BRICK_WIDTH/2, 0, // Left
0, BRICK_HEIGHT/2, // Up
BRICK_WIDTH/2, 0, // Right
0, -BRICK_HEIGHT/2 // Down
});
break;
case DOWN_RIGHT_TRIANGLE:
brickShape.set(new float[] {
BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top right
BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom right
-BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom left
});
break;
case UP_RIGHT_TRIANGLE:
brickShape.set(new float[] {
BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top right
BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom right
-BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top left
});
break;
case UP_LEFT_TRIANGLE:
brickShape.set(new float[] {
-BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top left
BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top right
-BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom left
});
break;
case DOWN_LEFT_TRIANGLE:
brickShape.set(new float[] {
-BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top left
BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom right
-BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom left
});
break;
case HALF_LOWER:
brickShape.set(new float[] {
-BRICK_WIDTH/2, 0, // Top left
BRICK_WIDTH/2, 0, // Top right
BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom right
-BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom left
});
break;
case HALF_UPPER:
brickShape.set(new float[] {
-BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top left
BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top right
BRICK_WIDTH/2, 0, // Bottom right
-BRICK_WIDTH/2, 0, // Bottom left
});
break;
case HALF_LEFT:
brickShape.set(new float[] {
-BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top left
0, BRICK_HEIGHT/2, // Top right
0, -BRICK_HEIGHT/2, // Bottom right
-BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom left
});
break;
case HALF_RIGHT:
brickShape.set(new float[] {
0, BRICK_HEIGHT/2, // Top left
BRICK_WIDTH/2, BRICK_HEIGHT/2, // Top right
BRICK_WIDTH/2, -BRICK_HEIGHT/2, // Bottom right
0, -BRICK_HEIGHT/2, // Bottom left
});
break;
default:
brickShape.setAsBox(BRICK_WIDTH/2, BRICK_HEIGHT/2, Vector2.Zero, 0f);
}
brickShape.setAsBox(BRICK_WIDTH/2, BRICK_HEIGHT/2,
new Vector2(BRICK_WIDTH/2,BRICK_HEIGHT/2), 0);
FixtureDef brickFixture = new FixtureDef();
brickFixture.shape = brickShape;
brickFixture.friction = 0f;
brickFixture.density = 0.5f;
brickFixture.filter.categoryBits = EntityType.BRICK;
brickFixture.filter.maskBits = EntityType.BALL | EntityType.BRICK | EntityType.BOUNDARY;
brickFixture.filter.maskBits = EntityType.BALL;
body = state.world.createBody(brickBody);
body.createFixture(brickFixture);
@ -208,12 +103,6 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
public void endContact(Entity contacted) {
}
@Override
public void dispose() {
solid.dispose();
pm.dispose();
}
public boolean hit() {
if (state.bricks.size-1 <= Ball.BLOCKS_FOR_BOOST) {
for (Ball ball : state.balls) {

View File

@ -1,17 +0,0 @@
package com.me.brickbuster.entity;
public enum BrickShape {
RECTANGLE,
DIAMOND,
DOWN_RIGHT_TRIANGLE,
UP_RIGHT_TRIANGLE,
UP_LEFT_TRIANGLE,
DOWN_LEFT_TRIANGLE,
HALF_UPPER,
HALF_LOWER,
HALF_LEFT,
HALF_RIGHT,
;
}

View File

@ -1,19 +0,0 @@
package com.me.brickbuster.entity;
public enum BrickType {
STANDARD_10,
STANDARD_20,
STANDARD_30,
STANDARD_40,
STANDARD_50,
STANDARD_60,
STANDARD_70,
STANDARD_80,
EXPLOSIVE,
HARD,
HARDER,
UNBREAKABLE
;
}

View File

@ -23,8 +23,6 @@ public abstract class Entity {
public abstract void update(float dt);
public void dispose() {}
public Vector2 getPos() {
return pos;
}

View File

@ -42,7 +42,9 @@ public enum PowerUpType {
}
public PowerUp createInstance(PlayState state, Brick brick) {
return createInstance(state, new Vector2(brick.getX(), brick.getY()));
return createInstance(state,
new Vector2(brick.getX()+Brick.BRICK_WIDTH/2,
brick.getY()+Brick.BRICK_HEIGHT/2));
}
public PowerUp createInstance(PlayState state, Vector2 pos) {

View File

@ -95,19 +95,19 @@ public class PlayState extends State {
powerUps = new Array<PowerUp>();
paddle = new Paddle(this);
float brick_padding = (BOARD_WIDTH - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1);
float brick_padding = ((BrickBuster.BOARD_WIDTH/PIXEL_PER_METER) - COLUMNS * Brick.BRICK_WIDTH) / (COLUMNS + 1);
bricks = new Array<Brick>();
for (int col = 0; col < COLUMNS; col++) {
for (int row = ROWS-1; row >= 0; row--) {
float x = brick_padding + Brick.BRICK_WIDTH/2 + (col * (Brick.BRICK_WIDTH + brick_padding));
float y = brick_padding + Brick.BRICK_HEIGHT/2 + (row * (Brick.BRICK_HEIGHT + brick_padding));
for (int row = 0; row < ROWS; row++) {
float x = brick_padding + (col * (Brick.BRICK_WIDTH + brick_padding));
float y = brick_padding + Brick.BRICK_HEIGHT + (row * (Brick.BRICK_HEIGHT + brick_padding));
PowerUpType powerUpType = null;
if (MathUtils.randomBoolean(POWERUP_CHANCE)) {
powerUpType = PowerUpType.getWeightedRandom();
}
bricks.add(new Brick(this, powerUpType, x, BOARD_HEIGHT - y));
bricks.add(new Brick(this, powerUpType, x, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER - y));
}
}

View File

@ -26,10 +26,6 @@ public abstract class State extends ScreenAdapter {
this.disposed = true;
}
public BrickBuster getGame() {
return game;
}
public abstract void setup();
public abstract void render();