' Pong ' Player vs. computer ' ' Release 3.0 ' New keyboard input ' Nicer layout ' Fixed bug when the ball was stuck at the top ' ' 2.0 ' It's much faster measured in pixels, so it can take really high speeds. ' ' The game pauses. ' It also pauses when you or the computer loses. ' ' Version 1.1 ' the speed in y-direction changes when you moves the ball up/down ' ' Made by Olle Bergkvist 2006 reboot: CLS PRINT PRINT "Welcome to Pong! 3.0.0" PRINT " Made by Olle Bergkvist 2006" PRINT PRINT "You play against the computer. First to 5 points wins." PRINT "Use the arrow keys to move. Or the keys 8 or 2 for better performance. Quit with Esc." PRINT INPUT "What speed do you want? Anything above 1 is good. ", speed SCREEN 13 score1 = 0 score2 = 0 RANDOMIZE TIMER restart: xpos = 160 ypos = INT(180 * RND) + 10 xmov = 4 ymov = 4 box1 = ypos box2 = ypos CLS '---------------Main loop DO 'player moves keyn = INP(96) ' keyboard input - thanks to IDK! SELECT CASE keyn CASE 72 box1 = box1 - 3 CASE 80 box1 = box1 + 3 CASE 1 END END SELECT ' computer moves SELECT CASE box2 CASE IS < ypos box2 = box2 + 3 CASE IS > ypos box2 = box2 - 3 END SELECT 'left border of screen IF xpos < 10 THEN xmov = -xmov ' reverse x-speed 'lose IF ABS(ypos - box1) > 20 THEN score2 = score2 + 1 time = TIMER DO LOOP WHILE time + .5 > TIMER GOTO restart 'hit - change y-speed ELSE SELECT CASE key$ CASE CHR$(0) + "H" ymov = ymov - 1 CASE CHR$(0) + "P" ymov = ymov + 1 END SELECT END IF END IF 'right border of screen IF xpos > 310 THEN xmov = -xmov ' reverse x-speed 'lose IF ABS(ypos - box2) > 20 THEN score1 = score1 + 1 time = TIMER DO LOOP WHILE time + .5 > TIMER GOTO restart 'hit - change y-speed ELSE SELECT CASE box2 CASE IS < ypos ymov = ymov + 1 CASE IS > ypos ymov = ymov - 1 END SELECT END IF END IF 'reverse y-speed IF ypos < 10 OR ypos > 190 THEN ymov = -ymov xpos = xpos + xmov ypos = ypos + ymov CLS LINE (0, 5)-(320, 5) LINE (0, 195)-(320, 195) LOCATE 1, 16, 0 PRINT score1; " - "; score2 LOCATE 1, 35 PRINT keyn CIRCLE (xpos, ypos), 5 LINE (5, box1 - 20)-(5, box1 + 20) LINE (315, box2 - 20)-(315, box2 + 20) time = TIMER DO z$ = INKEY$ ' dont fill buffer LOOP WHILE time + 1 / speed > TIMER LOOP WHILE score1 < 5 AND score2 < 5 '----------------End of main loop LOCATE 10, 10, 0 SELECT CASE score1 CASE IS > score2 PRINT "You won!" CASE IS < score2 PRINT "The computer won!" END SELECT LOCATE 12, 10, 0 PRINT "Press Spacebar to play again" LOCATE 13, 10, 0 PRINT "Press Esc to quit" DO SLEEP key$ = INKEY$ SELECT CASE key$ CASE " " GOTO reboot CASE CHR$(27) END END SELECT LOOP