Pong
Pong
Game
30 CLS: LET xx = 31: FOR yy = minY TO maxY STEP 2: GOSUB 2000: NEXT yy
40 DIM coords(1, 1) As Byte: REM Player 0 (Left) and 1 (Right) coordinates
50 LET h = 5: REM players height (in "points"). A "point" is 4 pixels
60 LET x = startX: LET y = startY: REM Screen resolution is 64
70 LET coords(0, 0) = minX: LET coords(1, 0) = maxX
80 LET coords(0, 1) = minY + (maxY - minY) / 2: LET coords(1, 1) = coords(0, 1)
90 LET dx = 1: LET dy = 1: LET delay = dSlow: REM Ball speed
91 LET score(0) = 0: LET score(1) = 0: REM Initializes scores
120 LET y = y + dy
130 IF y < minY THEN
LET y = minY: BEEP 0.02,10: LET dy = -dy
ELSEIF y > maxY THEN
LET y = maxY: BEEP 0.02,10: LET dy = -dy
END IF
140 REM Checks if computer must move
150 LET px = coords(comp, 0): LET py = coords(comp, 1)
160 IF py > y AND RND > diff THEN REM Must go up
LET p = comp
GOSUB 1500: REM Updates player padel (up)
ELSEIF py + h - 1 < y AND RND > diff THEN
LET p = comp
GOSUB 1600: REM Updates player padel (down)
END IF
0999 END
1000 REM Draws player p at p(p, 0), p(p, 1)
1010 LET xx = coords(p, 0)
1020 LET yy = coords(p, 1)
1030 FOR i = 1 TO h: GOSUB 2000: LET yy = yy + 1: NEXT i
1040 RETURN
1500 REM Moves up the padel for user p (p = 0 => Left, p = 1 = Right)
1510 LET xx = px
1520 FOR i = 0 TO 1: IF py <= minY THEN EXIT FOR: END IF
1530 LET py = py - 1
1540 LET yy = py: GOSUB 2000: REM Draws padel top
1550 LET yy = py + h: GOSUB 2000: REM Erases padel bottom
1560 NEXT i
1570 LET coords(p, 1) = py: RETURN
1600 REM Moves down the padel for user p (p = 0 => Left, p = 1 = Right)
1610 LET xx = px: LET yy = py
1620 FOR i = 0 TO 1: IF py + h > maxY THEN EXIT FOR: END IF
1630 LET yy = py: GOSUB 2000: REM Erases padel top
1640 LET yy = py + h: GOSUB 2000: REM Draws padel bottom
1650 LET py = py + 1
1660 NEXT i
1670 LET coords(p, 1) = py: RETURN