i have a bouncing ball, and i tried to make so when it bounces once, the speed gets higher.
In my ball class, i have a float speed;
and i initialize
Perhaps speed
is declared as type float
.
You can do the math by converting speed from float to integer like this:
public void BallMovement()
{
int speedInt = Convert.Int32(speed);
if (movingUp) { ballRect.Y -= speedInt; }
if (!movingUp) { ballRect.Y += speedInt; }
if (movingLeft) { ballRect.X -= speedInt; }
if (!movingLeft) { ballRect.X += speedInt; }
if (ballPosition.Y < 85)
{
movingUp = false;
}
if (ballPosition.Y >= 480)
{
movingUp = true;
}
....
On the other hand, if you want the compiler to convert it for you (multiple times), you could cast each of the occasions where you reference speed
with (int)speed
.