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

Function testAnimPan

tests/game_player_pan.cpp:96–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96static void testAnimPan(Game_Player::PanDirection dir_x, Game_Player::PanDirection dir_y, int speed) {
97 static constexpr auto map_id = MockMap::ePass40x30;
98
99 const MockGame mg(map_id);
100 auto& ch = *mg.GetPlayer();
101
102 ch.SetMapId(static_cast<int>(map_id));
103 ch.MoveTo(static_cast<int>(map_id), 20, 15);
104
105 ch.StartPan(dir_x, 1, speed);
106 ch.StartPan(dir_y, 2, speed);
107
108 auto wait = 2 * SCREEN_TILE_SIZE / (2 << speed);
109
110 int step_x = 2 << speed;
111 int step_y = 2 << speed;
112 int dx = 0;
113 int dy = 0;
114 int fx = 1 * SCREEN_TILE_SIZE;
115 int fy = 2 * SCREEN_TILE_SIZE;
116
117 if (dir_x == Game_Player::PanRight) {
118 fx = -1 * SCREEN_TILE_SIZE;
119 }
120 if (dir_y == Game_Player::PanDown) {
121 fy = -2 * SCREEN_TILE_SIZE;
122 }
123
124 CAPTURE(speed);
125 CAPTURE(dir_x);
126 CAPTURE(dir_y);
127 CAPTURE(step_x);
128 CAPTURE(step_y);
129 CAPTURE(wait);
130 CAPTURE(fx);
131 CAPTURE(fy);
132
133 testPanAbs(ch, true, false, 0, 0, fx, fy, wait);
134
135 for (int i = 1; i < wait; ++i) {
136 ForceUpdate(ch);
137 if (dir_x == Game_Player::PanRight) {
138 dx = std::max(dx - step_x, fx);
139 } else {
140 dx = std::min(dx + step_x, fx);
141 }
142 if (dir_y == Game_Player::PanDown) {
143 dy = std::max(dy - step_y, fy);
144 } else {
145 dy = std::min(dy + step_y, fy);
146 }
147 testPanAbs(ch, true, false, dx, dy, fx, fy, wait - i);
148 }
149
150 ForceUpdate(ch);
151 testPanAbs(ch, false, false, fx, fy, fx, fy, 0);
152
153 ch.ResetPan(speed);

Callers 1

Calls 9

testPanAbsFunction · 0.85
maxFunction · 0.85
minFunction · 0.85
GetPlayerMethod · 0.80
SetMapIdMethod · 0.80
StartPanMethod · 0.80
ResetPanMethod · 0.80
ForceUpdateFunction · 0.70
MoveToMethod · 0.45

Tested by

no test coverage detected