Example usage for com.badlogic.gdx.maps.objects RectangleMapObject isVisible

List of usage examples for com.badlogic.gdx.maps.objects RectangleMapObject isVisible

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps.objects RectangleMapObject isVisible.

Prototype

public boolean isVisible() 

Source Link

Usage

From source file:com.prisonbreak.game.MapControlRenderer.java

private void initializeGuards() {
    String type, sheetName, direction;
    guards = new Array<Guard>();

    // extract all guard objects in map
    MapObjects guardObjects = map.getLayers().get("Guards").getObjects();

    // for each object
    for (MapObject guard : guardObjects) {
        RectangleMapObject rectGuard = (RectangleMapObject) guard;

        // if current guard is "not visible" -> ignore
        if (!rectGuard.isVisible()) {
            continue;
        }//from w w  w .j  a v  a2 s.c o  m

        // extract values of attributes of 'guard' object
        type = rectGuard.getProperties().get("type", "none", String.class);
        sheetName = rectGuard.getProperties().get("sheetName", "", String.class);
        if (type.equalsIgnoreCase("none")) {
            Gdx.app.log("Error: ", "'type' attribute not found");
            return;
        }

        // if stationary guard
        if (type.equalsIgnoreCase("stationary")) {
            direction = rectGuard.getProperties().get("direction", "none", String.class);
            if (direction.equalsIgnoreCase("none")) {
                Gdx.app.log("Error: ", "invalid value for direction attribute");
                return;
            }

            // create the specified guard
            Guard specifiedGuard = new StationGuard(sheetName, direction, rectGuard.getRectangle().getX(),
                    rectGuard.getRectangle().getY());
            specifiedGuard.setMapControlRenderer(this);

            // add the corresponding guard to the array
            guards.add(specifiedGuard);
        }
        // if patrol guard
        else if (type.equalsIgnoreCase("patrol")) {
            float secondDelay = rectGuard.getProperties().get("delay", Float.class);

            // create the specified guard (without setting mark points)
            Guard specifiedGuard = new PatrolGuard(sheetName, rectGuard.getRectangle().getX(),
                    rectGuard.getRectangle().getY(), secondDelay);
            specifiedGuard.setMapControlRenderer(this);

            // extract list of mark points from the map
            String listPoints = rectGuard.getProperties().get("markPoints", String.class);
            String[] tileIndices = listPoints.split(",");
            for (int i = 0, indexX, indexY; i < tileIndices.length; i += 2) {
                indexX = Integer.parseInt(tileIndices[i]);
                indexY = Integer.parseInt(tileIndices[i + 1]);

                //                    Gdx.app.log("x: ", "" + indexX);
                //                    Gdx.app.log("y: ", "" + indexY);

                if (!((PatrolGuard) specifiedGuard).addMarkPoint(new Vector2(indexX * 32f, indexY * 32f))) {
                    Gdx.app.log("Cannot add mark point ", "(indeX, indexY)");
                }
            }

            //                Gdx.app.log("Mark point 1: ", ((PatrolGuard) specifiedGuard).listMarkPoints.get(0).toString());
            //                Gdx.app.log("Mark point 2: ", ((PatrolGuard) specifiedGuard).listMarkPoints.get(1).toString());

            // add the corresponding guard to the array
            guards.add(specifiedGuard);
        }
    }
}