diff --git a/core/assets/sprites/ball.png b/core/assets/sprites/ball.png new file mode 100644 index 0000000..2f6772e Binary files /dev/null and b/core/assets/sprites/ball.png differ diff --git a/core/assets/sprites/brick_DIAMOND.png b/core/assets/sprites/brick_DIAMOND.png new file mode 100644 index 0000000..ef2ba03 Binary files /dev/null and b/core/assets/sprites/brick_DIAMOND.png differ diff --git a/core/assets/sprites/brick_DOWN_LEFT_TRIANGLE.png b/core/assets/sprites/brick_DOWN_LEFT_TRIANGLE.png new file mode 100644 index 0000000..17e0021 Binary files /dev/null and b/core/assets/sprites/brick_DOWN_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_DOWN_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_DOWN_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..3bde121 Binary files /dev/null and b/core/assets/sprites/brick_DOWN_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_DOWN_TRIANGLE.png b/core/assets/sprites/brick_DOWN_TRIANGLE.png new file mode 100644 index 0000000..c3e76e9 Binary files /dev/null and b/core/assets/sprites/brick_DOWN_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_DOWN_LEFT_TRIANGLE.png b/core/assets/sprites/brick_FULL_DOWN_LEFT_TRIANGLE.png new file mode 100644 index 0000000..694b42f Binary files /dev/null and b/core/assets/sprites/brick_FULL_DOWN_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_HALF_DOWN_TRIANGLE.png b/core/assets/sprites/brick_FULL_HALF_DOWN_TRIANGLE.png new file mode 100644 index 0000000..9c197f4 Binary files /dev/null and b/core/assets/sprites/brick_FULL_HALF_DOWN_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_HALF_LEFT_TRIANGLE.png b/core/assets/sprites/brick_FULL_HALF_LEFT_TRIANGLE.png new file mode 100644 index 0000000..52c7653 Binary files /dev/null and b/core/assets/sprites/brick_FULL_HALF_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_HALF_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_FULL_HALF_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..14c01b3 Binary files /dev/null and b/core/assets/sprites/brick_FULL_HALF_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_HALF_UP_TRIANGLE.png b/core/assets/sprites/brick_FULL_HALF_UP_TRIANGLE.png new file mode 100644 index 0000000..d65279b Binary files /dev/null and b/core/assets/sprites/brick_FULL_HALF_UP_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_LEFT_DOWN_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_FULL_LEFT_DOWN_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..8c0de03 Binary files /dev/null and b/core/assets/sprites/brick_FULL_LEFT_DOWN_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_LEFT_UP_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_FULL_LEFT_UP_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..ecde3dd Binary files /dev/null and b/core/assets/sprites/brick_FULL_LEFT_UP_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_FULL_UP_LEFT_TRIANGLE.png b/core/assets/sprites/brick_FULL_UP_LEFT_TRIANGLE.png new file mode 100644 index 0000000..124445f Binary files /dev/null and b/core/assets/sprites/brick_FULL_UP_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_DOWN_TRIANGLE.png b/core/assets/sprites/brick_HALF_DOWN_TRIANGLE.png new file mode 100644 index 0000000..f1fd698 Binary files /dev/null and b/core/assets/sprites/brick_HALF_DOWN_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_LEFT_SQUARE.png b/core/assets/sprites/brick_HALF_LEFT_SQUARE.png new file mode 100644 index 0000000..4c51733 Binary files /dev/null and b/core/assets/sprites/brick_HALF_LEFT_SQUARE.png differ diff --git a/core/assets/sprites/brick_HALF_LEFT_TRIANGLE.png b/core/assets/sprites/brick_HALF_LEFT_TRIANGLE.png new file mode 100644 index 0000000..77ea047 Binary files /dev/null and b/core/assets/sprites/brick_HALF_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_LOWER_RECTANGLE.png b/core/assets/sprites/brick_HALF_LOWER_RECTANGLE.png new file mode 100644 index 0000000..762830b Binary files /dev/null and b/core/assets/sprites/brick_HALF_LOWER_RECTANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_RIGHT_SQUARE.png b/core/assets/sprites/brick_HALF_RIGHT_SQUARE.png new file mode 100644 index 0000000..130840b Binary files /dev/null and b/core/assets/sprites/brick_HALF_RIGHT_SQUARE.png differ diff --git a/core/assets/sprites/brick_HALF_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_HALF_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..9d36f2d Binary files /dev/null and b/core/assets/sprites/brick_HALF_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_UPPER_RECTANGLE.png b/core/assets/sprites/brick_HALF_UPPER_RECTANGLE.png new file mode 100644 index 0000000..eed95b4 Binary files /dev/null and b/core/assets/sprites/brick_HALF_UPPER_RECTANGLE.png differ diff --git a/core/assets/sprites/brick_HALF_UP_TRIANGLE.png b/core/assets/sprites/brick_HALF_UP_TRIANGLE.png new file mode 100644 index 0000000..e89c9ad Binary files /dev/null and b/core/assets/sprites/brick_HALF_UP_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_LEFT_DOWN_LEFT_TRIANGLE.png b/core/assets/sprites/brick_LEFT_DOWN_LEFT_TRIANGLE.png new file mode 100644 index 0000000..d45032a Binary files /dev/null and b/core/assets/sprites/brick_LEFT_DOWN_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_LEFT_DOWN_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_LEFT_DOWN_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..cdcae58 Binary files /dev/null and b/core/assets/sprites/brick_LEFT_DOWN_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_LEFT_TRIANGLE.png b/core/assets/sprites/brick_LEFT_TRIANGLE.png new file mode 100644 index 0000000..2524336 Binary files /dev/null and b/core/assets/sprites/brick_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_LEFT_UP_LEFT_TRIANGLE.png b/core/assets/sprites/brick_LEFT_UP_LEFT_TRIANGLE.png new file mode 100644 index 0000000..e371c4f Binary files /dev/null and b/core/assets/sprites/brick_LEFT_UP_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_LEFT_UP_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_LEFT_UP_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..2fdb299 Binary files /dev/null and b/core/assets/sprites/brick_LEFT_UP_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_RECTANGLE.png b/core/assets/sprites/brick_RECTANGLE.png new file mode 100644 index 0000000..a62a75f Binary files /dev/null and b/core/assets/sprites/brick_RECTANGLE.png differ diff --git a/core/assets/sprites/brick_RIGHT_DOWN_LEFT_TRIANGLE.png b/core/assets/sprites/brick_RIGHT_DOWN_LEFT_TRIANGLE.png new file mode 100644 index 0000000..3322407 Binary files /dev/null and b/core/assets/sprites/brick_RIGHT_DOWN_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_RIGHT_DOWN_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_RIGHT_DOWN_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..9b206b7 Binary files /dev/null and b/core/assets/sprites/brick_RIGHT_DOWN_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..0c87c29 Binary files /dev/null and b/core/assets/sprites/brick_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_RIGHT_UP_LEFT_TRIANGLE.png b/core/assets/sprites/brick_RIGHT_UP_LEFT_TRIANGLE.png new file mode 100644 index 0000000..3b98cb6 Binary files /dev/null and b/core/assets/sprites/brick_RIGHT_UP_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_RIGHT_UP_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_RIGHT_UP_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..c0169ef Binary files /dev/null and b/core/assets/sprites/brick_RIGHT_UP_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_UP_LEFT_TRIANGLE.png b/core/assets/sprites/brick_UP_LEFT_TRIANGLE.png new file mode 100644 index 0000000..665b188 Binary files /dev/null and b/core/assets/sprites/brick_UP_LEFT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_UP_RIGHT_TRIANGLE.png b/core/assets/sprites/brick_UP_RIGHT_TRIANGLE.png new file mode 100644 index 0000000..493999e Binary files /dev/null and b/core/assets/sprites/brick_UP_RIGHT_TRIANGLE.png differ diff --git a/core/assets/sprites/brick_UP_TRIANGLE.png b/core/assets/sprites/brick_UP_TRIANGLE.png new file mode 100644 index 0000000..97903d3 Binary files /dev/null and b/core/assets/sprites/brick_UP_TRIANGLE.png differ diff --git a/core/assets/textures.atlas b/core/assets/textures.atlas new file mode 100644 index 0000000..b0fe39a --- /dev/null +++ b/core/assets/textures.atlas @@ -0,0 +1,257 @@ + +textures.png +size: 1024,1024 +format: RGBA8888 +filter: MipMapLinearLinear,MipMapLinearLinear +repeat: none +ball + rotate: false + xy: 800, 824 + size: 128, 128 + orig: 128, 128 + offset: 0, 0 + index: -1 +brick_DIAMOND + rotate: false + xy: 8, 824 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_DOWN_LEFT_TRIANGLE + rotate: false + xy: 8, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_DOWN_RIGHT_TRIANGLE + rotate: false + xy: 272, 824 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_DOWN_TRIANGLE + rotate: false + xy: 8, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_DOWN_LEFT_TRIANGLE + rotate: false + xy: 272, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_HALF_DOWN_TRIANGLE + rotate: false + xy: 536, 824 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_HALF_LEFT_TRIANGLE + rotate: false + xy: 8, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_HALF_RIGHT_TRIANGLE + rotate: false + xy: 272, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_HALF_UP_TRIANGLE + rotate: false + xy: 536, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_LEFT_DOWN_RIGHT_TRIANGLE + rotate: false + xy: 8, 280 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_LEFT_UP_RIGHT_TRIANGLE + rotate: false + xy: 272, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_FULL_UP_LEFT_TRIANGLE + rotate: false + xy: 536, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_DOWN_TRIANGLE + rotate: false + xy: 8, 144 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_LEFT_SQUARE + rotate: false + xy: 272, 280 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_LEFT_TRIANGLE + rotate: false + xy: 536, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_LOWER_RECTANGLE + rotate: false + xy: 8, 8 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_RIGHT_SQUARE + rotate: false + xy: 272, 144 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_RIGHT_TRIANGLE + rotate: false + xy: 536, 280 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_UPPER_RECTANGLE + rotate: false + xy: 272, 8 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_HALF_UP_TRIANGLE + rotate: false + xy: 536, 144 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_LEFT_DOWN_LEFT_TRIANGLE + rotate: false + xy: 536, 8 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 + +textures2.png +size: 1024,1024 +format: RGBA8888 +filter: MipMapLinearLinear,MipMapLinearLinear +repeat: none +brick_LEFT_DOWN_RIGHT_TRIANGLE + rotate: false + xy: 8, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_LEFT_TRIANGLE + rotate: false + xy: 8, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_LEFT_UP_LEFT_TRIANGLE + rotate: false + xy: 272, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_LEFT_UP_RIGHT_TRIANGLE + rotate: false + xy: 8, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RECTANGLE + rotate: false + xy: 272, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RIGHT_DOWN_LEFT_TRIANGLE + rotate: false + xy: 536, 688 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RIGHT_DOWN_RIGHT_TRIANGLE + rotate: false + xy: 8, 280 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RIGHT_TRIANGLE + rotate: false + xy: 272, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RIGHT_UP_LEFT_TRIANGLE + rotate: false + xy: 536, 552 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_RIGHT_UP_RIGHT_TRIANGLE + rotate: false + xy: 8, 144 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_UP_LEFT_TRIANGLE + rotate: false + xy: 272, 280 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_UP_RIGHT_TRIANGLE + rotate: false + xy: 536, 416 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 +brick_UP_TRIANGLE + rotate: false + xy: 8, 8 + size: 256, 128 + orig: 256, 128 + offset: 0, 0 + index: -1 diff --git a/core/assets/textures.png b/core/assets/textures.png new file mode 100644 index 0000000..9983e65 Binary files /dev/null and b/core/assets/textures.png differ diff --git a/core/assets/textures2.png b/core/assets/textures2.png new file mode 100644 index 0000000..85d0ec9 Binary files /dev/null and b/core/assets/textures2.png differ diff --git a/core/src/com/me/brickbuster/BrickBuster.java b/core/src/com/me/brickbuster/BrickBuster.java index f75e153..df4d0ac 100644 --- a/core/src/com/me/brickbuster/BrickBuster.java +++ b/core/src/com/me/brickbuster/BrickBuster.java @@ -2,6 +2,7 @@ package com.me.brickbuster; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; @@ -28,6 +29,8 @@ public class BrickBuster extends Game { public ShapeRenderer sr; public PolygonSpriteBatch pb; + public AssetManager assets; + @Override public void create () { cam = new OrthographicCamera(); @@ -42,6 +45,8 @@ public class BrickBuster extends Game { sr = new ShapeRenderer(); pb = new PolygonSpriteBatch(); + assets = new AssetManager(); + setScreen(new MenuState(this)); } diff --git a/core/src/com/me/brickbuster/entity/Ball.java b/core/src/com/me/brickbuster/entity/Ball.java index 828a2c7..8490258 100644 --- a/core/src/com/me/brickbuster/entity/Ball.java +++ b/core/src/com/me/brickbuster/entity/Ball.java @@ -2,6 +2,8 @@ package com.me.brickbuster.entity; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.math.MathUtils; @@ -27,22 +29,29 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener { private boolean isStuck = true; private boolean touchedPaddle = false; + private TextureRegion texture; + private Body body; 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; + + texture = state.textures.findRegion("ball"); + createBody(); } @Override public void render(ShapeRenderer sr) { - sr.begin(ShapeType.Filled); - sr.setColor(BALL_COLOR); - sr.circle(pos.x * PlayState.PIXEL_PER_METER, - pos.y * PlayState.PIXEL_PER_METER, - RADIUS * PlayState.PIXEL_PER_METER); - sr.end(); + SpriteBatch sb = state.getGame().sb; + sb.begin(); + sb.setColor(Color.WHITE); + sb.draw(texture, (pos.x - RADIUS) * PlayState.PIXEL_PER_METER, + (pos.y - RADIUS) * PlayState.PIXEL_PER_METER, + RADIUS*2 * PlayState.PIXEL_PER_METER, + RADIUS*2 * PlayState.PIXEL_PER_METER); + sb.end(); } @Override diff --git a/core/src/com/me/brickbuster/entity/Brick.java b/core/src/com/me/brickbuster/entity/Brick.java index 5b52fbc..4db3a8d 100644 --- a/core/src/com/me/brickbuster/entity/Brick.java +++ b/core/src/com/me/brickbuster/entity/Brick.java @@ -1,18 +1,14 @@ package com.me.brickbuster.entity; -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.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.badlogic.gdx.math.EarClippingTriangulator; +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.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; @@ -22,18 +18,13 @@ import com.me.brickbuster.state.PlayState; public class Brick extends Entity implements PhysicsBody, CollisionListener { - public static final float BRICK_WIDTH = 4.6f; - public static final float BRICK_HEIGHT = 2.3f; - - private static final EarClippingTriangulator ECT = new EarClippingTriangulator(); - private static final Vector2 tmp = new Vector2(); + public static final float BRICK_WIDTH = 5.2f; + public static final float BRICK_HEIGHT = 2.6f; private BrickType type; private BrickShape.Shape shape; private PowerUpType powerUpType; - private Pixmap pm; - private Texture solid; private TextureRegion region; private Body body; @@ -44,32 +35,20 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener { this.type = type; this.shape = shape; this.powerUpType = powerUpType; - this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888); - this.pm.setColor(type.getColor()); - this.pm.fill(); - this.solid = new Texture(pm); - this.region = new TextureRegion(solid); + this.region = state.textures.findRegion("brick_" + shape.name()); 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(); + SpriteBatch sb = state.getGame().sb; + sb.setColor(type.getColor()); + float x = (getX() - BRICK_WIDTH/2) * PlayState.PIXEL_PER_METER; + float y = (getY() - BRICK_HEIGHT/2) * PlayState.PIXEL_PER_METER; + sb.draw(region, x, y, + BRICK_WIDTH/2 * PlayState.PIXEL_PER_METER, BRICK_HEIGHT/2 * PlayState.PIXEL_PER_METER, + BRICK_WIDTH * PlayState.PIXEL_PER_METER, BRICK_HEIGHT * PlayState.PIXEL_PER_METER, + 1f, 1f, MathUtils.radiansToDegrees * body.getAngle()); } @Override @@ -169,12 +148,6 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener { body.setTransform(pos, 0); } - @Override - public void dispose() { - solid.dispose(); - pm.dispose(); - } - public BrickType getType() { return type; } diff --git a/core/src/com/me/brickbuster/entity/BrickShape.java b/core/src/com/me/brickbuster/entity/BrickShape.java index 2e40c9d..61a5f09 100644 --- a/core/src/com/me/brickbuster/entity/BrickShape.java +++ b/core/src/com/me/brickbuster/entity/BrickShape.java @@ -14,55 +14,67 @@ public class BrickShape { public enum Shape { - RECTANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT), + RECTANGLE(0, 0, BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT), - HALF_LEFT_SQUARE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), - HALF_RIGHT_SQUARE(BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), - HALF_UPPER_RECTANGLE(MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT), - HALF_LOWER_RECTANGLE(BOTTOM_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | BOTTOM_RIGHT), + HALF_LEFT_SQUARE(1, 0, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), + HALF_RIGHT_SQUARE(2, 0, BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), + HALF_UPPER_RECTANGLE(4, 0, MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT), + HALF_LOWER_RECTANGLE(5, 0, BOTTOM_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | BOTTOM_RIGHT), - DIAMOND(MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_MIDDLE), + DIAMOND(2, 1, MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_MIDDLE), - UP_TRIANGLE(BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_RIGHT), - HALF_UP_TRIANGLE(BOTTOM_LEFT | CENTER | BOTTOM_RIGHT), - FULL_HALF_UP_TRIANGE(BOTTOM_LEFT | MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_RIGHT), - DOWN_TRIANGLE(TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE), - HALF_DOWN_TRIANGLE(TOP_LEFT | TOP_RIGHT | CENTER), - FULL_HALF_DOWN_TRIANGE(MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT | BOTTOM_MIDDLE), - LEFT_TRIANGLE(MIDDLE_LEFT | TOP_RIGHT | BOTTOM_RIGHT), - HALF_LEFT_TRIANGLE(CENTER | TOP_RIGHT | BOTTOM_RIGHT), - FULL_HALF_LEFT_TRIANGE(MIDDLE_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE), - RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | MIDDLE_RIGHT), - HALF_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | CENTER), - FULL_HALF_RIGHT_TRIANGE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_MIDDLE), + UP_TRIANGLE(2, 2, BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_RIGHT), + HALF_UP_TRIANGLE(3, 5, BOTTOM_LEFT | CENTER | BOTTOM_RIGHT), + FULL_HALF_UP_TRIANGLE(1, 5, BOTTOM_LEFT | MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_RIGHT), + DOWN_TRIANGLE(2, 3, TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE), + HALF_DOWN_TRIANGLE(2, 5, TOP_LEFT | TOP_RIGHT | CENTER), + FULL_HALF_DOWN_TRIANGLE(0, 5, MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT | BOTTOM_MIDDLE), + LEFT_TRIANGLE(3, 4, MIDDLE_LEFT | TOP_RIGHT | BOTTOM_RIGHT), + HALF_LEFT_TRIANGLE(2, 4, CENTER | TOP_RIGHT | BOTTOM_RIGHT), + FULL_HALF_LEFT_TRIANGLE(1, 3, MIDDLE_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE), + RIGHT_TRIANGLE(0, 4, BOTTOM_LEFT | TOP_LEFT | MIDDLE_RIGHT), + HALF_RIGHT_TRIANGLE(1, 4, BOTTOM_LEFT | TOP_LEFT | CENTER), + FULL_HALF_RIGHT_TRIANGLE(0, 3, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_MIDDLE), - DOWN_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_RIGHT | BOTTOM_RIGHT), - LEFT_DOWN_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), - FULL_LEFT_DOWN_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), - RIGHT_DOWN_RIGHT_TRIANGLE(BOTTOM_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), + DOWN_RIGHT_TRIANGLE(0, 1, BOTTOM_LEFT | TOP_RIGHT | BOTTOM_RIGHT), + LEFT_DOWN_RIGHT_TRIANGLE(0, 6, BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), + FULL_LEFT_DOWN_RIGHT_TRIANGLE(3, 1, BOTTOM_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), + RIGHT_DOWN_RIGHT_TRIANGLE(2, 6, BOTTOM_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), - UP_RIGHT_TRIANGLE(TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT), - LEFT_UP_RIGHT_TRIANGLE(TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), - FULL_LEFT_UP_RIGHT_TRIANGLE(TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE), - RIGHT_UP_RIGHT_TRIANGLE(TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), + UP_RIGHT_TRIANGLE(0, 2, TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT), + LEFT_UP_RIGHT_TRIANGLE(0, 7, TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE), + FULL_LEFT_UP_RIGHT_TRIANGLE(3, 0, TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE), + RIGHT_UP_RIGHT_TRIANGLE(2, 7, TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT), - UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT), - LEFT_UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE), - FULL_UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE), - RIGHT_UP_LEFT_TRIANGLE(BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT), + UP_LEFT_TRIANGLE(1, 2, BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT), + LEFT_UP_LEFT_TRIANGLE(1, 7, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE), + FULL_UP_LEFT_TRIANGLE(3, 2, BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE), + RIGHT_UP_LEFT_TRIANGLE(3, 7, BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT), - DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | BOTTOM_RIGHT), - LEFT_DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | BOTTOM_MIDDLE), - FULL_DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_RIGHT), - RIGHT_DOWN_LEFT_TRIANGLE(BOTTOM_MIDDLE | TOP_MIDDLE | BOTTOM_RIGHT), + DOWN_LEFT_TRIANGLE(1, 1, BOTTOM_LEFT | TOP_LEFT | BOTTOM_RIGHT), + LEFT_DOWN_LEFT_TRIANGLE(1, 6, BOTTOM_LEFT | TOP_LEFT | BOTTOM_MIDDLE), + FULL_DOWN_LEFT_TRIANGLE(3, 3, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_RIGHT), + RIGHT_DOWN_LEFT_TRIANGLE(3, 6, BOTTOM_MIDDLE | TOP_MIDDLE | BOTTOM_RIGHT), ; + private int row; + private int col; private int mask; - Shape(int mask) { + Shape(int row, int col, int mask) { + this.row = row; + this.col = col; this.mask = mask; } + public int getRow() { + return row; + } + + public int getCol() { + return col; + } + public int getMask() { return mask; } diff --git a/core/src/com/me/brickbuster/layout/GridLevelLoader.java b/core/src/com/me/brickbuster/layout/GridLevelLoader.java index d9f8579..4ad351b 100644 --- a/core/src/com/me/brickbuster/layout/GridLevelLoader.java +++ b/core/src/com/me/brickbuster/layout/GridLevelLoader.java @@ -5,7 +5,7 @@ import com.me.brickbuster.state.PlayState; public class GridLevelLoader implements LevelLoader { public static final float POWER_UP_CHANCE = 0.15f; - public static final int COLUMNS = 11; + public static final int COLUMNS = 10; public static final int ROWS = 20; public static final int ROUNDS = 2; @@ -19,7 +19,7 @@ public class GridLevelLoader implements LevelLoader { @Override public Level getNextLevel() { if (playCount++ < ROUNDS) { - return new Level(new GridLayout(state, COLUMNS, ROWS, POWER_UP_CHANCE)); + return new Level(new GridLayout(state, COLUMNS, ROWS, POWER_UP_CHANCE, true, true)); } return null; } diff --git a/core/src/com/me/brickbuster/state/EditorState.java b/core/src/com/me/brickbuster/state/EditorState.java index 0499c76..a56babf 100644 --- a/core/src/com/me/brickbuster/state/EditorState.java +++ b/core/src/com/me/brickbuster/state/EditorState.java @@ -46,6 +46,8 @@ public class EditorState extends FieldState { @Override public void setup() { + super.setup(); + world = new World(new Vector2(), false); world.setContactListener(new Box2dContactListener()); @@ -62,6 +64,7 @@ public class EditorState extends FieldState { @Override public void render() { + game.sb.begin(); for (int col = 0; col < bricks.length; col++) { for (int row = 0; row < bricks[col].length; row++) { if (col == this.col && row == this.row && !blink) { @@ -77,6 +80,7 @@ public class EditorState extends FieldState { if (!blink) { placeHolder.render(game.sr); } + game.sb.end(); debugRenderer.render(world, game.cam.combined.cpy().scl(PlayState.PIXEL_PER_METER)); diff --git a/core/src/com/me/brickbuster/state/FieldState.java b/core/src/com/me/brickbuster/state/FieldState.java index d5812cc..f7ff6fd 100644 --- a/core/src/com/me/brickbuster/state/FieldState.java +++ b/core/src/com/me/brickbuster/state/FieldState.java @@ -1,14 +1,24 @@ package com.me.brickbuster.state; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.physics.box2d.World; import com.me.brickbuster.BrickBuster; public abstract class FieldState extends State { public World world; + public TextureAtlas textures; public FieldState(BrickBuster game) { super(game); } + @Override + public void setup() { + game.assets.load("textures.atlas", TextureAtlas.class); + game.assets.finishLoading(); + + textures = game.assets.get("textures.atlas", TextureAtlas.class); + } + } diff --git a/core/src/com/me/brickbuster/state/PlayState.java b/core/src/com/me/brickbuster/state/PlayState.java index f1672ab..0e873ba 100644 --- a/core/src/com/me/brickbuster/state/PlayState.java +++ b/core/src/com/me/brickbuster/state/PlayState.java @@ -2,6 +2,8 @@ package com.me.brickbuster.state; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.*; import com.badlogic.gdx.utils.Array; @@ -19,7 +21,7 @@ public class PlayState extends FieldState { public static final float BOARD_WIDTH = 54f; public static final float BOARD_HEIGHT = 96f; public static final float PIXEL_PER_METER = BrickBuster.BOARD_WIDTH / BOARD_WIDTH; - public static final float EDGE_PADDING = 1.7f; + public static final float EDGE_PADDING = 1f; public static final Vector2 lowerLeftCorner = new Vector2(EDGE_PADDING,0); @@ -53,11 +55,14 @@ public class PlayState extends FieldState { @Override public void setup() { + super.setup(); + // Initialize a world with no gravity world = new World(new Vector2(), false); world.setContactListener(new Box2dContactListener()); bodies = new Array(); + //levelLoader = new FileLevelLoader(this); levelLoader = new GridLevelLoader(this); currentLevel = levelLoader.getNextLevel(); @@ -75,9 +80,11 @@ public class PlayState extends FieldState { } long start = System.nanoTime(); + game.sb.begin(); for (Brick block : bricks) { block.render(game.sr); } + game.sb.end(); for (PowerUp powerUp : powerUps) { powerUp.render(game.sr); }