Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.co.samatkins.roguelike.play;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.utils.Json;
- import com.badlogic.gdx.utils.JsonValue;
- public class Interactable implements Json.Serializable {
- public enum Type {
- // Description Glyph Color Solid Opaque
- DOOR_OPEN ("an Open Door", 1,4, new Color(0x6c2d00ff), false, false),
- DOOR_CLOSED ("a Closed Door", 0,4, new Color(0x6c2d00ff), true, true);
- public int col, row;
- public Color color;
- public boolean solid,
- opaque;
- public String description;
- Type(String description, int col, int row, Color color, boolean solid, boolean opaque) {
- this.description = description;
- this.col = col;
- this.row = row;
- this.color = color;
- this.solid = solid;
- this.opaque = opaque;
- }
- }
- public int x,y;
- public Type type;
- public Interactable() {
- }
- public Interactable(Type type) {
- this.type = type;
- }
- /**
- * The actor attempts to interact with this Iteractable
- * @param actor
- * @return Whether the actor was successful.
- */
- public boolean interact(Creature actor) {
- switch (type) {
- case DOOR_CLOSED:
- type = Type.DOOR_OPEN;
- return true;
- case DOOR_OPEN:
- if (actor.world.getTileAt(x, y).creature != null) {
- return false;
- }
- type = Type.DOOR_CLOSED;
- return true;
- }
- return false;
- }
- public String describe() {
- return type.description;
- }
- @Override
- public void write(Json json) {
- json.writeValue("x", x);
- json.writeValue("y", y);
- json.writeValue("type", type.name());
- }
- @Override
- public void read(Json json, JsonValue jsonData) {
- x = jsonData.getInt("x");
- y = jsonData.getInt("y");
- type = Type.valueOf(jsonData.getString("type"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment