summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/maps/map2.tmx4
-rw-r--r--src/game.cpp3
-rw-r--r--src/map.cpp10
-rw-r--r--src/map.h9
-rw-r--r--src/sprite.h1
-rw-r--r--src/transform_system.cpp37
6 files changed, 63 insertions, 1 deletions
diff --git a/res/maps/map2.tmx b/res/maps/map2.tmx index 594fd93..87dbb1e 100644 --- a/res/maps/map2.tmx +++ b/res/maps/map2.tmx
@@ -1,5 +1,5 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="12"> 2<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="64" height="64" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="13">
3 <tileset firstgid="1" name="fromRom" tilewidth="16" tileheight="16" tilecount="180" columns="10"> 3 <tileset firstgid="1" name="fromRom" tilewidth="16" tileheight="16" tilecount="180" columns="10">
4 <image source="map2_tiles.png" width="160" height="288"/> 4 <image source="map2_tiles.png" width="160" height="288"/>
5 <tile id="61"> 5 <tile id="61">
@@ -695,6 +695,7 @@
695 <property name="collisionOffsetX" type="int" value="-8"/> 695 <property name="collisionOffsetX" type="int" value="-8"/>
696 <property name="collisionOffsetY" type="int" value="-8"/> 696 <property name="collisionOffsetY" type="int" value="-8"/>
697 <property name="collisionWidth" type="int" value="12"/> 697 <property name="collisionWidth" type="int" value="12"/>
698 <property name="enclosureZone" value="ionia_enclosure"/>
698 <property name="shadow" type="bool" value="true"/> 699 <property name="shadow" type="bool" value="true"/>
699 <property name="wander" type="bool" value="true"/> 700 <property name="wander" type="bool" value="true"/>
700 </properties> 701 </properties>
@@ -703,6 +704,7 @@
703 <object id="11" name="debugWarp_rightside" type="warp" x="911.333" y="431.667"> 704 <object id="11" name="debugWarp_rightside" type="warp" x="911.333" y="431.667">
704 <point/> 705 <point/>
705 </object> 706 </object>
707 <object id="12" name="ionia_enclosure" type="zone" x="800" y="80" width="96" height="96"/>
706 </objectgroup> 708 </objectgroup>
707 <layer id="1" name="Layer 0" width="64" height="64"> 709 <layer id="1" name="Layer 0" width="64" height="64">
708 <data encoding="csv"> 710 <data encoding="csv">
diff --git a/src/game.cpp b/src/game.cpp index 729e665..5c0017d 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -66,6 +66,9 @@ void Game::loadMap(std::string filename) {
66 getSystem<CharacterSystem>().initSprite(spriteId); 66 getSystem<CharacterSystem>().initSprite(spriteId);
67 getSprite(spriteId).wander = true; 67 getSprite(spriteId).wander = true;
68 } 68 }
69 if (!p.enclosureZone.empty()) {
70 getSprite(spriteId).enclosureZone = p.enclosureZone;
71 }
69 } 72 }
70 73
71 for (const Trigger& t : map_->getTriggers()) { 74 for (const Trigger& t : map_->getTriggers()) {
diff --git a/src/map.cpp b/src/map.cpp index 7bff071..5845009 100644 --- a/src/map.cpp +++ b/src/map.cpp
@@ -78,6 +78,8 @@ Map::Map(std::string_view name) : name_(name) {
78 p.shadow = property.getBoolValue(); 78 p.shadow = property.getBoolValue();
79 } else if (property.getName() == "wander") { 79 } else if (property.getName() == "wander") {
80 p.wander = property.getBoolValue(); 80 p.wander = property.getBoolValue();
81 } else if (property.getName() == "enclosureZone") {
82 p.enclosureZone = property.getStringValue();
81 } 83 }
82 } 84 }
83 85
@@ -118,6 +120,14 @@ Map::Map(std::string_view name) : name_(name) {
118 } 120 }
119 121
120 prototypes_.push_back(std::move(p)); 122 prototypes_.push_back(std::move(p));
123 } else if (object.getType() == "zone") {
124 Zone z;
125 z.ul.x() = object.getPosition().x;
126 z.ul.y() = object.getPosition().y;
127 z.dr.x() = z.ul.x() + object.getAABB().width;
128 z.dr.y() = z.ul.y() + object.getAABB().height;
129
130 zones_[object.getName()] = std::move(z);
121 } 131 }
122 } 132 }
123 } 133 }
diff --git a/src/map.h b/src/map.h index c5ecc64..e4096f4 100644 --- a/src/map.h +++ b/src/map.h
@@ -25,6 +25,7 @@ struct Prototype {
25 std::string interactionScript; 25 std::string interactionScript;
26 bool shadow = false; 26 bool shadow = false;
27 bool wander = false; 27 bool wander = false;
28 std::string enclosureZone;
28}; 29};
29 30
30struct Trigger { 31struct Trigger {
@@ -34,6 +35,11 @@ struct Trigger {
34 std::string script; 35 std::string script;
35}; 36};
36 37
38struct Zone {
39 vec2i ul;
40 vec2i dr;
41};
42
37class Map { 43class Map {
38public: 44public:
39 45
@@ -61,6 +67,8 @@ public:
61 67
62 const std::vector<Trigger>& getTriggers() const { return triggers_; } 68 const std::vector<Trigger>& getTriggers() const { return triggers_; }
63 69
70 const Zone& getZone(const std::string& name) const { return zones_.at(name); }
71
64private: 72private:
65 73
66 std::string name_; 74 std::string name_;
@@ -72,6 +80,7 @@ private:
72 std::vector<Prototype> prototypes_; 80 std::vector<Prototype> prototypes_;
73 std::map<std::string, vec2i> warpPoints_; 81 std::map<std::string, vec2i> warpPoints_;
74 std::vector<Trigger> triggers_; 82 std::vector<Trigger> triggers_;
83 std::map<std::string, Zone> zones_;
75}; 84};
76 85
77#endif /* end of include guard: MAP_H_D95D6D47 */ 86#endif /* end of include guard: MAP_H_D95D6D47 */
diff --git a/src/sprite.h b/src/sprite.h index 82849fa..e0cff0c 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -53,6 +53,7 @@ public:
53 vec2i collisionSize; 53 vec2i collisionSize;
54 std::string interactionScript; 54 std::string interactionScript;
55 std::string walkthroughScript; 55 std::string walkthroughScript;
56 std::string enclosureZone;
56 57
57 // Animation 58 // Animation
58 bool isAnimated = false; 59 bool isAnimated = false;
diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 1d4a9f3..b5e9b7c 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp
@@ -67,6 +67,11 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
67 vec2i oldTileDR = oldColDR / map.getTileSize(); 67 vec2i oldTileDR = oldColDR / map.getTileSize();
68 vec2i newTileDR = newColDR / map.getTileSize(); 68 vec2i newTileDR = newColDR / map.getTileSize();
69 69
70 const Zone* enclosureZone = nullptr;
71 if (!sprite.enclosureZone.empty()) {
72 enclosureZone = &map.getZone(sprite.enclosureZone);
73 }
74
70 if (dirHasDir(sprite.dir, Direction::right)) { 75 if (dirHasDir(sprite.dir, Direction::right)) {
71 if (newTileDR.x() > oldTileDR.x() && 76 if (newTileDR.x() > oldTileDR.x() &&
72 newColDR.x() < mapBounds.w()) { 77 newColDR.x() < mapBounds.w()) {
@@ -80,6 +85,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
80 } 85 }
81 } 86 }
82 87
88 if (!result.horiz.blocked && enclosureZone) {
89 if (oldColDR.x() <= enclosureZone->dr.x() &&
90 newColDR.x() > enclosureZone->dr.x()) {
91 result.horiz.blocked = true;
92 result.horiz.dir = Direction::right;
93 }
94 }
95
83 if (!result.horiz.blocked) { 96 if (!result.horiz.blocked) {
84 auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX}); 97 auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX});
85 for (; 98 for (;
@@ -113,6 +126,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
113 } 126 }
114 } 127 }
115 128
129 if (!result.horiz.blocked && enclosureZone) {
130 if (oldColUL.x() >= enclosureZone->ul.x() &&
131 newColUL.x() < enclosureZone->ul.x()) {
132 result.horiz.blocked = true;
133 result.horiz.dir = Direction::left;
134 }
135 }
136
116 if (!result.horiz.blocked) { 137 if (!result.horiz.blocked) {
117 auto it = leftCollidables_.lower_bound({oldColUL.x(), 0}); 138 auto it = leftCollidables_.lower_bound({oldColUL.x(), 0});
118 for (; 139 for (;
@@ -146,6 +167,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
146 } 167 }
147 } 168 }
148 169
170 if (!result.vert.blocked && enclosureZone) {
171 if (oldColDR.y() <= enclosureZone->dr.y() &&
172 newColDR.y() > enclosureZone->dr.y()) {
173 result.vert.blocked = true;
174 result.vert.dir = Direction::down;
175 }
176 }
177
149 if (!result.vert.blocked) { 178 if (!result.vert.blocked) {
150 auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX}); 179 auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX});
151 for (; 180 for (;
@@ -179,6 +208,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
179 } 208 }
180 } 209 }
181 210
211 if (!result.vert.blocked && enclosureZone) {
212 if (oldColUL.y() >= enclosureZone->ul.y() &&
213 newColUL.y() < enclosureZone->ul.y()) {
214 result.vert.blocked = true;
215 result.vert.dir = Direction::up;
216 }
217 }
218
182 if (!result.vert.blocked) { 219 if (!result.vert.blocked) {
183 auto it = upCollidables_.lower_bound({oldColUL.y(), 0}); 220 auto it = upCollidables_.lower_bound({oldColUL.y(), 0});
184 for (; 221 for (;