Skip to content

Commit d408848

Browse files
committed
root_sapling: spawn a bit below when spawning in slopes
This is so that the root isn't exposed when spawning in slopes. closes #3607
1 parent 2dcf2f7 commit d408848

2 files changed

Lines changed: 65 additions & 8 deletions

File tree

src/badguy/root_sapling.cpp

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "audio/sound_manager.hpp"
2020
#include "badguy/root.hpp"
2121
#include "collision/collision_system.hpp"
22+
#include "math/aatriangle.hpp"
2223
#include "math/random.hpp"
2324
#include "object/player.hpp"
2425
#include "object/tilemap.hpp"
@@ -129,6 +130,57 @@ RootSapling::get_allowed_directions() const
129130
return { Direction::UP, Direction::DOWN, Direction::LEFT, Direction::RIGHT };
130131
}
131132

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+
132184
void
133185
RootSapling::summon_root()
134186
{
@@ -205,20 +257,24 @@ RootSapling::summon_root()
205257
if (!tile_p || result.box.empty())
206258
continue;
207259

260+
if ((*tile_p)->is_unisolid())
261+
continue;
262+
263+
(*axis) = 0.f;
208264
switch (m_dir)
209265
{
210-
case Direction::UP:
211266
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));
215271
break;
216272

217-
case Direction::LEFT:
218273
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));
222278
break;
223279

224280
default: assert(false); break;

src/badguy/root_sapling.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class RootSapling final : public BadGuy
4848
virtual std::vector<Direction> get_allowed_directions() const override;
4949

5050
private:
51+
float get_tile_spawn_pos_offset(const Tile& tile);
5152
void summon_root();
5253
bool should_summon_root(const Rectf& bbox);
5354

0 commit comments

Comments
 (0)