Problems with Collission

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???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
you've put at the line:
"xdelta=-xdelta;//de-increment balls coorderates to make it move up the screen eg makes it bounce."

if you want it to move UP the screen, surely its the y axis you want to reverse, rather than the x axis
Topic archived. No new replies allowed.