'Updated by Kenneth and bplus on June 20, 2019.
_TITLE "PING PONG 2"
RANDOMIZE TIMER
_FULLSCREEN
begin:
CLEAR
CLS
SCREEN 13
COLOR 7
PRINT " PING PONG 2"
PRINT: PRINT
PRINT "By Kenneth G. and bplus"
PRINT: PRINT
PRINT "Use the up and down arrow keys to move"
PRINT "the left paddle. If the ball passes the"
PRINT "computer's paddle, you get a point."
PRINT "Whoever gets 10 points first wins."
PRINT "Press Esc to end anytime."
PRINT: PRINT
INPUT "(F)ast, (M)edium, (S)low, (Q)uit:"; sp$
IF sp$ = "F" OR sp$ = "f" OR sp$ = "FAST" OR sp$ = "fast" OR sp$ = "Fast" THEN sd = 30
IF sp$ = "M" OR sp$ = "m" OR sp$ = "MEDIUM" OR sp$ = "medium" OR sp$ = "Medium" THEN sd = 20
IF sp$ = "S" OR sp$ = "s" OR sp$ = "SLOW" OR sp$ = "slow" OR sp$ = "Slow" THEN sd = 10
IF sp$ = "Q" OR sp$ = "q" OR sp$ = "QUIT" OR sp$ = "quit" OR sp$ = "Quit" THEN CLEAR: END
IF sd = 0 THEN sd = 10
INPUT "Press enter to start."; st$
start:
_LIMIT sd
CLS
x = 10: y = 100
x2 = 305: y2 = 100
a = 140: b = 100
d = 0: po1 = 0: po2 = 0
l = 1: r = 0
dr$ = ""
DO
CLS
LINE (10, 15)-(305, 176), 1, BF
LOCATE 1, 5: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
a$ = INKEY$
IF a$ = CHR$(27) THEN CLEAR: END
'your paddle
IF a$ = CHR$(0) + CHR$(72) THEN y = y - 10
IF a$ = CHR$(0) + CHR$(80) THEN y = y + 10
IF y < 10 THEN y = 10
IF y > 170 THEN y = 170
LINE (x, y)-(x + 2, y + 15), 4, BF
ball:
'the ball is always moving left or right in inc of 5
IF l = 1 THEN a = a - 5: b = b + d
IF r = 1 THEN a = a + 5: b = b + d
IF a = x + 5 THEN
IF b < y + 16 AND b > y - 1 THEN 'paddle hit ball send it back
r = 1
l = 0
d = INT(RND * 10) - 5: PLAY "l30c"
END IF
END IF
IF b < 20 THEN d = RND * 5 + 1
IF b > 170 THEN d = RND * 5 - 5
IF b > y + 16 OR b < y - 1 THEN po1 = 1 'ball misses paddle on
IF b > y2 + 16 OR b < y2 - 1 THEN po2 = 1
IF a > x2 - 5 AND a < x2 + 2 THEN
IF b < y2 + 16 AND b > y2 - 1 THEN 'paddle hit ball send it back
r = 0
l = 1
d = INT(RND * 10) - 5: PLAY "l30c"
END IF
END IF
IF a < x + 5 AND po1 = 1 THEN p2 = p2 + 1 'ball misses paddle on x spot
IF a >= x2 AND po2 = 1 THEN p = p + 1
IF p = 10 THEN
LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
PRINT "YOU WIN, ";
INPUT "Press enter."; mm$
GOTO begin:
END IF
IF p2 = 10 THEN
LOCATE 1, 1: PRINT "You:"; p: LOCATE 1, 25: PRINT "Computer:"; p2
PRINT "COMPUTER WINS, ";
INPUT "Press enter."; mm$
GOTO begin:
END IF
IF a >= x2 AND po2 = 1 THEN GOTO start
IF a <= x AND po1 = 1 THEN GOTO start
po2 = 0
po1 = 0
CIRCLE (a, b), 3, 15
computer:
LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
IF l = 1 THEN GOTO tim:
IF d < 0 THEN y2 = y2 - 6
IF d > 0 THEN y2 = y2 + 6
IF RND < .90 THEN '<<<<<<<<<<<<<<<<<<<<<<< sorry computer you are too perfect
IF b < y2 THEN y2 = y2 - 7
IF b > y2 + 15 THEN y2 = y2 + 7
END IF
IF y2 < 10 THEN dr2$ = "down"
IF y2 > 170 THEN dr2$ = "up"
IF dr2$ = "down" THEN
RANDOMIZE TIMER
rad = INT(RND * 3) + 2
y2 = y2 + rad
END IF
IF dr2$ = "up" THEN
RANDOMIZE TIMER
rad = INT(RND * 3) + 2
y2 = y2 - rad
END IF
LINE (x2, y2)-(x2 + 2, y2 + 15), 4, BF
tim:
_DISPLAY
_LIMIT sd
LOOP