Computer Science Canada Help on Pong Program |
Author: | Comp_Expert777 [ Thu Dec 25, 2003 10:10 am ] |
Post subject: | Help on Pong Program |
I need help on my pong game. I cant figure out how to make the ball bounce off the paddles on my pong program. Can someone help me? Here is the code: drawfillbox (0,0,maxx,maxy,black) var font1, font2, font3 : int font1:= Font.New ("serif:220:bold") font2 := Font.New ("sans serif:15:bold") font3 := Font.New ("sans serif:15:bold") Font.Draw ("Pong", 5,150,font1,white) Font.Draw ("Start Game", 265,100,font2,white) Font.Draw ("Quit Game", 265,50,font3,white) drawfillbox (50,20,150,30,brightblue) drawfillbox (405,375,500,385,brightred) var ch : string (1) var x, y, btnnum, btnupdown : int loop if buttonmoved ("down") then buttonwait ("down", x,y,btnnum,btnupdown) locate (1,1) for i : 1..100 %Variables var y1 : int var x1 : int var c : int if x > 256 and x < 400 then if y > 100 and y < 300 then View.Set ("offscreenonly") View.Update cls %Second Page View.Set ("offscreenonly") var chars : array char of boolean var x2,y2,x3,y3 : int := 0 var row : int := 630 var column : int :=2 loop var rowchange, columnchange := 1 loop drawfillbox (0,0,maxx,maxy,black) if row = 630 or row= 0 then rowchange := -rowchange end if if column= 394 or column = 0 then columnchange := -columnchange end if locatexy (row,column) drawfilloval (row,column,10,10,brightgreen) row :=row + rowchange column:= column+columnchange Input.KeyDown (chars) locate (1,1) drawfillbox (x2+5,y2,x2+15,y2+70,brightblue) if chars (KEY_UP_ARROW) then y2 := y2+2 end if if chars (KEY_DOWN_ARROW) then y2 := y2-2 end if if y2<0 then y2:=0 end if if y2>328 then y2:=328 end if Input.KeyDown (chars) locate (1,1) drawfillbox (x3+635,y3,x3+625,y3+70,brightblue) if chars ('w') then y3 := y3+2 end if if chars ('s') then y3 := y3-2 end if if y3<0 then y3:=0 end if if y3>328 then y3:=328 end if drawline(maxx div 2,0,maxx div 2,maxy,brightgreen) View.Update cls drawfillbox (0,0,maxx,maxy,black) end loop end loop end if end if end for end if end loop |
Author: | DanShadow [ Thu Dec 25, 2003 11:15 am ] | ||
Post subject: | |||
An easier way, (but a little worse) is this way. Take a look:
|
Author: | Comp_Expert777 [ Thu Dec 25, 2003 12:42 pm ] |
Post subject: | |
Where can I put that in my code? I am sorry for asking that question. I still have a little trouble with Turing so I can get some help plz but thanks for posting the code. |
Author: | Comp_Expert777 [ Thu Jan 15, 2004 10:34 am ] | ||
Post subject: | |||
Thanks I got the ball bounce off the paddle now but I am trying to make a score board but I dont know y it doesnt work. Here is my code take a look at it. Can u plz help me this is a final project and i only have 3 three more days left.
|
Author: | DanShadow [ Thu Jan 15, 2004 1:29 pm ] | ||
Post subject: | |||
Well try this scoreboard, but change variable names to suit your program:
Yes, the "locate" command is locating the text in the wrong area, but I dont have Turing on this computer, so try and fix it yourself. But the basic design of that should work for your program. |
Author: | Comp_Expert777 [ Thu Jan 15, 2004 10:14 pm ] |
Post subject: | |
Their is a problem on your code and I can figure out wut it means. When I run the program it says 'procedure's may only be declared at the program, module, or monitor level and it highlights proc on ur code and says that. Can u plz help me? |
Author: | Thuged_Out_G [ Fri Jan 16, 2004 9:59 am ] |
Post subject: | |
you have to declare procedures at the top of your program....with the rest of your procedures |
Author: | Comp_Expert777 [ Sat Jan 17, 2004 1:23 pm ] |
Post subject: | |
I dont have any procedures in my program because I dont really get procedures that much so can you plz help me. |
Author: | Thuged_Out_G [ Sat Jan 17, 2004 1:44 pm ] |
Post subject: | |
that scoreboard you were giving is a procedure |
Author: | Comp_Expert777 [ Mon Jan 19, 2004 5:02 pm ] | ||
Post subject: | |||
I got the scoreboard to work but when the ball hits the paddle too it counts as a point too so can u help me on it here is the code:
|
Author: | Eulogy [ Mon Mar 29, 2004 6:03 pm ] |
Post subject: | Bump |
Bump. Same problem with the scoreboard suggested. Any one know of a solution? |
Author: | Tony [ Mon Mar 29, 2004 6:23 pm ] |
Post subject: | |
umm... That's because the paddles don't deflect the ball it goes right though them and hits the score line |