Brick Breaker Help
Author |
Message |
miller6
|
Posted: Wed Jan 13, 2010 11:27 am Post subject: Brick Breaker Help |
|
|
I am trying to make the game brick breaker on turing but am having problems with the whole ball hitting and rebounding off the sliding bar off the bottom. i was thinking collision detection but am confused , PLEASE HELP
this is what i have so far:
setscreen ("nocursor")
setscreen ("graphics:vga")
var WinId : int
var ch : string (1) % box move
const right := chr (203) % box move
const left := chr (205) % box move
var counter : int := 10 % counter for the bow moving
var x := 0 % drop sflake
WinId := Window.Open ("position:centre;centre,graphics:1010;695")
drawfillbox (1, 1, maxx, maxy, 255)
var sflake : int := Pic.FileNew ("sflake.gif")
% Pic.Draw (sflake, 0, 100, picMerge)
var box : int := Pic.FileNew ("box2.bmp")
drawfillbox (500, 500, 625, 520, 5)
drawfillbox (500, 400, 625, 420, 5)
drawfillbox (550, 450, 675, 470, 5)
drawfillbox (550, 550, 675, 570, 5)
drawfillbox (320, 500, 445, 520, 5)
drawfillbox (375, 550, 500, 570, 5)
drawfillbox (320, 400, 445, 420, 5)
drawfillbox (375, 450, 500, 470, 5)
drawfillbox (210, 550, 335, 570, 5)
drawfillbox (210, 450, 335, 470, 5)
drawfillbox (160, 500, 285, 520, 5)
drawfillbox (160, 400, 285, 420, 5)
drawfillbox (720, 550, 845, 570, 5)
drawfillbox (665, 500, 790, 520, 5)
drawfillbox (665, 400, 790, 420, 5)
drawfillbox (720, 450, 845, 470, 5)
process movesflake (sflake : int)
for decreasing y : 200 .. 0
x := x + 1
Pic.Draw (sflake, x, y, picMerge)
delay (35)
Pic.Draw (sflake, x, y, picXor)
end for
end movesflake
Pic.Draw (box, 1, 1, picCopy)
process movebox (box : int)
loop
getch (ch)
if ch = right then
counter := counter - 10
% Pic.Draw (box, counter + 10, 1, picCopy)
elsif ch = chr (205) then
counter := counter + 10
% Pic.Draw (box, counter - 10, 1, picCopy)
end if
Pic.Draw (box, counter, 1, picCopy)
end loop
end movebox
fork movesflake (sflake)
fork movebox (box) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Wed Jan 13, 2010 4:34 pm Post subject: RE:Brick Breaker Help |
|
|
Please fill out the template provided properly next time. This makes it easier for us to help you, which means it's more likely that we will help you.
You need to detect when the ball has collided with the top surface of the box (which is a line segment) and then reverse its vertical direction. You probably do not need to handle collisions with the side of the box, as the ball is going off the screen anyway. |
|
|
|
|
|
miller6
|
Posted: Wed Jan 13, 2010 5:51 pm Post subject: Re: Brick Breaker Help |
|
|
I am sorry, still learning how to use the templates!
So would i have to construct a line segment on top of the box and have it move the same way as the box does, and then use collision detection? |
|
|
|
|
|
DemonWasp
|
Posted: Wed Jan 13, 2010 6:03 pm Post subject: RE:Brick Breaker Help |
|
|
You don't have to draw it, and you already know everything you need to know about it (its location).
You literally only have to test whether the bottom of the ball is below the top of the box and whether the ball's X coordinate is within the area occupied by the box. Draw it out on paper if you still don't understand, it'll make it easier (I promise - I draw stuff out on paper when coding pretty frequently). |
|
|
|
|
|
miller6
|
Posted: Wed Jan 13, 2010 6:14 pm Post subject: Re: Brick Breaker Help |
|
|
okay, so once i have the collision detection statement, how am i able to make it so that it bouces back up at a different angle?
Turing: |
if x + 59 >= counter and x <= counter + 1440 then
|
|
|
|
|
|
|
DemonWasp
|
Posted: Wed Jan 13, 2010 10:42 pm Post subject: RE:Brick Breaker Help |
|
|
The "angle" of movement is determined by the speed of the ball in the X and Y directions (if you know enough trigonometry, angle = tan ( yspeed / xspeed ) ). If you want a different angle, simply randomize the xspeed and yspeed values - just make sure that yspeed is positive, or the ball could go down, through your paddle.
If you want the ball to bounce off like you would expect, just set the value of yspeed to the negative of the old value of yspeed. This will force the ball to switch its vertical direction.
You should be able to generalize that to all collisions with surfaces aligned with the X and Y axes with a bit of thought and a piece of paper and pencil. |
|
|
|
|
|
wysper
|
Posted: Mon Apr 26, 2010 11:05 am Post subject: RE:Brick Breaker Help |
|
|
i like brick breaker..i hope this helped lol |
|
|
|
|
|
|
|