Compare commits

..

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

70 changed files with 177 additions and 2119 deletions

View File

@ -44,7 +44,6 @@ project(":desktop") {
dependencies { dependencies {
compile project(":core") compile project(":core")
compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"

View File

@ -1,358 +0,0 @@
{
bricks: [
{
row: 15
type: HARD
shape: RECTANGLE
}
{
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 1
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 1
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 1
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 1
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 1
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 1
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 2
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 2
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 2
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 2
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 2
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 2
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 3
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 3
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 3
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 3
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 3
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 3
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 4
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 4
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 4
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 4
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 4
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 4
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 5
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 5
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 5
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 5
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 5
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 5
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 6
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 6
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 6
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 6
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 6
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 6
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 7
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 7
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 7
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 7
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 7
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 7
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 8
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 8
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 8
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 8
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 8
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 8
row: 20
type: STANDARD_40
shape: RECTANGLE
}
{
col: 9
row: 15
type: HARD
shape: RECTANGLE
}
{
col: 9
row: 16
type: STANDARD_50
shape: RECTANGLE
}
{
col: 9
row: 17
type: STANDARD_80
shape: RECTANGLE
}
{
col: 9
row: 18
type: STANDARD_60
shape: RECTANGLE
}
{
col: 9
row: 19
type: STANDARD_70
shape: RECTANGLE
}
{
col: 9
row: 20
type: STANDARD_40
shape: RECTANGLE
}
]
}

View File

@ -1,598 +0,0 @@
{
bricks: [
{
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
row: 6
type: STANDARD_40
shape: DIAMOND
}
{
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
row: 9
type: STANDARD_40
shape: FULL_LEFT_UP_RIGHT_TRIANGLE
}
{
row: 10
type: STANDARD_40
shape: RIGHT_UP_RIGHT_TRIANGLE
}
{
col: 1
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 1
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 1
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
col: 1
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 1
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 1
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 1
row: 11
type: STANDARD_40
shape: FULL_LEFT_UP_RIGHT_TRIANGLE
}
{
col: 1
row: 12
type: STANDARD_40
shape: RIGHT_UP_RIGHT_TRIANGLE
}
{
col: 2
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 2
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 2
row: 7
type: STANDARD_50
shape: DIAMOND
}
{
col: 2
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 2
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 2
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 2
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 2
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 2
row: 13
type: STANDARD_40
shape: FULL_LEFT_UP_RIGHT_TRIANGLE
}
{
col: 2
row: 14
type: STANDARD_40
shape: RIGHT_UP_RIGHT_TRIANGLE
}
{
col: 3
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 3
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 3
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
col: 3
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 3
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 3
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 3
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 3
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 3
row: 13
type: STANDARD_80
shape: RECTANGLE
}
{
col: 3
row: 14
type: STANDARD_80
shape: RECTANGLE
}
{
col: 3
row: 15
type: STANDARD_40
shape: FULL_LEFT_UP_RIGHT_TRIANGLE
}
{
col: 3
row: 16
type: STANDARD_40
shape: RIGHT_UP_RIGHT_TRIANGLE
}
{
col: 4
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 4
row: 6
type: STANDARD_40
shape: DIAMOND
}
{
col: 4
row: 7
type: STANDARD_50
shape: DIAMOND
}
{
col: 4
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 4
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 4
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 4
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 4
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 4
row: 13
type: STANDARD_80
shape: RECTANGLE
}
{
col: 4
row: 14
type: STANDARD_80
shape: RECTANGLE
}
{
col: 4
row: 15
type: STANDARD_70
shape: RECTANGLE
}
{
col: 4
row: 16
type: STANDARD_60
shape: RECTANGLE
}
{
col: 4
row: 17
type: STANDARD_40
shape: FULL_LEFT_UP_RIGHT_TRIANGLE
}
{
col: 4
row: 18
type: STANDARD_40
shape: RIGHT_UP_RIGHT_TRIANGLE
}
{
col: 5
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 5
row: 6
type: STANDARD_40
shape: DIAMOND
}
{
col: 5
row: 7
type: STANDARD_50
shape: DIAMOND
}
{
col: 5
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 5
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 5
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 5
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 5
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 5
row: 13
type: STANDARD_80
shape: RECTANGLE
}
{
col: 5
row: 14
type: STANDARD_80
shape: RECTANGLE
}
{
col: 5
row: 15
type: STANDARD_70
shape: RECTANGLE
}
{
col: 5
row: 16
type: STANDARD_60
shape: RECTANGLE
}
{
col: 5
row: 17
type: STANDARD_40
shape: FULL_UP_LEFT_TRIANGLE
}
{
col: 5
row: 18
type: STANDARD_40
shape: LEFT_UP_LEFT_TRIANGLE
}
{
col: 6
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 6
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 6
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
col: 6
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 6
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 6
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 6
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 6
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 6
row: 13
type: STANDARD_80
shape: RECTANGLE
}
{
col: 6
row: 14
type: STANDARD_80
shape: RECTANGLE
}
{
col: 6
row: 15
type: STANDARD_40
shape: FULL_UP_LEFT_TRIANGLE
}
{
col: 6
row: 16
type: STANDARD_40
shape: LEFT_UP_LEFT_TRIANGLE
}
{
col: 7
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 7
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 7
row: 7
type: STANDARD_50
shape: DIAMOND
}
{
col: 7
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 7
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 7
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 7
row: 11
type: STANDARD_50
shape: RECTANGLE
}
{
col: 7
row: 12
type: STANDARD_50
shape: RECTANGLE
}
{
col: 7
row: 13
type: STANDARD_40
shape: FULL_UP_LEFT_TRIANGLE
}
{
col: 7
row: 14
type: STANDARD_40
shape: LEFT_UP_LEFT_TRIANGLE
}
{
col: 8
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 8
row: 6
type: STANDARD_60
shape: DIAMOND
}
{
col: 8
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
col: 8
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 8
row: 9
type: STANDARD_50
shape: RECTANGLE
}
{
col: 8
row: 10
type: STANDARD_50
shape: RECTANGLE
}
{
col: 8
row: 11
type: STANDARD_40
shape: FULL_UP_LEFT_TRIANGLE
}
{
col: 8
row: 12
type: STANDARD_40
shape: LEFT_UP_LEFT_TRIANGLE
}
{
col: 9
row: 5
type: STANDARD_40
shape: HALF_LOWER_RECTANGLE
}
{
col: 9
row: 6
type: STANDARD_40
shape: DIAMOND
}
{
col: 9
row: 7
type: STANDARD_40
shape: DIAMOND
}
{
col: 9
row: 8
type: STANDARD_40
shape: RECTANGLE
}
{
col: 9
row: 9
type: STANDARD_40
shape: FULL_UP_LEFT_TRIANGLE
}
{
col: 9
row: 10
type: STANDARD_40
shape: LEFT_UP_LEFT_TRIANGLE
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,257 +0,0 @@
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -2,19 +2,15 @@ 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;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport; import com.badlogic.gdx.utils.viewport.Viewport;
import com.me.brickbuster.state.MenuState; import com.me.brickbuster.state.MenuState;
import com.me.brickbuster.state.PlayState;
public class BrickBuster extends Game { public class BrickBuster extends Game {
@ -28,11 +24,8 @@ public class BrickBuster extends Game {
public BitmapFont font; public BitmapFont font;
public SpriteBatch sb; public SpriteBatch sb;
public SpriteBatch fb;
public ShapeRenderer sr; public ShapeRenderer sr;
public AssetManager assets;
@Override @Override
public void create () { public void create () {
cam = new OrthographicCamera(); cam = new OrthographicCamera();
@ -44,17 +37,14 @@ public class BrickBuster extends Game {
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
sb = new SpriteBatch(); sb = new SpriteBatch();
fb = new SpriteBatch();
sr = new ShapeRenderer(); sr = new ShapeRenderer();
assets = new AssetManager();
setScreen(new MenuState(this)); setScreen(new MenuState(this));
} }
@Override @Override
public void render () { public void render () {
Gdx.gl.glClearColor(0f,0f,0f,1); Gdx.gl.glClearColor(0.5f,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Render the current Screen (State) // Render the current Screen (State)
super.render(); super.render();
@ -64,10 +54,8 @@ public class BrickBuster extends Game {
public void resize(int width, int height) { public void resize(int width, int height) {
viewport.update(width, height); viewport.update(width, height);
Matrix4 projection = cam.combined.cpy().scl(PlayState.PIXEL_PER_METER); sb.setProjectionMatrix(cam.combined);
sb.setProjectionMatrix(projection); sr.setProjectionMatrix(cam.combined);
fb.setProjectionMatrix(cam.combined);
sr.setProjectionMatrix(projection);
super.resize(width, height); super.resize(width, height);
} }

View File

@ -2,8 +2,6 @@ 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;
@ -23,32 +21,27 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
public static final int BLOCKS_FOR_BOOST = 39; public static final int BLOCKS_FOR_BOOST = 39;
public static final float MINIMUM_ANGLE = MathUtils.PI/16; public static final float MINIMUM_ANGLE = MathUtils.PI/16;
public static final float CORRECTION_IMPULSE = 3f;
private float speed; private float speed;
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(SpriteBatch sb, ShapeRenderer sr) { public void render(ShapeRenderer sr) {
sb.setColor(Color.WHITE); sr.begin(ShapeType.Filled);
sb.draw(texture, pos.x - RADIUS, sr.setColor(BALL_COLOR);
pos.y - RADIUS, sr.circle(pos.x * PlayState.PIXEL_PER_METER,
RADIUS*2, pos.y * PlayState.PIXEL_PER_METER,
RADIUS*2); RADIUS * PlayState.PIXEL_PER_METER);
sr.end();
} }
@Override @Override
@ -71,13 +64,12 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
} }
Vector2 velocity = body.getLinearVelocity(); Vector2 velocity = body.getLinearVelocity();
body.setLinearVelocity(velocity.nor().scl(speed));
float rad = velocity.angleRad(); float rad = velocity.angleRad();
if (Math.abs(rad) < MINIMUM_ANGLE || Math.abs(rad) > MathUtils.PI - MINIMUM_ANGLE) { 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(new Vector2(0, rad > 0? 1 : -1), pos, true);
body.applyLinearImpulse(impulse, pos, true);
} }
body.setLinearVelocity(velocity.nor().scl(speed));
} }
@Override @Override
@ -102,7 +94,8 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
ballFixture.filter.categoryBits = EntityType.BALL; ballFixture.filter.categoryBits = EntityType.BALL;
ballFixture.filter.maskBits = EntityType.BOUNDARY | EntityType.BRICK ballFixture.filter.maskBits = EntityType.BOUNDARY | EntityType.BRICK
| EntityType.PADDLE | EntityType.SHIELD; | EntityType.PADDLE | EntityType.POWER_UP
| EntityType.SHIELD;
body = state.world.createBody(ballBody); body = state.world.createBody(ballBody);
body.createFixture(ballFixture); body.createFixture(ballFixture);
@ -127,16 +120,15 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
} }
public Vector2 paddleReflectAngle() { public Vector2 paddleReflectAngle() {
Paddle paddle = ((PlayState) state).paddle; float rel = (pos.x - state.paddle.getX()) + (state.paddle.getWidth()/2);
float rel = (pos.x - paddle.getX()) + (paddle.getWidth()/2); float newAngle = MathUtils.PI - (MathUtils.PI * (rel / state.paddle.getWidth()));
float newAngle = MathUtils.PI - (MathUtils.PI * (rel / paddle.getWidth()));
newAngle = MathUtils.clamp(newAngle, MINIMUM_ANGLE, MathUtils.PI-MINIMUM_ANGLE); newAngle = MathUtils.clamp(newAngle, MINIMUM_ANGLE, MathUtils.PI-MINIMUM_ANGLE);
return new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle)); return new Vector2(MathUtils.cos(newAngle), MathUtils.sin(newAngle));
} }
public void launch() { public void launch() {
Vector2 direction; Vector2 direction;
if (((PlayState) state).paddle.isSticky()) { if (state.paddle.isSticky()) {
direction = paddleReflectAngle(); direction = paddleReflectAngle();
} else { } else {
// launch at random angle between 135 and 45 degrees // launch at random angle between 135 and 45 degrees
@ -148,10 +140,10 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
} }
public void paddleCollision() { public void paddleCollision() {
if (((PlayState) state).paddle.isSticky()) { if (state.paddle.isSticky()) {
isStuck = true; isStuck = true;
body.setLinearVelocity(new Vector2()); body.setLinearVelocity(new Vector2());
setY(((PlayState) state).paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS); setY(state.paddle.getY() + Paddle.PADDLE_HEIGHT + RADIUS);
return; return;
} }
body.setLinearVelocity(paddleReflectAngle().scl(speed)); body.setLinearVelocity(paddleReflectAngle().scl(speed));
@ -160,13 +152,17 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
@Override @Override
public void setX(float x) { public void setX(float x) {
super.setX(x); super.setX(x);
body.setTransform(pos, 0); Vector2 bodyPos = body.getPosition();
bodyPos.x = x;
body.setTransform(bodyPos, 0);
} }
@Override @Override
public void setY(float y) { public void setY(float y) {
super.setY(y); super.setY(y);
body.setTransform(pos, 0); Vector2 bodyPos = body.getPosition();
bodyPos.y = y;
body.setTransform(bodyPos, 0);
} }
public void setSpeed(float speed) { public void setSpeed(float speed) {

View File

@ -1,9 +1,10 @@
package com.me.brickbuster.entity; package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.Color;
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.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
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;
@ -13,42 +14,45 @@ 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;
import com.me.brickbuster.physics.PhysicsBody; import com.me.brickbuster.physics.PhysicsBody;
import com.me.brickbuster.state.FieldState;
import com.me.brickbuster.state.PlayState; 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 = 5.2f; public static final Color DEFAULT_COLOR = Color.FOREST;
public static final float BRICK_HEIGHT = 2.6f; public static final float BRICK_WIDTH = 5f;
public static final float BRICK_HEIGHT = 2.5f;
private BrickType type;
private BrickShape.Shape shape;
private PowerUpType powerUpType; private PowerUpType powerUpType;
private Color color;
private TextureRegion region;
private Body body; private Body body;
private boolean hitByBall = false; private boolean hitByBall = false;
public Brick(FieldState state, BrickType type, BrickShape.Shape shape, PowerUpType powerUpType, float x, float y) { public Brick(PlayState state, PowerUpType powerUpType, float x, float y) {
this(state, powerUpType, true, x, y);
}
public Brick(PlayState state, PowerUpType powerUpType, boolean hidePowerup, float x, float y) {
this(state, powerUpType, DEFAULT_COLOR, hidePowerup, x, y);
}
public Brick(PlayState state, PowerUpType powerUpType, Color color, boolean hidePowerUp, float x, float y) {
super(state, x, y); super(state, x, y);
this.type = type;
this.shape = shape;
this.powerUpType = powerUpType; this.powerUpType = powerUpType;
this.region = state.textures.findRegion("brick_" + shape.name()); this.color = powerUpType != null && !hidePowerUp? powerUpType.getColor() : color;
createBody(); createBody();
} }
@Override @Override
public void render(SpriteBatch sb, ShapeRenderer sr) { public void render(ShapeRenderer sr) {
sb.setColor(type.getColor()); sr.begin(ShapeType.Filled);
float x = pos.x - BRICK_WIDTH/2; sr.setColor(color);
float y = pos.y - BRICK_HEIGHT/2; sr.rect(pos.x * PlayState.PIXEL_PER_METER, pos.y * PlayState.PIXEL_PER_METER,
sb.draw(region, x, y, 0f, 0f,
BRICK_WIDTH/2, BRICK_HEIGHT/2, BRICK_WIDTH * PlayState.PIXEL_PER_METER, BRICK_HEIGHT * PlayState.PIXEL_PER_METER,
BRICK_WIDTH, BRICK_HEIGHT,
1f, 1f, 1f, 1f,
MathUtils.radiansToDegrees * body.getAngle()); body.getAngle() * MathUtils.radiansToDegrees);
sr.end();
} }
@Override @Override
@ -57,10 +61,6 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
hit(); hit();
hitByBall = false; hitByBall = false;
} }
if (getY() + BRICK_HEIGHT < 0) {
delete();
}
} }
@Override @Override
@ -74,49 +74,16 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
brickBody.type = BodyDef.BodyType.StaticBody; brickBody.type = BodyDef.BodyType.StaticBody;
brickBody.position.set(pos.cpy()); brickBody.position.set(pos.cpy());
int shapeMask = shape.getMask();
Vector2[] vertices = new Vector2[Integer.bitCount(shapeMask)];
int v = 0;
if ((shapeMask & BrickShape.BOTTOM_LEFT) != 0) {
vertices[v++] = new Vector2(-BRICK_WIDTH/2, -BRICK_HEIGHT/2);
}
if ((shapeMask & BrickShape.MIDDLE_LEFT) != 0) {
vertices[v++] = new Vector2(-BRICK_WIDTH/2, 0);
}
if ((shapeMask & BrickShape.TOP_LEFT) != 0) {
vertices[v++] = new Vector2(-BRICK_WIDTH/2, BRICK_HEIGHT/2);
}
if ((shapeMask & BrickShape.TOP_MIDDLE) != 0) {
vertices[v++] = new Vector2(0, BRICK_HEIGHT/2);
}
if ((shapeMask & BrickShape.CENTER) != 0) {
vertices[v++] = new Vector2(0, 0);
}
if ((shapeMask & BrickShape.TOP_RIGHT) != 0) {
vertices[v++] = new Vector2(BRICK_WIDTH/2, BRICK_HEIGHT/2);
}
if ((shapeMask & BrickShape.MIDDLE_RIGHT) != 0) {
vertices[v++] = new Vector2(BRICK_WIDTH/2, 0);
}
if ((shapeMask & BrickShape.BOTTOM_RIGHT) != 0) {
vertices[v++] = new Vector2(BRICK_WIDTH/2, -BRICK_HEIGHT/2);
}
if ((shapeMask & BrickShape.BOTTOM_MIDDLE) != 0) {
vertices[v++] = new Vector2(0, -BRICK_HEIGHT/2);
}
PolygonShape brickShape = new PolygonShape(); PolygonShape brickShape = new PolygonShape();
brickShape.set(vertices); brickShape.setAsBox(BRICK_WIDTH/2, BRICK_HEIGHT/2,
new Vector2(BRICK_WIDTH/2,BRICK_HEIGHT/2), 0);
FixtureDef brickFixture = new FixtureDef(); FixtureDef brickFixture = new FixtureDef();
brickFixture.shape = brickShape; brickFixture.shape = brickShape;
brickFixture.friction = 0f; brickFixture.friction = 0f;
brickFixture.density = 0.5f;
brickFixture.filter.categoryBits = EntityType.BRICK; 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 = state.world.createBody(brickBody);
body.createFixture(brickFixture); body.createFixture(brickFixture);
@ -136,39 +103,15 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
public void endContact(Entity contacted) { public void endContact(Entity contacted) {
} }
@Override
public void setX(float x) {
super.setX(x);
body.setTransform(pos, 0);
}
@Override
public void setY(float y) {
super.setY(y);
body.setTransform(pos, 0);
}
public BrickType getType() {
return type;
}
public BrickShape.Shape getShape() {
return shape;
}
public PowerUpType getPowerUpType() {
return powerUpType;
}
public boolean hit() { public boolean hit() {
if (((PlayState) state).bricks.size-1 <= Ball.BLOCKS_FOR_BOOST) { if (state.bricks.size-1 <= Ball.BLOCKS_FOR_BOOST) {
for (Ball ball : ((PlayState) state).balls) { for (Ball ball : state.balls) {
ball.setSpeed(Ball.BOOST_SPEED); ball.setSpeed(Ball.BOOST_SPEED);
} }
} }
if (powerUpType != null) { if (powerUpType != null) {
((PlayState) state).powerUps.add(powerUpType.createInstance((PlayState) state, this)); state.powerUps.add(powerUpType.createInstance(state, this));
} }
deleted = true; deleted = true;

View File

@ -1,84 +0,0 @@
package com.me.brickbuster.entity;
public class BrickShape {
public static final int BOTTOM_LEFT = 0x1;
public static final int MIDDLE_LEFT = 0x1 << 1;
public static final int TOP_LEFT = 0x1 << 2;
public static final int TOP_MIDDLE = 0x1 << 3;
public static final int CENTER = 0x1 << 4;
public static final int TOP_RIGHT = 0x1 << 5;
public static final int MIDDLE_RIGHT = 0x1 << 6;
public static final int BOTTOM_RIGHT = 0x1 << 7;
public static final int BOTTOM_MIDDLE = 0x1 << 8;
public enum Shape {
RECTANGLE(0, 0, BOTTOM_LEFT | TOP_LEFT | TOP_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(2, 1, MIDDLE_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(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(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(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(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 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;
}
}
}

View File

@ -1,31 +0,0 @@
package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.Color;
public enum BrickType {
STANDARD_10(new Color(0xf1f1f1ff)),
STANDARD_20(new Color(0xff8f00ff)),
STANDARD_30(Color.CYAN),
STANDARD_40(Color.GREEN),
STANDARD_50(Color.RED),
STANDARD_60(new Color(0x0070ffff)),
STANDARD_70(new Color(0xff00ffff)),
STANDARD_80(new Color(0xffff00ff)),
EXPLOSIVE(Color.GRAY),
HARD(new Color(0x9d9d9dff)),
HARDER(new Color(0xbcae00ff)),
UNBREAKABLE(Color.BLACK)
;
private Color color;
BrickType(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
}

View File

@ -1,31 +1,28 @@
package com.me.brickbuster.entity; package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.me.brickbuster.state.FieldState; import com.me.brickbuster.state.PlayState;
public abstract class Entity { public abstract class Entity {
protected FieldState state; protected PlayState state;
protected Vector2 pos; protected Vector2 pos;
protected boolean deleted = false; protected boolean deleted = false;
public Entity(FieldState state, Vector2 pos) { public Entity(PlayState state, Vector2 pos) {
this(state, pos.x, pos.y); this(state, pos.x, pos.y);
} }
public Entity(FieldState state, float x, float y) { public Entity(PlayState state, float x, float y) {
this.state = state; this.state = state;
this.pos = new Vector2(x, y); this.pos = new Vector2(x, y);
} }
public abstract void render(SpriteBatch sb, ShapeRenderer sr); public abstract void render(ShapeRenderer sr);
public abstract void update(float dt); public abstract void update(float dt);
public void dispose() {}
public Vector2 getPos() { public Vector2 getPos() {
return pos; return pos;
} }

View File

@ -3,7 +3,6 @@ package com.me.brickbuster.entity;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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;
@ -21,7 +20,7 @@ import net.dermetfan.utils.Pair;
public class Paddle extends Entity implements PhysicsBody { public class Paddle extends Entity implements PhysicsBody {
public static final Color STICKY_COLOR = Color.GRAY; public static final Color STICKY_COLOR = Color.GRAY;
public static final Color PADDLE_COLOR = Color.WHITE; public static final Color PADDLE_COLOR = Color.BLACK;
public static final float DEFAULT_WIDTH = 7.5f; public static final float DEFAULT_WIDTH = 7.5f;
public static final float PADDLE_HEIGHT = 0.75f; public static final float PADDLE_HEIGHT = 0.75f;
@ -39,10 +38,13 @@ public class Paddle extends Entity implements PhysicsBody {
} }
@Override @Override
public void render(SpriteBatch sb, ShapeRenderer sr) { public void render(ShapeRenderer sr) {
sr.begin(ShapeType.Filled); sr.begin(ShapeType.Filled);
sr.setColor(sticky? STICKY_COLOR : PADDLE_COLOR); sr.setColor(sticky? STICKY_COLOR : PADDLE_COLOR);
sr.rect(pos.x - width/2, pos.y, width, PADDLE_HEIGHT); sr.rect((getX() - width/2) * PlayState.PIXEL_PER_METER,
getY() * PlayState.PIXEL_PER_METER,
width * PlayState.PIXEL_PER_METER,
PADDLE_HEIGHT * PlayState.PIXEL_PER_METER);
sr.end(); sr.end();
} }
@ -66,7 +68,7 @@ public class Paddle extends Entity implements PhysicsBody {
} }
if (!MathUtils.isZero(adjust)) { if (!MathUtils.isZero(adjust)) {
setX(pos.x + adjust); setX(pos.x + adjust);
for (Ball ball : ((PlayState) state).balls) { for (Ball ball : state.balls) {
if (ball.isStuck()) { if (ball.isStuck()) {
ball.setX(ball.getX() + adjust); ball.setX(ball.getX() + adjust);
} }
@ -105,13 +107,17 @@ public class Paddle extends Entity implements PhysicsBody {
@Override @Override
public void setX(float x) { public void setX(float x) {
super.setX(x); super.setX(x);
body.setTransform(pos, 0); Vector2 bodyPos = body.getPosition();
bodyPos.x = x;
body.setTransform(bodyPos, 0);
} }
@Override @Override
public void setY(float y) { public void setY(float y) {
super.setY(y); super.setY(y);
body.setTransform(pos, 0); Vector2 bodyPos = body.getPosition();
bodyPos.y = y;
body.setTransform(bodyPos, 0);
} }
public float getWidth() { public float getWidth() {
@ -122,7 +128,7 @@ public class Paddle extends Entity implements PhysicsBody {
if (this.width == width) { if (this.width == width) {
return; return;
} }
((PlayState) state).world.destroyBody(body); state.world.destroyBody(body);
this.width = width; this.width = width;
createBody(); createBody();
} }

View File

@ -1,7 +1,6 @@
package com.me.brickbuster.entity; package com.me.brickbuster.entity;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
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;
@ -25,17 +24,19 @@ public class Shield extends Entity implements PhysicsBody {
} }
@Override @Override
public void render(SpriteBatch sb, ShapeRenderer sr) { public void render(ShapeRenderer sr) {
sr.begin(ShapeRenderer.ShapeType.Filled); sr.begin(ShapeRenderer.ShapeType.Filled);
sr.setColor(PowerUpType.SHIELD.getColor()); sr.setColor(PowerUpType.SHIELD.getColor());
sr.rect(0, pos.y, PlayState.BOARD_WIDTH, SHIELD_HEIGHT); sr.rect(0, pos.y * PlayState.PIXEL_PER_METER,
PlayState.BOARD_WIDTH * PlayState.PIXEL_PER_METER,
SHIELD_HEIGHT * PlayState.PIXEL_PER_METER);
sr.end(); sr.end();
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
if (deleted) { if (deleted) {
((PlayState) state).removeShield(this); state.removeShield(this);
} }
} }

View File

@ -12,7 +12,7 @@ public class GluePowerUp extends PowerUp {
@Override @Override
public void activate() { public void activate() {
((PlayState) state).paddle.setSticky(true); state.paddle.setSticky(true);
} }
} }

View File

@ -13,8 +13,8 @@ public class LongerPaddlePowerUp extends PowerUp {
@Override @Override
public void activate() { public void activate() {
if (((PlayState) state).paddle.getWidth() < Paddle.DEFAULT_WIDTH*2.5) { if (state.paddle.getWidth() < Paddle.DEFAULT_WIDTH*2.5) {
((PlayState) state).paddle.setWidth(((PlayState) state).paddle.getWidth() + Paddle.DEFAULT_WIDTH/2); state.paddle.setWidth(state.paddle.getWidth() + Paddle.DEFAULT_WIDTH/2);
} }
} }
} }

View File

@ -19,9 +19,9 @@ public class MultiBallPowerUp extends PowerUp {
@Override @Override
public void activate() { public void activate() {
for (int x = 0; x < 2; x++) { for (int x = 0; x < 2; x++) {
Ball ball = new Ball((PlayState) state); Ball ball = new Ball(state);
ball.launch(); ball.launch();
((PlayState) state).balls.add(ball); state.balls.add(ball);
} }
} }
} }

View File

@ -1,7 +1,6 @@
package com.me.brickbuster.entity.powerup; package com.me.brickbuster.entity.powerup;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.Vector2; import com.badlogic.gdx.math.Vector2;
@ -36,10 +35,12 @@ public abstract class PowerUp extends Entity implements PhysicsBody, CollisionLi
} }
@Override @Override
public void render(SpriteBatch sb, ShapeRenderer sr) { public void render(ShapeRenderer sr) {
sr.begin(ShapeType.Filled); sr.begin(ShapeType.Filled);
sr.setColor(color); sr.setColor(color);
sr.circle(pos.x, pos.y, RADIUS, 20); sr.circle(getX() * PlayState.PIXEL_PER_METER,
getY() * PlayState.PIXEL_PER_METER,
RADIUS * PlayState.PIXEL_PER_METER);
sr.end(); sr.end();
} }
@ -74,7 +75,7 @@ public abstract class PowerUp extends Entity implements PhysicsBody, CollisionLi
ballFixture.isSensor = true; ballFixture.isSensor = true;
ballFixture.filter.categoryBits = EntityType.POWER_UP; ballFixture.filter.categoryBits = EntityType.POWER_UP;
ballFixture.filter.maskBits = EntityType.PADDLE; ballFixture.filter.maskBits = EntityType.PADDLE | EntityType.BALL;
body = state.world.createBody(ballBody); body = state.world.createBody(ballBody);
body.createFixture(ballFixture); body.createFixture(ballFixture);

View File

@ -42,7 +42,9 @@ public enum PowerUpType {
} }
public PowerUp createInstance(PlayState state, Brick brick) { 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) { public PowerUp createInstance(PlayState state, Vector2 pos) {

View File

@ -12,7 +12,7 @@ public class ShieldPowerUp extends PowerUp {
@Override @Override
public void activate() { public void activate() {
((PlayState) state).addShield(); state.addShield();
} }
} }

View File

@ -1,12 +0,0 @@
package com.me.brickbuster.layout;
import com.badlogic.gdx.utils.Array;
import com.me.brickbuster.entity.Brick;
public interface BrickLayout {
void initialize();
Array<Brick> getBricks();
}

View File

@ -1,41 +0,0 @@
package com.me.brickbuster.layout;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import com.me.brickbuster.entity.Brick;
import com.me.brickbuster.state.PlayState;
public class FileLayout implements BrickLayout {
private static final Json JSON = new Json();
private PlayState state;
private Array<Brick> bricks;
private FileHandle file;
public FileLayout(PlayState state, FileHandle file) {
this.state = state;
this.file = file;
}
@Override
public void initialize() {
bricks = new Array<Brick>();
LevelJsonTemplate level = JSON.fromJson(LevelJsonTemplate.class, file);
for (LevelJsonTemplate.BrickJsonTemplate brick : level.bricks) {
final float x = PlayState.EDGE_PADDING + Brick.BRICK_WIDTH/2 + brick.col * Brick.BRICK_WIDTH;
final float y = PlayState.EDGE_PADDING + Brick.BRICK_HEIGHT/2 + brick.row * Brick.BRICK_HEIGHT;
bricks.add(new Brick(state, brick.type, brick.shape, brick.powerUp, x, PlayState.BOARD_HEIGHT - y));
}
}
@Override
public Array<Brick> getBricks() {
return bricks;
}
}

View File

@ -1,26 +0,0 @@
package com.me.brickbuster.layout;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.me.brickbuster.state.PlayState;
public class FileLevelLoader implements LevelLoader {
private PlayState state;
private int level = 1;
public FileLevelLoader(PlayState state) {
this.state = state;
}
@Override
public Level getNextLevel() {
FileHandle file = Gdx.files.internal("levels/level_" + level + ".json");
if (file.exists()) {
level++;
return new Level(new FileLayout(state, file), null, null);
}
return null;
}
}

View File

@ -1,80 +0,0 @@
package com.me.brickbuster.layout;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.me.brickbuster.entity.Brick;
import com.me.brickbuster.entity.BrickShape;
import com.me.brickbuster.entity.BrickType;
import com.me.brickbuster.entity.powerup.PowerUpType;
import com.me.brickbuster.state.PlayState;
public class GridLayout implements BrickLayout {
private final PlayState state;
private final int cols;
private final int rows;
private final float powerUpChance;
private BrickShape.Shape shape = null;
private BrickType type = null;
private boolean randomShape = false;
private boolean randomType = false;
private final Array<Brick> bricks;
public GridLayout(PlayState state, int cols, int rows, float powerUpChance) {
this(state, cols, rows, powerUpChance, false, false);
}
public GridLayout(PlayState state, int cols, int rows, float powerUpChance, boolean randomShape, boolean randomType) {
this(state, cols, rows, powerUpChance, BrickShape.Shape.RECTANGLE, BrickType.STANDARD_10);
this.randomShape = randomShape;
this.randomType = randomType;
}
public GridLayout(PlayState state, int cols, int rows, float powerUpChance, BrickShape.Shape shape, BrickType type) {
this.state = state;
this.cols = cols;
this.rows = rows;
this.powerUpChance = powerUpChance;
this.shape = shape;
this.type = type;
this.bricks = new Array<Brick>(cols * rows);
}
@Override
public void initialize() {
for (int col = 0; col < cols; col++) {
for (int row = 0; row < rows; row++) {
bricks.add(getBrickForCell(row, col));
}
}
}
protected Brick getBrickForCell(int row, int col) {
final float x = PlayState.EDGE_PADDING + Brick.BRICK_WIDTH/2 + col * Brick.BRICK_WIDTH;
final float y = PlayState.EDGE_PADDING + Brick.BRICK_HEIGHT/2 + row * Brick.BRICK_HEIGHT;
PowerUpType powerUpType = null;
if (MathUtils.randomBoolean(powerUpChance)) {
powerUpType = PowerUpType.getWeightedRandom();
}
if (randomType) {
type = BrickType.values()[MathUtils.random(BrickType.values().length-1)];
}
if (randomShape) {
shape = BrickShape.Shape.values()[MathUtils.random(BrickShape.Shape.values().length-1)];
}
return new Brick(state, type, shape, powerUpType, x, PlayState.BOARD_HEIGHT - y);
}
@Override
public Array<Brick> getBricks() {
return bricks;
}
}

View File

@ -1,35 +0,0 @@
package com.me.brickbuster.layout;
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 = 10;
public static final int ROWS = 20;
public static final int ROUNDS = 2;
private PlayState state;
private boolean randomShape;
private boolean randomType;
private int playCount = 0;
public GridLevelLoader(PlayState state) {
this(state, false, false)
}
public GridLevelLoader(PlayState state, boolean randomShape, boolean randomType) {
this.state = state;
this.randomShape = randomShape;
this.randomType = randomType;
}
@Override
public Level getNextLevel() {
if (playCount++ < ROUNDS) {
return new Level(new GridLayout(state, COLUMNS, ROWS, POWER_UP_CHANCE, randomShape, randomType));
}
return null;
}
}

View File

@ -1,33 +0,0 @@
package com.me.brickbuster.layout;
import com.badlogic.gdx.graphics.Texture;
public class Level {
private final BrickLayout layout;
private final Texture background;
private final Texture border;
public Level(BrickLayout layout) {
this(layout, null, null);
}
public Level(BrickLayout layout, Texture background, Texture border) {
this.layout = layout;
this.background = background;
this.border = border;
}
public BrickLayout getLayout() {
return layout;
}
public Texture getBackground() {
return background;
}
public Texture getBorder() {
return border;
}
}

View File

@ -1,23 +0,0 @@
package com.me.brickbuster.layout;
import com.me.brickbuster.entity.BrickShape;
import com.me.brickbuster.entity.BrickType;
import com.me.brickbuster.entity.powerup.PowerUpType;
import java.util.List;
public class LevelJsonTemplate {
public String backgroundFile;
public String borderFile;
public List<BrickJsonTemplate> bricks;
public static class BrickJsonTemplate {
public int col;
public int row;
public BrickType type;
public BrickShape.Shape shape;
public PowerUpType powerUp;
}
}

View File

@ -1,7 +0,0 @@
package com.me.brickbuster.layout;
public interface LevelLoader {
Level getNextLevel();
}

View File

@ -1,233 +0,0 @@
package com.me.brickbuster.state;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Json;
import com.me.brickbuster.BrickBuster;
import com.me.brickbuster.entity.Brick;
import com.me.brickbuster.entity.BrickShape;
import com.me.brickbuster.entity.BrickType;
import com.me.brickbuster.entity.powerup.PowerUpType;
import com.me.brickbuster.layout.LevelJsonTemplate;
import com.me.brickbuster.physics.Box2dContactListener;
import java.util.ArrayList;
public class EditorState extends FieldState {
public static final long BLINK_INTERVAL = 250l;
public static final int COLUMNS = 10;
public static final int ROWS = 33;
private Brick placeHolder;
private Brick[][] bricks = new Brick[COLUMNS][ROWS];
private int col = 0;
private int row = 0;
private PowerUpType curPowerUpType;
private BrickShape.Shape curShape;
private BrickType curType;
private Box2DDebugRenderer debugRenderer;
private long lastBlink = System.currentTimeMillis();
private boolean blink = false;
public EditorState(BrickBuster game) {
super(game);
}
@Override
public void setup() {
super.setup();
world = new World(new Vector2(), false);
world.setContactListener(new Box2dContactListener());
curPowerUpType = null;
curShape = BrickShape.Shape.RECTANGLE;
curType = BrickType.STANDARD_10;
updatePlaceHolder();
Gdx.input.setInputProcessor(new InputProcessor());
debugRenderer = new Box2DDebugRenderer();
}
@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) {
continue;
}
Brick brick = bricks[col][row];
if (brick != null) {
brick.render(game.sb, game.sr);
}
}
}
if (!blink) {
placeHolder.render(game.sb, game.sr);
}
game.sb.end();
debugRenderer.render(world, game.cam.combined.cpy().scl(PlayState.PIXEL_PER_METER));
game.fb.begin();
game.font.setColor(Color.GRAY);
game.font.draw(game.fb, String.format("Current powerup: %s", curPowerUpType), 10, 230);
game.font.draw(game.fb, "WASD: Move brick", 10, 170);
game.font.draw(game.fb, "ENTER: Set brick BACKSPACE: Delete brick F12: Save", 10, 110);
game.font.draw(game.fb, "UP/DOWN: type LEFT/RIGHT: shape SPACE: powerup", 10, 55);
game.fb.end();
}
@Override
public void update(float dt) {
long now = System.currentTimeMillis();
if (now - lastBlink > BLINK_INTERVAL) {
blink = !blink;
lastBlink = now;
}
}
private void updatePlaceHolder() {
if (placeHolder != null) {
world.destroyBody(placeHolder.getBody());
}
placeHolder = createBrick();
}
private Brick createBrick() {
return new Brick(this, curType, curShape, curPowerUpType, getBrickX(), getBrickY());
}
private float getBrickX() {
return PlayState.EDGE_PADDING + Brick.BRICK_WIDTH/2 + col * Brick.BRICK_WIDTH;
}
private float getBrickY() {
return PlayState.BOARD_HEIGHT - (PlayState.EDGE_PADDING + Brick.BRICK_HEIGHT/2 + row * Brick.BRICK_HEIGHT);
}
private void saveToFile() {
Json json = new Json();
FileHandle file = Gdx.files.external("level.json");
LevelJsonTemplate level = new LevelJsonTemplate();
level.bricks = new ArrayList<LevelJsonTemplate.BrickJsonTemplate>();
for (int col = 0; col < bricks.length; col++) {
for (int row = 0; row < bricks[col].length; row++) {
Brick brick = bricks[col][row];
if (brick == null) {
continue;
}
LevelJsonTemplate.BrickJsonTemplate brickJson = new LevelJsonTemplate.BrickJsonTemplate();
brickJson.col = col;
brickJson.row = row;
brickJson.type = brick.getType();
brickJson.shape = brick.getShape();
brickJson.powerUp = brick.getPowerUpType();
level.bricks.add(brickJson);
}
}
file.writeString(json.prettyPrint(level), false);
System.out.println("level.json saved to " + file.file().getAbsolutePath());
}
private final class InputProcessor extends InputAdapter {
@Override
public boolean keyDown(int keycode) {
int next = -1;
switch (keycode) {
case Input.Keys.UP:
next = curType.ordinal() == BrickType.values().length-1? 0 : curType.ordinal()+1;
curType = BrickType.values()[next];
updatePlaceHolder();
break;
case Input.Keys.DOWN:
next = curType.ordinal() == 0? BrickType.values().length-1 : curType.ordinal()-1;
curType = BrickType.values()[next];
updatePlaceHolder();
break;
case Input.Keys.LEFT:
next = curShape.ordinal() == 0? BrickShape.Shape.values().length-1 : curShape.ordinal()-1;
curShape = BrickShape.Shape.values()[next];
updatePlaceHolder();
break;
case Input.Keys.RIGHT:
next = curShape.ordinal() == BrickShape.Shape.values().length-1? 0 : curShape.ordinal()+1;
curShape = BrickShape.Shape.values()[next];
updatePlaceHolder();
break;
case Input.Keys.W:
if (row > 0) {
row--;
placeHolder.setY(getBrickY());
}
break;
case Input.Keys.A:
if (col > 0) {
col--;
placeHolder.setX(getBrickX());
}
break;
case Input.Keys.S:
if (row < ROWS-1) {
row++;
placeHolder.setY(getBrickY());
}
break;
case Input.Keys.D:
if (col < COLUMNS-1) {
col++;
placeHolder.setX(getBrickX());
}
break;
case Input.Keys.SPACE:
next = curPowerUpType == null? 0 : curPowerUpType.ordinal()+1;
if (next >= curPowerUpType.values().length) {
curPowerUpType = null;
} else {
curPowerUpType = PowerUpType.values()[next];
}
break;
case Input.Keys.ENTER:
if (bricks[col][row] != null) {
world.destroyBody(bricks[col][row].getBody());
bricks[col][row].dispose();
}
bricks[col][row] = createBrick();
break;
case Input.Keys.BACKSPACE:
if (bricks[col][row] != null) {
world.destroyBody(bricks[col][row].getBody());
bricks[col][row].dispose();
bricks[col][row] = null;
}
break;
case Input.Keys.F12:
saveToFile();
break;
default:
return false;
}
return true;
}
}
}

View File

@ -1,30 +0,0 @@
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);
}
@Override
public void dispose() {
super.dispose();
textures.dispose();
}
}

View File

@ -1,7 +1,6 @@
package com.me.brickbuster.state; package com.me.brickbuster.state;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.me.brickbuster.BrickBuster; import com.me.brickbuster.BrickBuster;
@ -21,13 +20,11 @@ public class MenuState extends State {
@Override @Override
public void render() { public void render() {
game.sb.setProjectionMatrix(game.cam.combined);
game.sb.begin(); game.sb.begin();
game.sb.draw(playButton, game.sb.draw(playButton,
BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2, BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2,
BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2); BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2);
game.sb.end(); game.sb.end();
game.sb.setProjectionMatrix(game.cam.combined.cpy().scl(PlayState.PIXEL_PER_METER));
} }
@Override @Override
@ -42,11 +39,6 @@ public class MenuState extends State {
dispose(); dispose();
} }
} }
if(Gdx.input.isKeyJustPressed(Input.Keys.F12)) {
game.setScreen(new EditorState(game));
dispose();
}
} }
@Override @Override

View File

@ -2,42 +2,45 @@ 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.math.MathUtils;
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;
import com.me.brickbuster.BrickBuster; import com.me.brickbuster.BrickBuster;
import com.me.brickbuster.entity.*; import com.me.brickbuster.entity.*;
import com.me.brickbuster.entity.powerup.PowerUp; import com.me.brickbuster.entity.powerup.PowerUp;
import com.me.brickbuster.layout.*; import com.me.brickbuster.entity.powerup.PowerUpType;
import com.me.brickbuster.physics.Box2dContactListener; import com.me.brickbuster.physics.Box2dContactListener;
import com.me.brickbuster.physics.EntityType; import com.me.brickbuster.physics.EntityType;
import java.util.Iterator; import java.util.Iterator;
public class PlayState extends FieldState { public class PlayState extends State {
public static final float PIXEL_PER_METER = 40f; // Board dimension: 54x96 meters
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 EDGE_PADDING = .125f;
public static final float EDGE_PADDING = 1f;
public static final float POWERUP_CHANCE = 0.15f;
public static final int COLUMNS = 9;
public static final int ROWS = 8;
public static final Vector2 lowerLeftCorner = public static final Vector2 lowerLeftCorner =
new Vector2(EDGE_PADDING,0); new Vector2(EDGE_PADDING,EDGE_PADDING);
public static final Vector2 lowerRightCorner = public static final Vector2 lowerRightCorner =
new Vector2(BrickBuster.BOARD_WIDTH/PIXEL_PER_METER-EDGE_PADDING,0); new Vector2(BrickBuster.BOARD_WIDTH/PIXEL_PER_METER-EDGE_PADDING,EDGE_PADDING);
public static final Vector2 upperRightCorner = public static final Vector2 upperRightCorner =
new Vector2(BrickBuster.BOARD_WIDTH/PIXEL_PER_METER-EDGE_PADDING, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER-EDGE_PADDING); new Vector2(BrickBuster.BOARD_WIDTH/PIXEL_PER_METER-EDGE_PADDING, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER-EDGE_PADDING);
public static final Vector2 upperLeftCorner = public static final Vector2 upperLeftCorner =
new Vector2(EDGE_PADDING, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER-EDGE_PADDING); new Vector2(EDGE_PADDING, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER-EDGE_PADDING);
public World world;
public Body playArea; public Body playArea;
public Array<Body> bodies; public Array<Body> bodies;
public LevelLoader levelLoader;
public Level currentLevel;
public Array<PowerUp> powerUps; public Array<PowerUp> powerUps;
public Paddle paddle; public Paddle paddle;
public Array<Ball> balls; public Array<Ball> balls;
@ -55,17 +58,63 @@ 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);
currentLevel = levelLoader.getNextLevel();
initializeLevel(); // define a playArea body with position set to 0
BodyDef playAreaDef = new BodyDef();
playAreaDef.type = BodyDef.BodyType.StaticBody;
playAreaDef.position.set(new Vector2());
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);
// Top edge
screenEdge.set(upperRightCorner, upperLeftCorner);
playArea.createFixture(playAreaFixture);
// Left edge
screenEdge.set(upperLeftCorner, lowerLeftCorner);
playArea.createFixture(playAreaFixture);
// Bottom edge
//screenEdge.set(lowerLeftCorner, lowerRightCorner);
//playArea.createFixture(playAreaFixture);
screenEdge.dispose();
powerUps = new Array<PowerUp>();
paddle = new Paddle(this);
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 = 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, BrickBuster.BOARD_HEIGHT/PIXEL_PER_METER - y));
}
}
balls = new Array<Ball>();
balls.add(new Ball(this));
shields = new Array<Shield>();
} }
@Override @Override
@ -79,32 +128,28 @@ 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.sb, game.sr); block.render(game.sr);
}
for (PowerUp powerUp : powerUps) {
powerUp.render(game.sr);
} }
for (Ball ball : balls) { for (Ball ball : balls) {
ball.render(game.sb, game.sr); ball.render(game.sr);
}
game.sb.end();
for (PowerUp powerUp : powerUps) {
powerUp.render(game.sb, game.sr);
} }
for (Shield shield : shields) { for (Shield shield : shields) {
shield.render(game.sb, game.sr); shield.render(game.sr);
} }
paddle.render(game.sb, game.sr); paddle.render(game.sr);
//debugRenderer.render(world, game.cam.combined.cpy().scl(PIXEL_PER_METER)); //debugRenderer.render(world, game.cam.combined.cpy().scl(PIXEL_PER_METER));
long renderTime = System.nanoTime() - start; long renderTime = System.nanoTime() - start;
game.fb.begin(); game.sb.begin();
game.font.setColor(Color.GRAY); game.font.setColor(Color.GRAY);
game.font.draw(game.fb, String.format("FPS: %d Update: %.2f ms Render: %.2f ms", game.font.draw(game.sb, String.format("FPS: %d Update: %.2f ms Render: %.2f ms",
Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 10, BrickBuster.BOARD_HEIGHT-10); Gdx.graphics.getFramesPerSecond(), updateTime/1000000f, renderTime/1000000f), 10, BrickBuster.BOARD_HEIGHT-10);
game.fb.end(); game.sb.end();
} }
@Override @Override
@ -147,18 +192,12 @@ public class PlayState extends FieldState {
brick.update(dt); brick.update(dt);
if (brick.isDeleted()) { if (brick.isDeleted()) {
it.remove(); it.remove();
brick.dispose();
world.destroyBody(brick.getBody()); world.destroyBody(brick.getBody());
} }
} }
if (bricks.size == 0) { if (bricks.size == 0) {
currentLevel = levelLoader.getNextLevel();
if (currentLevel == null) {
game.setScreen(new MenuState(game)); game.setScreen(new MenuState(game));
dispose(); dispose();
} else {
initializeLevel();
}
return; return;
} }
@ -182,46 +221,6 @@ public class PlayState extends FieldState {
paddle = null; paddle = null;
} }
private void initializeLevel() {
world.getBodies(bodies);
for (Body b : bodies) {
world.destroyBody(b);
}
// Set up the borders
BodyDef playAreaDef = new BodyDef();
playAreaDef.type = BodyDef.BodyType.StaticBody;
playAreaDef.position.set(new Vector2());
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);
screenEdge.set(lowerRightCorner, upperRightCorner);
playArea.createFixture(playAreaFixture);
screenEdge.set(upperRightCorner, upperLeftCorner);
playArea.createFixture(playAreaFixture);
screenEdge.set(upperLeftCorner, lowerLeftCorner);
playArea.createFixture(playAreaFixture);
screenEdge.dispose();
powerUps = new Array<PowerUp>();
paddle = new Paddle(this);
BrickLayout layout = currentLevel.getLayout();
layout.initialize();
bricks = layout.getBricks();
balls = new Array<Ball>();
balls.add(new Ball(this));
shields = new Array<Shield>();
}
public int getShieldCount() { public int getShieldCount() {
return shields.size; return shields.size;
} }

View File

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

View File

@ -7,9 +7,12 @@ import com.me.brickbuster.BrickBuster;
public class DesktopLauncher { public class DesktopLauncher {
public static void main (String[] arg) { public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 432; config.width = 450;
config.height = 768; config.height = 800;
config.title = BrickBuster.TITLE; config.title = BrickBuster.TITLE;
//config.vSyncEnabled = false;
//config.foregroundFPS = 0;
new LwjglApplication(new BrickBuster(), config); new LwjglApplication(new BrickBuster(), config);
} }
} }

View File

@ -1,17 +0,0 @@
package com.me.brickbuster.desktop;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
public class TextureSetup {
public static void main(String[] args) {
TexturePacker.Settings settings = new TexturePacker.Settings();
settings.paddingX = 8;
settings.paddingY = 8;
settings.filterMin = Texture.TextureFilter.MipMapLinearLinear;
settings.filterMag = Texture.TextureFilter.MipMapLinearLinear;
TexturePacker.process(settings,"sprites", "./", "textures");
}
}