|
Post by prutas on Jun 7, 2005 9:30:52 GMT -5
Tried to make a 20-line pong game, but failed miserably. Probably could make it shorter, though.
TextMode(TEXT_BUFFERED) dim p1x, p2x, bx, by, inkey, hdl, a, i, dir, score1, score2 p1x = 15: p2x = 15: bx = 15: by = 5 :dir = -1 while true cls: hdl = rnd() % 2 if ScanKeyDown(VK_LEFT) and (p1x-1) <> 0 then p1x = p1x - 1 endif if ScanKeyDown(VK_RIGHT) and (p1x+1) <> 35 then p1x = p1x + 1 endif if ScanKeyDown(VK_NUMPAD4) and (p2x-1) <> 0 then p2x = p2x - 1 endif if ScanKeyDown(VK_NUMPAD6) and (p2x+1) <> 35 then p2x = p2x + 1 endif locate p1x,1 : print "<--->" :locate p2x,25 :print "<--->" if a = 0 and by <> 24 then by = by + 1 else for i = 0 to 4 if bx = p2x+i and by = 24 and hdl = 0 then dir = 0 endif if bx = p2x+i and by = 24 and hdl = 1 then dir = 1 endif if bx = p1x+i and by = 2 and hdl = 0 then dir = 2 endif if bx = p1x+i and by = 2 and hdl = 1 then dir = 3 endif a = 1: next: endif if dir = 0 then by = by - 1: bx = bx - 1 elseif dir = 1 then by = by - 1: bx = bx + 1 elseif dir = 2 then by = by + 1: bx = bx - 1 elseif dir = 3 then by = by + 1: bx = bx + 1: endif if by = 1 then score2 = score2 + 100: bx = 15: by = 5: a = 0: dir = -1: endif if by = 25 then score1 = score1 + 100: bx = 15: by = 5: a = 0: dir = -1: endif locate bx,by: print "@" locate 1,10: print "PLAYER 1 SCORE: "+score1 locate 1,11: print "PLAYER 2 SCORE: "+score2 sleep(80): DrawText() wend
|
|
|
Post by prutas on Jun 7, 2005 18:54:58 GMT -5
A shorter, 20-line version
TextMode(TEXT_BUFFERED): dim p1x, p2x, bx, by, inkey, hdl, a, i, dir, score1, score2 p1x = 15: p2x = 15: bx = 15: by = 5 :dir = -1: while true cls: hdl = rnd() % 2 : if ScanKeyDown(VK_LEFT) and (p1x-1) <> 0 then p1x = p1x - 1 endif if ScanKeyDown(VK_RIGHT) and (p1x+1) <> 35 then p1x = p1x + 1 endif if ScanKeyDown(VK_NUMPAD4) and (p2x-1) <> 0 then p2x = p2x - 1 endif if ScanKeyDown(VK_NUMPAD6) and (p2x+1) <> 35 then p2x = p2x + 1 endif locate p1x,1 : print "<--->" :locate p2x,25 :print "<--->" if a = 0 and by <> 24 then by = by + 1 else for i = 0 to 4 if bx = p2x+i and by = 24 and hdl = 0 then dir = 0 endif if bx = p2x+i and by = 24 and hdl = 1 then dir = 1 endif if bx = p1x+i and by = 2 and hdl = 0 then dir = 2 endif if bx = p1x+i and by = 2 and hdl = 1 then dir = 3 endif: a = 1: next: endif if dir = 0 then by = by - 1: bx = bx - 1 elseif dir = 1 then by = by - 1: bx = bx + 1 elseif dir = 2 then by = by + 1: bx = bx - 1 elseif dir = 3 then by = by + 1: bx = bx + 1: endif if by = 1 then score2 = score2 + 100: bx = 15: by = 5: a = 0: dir = -1: endif if by = 25 then score1 = score1 + 100: bx = 15: by = 5: a = 0: dir = -1: endif locate bx,by: print "@": locate 1,10: print "PLAYER 1 SCORE: "+score1 locate 1,11: print "PLAYER 2 SCORE: "+score2 : sleep(80): DrawText(): wend
|
|
|
Post by Trooper on Jun 12, 2005 20:17:30 GMT -5
Why not just put colons between every line and make it a 1 line pong program? =)
|
|
|
Post by GuppyB on Jun 12, 2005 20:38:00 GMT -5
It's nice that you've compressed the PONG into such a small file...however... the only problem is you are not doing any kind of left or right wall detection so that the ball hits the wall and just runs straight down it as opposed to bouncing off it, which is an essential part of the game.
...G
|
|
|
Post by Guest on Aug 18, 2005 17:24:39 GMT -5
I tweaked it so that the ball will bounce off the walls. Sorry to say it is no longer a 20 line pong game.'Concentrated Pong 'Straightened out by Jonathan Roper TextMode(TEXT_BUFFERED) dim p1x, p2x, bx, by, inkey, a, i, dir, score1, score2 :p1x = 15: p2x = 15: bx = 15: by = 5 :dir = -1 while true:cls if ScanKeyDown(VK_LEFT) and (p1x-1) <> 0 then p1x = p1x - 1 endif if ScanKeyDown(VK_RIGHT) and (p1x+1) <> 35 then p1x = p1x + 1 endif if ScanKeyDown(VK_NUMPAD4) and (p2x-1) <> 0 then p2x = p2x - 1 endif if ScanKeyDown(VK_NUMPAD6) and (p2x+1) <> 35 then p2x = p2x + 1 endif locate p1x, 1 : print "<--->" :locate p2x,25 : print "<--->" if a = 0 and by <> 24 then by = by + 1 else if bx = p2x+0 and by = 24 then dir = 0 endif if bx = p2x+1 and by = 24 then dir = 0 endif if bx = p2x+2 and by = 24 then dir = 4 endif if bx = p2x+3 and by = 24 then dir = 1 endif if bx = p2x+4 and by = 24 then dir = 1 endif if bx = p1x+0 and by = 2 then dir = 2 endif if bx = p1x+1 and by = 2 then dir = 2 endif if bx = p1x+2 and by = 2 then dir = 5 endif if bx = p1x+3 and by = 2 then dir = 3 endif if bx = p1x+4 and by = 2 then dir = 3 endif: a = 1: endif if bx = 0 and dir = 0 then: dir = 1 elseif bx = 0 and dir = 2 then: dir = 3 elseif bx = 40 and dir = 1 then: dir = 0 elseif bx = 40 and dir = 3 then: dir = 2: endif if dir = 0 then 'ul by = by - 1 bx = bx - 1 elseif dir = 1 then 'ur by = by - 1 bx = bx + 1 elseif dir = 2 then 'dl by = by + 1 bx = bx - 1 elseif dir = 3 then 'dr by = by + 1 bx = bx + 1 elseif dir = 4 then 'cu by = by - 1 elseif dir = 5 then 'cd by = by + 1 endif if by = 1 then score2 = score2 + 100: bx = 15: by = 5: a = 0: dir = -1: endif if by = 24 then score1 = score1 + 100: bx = 15: by = 5: a = 0: dir = -1: endif locate bx,by: print "@" :locate 1,1: print score1: locate 1,2: print score2 sleep(80): DrawText():wend
|
|
|
Post by GuppyB on Aug 19, 2005 14:34:51 GMT -5
It doesn't seem to work on my computer.
...G
|
|
|
Post by Flaran on Oct 9, 2005 17:46:40 GMT -5
I fixed his error... it was a simple numerical mistake...
'Concentrated Pong 'Straightened out by Jonathan Roper TextMode(TEXT_BUFFERED) dim p1x, p2x, bx, by, inkey, a, i, dir, score1, score2 :p1x = 15: p2x = 15: bx = 15: by = 5 :dir = -1 while true:cls if ScanKeyDown(VK_LEFT) and (p1x-1) <> 0 then p1x = p1x - 1 endif if ScanKeyDown(VK_RIGHT) and (p1x+1) <> 35 then p1x = p1x + 1 endif if ScanKeyDown(VK_NUMPAD4) and (p2x-1) <> 0 then p2x = p2x - 1 endif if ScanKeyDown(VK_NUMPAD6) and (p2x+1) <> 35 then p2x = p2x + 1 endif locate p1x, 1 : print "<--->" :locate p2x,25 : print "<--->" if a = 0 and by <> 24 then by = by + 1 else if bx = p2x+0 and by = 24 then dir = 0 endif if bx = p2x+1 and by = 24 then dir = 0 endif if bx = p2x+2 and by = 24 then dir = 4 endif if bx = p2x+3 and by = 24 then dir = 1 endif if bx = p2x+4 and by = 24 then dir = 1 endif if bx = p1x+0 and by = 2 then dir = 2 endif if bx = p1x+1 and by = 2 then dir = 2 endif if bx = p1x+2 and by = 2 then dir = 5 endif if bx = p1x+3 and by = 2 then dir = 3 endif if bx = p1x+4 and by = 2 then dir = 3 endif: a = 1: endif if bx = 0 and dir = 0 then: dir = 1 elseif bx = 0 and dir = 2 then: dir = 3 elseif bx = 40 and dir = 1 then: dir = 0 elseif bx = 40 and dir = 3 then: dir = 2: endif if dir = 0 then 'ul by = by - 1 bx = bx - 1 elseif dir = 1 then 'ur by = by - 1 bx = bx + 1 elseif dir = 2 then 'dl by = by + 1 bx = bx - 1 elseif dir = 3 then 'dr by = by + 1 bx = bx + 1 elseif dir = 4 then 'cu by = by - 1 elseif dir = 5 then 'cd by = by + 1 endif if by = 1 then score2 = score2 + 100: bx = 15: by = 5: a = 0: dir = -1: endif if by = 25 then score1 = score1 + 100: bx = 15: by = 5: a = 0: dir = -1: endif 'error was on THIS line -- 25 was 24 locate bx,by: print "@" :locate 1,1: print score1: locate 1,2: print score2 sleep(80): DrawText():wend
|
|
|
Post by GuppyB on Oct 10, 2005 8:09:22 GMT -5
Much better!
|
|
|
Post by Ha 22 lines on Oct 10, 2005 23:42:04 GMT -5
ya, for sure nice and simple pong game there! But I'm bored and competitive, so I made my own version!!! Muahaha! I know this is kinda a rude so I'm not gonna post my name (sure y'all could figure it out pretty easy though...). Anyway, Mebbe I can spark a competition? Here's my 22 line Opengl Pong game. Dim Pos# (1), Vel# (1), Paddle1#, Paddle2#, i, Score1, Score2 glTranslatef (0, 0, -10) : TextMode (TEXT_OVERLAID) : SetTextScroll (False) New : Vel# = Vec2 (.05, .05) : Pos# = Vec2 (0, 0) While True While SyncTimer (10) Pos# = Pos# + Vel# Paddle2# = Paddle2# + ScanKeyDown (VK_LEFT) * .1 - ScanKeyDown (VK_RIGHT) * .1 Paddle1# = Paddle1# + KeyDown ("A") * .1 - KeyDown ("D") * .1 if Abs (Pos# (1)) > 4.55 then if Sgn (Pos# (1)) = 1 then if Abs (Paddle2# - Pos#(0)) < 2 then Vel# (1) = -Vel# (1) else Score2 = Score2 + 100 : goto New endif else if Abs (Paddle1# - Pos#(0)) < 2 then Vel# (1) = -Vel# (1) else Score1 = Score1 + 100 : goto New endif endif : endif : if Abs (Pos# (0)) > 7.5 then Vel# (0) = -Vel# (0) endif Wend glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT) glPushMatrix (): glTranslatef (Pos#(0),Pos#(1),0): gosub DrawBall: glPopMatrix () glPushMatrix (): glTranslatef (Paddle1#,-5, 0) : gosub DrawPaddle: glPopMatrix () glPushMatrix (): glTranslatef (Paddle2#, 5, 0) : gosub DrawPaddle: glPopMatrix () Printr "Score : " + Score1 : Locate 0, 24 : Printr "Score : " + Score2 DrawText () : SwapBuffers () : Cls Wend DrawPaddle: glBegin (GL_QUADS): glVertex2f (-2, -.2): glVertex2f (-2, .2): glVertex2f (2, .2): glVertex2f (2, -.2): glEnd (): Return DrawBall: glBegin (GL_TRIANGLE_FAN) : for i = 0 to 9: glVertex2f (.25 * Sind (i * 36), .25 * Cosd (i * 36)) : next: glEnd (): Return I know it's really more than 22 lines, but the way I piled everything together is still fairly orderly. I thought the collisions and movement code were kinda cool-- 4 wall colissions, 2 paddle colissions, paddle movement and ball movement in just 7 lines and 5 if/then statements ! Heh, if you can come up with a better one, post away!!! ;D
|
|