joyrider
15-12-2005, 10:21 PM
Hi,
i'm trying to make a breakout game using jedi sdl and delphi. I'm using the supplied SpriteEngine. in my balls collisioncheck procedure i use to following code where middleX and middley Is the balls middle, rect1 is the rectangle for the ball and rect2 the rectangle for the block that's been hit
MiddleX := rect1.x +(rect1.w div 2);
MiddleY := Rect1.y +(rect1.h div 2);
if (MiddleX >= rect2.x) and (MiddleX <= Rect2.x + Rect2.w) then
begin
yi := yi * -1;
y := y + yi;
TBlock(Parentlist[tel]).IncreaseHits;
end
else
if (MiddleY >= rect2.y) and (MiddleY <= rect2.y + rect2.h) then
begin
xi := xi * -1;
x := x + xi;
TBlock(parentlist[tel]).IncreaseHits;
end
now that works ok but now i need to add some code to see when the ball hits the block at the corners and change the ball in the correct direction. how would i do that. also i'm stuck on something else as well the code for checking the corners may not be done when there are 2 blocks hit at the same time the above code should be enough then (i think).
can someone help me out here, i could upload my code if that'll be easier cause i'm getting nowhere.
a simple demo with a ball hitting a rectangle would help as well as long as it implements hits from the 4 corners of the rectangle and the ball
thanks
i'm trying to make a breakout game using jedi sdl and delphi. I'm using the supplied SpriteEngine. in my balls collisioncheck procedure i use to following code where middleX and middley Is the balls middle, rect1 is the rectangle for the ball and rect2 the rectangle for the block that's been hit
MiddleX := rect1.x +(rect1.w div 2);
MiddleY := Rect1.y +(rect1.h div 2);
if (MiddleX >= rect2.x) and (MiddleX <= Rect2.x + Rect2.w) then
begin
yi := yi * -1;
y := y + yi;
TBlock(Parentlist[tel]).IncreaseHits;
end
else
if (MiddleY >= rect2.y) and (MiddleY <= rect2.y + rect2.h) then
begin
xi := xi * -1;
x := x + xi;
TBlock(parentlist[tel]).IncreaseHits;
end
now that works ok but now i need to add some code to see when the ball hits the block at the corners and change the ball in the correct direction. how would i do that. also i'm stuck on something else as well the code for checking the corners may not be done when there are 2 blocks hit at the same time the above code should be enough then (i think).
can someone help me out here, i could upload my code if that'll be easier cause i'm getting nowhere.
a simple demo with a ball hitting a rectangle would help as well as long as it implements hits from the 4 corners of the rectangle and the ball
thanks