Code: Select all
const int poo0XOld = poo0X;
const int poo0YOld = poo0Y;
poo0X = ClampScreenX(poo0X, pooWidth);
poo0Y = ClampScreenY(poo0Y, pooHeight);
if (poo0X != poo0XOld) poo0SpeedX = -poo0SpeedX;
if (poo0Y != poo0YOld) poo0SpeedY = -poo0SpeedY;
My assumption is that the value of the poo0XOld should be -1 when my poo0 hits the left edge.
Because in the ClampScreenX, it is stated that if x<0, this function will return 0.
Code: Select all
int Game::ClampScreenX(int x, int width)
{
const int dudeRight = x + width;
if (x < 0) return 0;
if (dudeRight > gfx.ScreenWidth) return (gfx.ScreenWidth - 1) - width;
return x;
}
So at the moment that the poo hits the left edge. The poo0X's value should be less than (something like -1) so that the code would probably work like this
My assumption: At the moment that the poo hits the left edge. The poo0X's value is -1.
const int poo0XOld = -1; // poo0X's value before using the ClampScreenX
const int poo0YOld = poo0Y;
poo0X = 0; // poo0X's value after using the ClampScreenX(poo0X, pooWidth)
poo0Y = ClampScreenY(poo0Y, pooHeight);
if (0 != -1) poo0SpeedX = -poo0SpeedX;
if (poo0Y != poo0YOld) poo0SpeedY = -poo0SpeedY;
Is my assumption correct? Or I misunderstood something. I'm very new to programming. My question might be kind of stupid but I'm really confused. Trying to figure it out for hours but still cannot come up with good explanation. Thank you in advance.
Tlefacecat