package com.gebauz.PonPonChun.game.entities;
import com.gebauz.Bauzoid.graphics.Graphics;
import com.gebauz.Bauzoid.graphics.GraphicsObject;
import com.gebauz.Bauzoid.graphics.sprite.AtlasSprite;
import com.gebauz.Bauzoid.graphics.sprite.AtlasSpriteInstance;
import com.gebauz.Bauzoid.graphics.sprite.Sprite;
import com.gebauz.Bauzoid.graphics.sprite.SpriteRegion;
import com.gebauz.Bauzoid.math.MathUtil;
/** Blocks Sprite manager.
*
* @author chiu
*
*/
public class BlockSprites
extends GraphicsObject
{
// Constants========================================================================================
public static final int NUM_BLOCK_SPRITES =
14;
public static final float BLOCK_REGION_SIZE =
16;
public static final float BREAKBLOCK_REGION_SIZE =
18;
public static final int BREAKBLOCK_ANIM_REGIONS =
3;
public static final int BREAKBLOCK_SHARD_REGIONS =
5;
public static final int NUM_CRYSTALIZED_REGIONS =
4;
public static final int CRYSTALIZED_REGION_SIZE =
32;
public static final int NUM_ANIM_FRAMES =
3;
// Embedded Types===================================================================================
// Members==========================================================================================
private AtlasSprite mBlockAtlas =
null;
private AtlasSpriteInstance mBlockSprites
[] =
new AtlasSpriteInstance
[NUM_BLOCK_SPRITES
*NUM_ANIM_FRAMES
];
private AtlasSprite mBreakBlock =
null;
private AtlasSprite mCrystalized =
null;
private AtlasSpriteInstance mCrystalizedFrames
[] =
new AtlasSpriteInstance
[NUM_CRYSTALIZED_REGIONS
];
/** Selection cursor. */
private Sprite mCursor =
null;
/** Sprite for indicating immovable objects. */
private Sprite mNoMove =
null;
// Methods==========================================================================================
public BlockSprites
(Graphics graphics
)
{
super(graphics
);
}
public void init
()
{
//Texture blockTexture = new Texture(Gdx.files.internal("data/textures/blocks.png"));
mBlockAtlas =
new AtlasSprite
(getGraphics
(),
"data/textures/blocks.png");
mBlockAtlas.
init();
SpriteRegion
[] blockRegions =
new SpriteRegion
[NUM_BLOCK_SPRITES
*NUM_ANIM_FRAMES
];
for (int i =
0; i
< blockRegions.
length; i++
)
{
// offset by 1 to account for the margin between regions
float x =
(float)((i
% NUM_BLOCK_SPRITES
) * (BLOCK_REGION_SIZE+
1));
float y =
(float)((i / NUM_BLOCK_SPRITES
) * (BLOCK_REGION_SIZE+
1));
blockRegions
[i
] =
new SpriteRegion
(mBlockAtlas.
getTexture(), x, y, BLOCK_REGION_SIZE, BLOCK_REGION_SIZE
);
}
mBlockAtlas.
setRegions(blockRegions
);
//mBlockAtlas = new AtlasSprite(getGraphics(), blockTexture, blockRegions);
for (int i =
0; i
< mBlockSprites.
length; i++
)
{
mBlockSprites
[i
] = mBlockAtlas.
createSpriteInstance(i
);
}
//Texture breakBlockTexture = new Texture(Gdx.files.internal("data/textures/breakblock.png"));
mBreakBlock =
new AtlasSprite
(getGraphics
(),
"data/textures/breakblock.png");
mBreakBlock.
init();
SpriteRegion
[] breakBlockRegions =
new SpriteRegion
[BREAKBLOCK_ANIM_REGIONS + BREAKBLOCK_SHARD_REGIONS
];
for (int i =
0; i
< BREAKBLOCK_ANIM_REGIONS
; i++
)
{
// offset by 1 to account for the margin between regions
breakBlockRegions
[i
] =
new SpriteRegion
(mBreakBlock.
getTexture(),
(float)i
* (BREAKBLOCK_REGION_SIZE+
1), 0.0f, BREAKBLOCK_REGION_SIZE, BREAKBLOCK_REGION_SIZE
);
}
breakBlockRegions
[3] =
new SpriteRegion
(mBreakBlock.
getTexture(),
0,
19,
11,
13);
breakBlockRegions
[4] =
new SpriteRegion
(mBreakBlock.
getTexture(),
12,
19,
11,
13);
breakBlockRegions
[5] =
new SpriteRegion
(mBreakBlock.
getTexture(),
24,
19,
10,
13);
breakBlockRegions
[6] =
new SpriteRegion
(mBreakBlock.
getTexture(),
35,
19,
15,
13);
breakBlockRegions
[7] =
new SpriteRegion
(mBreakBlock.
getTexture(),
51,
19,
12,
13);
mBreakBlock.
setRegions(breakBlockRegions
);
mCrystalized =
new AtlasSprite
(getGraphics
(),
"data/textures/crystalized.png");
mCrystalized.
init();
SpriteRegion
[] crystalizedRegions =
new SpriteRegion
[NUM_CRYSTALIZED_REGIONS
];
for (int i =
0; i
< NUM_CRYSTALIZED_REGIONS
; i++
)
{
crystalizedRegions
[i
] =
new SpriteRegion
(mCrystalized.
getTexture(),
(float)i
* CRYSTALIZED_REGION_SIZE,
0, CRYSTALIZED_REGION_SIZE, CRYSTALIZED_REGION_SIZE
);
}
mCrystalized.
setRegions(crystalizedRegions
);
for (int i =
0; i
< NUM_CRYSTALIZED_REGIONS
; i++
)
{
mCrystalizedFrames
[i
] = mCrystalized.
createSpriteInstance(i
);
}
//mBreakBlock = new AtlasSprite(getGraphics(), breakBlockTexture, breakBlockRegions);
//Texture cursorTexture = new Texture(Gdx.files.internal("data/textures/cursor.png"));
//mCursor = new Sprite(getGraphics(), cursorTexture);
mCursor =
new Sprite
(getGraphics
(),
"data/textures/cursor.png");
mCursor.
init();
mCursor.
pivotX = Block.
BLOCK_SIZE;
mCursor.
pivotY = Block.
BLOCK_SIZE;
mCursor.
x =
0;
mCursor.
y =
0;
mCursor.
w = Block.
BLOCK_SIZE*2;
mCursor.
h = Block.
BLOCK_SIZE*2;
mNoMove =
new Sprite
(getGraphics
(),
"data/textures/no_move.png");
mNoMove.
init(0,
0, Block.
BLOCK_SIZE, Block.
BLOCK_SIZE);
}
public void exit
()
{
for (int i =
0; i
< NUM_CRYSTALIZED_REGIONS
; i++
)
{
mCrystalizedFrames
[i
] =
null;
}
for (int i =
0; i
< mBlockSprites.
length; i++
)
{
mBlockSprites
[i
] =
null;
}
if (mCrystalized
!=
null)
{
mCrystalized.
dispose();
mCrystalized =
null;
}
if (mBlockAtlas
!=
null)
{
mBlockAtlas.
dispose();
mBlockAtlas =
null;
}
if (mBreakBlock
!=
null)
{
mBreakBlock.
dispose();
mBreakBlock =
null;
}
if (mNoMove
!=
null)
{
mNoMove.
dispose();
mNoMove =
null;
}
if (mCursor
!=
null)
{
mCursor.
dispose();
mCursor =
null;
}
}
// Getters/Setters==================================================================================
public final AtlasSpriteInstance getBlockSprite
(int i
)
{
if (!MathUtil.
isInRange(i,
0, mBlockSprites.
length-
1))
return null;
return mBlockSprites
[i
];
}
public final AtlasSpriteInstance getCrystalizedFrame
(int i
)
{
if (!MathUtil.
isInRange(i,
0, mCrystalizedFrames.
length-
1))
return null;
return mCrystalizedFrames
[i
];
}
public final AtlasSprite getBreakSprite
()
{
return mBreakBlock
;
}
public final Sprite getCursor
()
{
return mCursor
;
}
public final Sprite getNoMove
()
{
return mNoMove
;
}
}