How Can I Bounce the ball everytime it hits the wall???
using GDIDrawer;
using System.Drawing;
int iX = 0; //x ball position
int iY = 0; //y ball position
int iXVelocity = 5; //amount ball moves in x direction for every loop
int iYVelocity = 5; //amount ball moves in y direction for every loop
//create a drawer window with a scale of 10
CDrawer Canvas = new CDrawer();
Canvas.Scale = 5;
//loop until the ball leaves the visible window
while ((iX < 160)||(iX > 0))
{
//erase the old ball
Canvas.Clear();
//draw the new ball
Canvas.AddEllipse(iX, iY, 1, 1);
//time delay to slow down the ball
System.Threading.Thread.Sleep(150);
//calculate the ball's new position
iX += iXVelocity;
iY += iYVelocity;
//check for bouncing off of the lower edge of the window
if ((iY > 120)||(iY < 0))
//reverse the y velocity (ball goes up)
iYVelocity = -iYVelocity;
}
}
}
}