summary refs log tree commit diff stats
path: root/data/maps/the_congruent/rooms/Flipped Magenta Room.txtpb
blob: db33a80bbff1d483a94c32c1b2e4a1c54aaaa942 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: "Flipped Magenta Room"
display_name: "Flipped Magenta Room"
panels {
  name: "LOOK"
  path: "Panels/Side Up 1/panel_1"
  clue: "look"
  answer: "cook"
  symbols: "sparkles"
}
panels {
  name: "SLOW"
  path: "Panels/Side Up 1/panel_2"
  clue: "slow"
  answer: "show"
  symbols: "sparkles"
}
panels {
  name: "RULE"
  path: "Panels/Side Up 1/panel_3"
  clue: "rule"
  answer: "rude"
  symbols: "sparkles"
}
panels {
  name: "MALE"
  path: "Panels/Side Up 1/panel_4"
  clue: "male"
  answer: "mace"
  symbols: "sparkles"
}
panels {
  name: "LAST"
  path: "Panels/Side Up 1/panel_5"
  clue: "last"
  answer: "fast"
  symbols: "sparkles"
}
panels {
  name: "LATE"
  path: "Panels/Side Up 1/panel_6"
  clue: "late"
  answer: "date"
  symbols: "sparkles"
}
panels {
  name: "LEFT"
  path: "Panels/Side Up 1/panel_7"
  clue: "left"
  answer: "heft"
  symbols: "sparkles"
}
panels {
  name: "LIST"
  path: "Panels/Side Up 1/panel_8"
  clue: "list"
  answer: "fist"
  symbols: "sparkles"
}
panels {
  name: "LUST"
  path: "Panels/Side Up 1/panel_9"
  clue: "lust"
  answer: "gust"
  symbols: "sparkles"
}
panels {
  name: "LAND"
  path: "Panels/Side Up 1/panel_10"
  clue: "land"
  answer: "sand"
  symbols: "sparkles"
}
#0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "map.h"
#include <tmxlite/Map.hpp>
#include <tmxlite/Layer.hpp>
#include <tmxlite/Property.hpp>
#include <tmxlite/TileLayer.hpp>
#include <tmxlite/Tileset.hpp>

Map::Map(std::string_view name) : name_(name) {
  std::string filename = "../res/maps/" + std::string(name) + ".tmx";
  tmx::Map mapfile;
  if (!mapfile.load(filename.c_str())) {
    throw std::invalid_argument("Could not find map file: " + filename);
  }

  const tmx::Vector2u& mapSize = mapfile.getTileCount();
  mapSize_.x() = mapSize.x;
  mapSize_.y() = mapSize.y;

  const tmx::Vector2u& tileSize = mapfile.getTileSize();
  tileSize_.x() = tileSize.x;
  tileSize_.y() = tileSize.y;

  int firstGID = 0;
  // There should only be one tileset.
  const tmx::Tileset& tileset = mapfile.getTilesets()[0];
  firstGID = tileset.getFirstGID();
  tilesetFilename_ = tileset.getImagePath();
  tilesetColumns_ = tileset.getColumnCount();

  for (const auto& layer : mapfile.getLayers()) {
    if (layer->getType() == tmx::Layer::Type::Tile) {
      const auto& tileLayer = layer->getLayerAs<tmx::TileLayer>();

      std::vector<Tile> tilesToStore;

      for (const auto& maptile : tileLayer.getTiles()) {
        Tile tile;
        tile.id = maptile.ID - firstGID;
        tile.flipHorizontal = (maptile.flipFlags & tmx::TileLayer::Horizontal) != 0;
        tile.flipVertical = (maptile.flipFlags & tmx::TileLayer::Vertical) != 0;

        for (const tmx::Property& property : tileset.getTile(maptile.ID)->properties) {
          if (property.getName() == "solid" && property.getBoolValue()) {
            tile.blocked = true;
          } else if (property.getName() == "runSound") {
            tile.step = stepTypeFromString(property.getStringValue());
          } else if (property.getName() == "medium") {
            if (property.getStringValue() == "ladder") {
              tile.medium = CharacterMedium::Ladder;
            } else if (property.getStringValue() == "water") {
              tile.medium = CharacterMedium::Water;
            }
          }
        }

        tilesToStore.push_back(std::move(tile));
      }

      bool above = false;
      for (const tmx::Property& property : tileLayer.getProperties()) {
        if (property.getName() == "above" && property.getBoolValue()) {
          above = true;
        }
      }

      if (above) {
        upperLayers_.push_back(std::move(tilesToStore));
      } else {
        lowerLayers_.push_back(std::move(tilesToStore));
      }
    } else if (layer->getType() == tmx::Layer::Type::Object) {
      const auto& objectLayer = layer->getLayerAs<tmx::ObjectGroup>();

      for (const tmx::Object& object : objectLayer.getObjects()) {
        if (object.getType() == "sprite") {
          Prototype p;
          p.name = object.getName();
          p.pos.x() = object.getPosition().x;
          p.pos.y() = object.getPosition().y;

          for (const tmx::Property& property : object.getProperties()) {
            if (property.getName() == "collisionOffsetX") {
              p.collisionOffset.x() = property.getIntValue();
            } else if (property.getName() == "collisionOffsetY") {
              p.collisionOffset.y() = property.getIntValue();
            } else if (property.getName() == "collisionWidth") {
              p.collisionSize.w() = property.getIntValue();
            } else if (property.getName() == "collisionHeight") {
              p.collisionSize.h() = property.getIntValue();
            } else if (property.getName() == "animation") {
              p.animationFilename = property.getStringValue();
            } else if (property.getName() == "interactionScript") {
              p.interactionScript = property.getStringValue();
            } else if (property.getName() == "shadow") {
              p.shadow = property.getBoolValue();
            } else if (property.getName() == "wander") {
              p.wander = property.getBoolValue();
            } else if (property.getName() == "enclosureZone") {
              p.enclosureZone = property.getStringValue();
            } else if (property.getName() == "movementSpeed") {
              p.movementSpeed = property.getIntValue();
            }
          }

          prototypes_.push_back(std::move(p));
        } else if (object.getType() == "warp") {
          vec2i point;
          point.x() = object.getPosition().x;
          point.y() = object.getPosition().y;

          warpPoints_[object.getName()] = std::move(point);
        } else if (object.getType() == "trigger") {
          Trigger t;
          t.name = object.getName();
          t.pos.x() = object.getPosition().x;
          t.pos.y() = object.getPosition().y;
          t.size.w() = object.getAABB().width;
          t.size.h() = object.getAABB().height;

          for (const tmx::Property& property : object.getProperties()) {
            if (property.getName() == "script") {
              t.script = property.getStringValue();
            }
          }

          triggers_.push_back(std::move(t));
        } else if (object.getType() == "tileSprite") {
          Prototype p;
          p.name = object.getName();
          p.pos.x() = std::floor(object.getPosition().x / 16) * 16;
          p.pos.y() = std::floor(object.getPosition().y / 16) * 16;
          p.collisionOffset = { 0, 0 };
          p.collisionSize = { 16, 16 };

          for (const tmx::Property& property : object.getProperties()) {
            if (property.getName() == "interactionScript") {
              p.interactionScript = property.getStringValue();
            }
          }

          prototypes_.push_back(std::move(p));
        } else if (object.getType() == "zone") {
          Zone z;
          z.ul.x() = object.getPosition().x;
          z.ul.y() = object.getPosition().y;
          z.dr.x() = z.ul.x() + object.getAABB().width;
          z.dr.y() = z.ul.y() + object.getAABB().height;

          zones_[object.getName()] = std::move(z);
        }
      }
    }
  }
}

bool Map::isBlocked(int x, int y) const {
  if (x < 0 || y < 0 || x >= mapSize_.w() || y >= mapSize_.h()) {
    return false;
  }

  int i = x + y * mapSize_.w();

  for (const std::vector<Tile>& layer : lowerLayers_) {
    if (layer.at(i).blocked) {
      return true;
    }
  }

  return false;
}

StepType Map::getStepType(int x, int y) const {
  if (x < 0 || y < 0 || x >= mapSize_.w() || y >= mapSize_.h()) {
    return StepType::none;
  }

  int i = x + y * mapSize_.w();

  for (const std::vector<Tile>& layer : lowerLayers_) {
    if (layer.at(i).step != StepType::none) {
      return layer.at(i).step;
    }
  }

  return StepType::none;
}

CharacterMedium Map::getMedium(int x, int y) const {
  CharacterMedium ret = CharacterMedium::Normal;

  if (x < 0 || y < 0 || x >= mapSize_.w() || y >= mapSize_.h()) {
    return ret;
  }

  int i = x + y * mapSize_.w();

  for (const std::vector<Tile>& layer : lowerLayers_) {
    if (layer.at(i).medium > ret) {
      ret = layer.at(i).medium;
    }
  }

  return ret;
}