List of usage examples for com.badlogic.gdx.maps.objects RectangleMapObject getName
public String getName()
From source file:com.prisonbreak.game.MapControlRenderer.java
private Array<Item> triggerInteraction() { for (MapObject object : interactionObjects) { // all interaction objects are guaranteed to be rectangle RectangleMapObject rectObject = (RectangleMapObject) object; // Gdx.app.log("object: ", rectObject.getRectangle().toString()); // Gdx.app.log("player: ", player.getSprite().getBoundingRectangle().toString()); // search and find for the object in interaction with Player if (rectObject.getRectangle().overlaps(player.getSprite().getBoundingRectangle())) { String directionCheck = rectObject.getProperties().get("contactDirection", "none", String.class); // Gdx.app.log("Contact direction: ", directionCheck); // Gdx.app.log("Player direction: ", player.getCurrentDirection()); // check if user faces object in correct direction if (directionCheck.equalsIgnoreCase("all") || (!player.getCurrentDirection().equalsIgnoreCase("none") && player.getCurrentDirection().equalsIgnoreCase(directionCheck))) { // retrieve type of interaction String type = rectObject.getProperties().get("type", "", String.class); // if searchable objects if (type.equalsIgnoreCase("search_interaction")) { interactHappen = true; // set the flag for type of interaction typeInteraction = TYPE_INTERACTION.SEARCH_INTERACTION; // extract attributes' values boolean haveItems = rectObject.getProperties().get("haveItems", false, Boolean.class); int listID = rectObject.getProperties().get("listItemID", -1, Integer.class); // if object does contain items // -> return list of those items // otherwise -> return null if (haveItems) { // get the item objectItems ID if (listID == -1) break; else return listItems.get(listID); }/*from w w w . ja va2 s . co m*/ } // if door object (open_lock_interaction) else if (type.equalsIgnoreCase("open_lock_interaction")) { // extract attributes' values boolean locked = rectObject.getProperties().get("locked", false, Boolean.class); int keyID = rectObject.getProperties().get("keyID", -1, Integer.class); Array<Item> needKey = new Array<Item>(); Item key = new Item("Needed key", keyID); needKey.add(key); // extract the name of current door in interaction with Player latestObjectName = rectObject.getName(); // set the status of current door in interaction with Player latestDoorLocked = locked; // Gdx.app.log("locked: ", latestDoorLocked + ""); // if the door is not locked // check the position of Player before invoking interaction // -> return the required key to lock it if (!latestDoorLocked) { MapObject o = doorObjects.get(latestObjectName); RectangleMapObject r = (RectangleMapObject) o; if (!r.getRectangle().overlaps(player.getSprite().getBoundingRectangle())) { interactHappen = true; // set the flag for type of interaction typeInteraction = TYPE_INTERACTION.OPEN_LOCK_INTERACTION; return needKey; } } // if the door is locked // -> return the required key to unlock it, or // the key with keyID = -1 ; indicate // that the door CANNOT be opened else { interactHappen = true; // set the flag for type of interaction typeInteraction = TYPE_INTERACTION.OPEN_LOCK_INTERACTION; return needKey; } } // if readable objects else if (type.equalsIgnoreCase("read_interaction")) { interactHappen = true; // set the flag for type of interaction typeInteraction = TYPE_INTERACTION.READ_INTERACTION; // extract attributes' values String message = rectObject.getProperties().get("message", "", String.class); // set the name of the object latestObjectName = rectObject.getProperties().get("name", "Object", String.class); // return a list with one "item" contain the message; id for item = -2 Array<Item> l = new Array<Item>(); Item mess = new Item("Written Message", -2); mess.setDescription(message); l.add(mess); return l; } // if password locking objects else if (type.equalsIgnoreCase("pass_unlock_interaction")) { boolean locked = rectObject.getProperties().get("locked", false, Boolean.class); // if the object has already been unlocked // -> return null; no interaction happens if (!locked) { return null; } // otherwise // -> return a list with first "item" containing the password, // and all the remaining items are ones that are inside // the object (in case of safe locker) else { interactHappen = true; // set the flag indicating the type of interaction typeInteraction = TYPE_INTERACTION.PASS_UNLOCK_INTERACTION; // extract the name of object in interaction latestObjectName = rectObject.getName(); // extract attributes String password = rectObject.getProperties().get("pass", "", String.class); Item passItem = new Item("Password", -3); // item contains password passItem.setDescription(password); // create the list Array<Item> list = new Array<Item>(); list.add(passItem); // if safe locker, add all the contained items into the list int listID = rectObject.getProperties().get("listItemID", -1, Integer.class); if (listID == -1) { Gdx.app.log("Error: ", "listItemID attribute not found"); } else { list.addAll(listItems.get(listID)); } return list; } } // if breakable object (here, break the office door) else if (type.equalsIgnoreCase("break_interaction")) { boolean broken = rectObject.getProperties().get("broken", true, Boolean.class); // if object has been cracked open (broken = true) // -> do nothing, no interaction happens, return null if (broken) { return null; } // otherwise // -> return the required item to break the object (door), which is a crowbar in this game else { interactHappen = true; typeInteraction = TYPE_INTERACTION.BREAK_INTERACTION; // extract the name of object in interaction latestObjectName = rectObject.getName(); int id = rectObject.getProperties().get("breakItemID", Integer.class); Item item = new Item("Required Item", id); Array<Item> l = new Array<Item>(); l.add(item); return l; } } } } } return null; }