Computer Science Canada Advice about my Pong game. |
Author: | PongHelp [ Tue Jun 12, 2012 8:42 am ] |
Post subject: | Advice about my Pong game. |
I am in a grade 11 computer course and I have encountered some problems with my program and would like some help. I dont want anyone to write the code for me, I would just like some pointers and some help, thanks. %Title screen% setscreen ("graphics") setscreen ("graphics:max;max") colourback (black) put" " put" " put" " put" " put" " put" " colour (white) put" " put" " put" " put" " put" " put" " put" " put" " put" " put" " put" " put" " put" BY: Keegan Beattie" put" " colour (brightgreen) put" 4 PLAYER GAME!" colour (37) put" " colour (white) put" " put" ------------- " put" // Controls // " put" ------------- " put" Player 1: 'w' to move up 's' to move down " put" Player 2: 'j' to move up 'm' move down " put" Player 3: 'up' to move up 'down' to move down" put" Player 4: '5' to move up '2' to move down " for i : 1..27 put " " end for var font4 : int font4 := Font.New ("Palatino:50:Bold") Font.Draw (" PONG 4.0", 436, 700, font4, brightgreen) %Displaying the controls and how to start% drawbox(480,765,815,680, white) drawbox(479,766,816,679, white) var font : int font := Font.New ("Palatino:24:Bold") Font.Draw ("Enter 'S' to start", 522, 270, font, yellow) drawbox(510,250,780,310, yellow) drawbox(509,249,781,311, yellow) drawbox(260,200,1010,820, white) drawbox(259,199,1011,821, white) %Intro % var startss:string get startss %If you press "s" the game starts% if startss = "s" then colourback (black) for i : 1..55 put " " end for %Get the players name% var p1name:string var p2name:string var p3name:string var p4name:string colour (54) put "Player 1, please enter your name: " get p1name put "Player 2, please enter your name: " get p2name colour (12) put "Player 3, please enter your name: " get p3name put "Player 4, please enter your name: " get p4name colourback (250) colour (white) put " " put " Blue Team: ".. put " Red Team: " put " " put " " put " " put " " var font1 : int font1 := Font.New ("Palatino:40:Bold") Font.Draw ("0", 525, 25, font1, 54) var font2 : int font2 := Font.New ("Palatino:40:Bold") Font.Draw ("0", 1175, 25, font2, 40) colourback(black) for i : 1 ..50 put " " end for %Display name for score% var pname1 : int pname1 := Font.New ("Palatino:12:Bold") Font.Draw (p1name, 95, 860, pname1, 54) var pname2 : int pname2 := Font.New ("Palatino:12:Bold") Font.Draw (p2name, 95, 830, pname2, 54) var pname3 : int pname3 := Font.New ("Palatino:12:Bold") Font.Draw (p3name, 753, 860, pname3, 12) var pname4 : int pname4 := Font.New ("Palatino:12:Bold") Font.Draw (p4name, 753, 830, pname4, 12) %The lines on the pong game% And some other stuff% drawbox(0,805,1500,806, white) drawbox(90,884,180,883, white) drawbox(743,884,827,883, white) end if %Actual Pong program% var pongBall:int var pongPaddle1:int var pongPaddle2:int var pongPaddle3:int var pongPaddle4:int %Displaying and counting the score% var team1Score:int := 0 var team2Score:int := 0 var ballX, ballY : int := 4 var ballR1, ballR2 : int := 4 var DX, DY : int := 1 var p1X, p1Y : int := 6 var p1R1, p1R2 : int :=6 var p1DX, p1DY : int := 1 var p2Y : int := 6 var p3Y : int := 6 var p4Y : int := 6 var chars : array char of boolean var chars2 : array char of boolean var chars3 : array char of boolean var chars4 : array char of boolean loop %Controlls for paddles% Input.KeyDown (chars) locate (4, 1) if chars ('w') then if p1Y <= 103 then p1Y:= p1Y+1 end if end if if chars ('s') then if p1Y >= -150 then p1Y:= p1Y-1 end if end if locate (10, 1) if chars ('j') then if p2Y<= 216 then p2Y:= p2Y+1 end if end if if chars ('m') then if p2Y >= -68 then p2Y:= p2Y-1 end if end if locate (10, 1) if chars (KEY_UP_ARROW) then if p3Y <= 103 then p3Y:= p3Y+1 end if end if if chars (KEY_DOWN_ARROW) then if p3Y >= -150 then p3Y:= p3Y-1 end if end if locate (10, 1) if chars ('5') then if p4Y <= 216 then p4Y:= p4Y+1 end if end if if chars ('2') then if p4Y >= -68 then p4Y:= p4Y-1 end if end if %The paddles% drawfilloval (ballX, ballY, ballR1, ballR2, 0)%The colour of the ball drawfillbox (640, 805, 641, 755,white) drawfillbox (640, 705, 641, 655,white) drawfillbox (640, 605, 641, 555,white) drawfillbox (640, 505, 641, 455,white) drawfillbox (640, 405, 641, 355,white) drawfillbox (640, 305, 641, 255,white) drawfillbox (640, 205, 641, 155,white) drawfillbox (640, 105, 641, 55,white) drawfillbox (640, 5, 641, 0,white) drawfillbox (23,p1Y+700,26,p1Y+570, 54) drawfillbox (23,p2Y+200,26,p2Y+70, 54) drawfillbox (1233,p3Y+700,1236,p3Y+570, 40) drawfillbox (1233,p4Y+200,1236,p4Y+70, 40) delay (5) drawfillbox (23,p1Y+700,26,p1Y+570, black) drawfillbox (23,p2Y+200,26,p2Y+70, black) drawfillbox (1233,p3Y+700,1236,p3Y+570, black) drawfillbox (1233,p4Y+200,1236,p4Y+70, black) drawfillbox (0 ,10 ,1400,-10,black) %The ball% drawfilloval (ballX, ballY, ballR1, ballR2, 7)%The colour of the balls tail ballX := ballX + DX ballY := ballY + DY if ballX = 0 or ballX = 1264 then DX := (-1)*DX elsif ballY = 800 or ballY = (0) then %THIS IS THE TOP AND BOTTOM THINGS DY := (-1)*DY end if if p1Y = 0 or p1Y = 1264 then p1DX := (-1)*p1DX elsif p1Y = 800 or p1Y = (0) then %THIS IS THE TOP AND BOTTOM THINGS p1DY := (-1)*p1DY end if end loop |
Author: | Raknarg [ Tue Jun 12, 2012 8:47 am ] |
Post subject: | RE:Advice about my Pong game. |
The first thing you should do is tell us what's going wrong with it. What's supposed to be working that isnt? Is something happening that you didnt expect? If you do want to help yourself like you said, basic debugging like this is a good place to start. |
Author: | PongHelp [ Tue Jun 12, 2012 8:53 am ] |
Post subject: | RE:Advice about my Pong game. |
Sorry, I have no idea how to get the ball to bounce off the paddle. I've asked my teacher but he said he wouldn't help. |
Author: | Dreadnought [ Tue Jun 12, 2012 9:09 am ] |
Post subject: | Re: Advice about my Pong game. |
You likely want the ball to bounce when it "hits" the paddle. How do you know if the ball has hit the paddle? How can you check this? |
Author: | Raknarg [ Tue Jun 12, 2012 9:21 am ] |
Post subject: | RE:Advice about my Pong game. |
The thing to remember is that you know where everything is at any given time, which people new to programming seem to often forget. |
Author: | irobots [ Thu Mar 28, 2013 10:44 am ] |
Post subject: | Re: Advice about my Pong game. |
Try using the whatdotcolour function on points around the circumference of the ball. Then if the dot colour on any of the whatdotcolour comes out to be the colour of your paddle, then the ball hit the paddle. |
Author: | Tony [ Thu Mar 28, 2013 12:14 pm ] |
Post subject: | Re: Advice about my Pong game. |
irobots @ Thu Mar 28, 2013 10:44 am wrote: Try using the whatdotcolour function on points around the circumference of the ball.
Please don't give out bad suggestions as "advice". |