Search in sources :

Example 1 with Vector2i

use of com.agorria.shootandmove.math.Vector2i 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

DrawablePlane (com.agorria.shootandmove.graphics.DrawablePlane)1 TextureRegion (com.agorria.shootandmove.graphics.TextureRegion)1 Vector2i (com.agorria.shootandmove.math.Vector2i)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1