I am working on a project at University,
Am trying to check if a ball and a rectangle collides and if true then make the ball which is 2D to make its way up the screen. Can anyone help???
BrickKiller::BrickKiller()//here we load our platform so we can use it.
{
//start poss of platform
x=230;
y=370;
//work out dimention of the platform
h=(y-10);//height
l=(x+40);//lengh
leftbound = ((x-20)&&(y-10));
rightbound =((x+20)&&(y+10));
//bottom =((y-10)&&(x+40))
//width = l;
Platform1.loadImage("Platforms.bmp");
dx=1;
speed = 4;
if ((x<=0) || (x>=400))
{
}
}
void MovingBall:: Move( GWindow &Gwin)
{
Gwin.setPenColour(BLACK);
Gwin.circle(xB,yB,rad);
// change the fill colour to red
Gwin.setPenColour(RED);
// update the current position
yB=yB+ydelta;
xB=xB+xdelta;
//draw a red circle at the current position
Gwin.circle(xB,yB,rad);
if ( (yB<=60) || (yB>=445 ) )
{
ydelta=-ydelta;
}
if ( (xB<=85) || (xB>=450) ) //allow only ball to move inside set amount of the screen.
{
xdelta=-xdelta;//de-increment balls coorderates to make it move up the screen eg makes it bounce.
}
BrickKiller platforms;
if ((xB<=platforms.leftbound) && (yB<=platforms.leftbound))
{
xdelta=-xdelta;
}
if (yB>=450)
{
Gwin.destroy();//distroy ball if goes past platform.
}
Gwin.circle(xB,yB,rad);
}