Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
169 lines (168 sloc) 4.38 KB
1 CLS
2 PRINT @ 139, "COCO-PONG"
3 PRINT @ 193, "COPYLEFT 2018, CHRIS PEDERSEN"
4 PRINT @ 259, "CONTROLS: 'W'=UP, 'S'=DOWN"
5 PRINT @ 324, "PRESS <ENTER> TO BEGIN"
6 INPUT PE$
7 REM PS=PLAYER'S SCORE, CS=COMPUTER'S SCORE
8 PS=0
9 CS=0
10 REM DRAW BACKGROUND
20 CLS
30 FOR X = 0 TO 63
40 FOR Y = 0 TO 31
50 SET(X,Y,1)
60 NEXT Y
70 NEXT X
100 REM DRAW PLAYER PADDLE
105 SET(4,15,5)
110 SET(4,17,5)
120 SET(4,19,5)
121 REM VARIABLES P1, P2, AND P3, KEEP TRACK OF PLAYER'S PADDLE POSITION
122 P1=15
123 P2=17
124 P3=19
130 REM DRAW OPPONENTS PADDLE
135 SET(58,15,5)
140 SET(58,17,5)
150 SET(58,19,5)
151 REM VARIABLES C1, C2, AND C3, KEEP TRACK OF COMPUTER'S PADDLE POSITION
152 C1=15
153 C2=17
154 C3=19
160 REM DRAW SCOREBOARD
170 PRINT @ 2, 0;" CTRL: W + S ";0
500 REM CREATE AND DRAW BALL
501 REM VARIABLES: RN=RUN, RS=RISE, BX=BALL-X-COORDINATE, BY=BALL-Y-COORDINATE...
502 REM C=COLOR, VB=VERTICAL-BOUNDARY-STRIKE, HB=HORIZONTAL-BOUNDARY-STRIKE
510 RS=2
515 RN=-2
520 BX=32
530 BY=15
531 C=2
532 VB=0
533 HB=0
534 SET(32,15,C)
535 REM SET BALL IN MOTION
540 REM FILL PREVIOUS POSITION OF BALL
549 REM MAIN GAME LOOP STARTS AT 550
550 SET(BX,BY,1)
553 REM PLAYER CONTROLS
555 UI$=INKEY$
556 IF UI$="W" OR UI$="S" THEN 558
557 GOTO 571
558 IF UI$="S" THEN 565
559 REM IF 'W' PRESSED, ERASE PREVIOUS POSITION OF PADDLE
560 IF P1<=4 THEN 571
561 SET(4, P1, 1): SET(4, P2, 1): SET(4, P3, 1)
562 P1=P1-6: P2=P2-6: P3=P3-6
563 SET(4, P1, 5): SET(4, P2, 5): SET(4, P3, 5)
564 GOTO 571
565 REM IF 'S' PRESSED, ERASE PREVIOUS POSITION OF PADDLE
566 IF P3>=30 THEN 571
567 SET(4, P1, 1): SET(4, P2, 1): SET(4, P3, 1)
568 P1=P1+6: P2=P2+6: P3=P3+6
569 SET(4, P1, 5): SET(4, P2, 5): SET(4, P3, 5)
570 GOTO 571
571 REM CREATE GAME AI (CONTROLS OPPONENTS PADDLE)
572 IF BY < C1 - 3 THEN 574
573 GOTO 579
574 REM MOVE COMPUTER OPPONENT'S PADDLE UP
575 SET(58, C1, 1): SET(58, C2, 1): SET(58, C3, 1)
576 C1=C1-6: C2=C2-6: C3=C3-6
577 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
578 GOTO 630
579 IF BY > C3 + 3 THEN 581
580 GOTO 630
581 REM MOVE COMPUTER OPPONENT'S PADDLE DOWN
582 SET(58, C1, 1): SET(58, C2, 1): SET(58, C3, 1)
583 C1=C1+6: C2=C2+6: C3=C3+6
584 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
630 REM DETECT HORIZONTAL BOUNDARY STRIKE (SCORE OR PADDLE STRIKE)
631 IF BX <= 6 OR BX >= 56 THEN HB=1
632 IF HB=1 THEN RN=RN*(-1)
633 IF HB=0 THEN 650
634 IF HB=1 AND (BY<P1 OR BY>P3) AND BX<=6 THEN 640
635 IF HB=1 AND (BY<C1 OR BY>C3) AND BX>=56 THEN 645
636 GOTO 650
640 CS=CS+1: GOSUB 3000
641 GOSUB 900
642 GOSUB 1000
643 HB=0
644 GOTO 550
645 PS=PS+1: GOSUB 3000
646 GOSUB 900
647 GOSUB 1100
648 HB=0
649 GOTO 550
650 REM DETECT VERTICAL BOUNDARY STRIKE
651 IF BY<=4 OR BY>=30 THEN VB=1
652 IF VB=1 THEN RS=RS*(-1)
670 HB=0
671 VB=0
680 REM SET COORDINATES FOR THE BALL'S NEW POSITION
690 BX=BX+RN
700 BY=BY+RS
750 REM DRAW BALL IN NEW POSITION
760 SET(BX,BY,C)
765 REM FOR-LOOP ON 770 CAUSES SHORT DELAY FOR SMOOTHER GRAPHICS
770 FOR X = 0 TO 7
775 ZZ=X
780 NEXT X
800 REM CHANGE BALL COLOR
810 IF C=7 THEN 840
820 C=7
830 GOTO 550
840 C=2
850 GOTO 550
900 PRINT @ 2, PS;" CTRL: W + S ";CS
920 RETURN
1000 REM RESET BALL AFTER COMPUTER SCORES
1010 SET(BX,BY,1)
1020 BX=48
1030 BY=RND(12)+10
1035 RN=-2
1040 SET(BX,BY,2)
1041 REM FOR-LOOP ON 1042 CAUSES SHORT PAUSE
1042 FOR X = 0 TO 25
1050 RETURN
1100 REM RESET BALL AFTER PLAYER SCORES
1110 SET(BX,BY,1)
1120 BX=14
1130 BY=RND(12)+10
1135 RN=2
1140 SET(BX,BY,2)
1141 REM FOR-LOOP ON 1142 CAUSES SHORT PAUSE
1142 FOR X = 0 TO 25
1150 RETURN
2000 REM MOVE COMPUTER OPPONENT'S PADDLE UP
2020 SET(58, C1, 1): SET(58, C2, 1): SET(58, C3, 1)
2030 C1=C1-6: C2=C2-6: C3=C3-6
2040 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
2090 RETURN
2100 REM MOVE COMPUTER OPPONENT'S PADDLE DOWN
2120 SET(58, C1, 1): SET(58, C2, 1): SET(58, C3, 1)
2130 C1=C1+6: C2=C2+6: C3=C3+6
2140 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
2190 RETURN
3000 REM END GAME AT 21 POINTS, ASK USER IF HE OR SHE WOULD LIKE TO PLAY AGAIN
3005 PRINT @ 2, PS;" CTRL: W + S ";CS
3010 IF PS >= 21 OR CS >= 21 THEN 3100
3020 GOTO 3500
3030 REM FOR-LOOP ON 3040 CAUSES SHORT DELAY
3040 FOR X = 0 TO 7
3050 ZZ=X
3060 NEXT X
3100 PRINT @ 170, "PLAY AGAIN ?"
3101 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
3102 PRINT @ 261, "'Y' FOR YES 'N' FOR NO"
3103 SET(58, C1, 5): SET(58, C2, 5): SET(58, C3, 5)
3104 PS=0: CS=O
3105 NG$=INKEY$
3120 IF NG$="Y" THEN 3400
3130 IF NG$="N" THEN 4000
3140 GOTO 3030
3400 GOTO 7
3500 RETURN
4000 CLS
5000 END
You can’t perform that action at this time.