MCPcopy Create free account
hub / github.com/EasyRPG/Player / testJump

Function testJump

tests/game_character_move.cpp:195–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195static void testJump(bool success, int x, int y, int dir, int face,
196 int dx, int dy, int freq, int speed, bool facing_locked) {
197
198 const MockGame mg(MockMap::ePassBlock20x15);
199 auto& ch = *mg.GetEvent(1);
200
201 ch.SetX(x);
202 ch.SetY(y);
203 ch.SetDirection(dir);
204 ch.SetFacing(face);
205 ch.SetMoveSpeed(speed);
206 ch.SetMoveFrequency(freq);
207 const auto maxstop = ch.GetMaxStopCount();
208 if (facing_locked) {
209 ch.SetFacingLocked(true);
210 }
211
212 CAPTURE(success);
213 CAPTURE(speed);
214 CAPTURE(freq);
215
216 const auto tx = x + dx;
217 const auto ty = y + dy;
218
219 // Expected direction after the jump finishes.
220 auto tdir = Down;
221 if (std::abs(dy) >= std::abs(dx)) {
222 tdir = dy >= 0 ? Down : Up;
223 } else {
224 tdir = dx >= 0 ? Right : Left;
225 }
226 auto tface = facing_locked ? face : tdir;
227
228 // Jump in place always succeeds
229 if (x == tx && y == ty) {
230 success = true;
231 }
232
233 INFO("BEFORE JUMP");
234
235 REQUIRE_EQ(ch.Jump(tx, ty), success);
236
237 if (!success) {
238 INFO("FAIL JUMP");
239 testChar(ch, tx, ty, tdir, tface, 0, false, 0, 0, freq, speed, 0, maxstop);
240 return;
241 }
242
243 testChar(ch, tx, ty, tdir, tface, 256, true, x, y, freq, speed, 0, maxstop);
244
245 // FIXME: Verify all speeds
246 static const int jump_speed[] = {8, 12, 16, 24, 32, 64};
247 const auto dt = jump_speed[speed - 1];
248
249 INFO("ANIMATE JUMP");
250
251 for(int i = 256 - dt; i > 0; i -= dt) {
252 ForceUpdate(ch);

Callers 1

Calls 12

SetDirectionMethod · 0.80
SetFacingMethod · 0.80
SetMoveSpeedMethod · 0.80
SetMoveFrequencyMethod · 0.80
GetMaxStopCountMethod · 0.80
SetFacingLockedMethod · 0.80
JumpMethod · 0.80
testCharFunction · 0.70
ForceUpdateFunction · 0.70
GetEventMethod · 0.45
SetXMethod · 0.45
SetYMethod · 0.45

Tested by

no test coverage detected