Render bricks and ball using sprites instead of constructed polygons
Changed field width to 10 blocks instead of 11
BIN
core/assets/sprites/ball.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
core/assets/sprites/brick_DIAMOND.png
Normal file
After Width: | Height: | Size: 1013 B |
BIN
core/assets/sprites/brick_DOWN_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_DOWN_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_DOWN_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_FULL_DOWN_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_FULL_HALF_DOWN_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_FULL_HALF_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_FULL_HALF_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 963 B |
BIN
core/assets/sprites/brick_FULL_HALF_UP_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
core/assets/sprites/brick_FULL_LEFT_DOWN_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_FULL_LEFT_UP_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_FULL_UP_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_HALF_DOWN_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
core/assets/sprites/brick_HALF_LEFT_SQUARE.png
Normal file
After Width: | Height: | Size: 730 B |
BIN
core/assets/sprites/brick_HALF_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_HALF_LOWER_RECTANGLE.png
Normal file
After Width: | Height: | Size: 678 B |
BIN
core/assets/sprites/brick_HALF_RIGHT_SQUARE.png
Normal file
After Width: | Height: | Size: 732 B |
BIN
core/assets/sprites/brick_HALF_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_HALF_UPPER_RECTANGLE.png
Normal file
After Width: | Height: | Size: 683 B |
BIN
core/assets/sprites/brick_HALF_UP_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
core/assets/sprites/brick_LEFT_DOWN_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_LEFT_DOWN_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_LEFT_UP_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_LEFT_UP_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_RECTANGLE.png
Normal file
After Width: | Height: | Size: 534 B |
BIN
core/assets/sprites/brick_RIGHT_DOWN_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_RIGHT_DOWN_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
core/assets/sprites/brick_RIGHT_UP_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_RIGHT_UP_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_UP_LEFT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_UP_RIGHT_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
core/assets/sprites/brick_UP_TRIANGLE.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
257
core/assets/textures.atlas
Normal file
@ -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
|
BIN
core/assets/textures.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
core/assets/textures2.png
Normal file
After Width: | Height: | Size: 16 KiB |
@ -2,6 +2,7 @@ package com.me.brickbuster;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Game;
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.assets.AssetManager;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
@ -28,6 +29,8 @@ public class BrickBuster extends Game {
|
|||||||
public ShapeRenderer sr;
|
public ShapeRenderer sr;
|
||||||
public PolygonSpriteBatch pb;
|
public PolygonSpriteBatch pb;
|
||||||
|
|
||||||
|
public AssetManager assets;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
cam = new OrthographicCamera();
|
cam = new OrthographicCamera();
|
||||||
@ -42,6 +45,8 @@ public class BrickBuster extends Game {
|
|||||||
sr = new ShapeRenderer();
|
sr = new ShapeRenderer();
|
||||||
pb = new PolygonSpriteBatch();
|
pb = new PolygonSpriteBatch();
|
||||||
|
|
||||||
|
assets = new AssetManager();
|
||||||
|
|
||||||
setScreen(new MenuState(this));
|
setScreen(new MenuState(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package com.me.brickbuster.entity;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
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;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
@ -27,22 +29,29 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
|
|||||||
private boolean isStuck = true;
|
private boolean isStuck = true;
|
||||||
private boolean touchedPaddle = false;
|
private boolean touchedPaddle = false;
|
||||||
|
|
||||||
|
private TextureRegion texture;
|
||||||
|
|
||||||
private Body body;
|
private Body body;
|
||||||
|
|
||||||
public Ball(PlayState state) {
|
public Ball(PlayState state) {
|
||||||
super(state, state.paddle.getX(), state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
|
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;
|
||||||
|
|
||||||
|
texture = state.textures.findRegion("ball");
|
||||||
|
|
||||||
createBody();
|
createBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(ShapeRenderer sr) {
|
public void render(ShapeRenderer sr) {
|
||||||
sr.begin(ShapeType.Filled);
|
SpriteBatch sb = state.getGame().sb;
|
||||||
sr.setColor(BALL_COLOR);
|
sb.begin();
|
||||||
sr.circle(pos.x * PlayState.PIXEL_PER_METER,
|
sb.setColor(Color.WHITE);
|
||||||
pos.y * PlayState.PIXEL_PER_METER,
|
sb.draw(texture, (pos.x - RADIUS) * PlayState.PIXEL_PER_METER,
|
||||||
RADIUS * PlayState.PIXEL_PER_METER);
|
(pos.y - RADIUS) * PlayState.PIXEL_PER_METER,
|
||||||
sr.end();
|
RADIUS*2 * PlayState.PIXEL_PER_METER,
|
||||||
|
RADIUS*2 * PlayState.PIXEL_PER_METER);
|
||||||
|
sb.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
package com.me.brickbuster.entity;
|
package com.me.brickbuster.entity;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
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.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
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.math.Vector2;
|
||||||
import com.badlogic.gdx.physics.box2d.Body;
|
import com.badlogic.gdx.physics.box2d.Body;
|
||||||
import com.badlogic.gdx.physics.box2d.BodyDef;
|
import com.badlogic.gdx.physics.box2d.BodyDef;
|
||||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||||
import com.badlogic.gdx.physics.box2d.PolygonShape;
|
import com.badlogic.gdx.physics.box2d.PolygonShape;
|
||||||
import com.badlogic.gdx.utils.ShortArray;
|
|
||||||
import com.me.brickbuster.entity.powerup.PowerUpType;
|
import com.me.brickbuster.entity.powerup.PowerUpType;
|
||||||
import com.me.brickbuster.physics.CollisionListener;
|
import com.me.brickbuster.physics.CollisionListener;
|
||||||
import com.me.brickbuster.physics.EntityType;
|
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 class Brick extends Entity implements PhysicsBody, CollisionListener {
|
||||||
|
|
||||||
public static final float BRICK_WIDTH = 4.6f;
|
public static final float BRICK_WIDTH = 5.2f;
|
||||||
public static final float BRICK_HEIGHT = 2.3f;
|
public static final float BRICK_HEIGHT = 2.6f;
|
||||||
|
|
||||||
private static final EarClippingTriangulator ECT = new EarClippingTriangulator();
|
|
||||||
private static final Vector2 tmp = new Vector2();
|
|
||||||
|
|
||||||
private BrickType type;
|
private BrickType type;
|
||||||
private BrickShape.Shape shape;
|
private BrickShape.Shape shape;
|
||||||
private PowerUpType powerUpType;
|
private PowerUpType powerUpType;
|
||||||
|
|
||||||
private Pixmap pm;
|
|
||||||
private Texture solid;
|
|
||||||
private TextureRegion region;
|
private TextureRegion region;
|
||||||
|
|
||||||
private Body body;
|
private Body body;
|
||||||
@ -44,32 +35,20 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.shape = shape;
|
this.shape = shape;
|
||||||
this.powerUpType = powerUpType;
|
this.powerUpType = powerUpType;
|
||||||
this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888);
|
this.region = state.textures.findRegion("brick_" + shape.name());
|
||||||
this.pm.setColor(type.getColor());
|
|
||||||
this.pm.fill();
|
|
||||||
this.solid = new Texture(pm);
|
|
||||||
this.region = new TextureRegion(solid);
|
|
||||||
createBody();
|
createBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(ShapeRenderer sr) {
|
public void render(ShapeRenderer sr) {
|
||||||
PolygonShape shape = (PolygonShape) body.getFixtureList().get(0).getShape();
|
SpriteBatch sb = state.getGame().sb;
|
||||||
float[] vertices = new float[shape.getVertexCount()*2];
|
sb.setColor(type.getColor());
|
||||||
for (int i = 0; i < vertices.length/2; i++) {
|
float x = (getX() - BRICK_WIDTH/2) * PlayState.PIXEL_PER_METER;
|
||||||
shape.getVertex(i, tmp);
|
float y = (getY() - BRICK_HEIGHT/2) * PlayState.PIXEL_PER_METER;
|
||||||
Vector2 vertex = body.getWorldPoint(tmp);
|
sb.draw(region, x, y,
|
||||||
vertices[i*2] = vertex.x * PlayState.PIXEL_PER_METER;
|
BRICK_WIDTH/2 * PlayState.PIXEL_PER_METER, BRICK_HEIGHT/2 * PlayState.PIXEL_PER_METER,
|
||||||
vertices[i*2 + 1] = vertex.y * PlayState.PIXEL_PER_METER;
|
BRICK_WIDTH * PlayState.PIXEL_PER_METER, BRICK_HEIGHT * PlayState.PIXEL_PER_METER,
|
||||||
}
|
1f, 1f, MathUtils.radiansToDegrees * body.getAngle());
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -169,12 +148,6 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
|
|||||||
body.setTransform(pos, 0);
|
body.setTransform(pos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
solid.dispose();
|
|
||||||
pm.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BrickType getType() {
|
public BrickType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -14,55 +14,67 @@ public class BrickShape {
|
|||||||
|
|
||||||
public enum Shape {
|
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_LEFT_SQUARE(1, 0, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE),
|
||||||
HALF_RIGHT_SQUARE(BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
HALF_RIGHT_SQUARE(2, 0, BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
HALF_UPPER_RECTANGLE(MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT),
|
HALF_UPPER_RECTANGLE(4, 0, MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT),
|
||||||
HALF_LOWER_RECTANGLE(BOTTOM_LEFT | MIDDLE_LEFT | MIDDLE_RIGHT | BOTTOM_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),
|
UP_TRIANGLE(2, 2, BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_RIGHT),
|
||||||
HALF_UP_TRIANGLE(BOTTOM_LEFT | CENTER | BOTTOM_RIGHT),
|
HALF_UP_TRIANGLE(3, 5, BOTTOM_LEFT | CENTER | BOTTOM_RIGHT),
|
||||||
FULL_HALF_UP_TRIANGE(BOTTOM_LEFT | MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_RIGHT),
|
FULL_HALF_UP_TRIANGLE(1, 5, BOTTOM_LEFT | MIDDLE_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_RIGHT),
|
||||||
DOWN_TRIANGLE(TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE),
|
DOWN_TRIANGLE(2, 3, TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE),
|
||||||
HALF_DOWN_TRIANGLE(TOP_LEFT | TOP_RIGHT | CENTER),
|
HALF_DOWN_TRIANGLE(2, 5, TOP_LEFT | TOP_RIGHT | CENTER),
|
||||||
FULL_HALF_DOWN_TRIANGE(MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT | BOTTOM_MIDDLE),
|
FULL_HALF_DOWN_TRIANGLE(0, 5, MIDDLE_LEFT | TOP_LEFT | TOP_RIGHT | MIDDLE_RIGHT | BOTTOM_MIDDLE),
|
||||||
LEFT_TRIANGLE(MIDDLE_LEFT | TOP_RIGHT | BOTTOM_RIGHT),
|
LEFT_TRIANGLE(3, 4, MIDDLE_LEFT | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
HALF_LEFT_TRIANGLE(CENTER | TOP_RIGHT | BOTTOM_RIGHT),
|
HALF_LEFT_TRIANGLE(2, 4, CENTER | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
FULL_HALF_LEFT_TRIANGE(MIDDLE_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE),
|
FULL_HALF_LEFT_TRIANGLE(1, 3, MIDDLE_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE),
|
||||||
RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | MIDDLE_RIGHT),
|
RIGHT_TRIANGLE(0, 4, BOTTOM_LEFT | TOP_LEFT | MIDDLE_RIGHT),
|
||||||
HALF_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | CENTER),
|
HALF_RIGHT_TRIANGLE(1, 4, BOTTOM_LEFT | TOP_LEFT | CENTER),
|
||||||
FULL_HALF_RIGHT_TRIANGE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | MIDDLE_RIGHT | BOTTOM_MIDDLE),
|
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),
|
DOWN_RIGHT_TRIANGLE(0, 1, BOTTOM_LEFT | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
LEFT_DOWN_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE),
|
LEFT_DOWN_RIGHT_TRIANGLE(0, 6, BOTTOM_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE),
|
||||||
FULL_LEFT_DOWN_RIGHT_TRIANGLE(BOTTOM_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
FULL_LEFT_DOWN_RIGHT_TRIANGLE(3, 1, BOTTOM_LEFT | TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
RIGHT_DOWN_RIGHT_TRIANGLE(BOTTOM_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),
|
UP_RIGHT_TRIANGLE(0, 2, TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
LEFT_UP_RIGHT_TRIANGLE(TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE),
|
LEFT_UP_RIGHT_TRIANGLE(0, 7, TOP_LEFT | TOP_MIDDLE | BOTTOM_MIDDLE),
|
||||||
FULL_LEFT_UP_RIGHT_TRIANGLE(TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE),
|
FULL_LEFT_UP_RIGHT_TRIANGLE(3, 0, TOP_LEFT | TOP_RIGHT | BOTTOM_RIGHT | BOTTOM_MIDDLE),
|
||||||
RIGHT_UP_RIGHT_TRIANGLE(TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
RIGHT_UP_RIGHT_TRIANGLE(2, 7, TOP_MIDDLE | TOP_RIGHT | BOTTOM_RIGHT),
|
||||||
|
|
||||||
UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT),
|
UP_LEFT_TRIANGLE(1, 2, BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT),
|
||||||
LEFT_UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE),
|
LEFT_UP_LEFT_TRIANGLE(1, 7, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE),
|
||||||
FULL_UP_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE),
|
FULL_UP_LEFT_TRIANGLE(3, 2, BOTTOM_LEFT | TOP_LEFT | TOP_RIGHT | BOTTOM_MIDDLE),
|
||||||
RIGHT_UP_LEFT_TRIANGLE(BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT),
|
RIGHT_UP_LEFT_TRIANGLE(3, 7, BOTTOM_MIDDLE | TOP_MIDDLE | TOP_RIGHT),
|
||||||
|
|
||||||
DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | BOTTOM_RIGHT),
|
DOWN_LEFT_TRIANGLE(1, 1, BOTTOM_LEFT | TOP_LEFT | BOTTOM_RIGHT),
|
||||||
LEFT_DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | BOTTOM_MIDDLE),
|
LEFT_DOWN_LEFT_TRIANGLE(1, 6, BOTTOM_LEFT | TOP_LEFT | BOTTOM_MIDDLE),
|
||||||
FULL_DOWN_LEFT_TRIANGLE(BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_RIGHT),
|
FULL_DOWN_LEFT_TRIANGLE(3, 3, BOTTOM_LEFT | TOP_LEFT | TOP_MIDDLE | BOTTOM_RIGHT),
|
||||||
RIGHT_DOWN_LEFT_TRIANGLE(BOTTOM_MIDDLE | 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;
|
private int mask;
|
||||||
|
|
||||||
Shape(int mask) {
|
Shape(int row, int col, int mask) {
|
||||||
|
this.row = row;
|
||||||
|
this.col = col;
|
||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRow() {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCol() {
|
||||||
|
return col;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMask() {
|
public int getMask() {
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import com.me.brickbuster.state.PlayState;
|
|||||||
public class GridLevelLoader implements LevelLoader {
|
public class GridLevelLoader implements LevelLoader {
|
||||||
|
|
||||||
public static final float POWER_UP_CHANCE = 0.15f;
|
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 ROWS = 20;
|
||||||
public static final int ROUNDS = 2;
|
public static final int ROUNDS = 2;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ public class GridLevelLoader implements LevelLoader {
|
|||||||
@Override
|
@Override
|
||||||
public Level getNextLevel() {
|
public Level getNextLevel() {
|
||||||
if (playCount++ < ROUNDS) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ public class EditorState extends FieldState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
super.setup();
|
||||||
|
|
||||||
world = new World(new Vector2(), false);
|
world = new World(new Vector2(), false);
|
||||||
world.setContactListener(new Box2dContactListener());
|
world.setContactListener(new Box2dContactListener());
|
||||||
|
|
||||||
@ -62,6 +64,7 @@ public class EditorState extends FieldState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
game.sb.begin();
|
||||||
for (int col = 0; col < bricks.length; col++) {
|
for (int col = 0; col < bricks.length; col++) {
|
||||||
for (int row = 0; row < bricks[col].length; row++) {
|
for (int row = 0; row < bricks[col].length; row++) {
|
||||||
if (col == this.col && row == this.row && !blink) {
|
if (col == this.col && row == this.row && !blink) {
|
||||||
@ -77,6 +80,7 @@ public class EditorState extends FieldState {
|
|||||||
if (!blink) {
|
if (!blink) {
|
||||||
placeHolder.render(game.sr);
|
placeHolder.render(game.sr);
|
||||||
}
|
}
|
||||||
|
game.sb.end();
|
||||||
|
|
||||||
debugRenderer.render(world, game.cam.combined.cpy().scl(PlayState.PIXEL_PER_METER));
|
debugRenderer.render(world, game.cam.combined.cpy().scl(PlayState.PIXEL_PER_METER));
|
||||||
|
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
package com.me.brickbuster.state;
|
package com.me.brickbuster.state;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||||
import com.badlogic.gdx.physics.box2d.World;
|
import com.badlogic.gdx.physics.box2d.World;
|
||||||
import com.me.brickbuster.BrickBuster;
|
import com.me.brickbuster.BrickBuster;
|
||||||
|
|
||||||
public abstract class FieldState extends State {
|
public abstract class FieldState extends State {
|
||||||
|
|
||||||
public World world;
|
public World world;
|
||||||
|
public TextureAtlas textures;
|
||||||
|
|
||||||
public FieldState(BrickBuster game) {
|
public FieldState(BrickBuster game) {
|
||||||
super(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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.me.brickbuster.state;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
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.math.Vector2;
|
||||||
import com.badlogic.gdx.physics.box2d.*;
|
import com.badlogic.gdx.physics.box2d.*;
|
||||||
import com.badlogic.gdx.utils.Array;
|
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_WIDTH = 54f;
|
||||||
public static final float BOARD_HEIGHT = 96f;
|
public static final float BOARD_HEIGHT = 96f;
|
||||||
public static final float PIXEL_PER_METER = BrickBuster.BOARD_WIDTH / BOARD_WIDTH;
|
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 =
|
public static final Vector2 lowerLeftCorner =
|
||||||
new Vector2(EDGE_PADDING,0);
|
new Vector2(EDGE_PADDING,0);
|
||||||
@ -53,11 +55,14 @@ public class PlayState extends FieldState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
super.setup();
|
||||||
|
|
||||||
// Initialize a world with no gravity
|
// Initialize a world with no gravity
|
||||||
world = new World(new Vector2(), false);
|
world = new World(new Vector2(), false);
|
||||||
world.setContactListener(new Box2dContactListener());
|
world.setContactListener(new Box2dContactListener());
|
||||||
bodies = new Array<Body>();
|
bodies = new Array<Body>();
|
||||||
|
|
||||||
|
//levelLoader = new FileLevelLoader(this);
|
||||||
levelLoader = new GridLevelLoader(this);
|
levelLoader = new GridLevelLoader(this);
|
||||||
currentLevel = levelLoader.getNextLevel();
|
currentLevel = levelLoader.getNextLevel();
|
||||||
|
|
||||||
@ -75,9 +80,11 @@ public class PlayState extends FieldState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
game.sb.begin();
|
||||||
for (Brick block : bricks) {
|
for (Brick block : bricks) {
|
||||||
block.render(game.sr);
|
block.render(game.sr);
|
||||||
}
|
}
|
||||||
|
game.sb.end();
|
||||||
for (PowerUp powerUp : powerUps) {
|
for (PowerUp powerUp : powerUps) {
|
||||||
powerUp.render(game.sr);
|
powerUp.render(game.sr);
|
||||||
}
|
}
|
||||||
|