use of com.agorria.shootandmove.graphics.TextureRegion in project ShootAndRun by IonAgorria.
the class GameView method drawText.
/**
* Draws the specified text in position by creating drawables
*
* @param drawables to add the drawables
* @param x position
* @param y position
* @param width of each character, 0 to use relative to height
* @param height of each character, 0 to use relative to width
* @param centerX enables centering in X axis
* @param centerY enables centering in Y axis
* @param lines to draw
*/
public void drawText(List<Drawable> drawables, float x, float y, float width, float height, boolean centerX, boolean centerY, String... lines) {
if (width == 0)
width = height * CHARACTER_ASPECT_WH;
else if (height == 0)
height = width * CHARACTER_ASPECT_HW;
float currentY = centerY ? -(lines.length * height * 0.5f) : 0;
// Draw lines in inverse order as the Y axis is upside down and I don't have time to make some dark magic
for (int i = lines.length - 1; 0 <= i; i--) {
String line = lines[i];
final char[] chars = line.toCharArray();
float currentX = centerX ? -(chars.length * width * 0.5f) : 0;
// Draw each character
for (char c : chars) {
if (c != ' ') {
// Attempt to get region for this character
TextureRegion region = characters.get(c);
if (region == null) {
region = unknownCharacter;
}
// Add drawable
drawables.add(new DrawableRectangle(x + currentX, y + currentY, width, height, region));
}
currentX += width;
}
currentY += height;
}
}
use of com.agorria.shootandmove.graphics.TextureRegion in project ShootAndRun by IonAgorria.
the class Door method getRegion.
/**
* Gets texture for door
*
* @param world to use
* @param location of texture region
* @return configured
*/
private TextureRegion getRegion(World world, Vector2i location) {
TextureRegion region = world.getTextureRegion(TextureAtlas.Atlas.Sprite32, location);
region = region.copy();
region.setRegion(region.x, region.y, 128 - Constants.TEXTURE_BLEED * 2, 128 - Constants.TEXTURE_BLEED * 2);
return region;
}
use of com.agorria.shootandmove.graphics.TextureRegion in project ShootAndRun by IonAgorria.
the class WorldLoader method parseTileLayer.
/**
* Parses single layer
*
* @param layer to parse
* @param layers map in world
* @param view to use
*/
private void parseTileLayer(LayerType layer, Map<LayerType, String> layers, GameView view) {
// Iterate tiles
String[] values = layers.get(layer).split(",");
for (int i = 0; i < values.length; i++) {
String value = values[i];
int tileGID = Integer.parseInt(value.trim());
if (tileGID != 0) {
int tileIndex = tileGID - tileFirstGID;
TextureRegion textureRegion = view.getTextureAtlas(tileAtlas).getRegion(tileIndex);
// Create the plane
int x = i % width;
int z = i / width;
float y;
switch(layer) {
case Ground:
groundMask[i] = true;
y = 0;
createPlane(x, y, z, DrawablePlane.Plane.Top, textureRegion);
break;
case Walls:
y = 0;
wallMask[i] = true;
// Create a wall for each adjacent ground tile
for (Map.Entry<DrawablePlane.Plane, Vector2i> entry : wallPlanes.entrySet()) {
Vector2i vector = entry.getValue();
int gx = x + vector.x;
int gz = z + vector.y;
int gi = gx + width * gz;
if (0 <= gi && gi < groundMask.length && groundMask[gi]) {
DrawablePlane.Plane plane = entry.getKey();
int wx = x;
int wz = z;
switch(plane) {
case Front:
wz += 1;
break;
case Right:
wx += 1;
break;
}
createPlane(wx, y, wz, plane, textureRegion);
}
}
break;
case Ceil:
y = WORLD_ROOF;
createPlane(x, y, z, DrawablePlane.Plane.Bottom, textureRegion);
break;
default:
throw new IllegalArgumentException("Unknown layer");
}
}
}
}
Aggregations