File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,11 @@ class Rectf final
147
147
return glm::distance (v1, v2);
148
148
}
149
149
150
+ /* *
151
+ * Returns a new Rectf that is grown / shrunk by the specified amount
152
+ * @param border The amount of pixels that the Rectangle should be
153
+ * grown (for positive values) or shrunk (for negative values)
154
+ */
150
155
Rectf grown (float border) const
151
156
{
152
157
// If the size would be shrunk below 0, do not resize.
@@ -157,6 +162,22 @@ class Rectf final
157
162
get_right () + border, get_bottom () + border);
158
163
}
159
164
165
+ /* *
166
+ * Returns a new Rectf instance that is grown / shrunk by the amounts specified by the vector.
167
+ *
168
+ * @param border The passed vector contains the horizontal amount as first component and the vertical amount
169
+ * as the second component.
170
+ */
171
+ Rectf grown (Vector border) const
172
+ {
173
+ // If the size would be shrunk below 0, do not resize.
174
+ if (m_size.width + border.x * 2 < 0 .f || m_size.height + border.y * 2 < 0 .f )
175
+ return *this ;
176
+
177
+ return Rectf (m_p1.x - border.x , m_p1.y - border.y ,
178
+ get_right () + border.x , get_bottom () + border.y );
179
+ }
180
+
160
181
// leave these two public to save the headaches of set/get functions for such
161
182
// simple things :)
162
183
Original file line number Diff line number Diff line change @@ -84,11 +84,16 @@ Climbable::update(float dt_sec)
84
84
{
85
85
if (it2->m_activate_try_timer ->started ())
86
86
{
87
+ auto bbox_with_grace = m_col.m_bbox .grown (Vector (GRACE_DX, GRACE_DY));
87
88
// The "-20" to y velocity prevents Tux from walking in place on the ground for horizonal adjustments.
88
- if (it2->m_player ->get_bbox ().get_left () < m_col.m_bbox .get_left () - GRACE_DX) it2->m_player ->add_velocity (Vector (POSITION_FIX_AX,-20 ));
89
- if (it2->m_player ->get_bbox ().get_right () > m_col.m_bbox .get_right () + GRACE_DX) it2->m_player ->add_velocity (Vector (-POSITION_FIX_AX,-20 ));
90
- if (it2->m_player ->get_bbox ().get_top () < m_col.m_bbox .get_top () - GRACE_DY) it2->m_player ->add_velocity (Vector (0 ,POSITION_FIX_AY));
91
- if (it2->m_player ->get_bbox ().get_bottom () > m_col.m_bbox .get_bottom () + GRACE_DY) it2->m_player ->add_velocity (Vector (0 ,-POSITION_FIX_AY));
89
+ if (it2->m_player ->get_bbox ().get_left () < bbox_with_grace.get_left ())
90
+ it2->m_player ->add_velocity (Vector (POSITION_FIX_AX, -20 ));
91
+ if (it2->m_player ->get_bbox ().get_right () > bbox_with_grace.get_right ())
92
+ it2->m_player ->add_velocity (Vector (-POSITION_FIX_AX, -20 ));
93
+ if (it2->m_player ->get_bbox ().get_top () < bbox_with_grace.get_top ())
94
+ it2->m_player ->add_velocity (Vector (0 , POSITION_FIX_AY));
95
+ if (it2->m_player ->get_bbox ().get_bottom () > bbox_with_grace.get_bottom ())
96
+ it2->m_player ->add_velocity (Vector (0 , -POSITION_FIX_AY));
92
97
}
93
98
if (may_climb (*(it2->m_player )))
94
99
{
You can’t perform that action at this time.
0 commit comments