Here it is -
Code: Select all
'Setup the screen...
SCREEN 7, 0, 1, 0
LINE (0, 0)-(320, 200), 0, BF
'DIMing the needed arrays for graphic storage
DIM p1(3, 25)
DIM p2(3, 25)
DIM ball(14, 12)
DIM p1c(55)
'Needed variables
p1y = 75
p2y = 75
ballx = 150
bally = 30
score = 0
scorex = 8
scorey = 1
scorewrdx = 2
scorewrdy = 1
xadj = 2
yadj = 2
'Load the paddles into memory
LINE (10, 10)-(15, 65), 1, BF
GET (10, 10)-(15, 65), p1
GET (10, 10)-(15, 65), p2
LINE (0, 0)-(320, 200), 0, BF
'Load the ball into memory
CIRCLE (20, 20), 7, 4
PAINT (20, 20), 4
GET (13, 14)-(27, 26), ball
LINE (0, 0)-(320, 200), 0, BF
'Main game loop
DO
press$ = INKEY$ 'Store keypresses
LINE (0, 0)-(320, 200), 0, BF 'Clear the screen. WAY faster than CLS
LOCATE scorewrdy, scorewrdx ' Print
PRINT "Score: " ' the
LOCATE scorey, scorex ' score
PRINT score '
WAIT &H3DA, 8 'Just something to make the graphics good
IF p1y >= 5 AND press$ = CHR$(0) + CHR$(72) THEN p1y = p1y - 3 'Player 1
IF p1y <137>= 300 THEN xadj = -2 ' from going off the screen)
IF ballx <= 5 THEN xadj = 2 '
IF ballx = 18 AND bally <p1y>= p1y - 2 THEN '
xadj = 2 ' Ball bouncing
score = score + 1 ' for player 1's
END IF ' paddle
IF ballx = 290 AND bally <p2y>= p2y - 2 THEN ' Ball bouncing
xadj = -2 ' for computer's
END IF ' paddle
ballx = ballx + xadj 'The bouncing part
bally = bally + yadj 'of the "Ball bouncing"
IF ballx = 10 THEN 'Checks to see if the ball went off the
LINE (0, 0)-(320, 200), 0, BF 'players side of the screen
PRINT "You lost!!!" 'Is so, print "You lost"
PCOPY 1, 0 'copy page 1 to page 0
FOR delay = 1 TO 50000: NEXT 'Just a delay
END
END IF
IF score = 20 THEN 'Checks to see if you've won
SLEEP 1 'If so, wait 1 sec
LINE (0, 0)-(320, 200), 0, BF 'Clear screen
LINE (0, 0)-(320, 200), 2, BF 'Fill screen green
LOCATE 12, 12 'Move cursor to 12,12
COLOR 4 'Set the color to red (4)
PRINT "You won!!!!" 'Print "You won!"
PCOPY 1, 0 'Copy page 1 to page 0
SLEEP 3 'Wait 3 seconds
COLOR 15 'Set the color back to white (15)
END
END IF
IF ballx = 300 THEN 'Checks to see if the computer missed
LINE (0, 0)-(320, 200), 0, BF 'If so, clear screen
score = score + 1 'And add one to score
END IF
IF p2y > 5 AND bally < p2y THEN p2y = p2y - 3 'Computer paddle AI
IF p2y <127> p2y THEN p2y = p2y + 3 '
PUT (18, p1y), p1 'Draw objects
PUT (295, p2y), p2 'at their
PUT (ballx, bally), ball 'final positions
PCOPY 1, 0 'Show everything
LOOP 'End of main loop