File tree 1 file changed +14
-9
lines changed
1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -22,18 +22,23 @@ void TimeCanvas::move(float dt)
22
22
{
23
23
/* Update position of square */
24
24
25
- _x += std::ceil ((_dx * dt * 60 ) / 1000 ); // (2 * 16 * 60) / 1000 --> 1.92
25
+ /* Rounding _dx up/down can affect the horizontal movement of the square.
26
+ * Rounding down when _dx is negative is essential to fix the slowness
27
+ * that happens when going from right to left.
28
+ */
29
+ if (_dx > 0 )
30
+ _x += std::ceil ((_dx * dt * 60 ) / 1000 ); // (2 * 16 * 60) / 1000 = 1.92 = 2
31
+ else
32
+ _x += std::floor ((_dx * dt * 60 ) / 1000 ); // (-2 * 16 * 60) / 1000 = -1.92 = -2
26
33
34
+ /* Rounding _dy up/down can also affect the vertical move of the square.
35
+ * If _dy is positive, round up, else the square will move sideways only.
36
+ * If _dy is negative, round down, else the square won't go up after colliding.
37
+ */
27
38
if (_dy > 0 )
28
- {
29
- // If _dy is positive, round up, else animation will move sideways only
30
39
_y += std::ceil ((_dy * dt * 60 ) / 1000 ); // (1 * 16 * 60) / 1000 = 0.96 = 1
31
- }
32
- else
33
- {
34
- // If _dy is negative, round down, else animation will not bounce up
35
- _y += std::floor ((_dy * dt * 60 ) / 1000 ); // (-1 * 16 * 60) / 1000 = -0.96 = -1
36
- }
40
+ else
41
+ _y += std::floor ((_dy * dt * 60 ) / 1000 ); // (-1 * 16 * 60) / 1000 = -0.96 = -1
37
42
38
43
if ( _x <= 0 || (_x >= (width ()-1 ) - _sq_sz) ) {
39
44
_dx *= -1 ;
You can’t perform that action at this time.
0 commit comments