10 REM Nebez Briefkani
20 REM Assignment #6: Computer Game
30 REM Code: NB
40 SCREEN 9
50 KEY OFF
60 CLS
100 DIM paddle(80)
101 DIM ball(60)
102 DIM rblock(190)
103 DIM gblock(190)
104 DIM bblock(190)
105 DIM cursor(100)
106 DIM bricks(1000)
107 DIM line1(10)
108 DIM line2(10)
109 DIM line3(10)
110 DIM line4(10)
200 REM -- This is where we get all of our drawings, backgrounds, etc., and put them into memory. We do this first to avoid having to do it when the program is actually running --
210 OPEN "I",#1,"OBJECTS.PIC"
215 REM -- This is a more efficient way of printing the picture to the screen, but the only downside is you have to specify the image dimensions yourself --
220 FOR y=0 to 133
230 FOR x=0 to 159
235 IF Y=133 AND X=159 THEN GOTO 270
240 INPUT#1,C:pset(x,y),C
250 next x
260 next y
270 CLOSE #1
400 REM -- Now that we've drawn everything to the screen, let's start saving things to the memory --
410 GET(0,0)-(63,19),bblock
420 GET(0,20)-(63,39),rblock
430 GET(0,40)-(63,59),gblock
440 GET(65,0)-(83,18),ball
450 GET(0,77)-(92,82),paddle
460 GET(0,84)-(158,133),bricks
470 GET(134,0)-(158,24),cursor
500 REM -- Now that everything has been saved to memory, we can close it all up and continue with the splash screen of the program --
510 CLS
600 REM -- Open up the splash screen --
605 SCREEN 7
610 OPEN "I",#1,"SPLASH.PIC"
620 x=0:y=0
630 IF EOF(1) THEN GOTO 800
640 INPUT#1,C
650 if c=-1 then y = y + 1:x = 0:goto 630
660 pset(x,y),c
670 x = x + 1
680 GOTO 630
690 CLOSE #1
800 REM -- Continue on with the program only after they've pushed a key... --
810 A$=INKEY$
820 IF A$="" THEN GOTO 810
830 CLS
900 REM -- Open up the main screen and ask the user what they'd like to do --
910 REM -- We're still in SCREEN 7 here --
915 CLS
920 PUT(81,30),bricks,pset:REM -- This is the BRICKS logo --
925 LOCATE ,15:PRINT "Main Screen"
930 LOCATE 13,14:PRINT "Play Game!"
940 LOCATE 16,14:PRINT "Instructions"
950 LOCATE 19,14:PRINT "About"
955 LOCATE 21,1:PRINT "USE ARROW KEYS TO NAVIGATE"
956 LOCATE 22,1:PRINT "PRESS SPACE TO SELECT"
960 CURRENTOPTION = 1:REM -- This is how we determine which option they've selected --
970 PUT(75,90),cursor,pset:REM -- This is the target to show what option they've selected. The moving part comes next --
1100 REM -- This is where we animate the selection process, and make the target dynamic --
1110 A$=INKEY$
1120 IF A$="" THEN GOTO 1110
1130 IF A$=CHR$(0)+CHR$(72) THEN GOSUB 15010:REM -- Up arrow key pressed --
1140 IF A$=CHR$(0)+CHR$(80) THEN GOSUB 15500:REM -- Down arrow key pressed --
1150 IF A$=" " THEN GOTO 1500
1200 GOTO 1110
1500 REM -- Once the user presses the space key, handle everything --
1510 REM -- For the selected game/page, we want to make the Instructions and About pages first, as they are the easiest --
1520 IF CURRENTOPTION = 1 THEN GOTO 2000
1530 IF CURRENTOPTION = 2 THEN GOTO 1600
1540 IF CURRENTOPTION = 3 THEN GOTO 1800
1600 REM -- This is the instructions page --
1605 CLS
1610 LOCATE 1,14:PRINT "INSTRUCTIONS"
1620 LOCATE 3,1:PRINT "The objective of the game BRICKS is to destroy all the bricks with the ball given to you"
1630 PRINT "To play, you use the left and right arrow keys to move the paddle around and hit the ball back everytime it reaches you"
1640 PRINT "If you miss the ball, and it touches the floor below you, you lose a life"
1650 PRINT "When you destroy a brick with the ball, your score is increased"
1660 PRINT "Once you have destroyed all the bricks, you move onto the next level"
1670 PRINT "If you lose all three (3) of your lives, the game is over"
1675 PRINT "TIP!!! Press the number keys 1-5 to skip through levels!"
1680 PRINT "Good luck!"
1690 A$=INKEY$
1700 IF A$="" THEN GOTO 1690
1710 GOTO 900
1800 REM -- This is the about page --
1805 CLS
1810 LOCATE 1,14:PRINT "ABOUT"
1820 LOCATE 6,1:PRINT "The BRICKS Game was created and developed by Nebez Briefkani as part of a end-of-year Computer Sciences assignment"
1830 A$=INKEY$
1840 IF A$="" THEN GOTO 1830
1850 GOTO 900
2000 REM -- And finally... we start the game! --
2001 RANDOMIZE TIMER:REM -- This is just for game randomization --
2005 SCREEN 9:REM -- We can finally go back into screen 9 --
2050 REM -- Start with some basic, start of game, variables --
2060 SCORE = 0
2070 LEVEL = 1
2080 LIVES = 3
2200 REM -- These are some variables for the start of ANY level, not just the start game --
2210 BALLX = 311
2220 BALLY = 270
2230 VELX = INT((RND*(-8))+6)/40
2240 VELY = -0.333
2250 PADDLEX = 340-92
2260 PADDLEY = 298
2300 REM -- This is where we draw out the level --
2305 LINE(0,0)-(640,350),7,BF:REM -- Our background will be grey
2310 LINE(0,305)-(640,350),0,BF
2320 GOSUB 16000:REM -- Update level sub --
2330 GOSUB 16050:REM -- Update score sub --
2340 GOSUB 16100:REM -- Update lives sub --
2400 REM -- Now we map out all of the levels --
2405 REM -- This is level 1 --
2410 IF LEVEL=1 THEN line1(0)=1:line1(1)=1:line1(2)=2:line1(3)=2:line1(4)=3:line1(5)=3:line1(6)=2:line1(7)=2:line1(8)=1:line1(9)=1
2420 IF LEVEL=1 THEN line2(0)=0:line2(1)=0:line2(2)=0:line2(3)=0:line2(4)=0:line2(5)=0:line2(6)=0:line2(7)=0:line2(8)=0:line2(9)=0
2430 IF LEVEL=1 THEN line3(0)=0:line3(1)=0:line3(2)=0:line3(3)=0:line3(4)=0:line3(5)=0:line3(6)=0:line3(7)=0:line3(8)=0:line3(9)=0
2440 IF LEVEL=1 THEN line4(0)=0:line4(1)=0:line4(2)=0:line4(3)=0:line4(4)=0:line4(5)=0:line4(6)=0:line4(7)=0:line4(8)=0:line4(9)=0
2450 IF LEVEL=1 THEN BLOCKS=10
2500 REM -- This is level 2 --
2510 IF LEVEL=2 THEN line1(0)=3:line1(1)=3:line1(2)=3:line1(3)=3:line1(4)=3:line1(5)=3:line1(6)=3:line1(7)=3:line1(8)=3:line1(9)=3
2520 IF LEVEL=2 THEN line2(0)=2:line2(1)=2:line2(2)=2:line2(3)=2:line2(4)=2:line2(5)=2:line2(6)=2:line2(7)=2:line2(8)=2:line2(9)=2
2530 IF LEVEL=2 THEN line3(0)=0:line3(1)=0:line3(2)=0:line3(3)=0:line3(4)=0:line3(5)=0:line3(6)=0:line3(7)=0:line3(8)=0:line3(9)=0
2540 IF LEVEL=2 THEN line4(0)=0:line4(1)=0:line4(2)=0:line4(3)=0:line4(4)=0:line4(5)=0:line4(6)=0:line4(7)=0:line4(8)=0:line4(9)=0
2550 IF LEVEL=2 THEN BLOCKS=20
2600 REM -- This is level 3 --
2610 IF LEVEL=3 THEN line1(0)=1:line1(1)=3:line1(2)=3:line1(3)=3:line1(4)=3:line1(5)=3:line1(6)=3:line1(7)=3:line1(8)=3:line1(9)=1
2620 IF LEVEL=3 THEN line2(0)=0:line2(1)=1:line2(2)=2:line2(3)=2:line2(4)=3:line2(5)=3:line2(6)=2:line2(7)=2:line2(8)=1:line2(9)=0
2630 IF LEVEL=3 THEN line3(0)=0:line3(1)=0:line3(2)=1:line3(3)=2:line3(4)=2:line3(5)=2:line3(6)=2:line3(7)=1:line3(8)=0:line3(9)=0
2640 IF LEVEL=3 THEN line4(0)=0:line4(1)=0:line4(2)=0:line4(3)=1:line4(4)=1:line4(5)=1:line4(6)=1:line4(7)=0:line4(8)=0:line4(9)=0
2650 IF LEVEL=3 THEN BLOCKS=28
2700 REM -- This is level 4 --
2710 IF LEVEL=4 THEN line1(0)=3:line1(1)=3:line1(2)=3:line1(3)=3:line1(4)=3:line1(5)=3:line1(6)=3:line1(7)=3:line1(8)=3:line1(9)=3
2720 IF LEVEL=4 THEN line2(0)=2:line2(1)=2:line2(2)=2:line2(3)=3:line2(4)=3:line2(5)=3:line2(6)=3:line2(7)=2:line2(8)=2:line2(9)=2
2730 IF LEVEL=4 THEN line3(0)=2:line3(1)=2:line3(2)=2:line3(3)=2:line3(4)=2:line3(5)=2:line3(6)=2:line3(7)=2:line3(8)=2:line3(9)=2
2740 IF LEVEL=4 THEN line4(0)=1:line4(1)=1:line4(2)=1:line4(3)=1:line4(4)=1:line4(5)=1:line4(6)=1:line4(7)=1:line4(8)=1:line4(9)=1
2750 IF LEVEL=4 THEN BLOCKS=40
2800 REM -- This is level 5, the final level --
2810 IF LEVEL=5 THEN line1(0)=3:line1(1)=0:line1(2)=3:line1(3)=0:line1(4)=3:line1(5)=0:line1(6)=3:line1(7)=0:line1(8)=3:line1(9)=0
2820 IF LEVEL=5 THEN line2(0)=0:line2(1)=3:line2(2)=0:line2(3)=3:line2(4)=0:line2(5)=3:line2(6)=0:line2(7)=3:line2(8)=0:line2(9)=3
2830 IF LEVEL=5 THEN line3(0)=2:line3(1)=0:line3(2)=2:line3(3)=0:line3(4)=2:line3(5)=0:line3(6)=2:line3(7)=0:line3(8)=2:line3(9)=0
2840 IF LEVEL=5 THEN line4(0)=0:line4(1)=1:line4(2)=0:line4(3)=1:line4(4)=0:line4(5)=1:line4(6)=0:line4(7)=1:line4(8)=0:line4(9)=1
2850 IF LEVEL=5 THEN BLOCKS=20
3000 REM -- Plot out the current map that we're in --
3010 FOR B=0 TO 9:REM -- For each block on first line --
3020 if line1(B)=3 THEN PUT(B*64,0),bblock,PSET
3030 if line1(B)=2 THEN PUT(B*64,0),rblock,PSET
3040 if line1(B)=1 THEN PUT(B*64,0),gblock,PSET
3050 NEXT B
3060 FOR B=0 TO 9:REM -- For each block on second line --
3070 if line2(B)=3 THEN PUT(B*64,20),bblock,PSET
3080 if line2(B)=2 THEN PUT(B*64,20),rblock,PSET
3090 if line2(B)=1 THEN PUT(B*64,20),gblock,PSET
3100 NEXT B
3110 FOR B=0 TO 9:REM -- For each block on third line --
3120 if line3(B)=3 THEN PUT(B*64,40),bblock,PSET
3130 if line3(B)=2 THEN PUT(B*64,40),rblock,PSET
3140 if line3(B)=1 THEN PUT(B*64,40),gblock,PSET
3150 NEXT B
3160 FOR B=0 TO 9:REM -- For each block on fourth line --
3170 if line4(B)=3 THEN PUT(B*64,60),bblock,PSET
3180 if line4(B)=2 THEN PUT(B*64,60),rblock,PSET
3190 if line4(B)=1 THEN PUT(B*64,60),gblock,PSET
3200 NEXT B
3210 REM -- This is for testing purposes --
3220 REM A$=INKEY$
3230 REM IF A$="" THEN GOTO 3220
3240 REM IF LEVEL=5 THEN LEVEL=1 ELSE LEVEL=LEVEL+1
3250 REM CLS:GOSUB 16000:GOTO 2300
3499 PUT(PaddleX,paddley),paddle,pset
3500 REM -- Start of game loop --
3510 GOSUB 16200:REM -- Collision detection sub --
3511 GOSUB 16000:GOSUB 16050:GOSUB 16100
3512 IF BLOCKS = 0 THEN IF LEVEL = 5 THEN CLS:LOCATE 11,35:PRINT "YOU WIN!":LOCATE 20,1:END ELSE CLS:LEVEL = LEVEL + 1:GOTO 2200
3513 IF BALLX<=1 THEN VELX=VELX*(-1)
3514 IF BALLX>=620 THEN VELX=VELX*(-1)
3515 IF BALLY<=1 THEN VELY=VELY*(-1)
3516 IF BALLY>=283 THEN IF LIVES=1 THEN CLS:LOCATE 11,35:PRINT "YOU LOSE!":LOCATE 20,1:END ELSE LIVES = LIVES - 1:GOTO 2200
3520 BALLX=BALLX+VELX
3530 BALLY=BALLY+VELY
3540 PUT(BALLX,BALLY),ball,pset
3550 A$=INKEY$
3560 IF A$="" THEN GOTO 3500
3570 IF A$=CHR$(0)+CHR$(77) THEN GOSUB 17000:REM -- Right key pressed --
3580 IF A$=CHR$(0)+CHR$(75) THEN GOSUB 18000:REM -- Left key pressed --
3585 REM -- this is for skipping through levels --
3591 IF A$="1" THEN CLS:LEVEL = 1:GOTO 2200
3592 IF A$="2" THEN CLS:LEVEL = 2:GOTO 2200
3593 IF A$="3" THEN CLS:LEVEL = 3:GOTO 2200
3594 IF A$="4" THEN CLS:LEVEL = 4:GOTO 2200
3595 IF A$="5" THEN CLS:LEVEL = 5:GOTO 2200
4590 GOTO 3500
14900 END
14910 REM -- Start of subroutines
15000 REM -- Start of Main screen subroutines --
15010 REM -- Up key pressed on main screen --
15011 IF CURRENTOPTION = 1 THEN RETURN
15015 PI = 3.14159265
15020 FOR Y=0.5*PI TO PI STEP 0.005
15030 YVAL = SIN(Y) * 22 + 90 + (CURRENTOPTION * 22) - 44:REM -- Use a SIN function to make the movement of the target extremely smooth --
15040 PUT(75,YVAL),cursor,pset
15050 NEXT Y
15060 CURRENTOPTION = CURRENTOPTION - 1
15400 RETURN
15500 REM -- Down key pressed on main screen --
15501 IF CURRENTOPTION = 3 THEN RETURN
15515 PI = 3.14159265
15520 FOR Y=0 TO 0.5*PI STEP 0.005
15530 YVAL = SIN(Y) * 22 + 90 + (CURRENTOPTION * 22) - 22:REM -- Use a SIN function to make the movement of the target extremely smooth --
15540 PUT(75,YVAL),cursor,pset
15550 NEXT Y
15560 CURRENTOPTION = CURRENTOPTION + 1
15900 RETURN
16000 REM -- Update level sub --
16010 LOCATE 23,60:PRINT "Level:"
16020 LOCATE 23,67:PRINT LEVEL
16030 RETURN
16050 REM -- Update score sub --
16060 LOCATE 23,10:PRINT "Score:"
16070 LOCATE 23,17:PRINT SCORE
16080 RETURN
16100 REM -- Update lives sub --
16110 LOCATE 23,40:PRINT "Lives:"
16120 LOCATE 23,47:PRINT LIVES
16130 RETURN
16200 REM -- Collision Detection sub --
16212 INVERTY=0:INVERTX=0
16213 FOR I=1 TO 17:REM -- the width of the ball is 19, so we check every pixel above the ball between 0 and 18 to see if it hits a block on the TOP --
16214 REM -- This is for block collision, and not walls --
16219 REM -- This next line is only for detecting collision on the top of the ball --
16220 IF POINT(BALLX+I,BALLY-1)=0 THEN BLOCKX=INT((BALLX+I)/64):BLOCKY = INT(BALLY / 20) - 1:LINE(BLOCKX*64,BLOCKY*20)-(BLOCKX*64+63,BLOCKY*20+19),7,BF:BLOCKS = BLOCKS - 1:SCORE=SCORE+10:INVERTY=1
16230 IF POINT(BALLX+19,BALLY+I)=0 THEN BLOCKX=INT((BALLX+19)/64)+ 1:BLOCKY = INT((BALLY+I) / 20):LINE(BLOCKX*64,BLOCKY*20)-(BLOCKX*64+63,BLOCKY*20+19),7,BF:BLOCKS = BLOCKS - 1:SCORE=SCORE+10:INVERTX=1
16240 IF POINT(BALLX-1,BALLY+I)=0 THEN BLOCKX=INT((BALLX-1)/64):BLOCKY = INT((BALLY+I) / 20):LINE(BLOCKX*64,BLOCKY*20)-(BLOCKX*64+63,BLOCKY*20+19),7,BF:BLOCKS = BLOCKS - 1:SCORE=SCORE+10:INVERTX=1
16250 IF POINT(BALLX+I,BALLY+19)=0 THEN INVERTY=1:REM -- You can't destroy blocks from the top, it's metal! --
16255 IF POINT(BALLX+I,BALLY+19)=14 THEN INVERTY=1:REM -- We hit the paddle! --
16260 NEXT I
16380 IF INVERTY=1 THEN VELY=VELY*(-1)
16390 IF INVERTX=1 THEN VELX=VELX*(-1)
16400 RETURN
17000 REM -- Move paddle right sub --
17010 IF PADDLEX+4>=545 THEN RETURN
17030 FOR I=1 TO 4:PADDLEX=PADDLEX+1:PUT(PADDLEX,PADDLEY),paddle,pset:NEXT I
17040 RETURN
18000 REM -- Move paddle left sub --
18010 IF PADDLEX-4<=5 THEN RETURN
18030 FOR I=1 TO 4:PADDLEX=PADDLEX-1:PUT(PADDLEX,PADDLEY),paddle,pset:NEXT I
18040 RETURN