|
19 | 19 | #include "audio/sound_manager.hpp" |
20 | 20 | #include "badguy/root.hpp" |
21 | 21 | #include "collision/collision_system.hpp" |
| 22 | +#include "math/aatriangle.hpp" |
22 | 23 | #include "math/random.hpp" |
23 | 24 | #include "object/player.hpp" |
24 | 25 | #include "object/tilemap.hpp" |
@@ -129,6 +130,57 @@ RootSapling::get_allowed_directions() const |
129 | 130 | return { Direction::UP, Direction::DOWN, Direction::LEFT, Direction::RIGHT }; |
130 | 131 | } |
131 | 132 |
|
| 133 | +float |
| 134 | +RootSapling::get_tile_spawn_pos_offset(const Tile& tile) |
| 135 | +{ |
| 136 | + if (!tile.is_slope()) |
| 137 | + return 0.f; |
| 138 | + |
| 139 | + AATriangle slope(tile.get_data()); |
| 140 | + int deform = slope.dir & AATriangle::DEFORM_MASK; |
| 141 | + |
| 142 | + switch (m_dir) |
| 143 | + { |
| 144 | + case Direction::UP: |
| 145 | + if (!slope.is_south()) |
| 146 | + return 0.f; |
| 147 | + |
| 148 | + if (deform == AATriangle::DEFORM_TOP) |
| 149 | + return 16.f; |
| 150 | + else |
| 151 | + return 32.f; |
| 152 | + |
| 153 | + case Direction::DOWN: |
| 154 | + if (slope.is_south()) |
| 155 | + return 0.f; |
| 156 | + |
| 157 | + if (deform == AATriangle::DEFORM_BOTTOM) |
| 158 | + return -16.f; |
| 159 | + else |
| 160 | + return -32.f; |
| 161 | + |
| 162 | + case Direction::LEFT: |
| 163 | + if (!slope.is_east()) |
| 164 | + return 0.f; |
| 165 | + |
| 166 | + if (deform == AATriangle::DEFORM_LEFT) |
| 167 | + return 16.f; |
| 168 | + else |
| 169 | + return 32.f; |
| 170 | + |
| 171 | + case Direction::RIGHT: |
| 172 | + if (slope.is_east()) |
| 173 | + return 0.f; |
| 174 | + |
| 175 | + if (deform == AATriangle::DEFORM_RIGHT) |
| 176 | + return -16.f; |
| 177 | + else |
| 178 | + return -32.f; |
| 179 | + |
| 180 | + default: assert(false); break; |
| 181 | + } |
| 182 | +} |
| 183 | + |
132 | 184 | void |
133 | 185 | RootSapling::summon_root() |
134 | 186 | { |
@@ -205,20 +257,24 @@ RootSapling::summon_root() |
205 | 257 | if (!tile_p || result.box.empty()) |
206 | 258 | continue; |
207 | 259 |
|
| 260 | + if ((*tile_p)->is_unisolid()) |
| 261 | + continue; |
| 262 | + |
| 263 | + (*axis) = 0.f; |
208 | 264 | switch (m_dir) |
209 | 265 | { |
210 | | - case Direction::UP: |
211 | 266 | case Direction::DOWN: |
212 | | - if ((*tile_p)->is_unisolid()) |
213 | | - continue; |
214 | | - (*axis) = result.box.p1().y; |
| 267 | + (*axis) += 32.f; |
| 268 | + [[fallthrough]]; |
| 269 | + case Direction::UP: |
| 270 | + (*axis) += result.box.p1().y + get_tile_spawn_pos_offset(*(*tile_p)); |
215 | 271 | break; |
216 | 272 |
|
217 | | - case Direction::LEFT: |
218 | 273 | case Direction::RIGHT: |
219 | | - if ((*tile_p)->is_unisolid()) |
220 | | - continue; |
221 | | - (*axis) = result.box.p1().x; |
| 274 | + (*axis) += 32.f; |
| 275 | + [[fallthrough]]; |
| 276 | + case Direction::LEFT: |
| 277 | + (*axis) += result.box.p1().x + get_tile_spawn_pos_offset(*(*tile_p)); |
222 | 278 | break; |
223 | 279 |
|
224 | 280 | default: assert(false); break; |
|
0 commit comments