Computer Science Canada Pong Collision border help |
Author: | gergysun [ Wed Nov 28, 2007 7:39 pm ] | ||
Post subject: | Pong Collision border help | ||
This game is realy ticking me off, I cannot seem to make the ball bounce off the top, and right inside the box that i have made...the left one works, and i ive tried but i cant get the ball to *end* when the paddle misses it, its just keeps on bouncing.... ergggg anyways, here is my code.
|
Author: | CodeMonkey2000 [ Wed Nov 28, 2007 7:49 pm ] | ||
Post subject: | Re: Pong Collision border help | ||
Basically, you need to remember that ballx and bally are the mid points of the ball. To see if the edge of the ball collides with the wall, you need to add/subtract the radius to ballx and bally.
|
Author: | gergysun [ Wed Nov 28, 2007 8:21 pm ] |
Post subject: | Re: Pong Collision border help |
Awsome thanks, but theres still 2 problems..... first of all, the bll doesnt bounce off the paddle, second, the ball doesnt stop when it misses the paddle ( thwn it hits the bottom line ) |
Author: | Jestar [ Wed Nov 28, 2007 8:32 pm ] |
Post subject: | Re: Pong Collision border help |
for the ball boucing off the paddle you could use whatdotcolor. |
Author: | gergysun [ Wed Nov 28, 2007 8:48 pm ] |
Post subject: | Re: Pong Collision border help |
I know i sound like to complete newbie, but lets say the following syntax is my paddle... Would i write whatdotcolor ( 80, 75: int ) : int ? drawfillbox (x - 80, 66, x + 80, 75, red) because thats what it said in the Turing help file as the syntax. |
Author: | Zampano [ Wed Nov 28, 2007 10:05 pm ] | ||
Post subject: | Re: Pong Collision border help | ||
gergysun @ Wed Nov 28, 2007 8:48 pm wrote: I know i sound like to complete newbie, but
lets say the following syntax is my paddle... Would i write whatdotcolor ( 80, 75: int ) : int ? drawfillbox (x - 80, 66, x + 80, 75, red) because thats what it said in the Turing help file as the syntax. That's one large paddle. But shouldn't the whatdotcolour which determines whether to bounce off not be a constant number (80,75)? In my mind it should be this.
If you had a whatdotcoour relating to the position of the paddle, you'd have to check every point on the top of the paddle, but the ball should hit the paddle on only one spot: the pixel below the direct centre, which is what the above checks. |
Author: | gergysun [ Wed Nov 28, 2007 10:14 pm ] |
Post subject: | Re: Pong Collision border help |
THanks, but it doesnt solve my problem here is my code drawfill (1, 399, 150, 150) var font1 : int font1 := Font.New ("Stencil:20") assert font1 > 0 Font.Draw ("Greg's Ping Pong Game", 160, 325, font1, red) Font.Free (font1) colorback (6) locate (7, 30) var title1 : int title1 := 10 loop %Title wiper drawfilloval (title1, 335, 20, 20, 12) exit when title1 = 600 delay (50) drawfilloval (title1, 335, 20, 20, 158) title1 := title1 + 10 end loop put " ---The intructions are ---- " put " " put " Move the Paddle with mouse " put " Each time you keep the ball up in the air you reieve a point" put " If you miss the ball, you lose " put " " put " " put " Press any key to begin " Input.Pause colourback (blue) cls setscreen ("offscreenonly") var ballx, bally, rise, run, rad, u, yy, xx : int ballx := maxx div 2 bally := maxy div 2 rad := 10 rise := 1 run := -1 loop var x, y, button : int Mouse.Where (x, y, button) Draw.FillOval (ballx, bally, rad, rad, yellow) ballx := ballx + run bally := bally + rise if ballx < 50 + rad or ballx > maxx - 50 - rad then run := run * -1 end if if bally < 50 + rad or bally > maxy - 50 - rad then rise := rise * -1 end if if bally = 10 and ballx < -80 and ballx < +80 then exit end if if whatdotcolour(ballx,bally-rad-1)=brightcyan then rise:=rise * 1 end if View.Update delay (10) cls Draw.Box (50, 50, maxx - 50, maxy - 50, white) drawfill (50,40,white, white) drawfillbox (x - 80, 66, x + 80, 75, brightcyan) drawline (40,30,40,370,black) drawline (40,30,600,30, black) drawline (600,30,600,370,black) drawline (600,370,40,370,black) drawfill (0,10,brightred,black) end loop |
Author: | gergysun [ Tue Dec 04, 2007 3:29 pm ] |
Post subject: | Re: Pong Collision border help |
lol, sorry, but ive got everything to work now..Thanks to all for helping me ![]() |