Search in sources :

Example 1 with TextureRegion

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;
    }
}
Also used : TextureRegion(com.agorria.shootandmove.graphics.TextureRegion) DrawableRectangle(com.agorria.shootandmove.graphics.DrawableRectangle) SuppressLint(android.annotation.SuppressLint)

Example 2 with TextureRegion

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;
}
Also used : TextureRegion(com.agorria.shootandmove.graphics.TextureRegion)

Example 3 with TextureRegion

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");
            }
        }
    }
}
Also used : TextureRegion(com.agorria.shootandmove.graphics.TextureRegion) DrawablePlane(com.agorria.shootandmove.graphics.DrawablePlane) DrawablePlane(com.agorria.shootandmove.graphics.DrawablePlane) Vector2i(com.agorria.shootandmove.math.Vector2i) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TextureRegion (com.agorria.shootandmove.graphics.TextureRegion)3 SuppressLint (android.annotation.SuppressLint)1 DrawablePlane (com.agorria.shootandmove.graphics.DrawablePlane)1 DrawableRectangle (com.agorria.shootandmove.graphics.DrawableRectangle)1 Vector2i (com.agorria.shootandmove.math.Vector2i)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1