***program start*** 10 '=========== BLOCK BREAKER ============= 20 GameTitle="BLOCK BREAKER" 30 ScreenWidth=128:ScreenHight=64 40 FontWidth=6:FontHight=8 50 Stage=1:Score=0:BallRad=2 60 HighScoreNum=ScreenHight/FontHight-3 65 dim HighScore[HighScoreNum]:gosub 9060 70 BlockXNum=7:BlockYNum=4:BlockHight=3:BlockNumMax=BlockYNum*BlockXNum 80 dim BlockX[BlockXNum*BlockYNum],BlockY[BlockXNum*BlockYNum] 90 dim BlockExist[BlockXNum*BlockYNum] 95 if (keyA()<>1)||(keyB()<>1) then gosub 8100 : 'read HighScore 100 '=========== Main Routine ============= 110 while -1 120 gosub 10000 :' Demo 125 while -1 130 gosub 1000 :' Stage 140 if gameOver=1 then gosub 11000:exit while 150 if gameClear=1 then gosub 12000 170 end while 200 end while 500 end 1000 '=============== STAGE =============== 1100 '------- STAGE MAIN ---------- 1105 '----- MAKE SCREEN ------- 1110 ScoreStr="SCORE":HiScoreStr="HISCO":StageStr="STAGE" 1120 ScoreAreaX=ScreenWidth-strlen(ScoreStr)*FontWidth-1 1130 y=0:gameClear=0:gameOver=0:hitNum=0:ddx=0:cls 1140 putStr ScoreAreaX,y,StageStr,1 : y=y+FontHight : StageY=y 1150 gosub 4020 : y=y+FontHight : 'Disp Stage 1160 putStr ScoreAreaX,y,HiScoreStr,1 : y=y+FontHight : HiScoreY=y 1170 gosub 4040 : y=y+FontHight : 'Disp HiScore 1180 putStr ScoreAreaX,y,ScoreStr,1 : y=y+FontHight : ScoreY=y 1190 gosub 4080 : y=y+FontHight : 'Disp Score 1200 CoatExX=0:CoatExX1=ScoreAreaX-3:CoatExY=0 1205 CoatExY1=ScreenHight-1:WallWidth=4 1207 CoatGap=8:BlockGap=1 1210 CoatInX=CoatExX+WallWidth:CoatInX1=CoatExX1-WallWidth 1215 CoatInY=WallWidth:CoatInY1=ScreenHight-1 1220 fill CoatExX,CoatExY,CoatExX1,CoatExY1,1 1230 fill CoatInX,CoatInY,CoatInX1,CoatInY1,0 1240 ' Disp Block 1250 BlockWidth=((CoatInX1-CoatInX+1)-CoatGap*2)/BlockXNum-BlockGap 1255 w=(CoatInX1-CoatInX+1)-(BlockWidth*BlockXNum+BlockGap*(BlockXNum-1)) 1256 w=(w-CoatGap*2)/2 1257 BlockLeftX=CoatInX+CoatGap+w 1258 BlockNum=BlockNumMax 1260 for y=0 to BlockYNum-1 1270 for x=0 to BlockXNum-1 1280 BlockX[x+BlockXNum*y]=BlockLeftX+(BlockWidth+BlockGap)*x 1290 BlockY[x+BlockXNum*y]=CoatInY+(BlockHight+BlockGap)*y+CoatGap 1295 BlockExist[x+BlockXNum*y]=1 1300 xx=BlockX[x+BlockXNum*y]:yy=BlockY[x+BlockXNum*y] 1310 fill xx,yy,xx+BlockWidth-1,yy+BlockHight-1,1 1315 next 1320 next 1330 ' Ball 1340 BallX=CoatInX+CoatGap+rand()*(CoatInX1-CoatInX-CoatGap*2)/255 1350 BallY=CoatInY+(BlockHight+BlockGap)*BlockYNum+CoatGap+5 1355 xx=BallX:yy=BallY:gosub 4140 :'ball disp 1360 ' Speed 1370 SleepTime=30-Stage*5:if SleepTime<5 then SleepTime=5 1375 if rand()<127 then dx=-1 else dx=1 1376 dy=1 1380 ' Pad 1390 PadWidth=20-Stage*3:if PadWidth<5 then PadWidth=5 1400 PadHight=3 1410 PadX=(CoatExX1-PadWidth)/2 1420 PadY=CoatInY1-PadHight 1425 lCount=0:rCount=0 1430 xx=PadX:yy=PadY:c=1:gosub 4110 :'pad disp 1440 sleep 500:' for ready 1500 '---------Stage Loop ---------- 1501 while -1 1505 ' Pad Move 1510 gosub 4200 1520 ' ball Move 1530 gosub 4400 1540 ' game over ? 1550 if (gameOver=1)||(gameClear=1) then exit while 1560 if SleepTime<>0 then sleep SleepTime 1565 'update 1570 end while 1600 '---------Stage End ----------- 1610 if gameClear=1 then 1620 Score=Score+Stage*500 1630 if hitNum<20 then bonus=20-hitNum:Score=Score+bonus*50 1640 return 1650 end if 1660 if gameOver=1 then 1680 return 1690 end if 1700 end :' never reach this point 4000 '----- STAGE Sub ----- 4010 'Disp Stage 4020 putStr ScoreAreaX,StageY,format("%-5D",Stage),1 4030 return 4040 'Disp HighScore 4050 gosub 9000 4060 putStr ScoreAreaX,HiScoreY,format("%-5D",HiScore),1 4070 return 4080 'Disp Score 4090 putStr ScoreAreaX,ScoreY,format("%-5D",Score),1 4100 return 4110 ' Pad Disp 4120 fill xx,yy,xx+PadWidth-1,yy+PadHight-1,c 4130 return 4140 ' Ball Disp 4150 putStr xx-BallRad,yy-BallRad-1,chr(139),1,xor 4160 return 4170 ' Ball Disp erase 4180 putStr xx-BallRad,yy-BallRad-1,chr(139),1,xor 4190 return 4200 '---------- Pad Move ------------------ 4205 tempX=PadX:tempY=PadY:'for pad erase 4210 L=keyA():R=keyR() 4220 if L=1 then lCount=lCount+1 else lCount=0 4225 if lCount>20 then lCount=20 4230 if R=1 then rCount=rCount+1 else rCount=0 4235 if rCount>20 then rCount=20 4240 if L=1 then PadX=PadX-(1+lCount/2) 4250 if R=1 then PadX=PadX+(1+rCount/2) 4260 if PadXCoatInX1 then PadX=CoatInX1-PadWidth+1 4275 xx=tempX:yy=tempY:c=0:gosub 4110:'pad erase 4280 xx=PadX:yy=PadY:c=1:gosub 4110 :'pad disp 4290 return 4400 '---------- Ball Move ----------------- 4420 '--- Check Collision --- 4425 bCollision=0:dxBack=dx:dyBack=dy 4430 'Wall 4440 if CoatInX+BallRad>BallX then dx=1:bCollision=1:gosub 9100 4450 if CoatInY+BallRad>BallY then dy=1:bCollision=1:gosub 9100 4460 if CoatInX1-BallRad=PadX-BallRad)&&(BallX<=PadX+PadWidth-1+BallRad) then 4510 bCollision=1:dy=-1:hitNum=hitNum+1 4515 if lCount>10 then ddx=ddx-1 4516 if rCount>10 then ddx=ddx+1 4517 gosub 9400:' set ddxCount 4520 gosub 9200:' pad sound 4530 end if 4540 end if 4550 if bCollision=1 then goto 5400 :' pass block collision check 4560 if BallYBlockY[BlockNumMax-1]+BallRad+BlockHight then goto 5400 4600 ' Block 4605 idx=0 4610 if dyBack>0 then 4620 for y=0 to BlockYNum-1 4630 '--- Up Side Collision Check --- 4635 yyy=BlockY[idx]:yyy1=yyy-BallRad 4640 if yyy1=BallY then 4650 for x=0 to BlockXNum-1 4660 if BlockExist[idx+x]=1 then 4670 xxx=BlockX[idx+x] 4680 if (xxx-BallRad<=BallX)&&(BallX<=xxx+BlockWidth-1+BallRad) then 4690 dy=-1:BlockExist[idx+x]=0 4700 gosub 9600 ' collision action 4710 exit for 4720 end if 4730 end if 4740 next 4750 if bCollision=1 then exit for 4770 end if 4775 idx=idx+BlockXNum 4777 next 4780 else 4790 for y=0 to BlockYNum-1 4800 '--- down Side Collision Check --- 4810 yyy=BlockY[idx]:yyy1=yyy+BlockHight-1+BallRad 4820 if yyy1=BallY then 4830 for x=0 to BlockXNum-1 4840 if BlockExist[idx+x]=1 then 4850 xxx=BlockX[idx+x] 4860 if (xxx-BallRad<=BallX)&&(BallX<=xxx+BlockWidth-1+BallRad) then 4870 dy=1:BlockExist[idx+x]=0 4880 gosub 9600 ' collision action 4890 exit for 4900 end if 4910 end if 4920 next 4930 if bCollision=1 then exit for 4940 end if 4950 idx=idx+BlockXNum 4960 next 4965 end if 4970 'if bCollision=1 then goto 5400 :' pass block collision check 5010 if dxBack>0 then 5020 for x=0 to BlockXNum-1 5030 '--- left Side Collision Check --- 5035 xxx=BlockX[x]:xxx1=xxx-BallRad 5040 if xxx1=BallX then 5050 for y=0 to BlockYNum-1 5055 idx=x+y*BlockXNum 5060 if BlockExist[idx]=1 then 5070 yyy=BlockY[idx] 5080 if (yyy-BallRad<=BallY)&&(BallY<=yyy+BlockHight-1+BallRad) then 5090 dx=-1:ddx=-ddx:BlockExist[idx]=0 5100 gosub 9600 ' collision action 5110 exit for 5120 end if 5130 end if 5140 next 5150 if bCollision=1 then exit for 5170 end if 5175 next 5180 else 5200 '--- Right Side Collision Check --- 5205 for x=0 to BlockXNum-1 5210 xxx=BlockX[x]:xxx1=xxx+BlockWidth-1+BallRad 5220 if xxx1=BallX then 5230 for y=0 to BlockYNum-1 5235 idx=x+y*BlockXNum 5240 if BlockExist[idx]=1 then 5250 yyy=BlockY[idx] 5260 if (yyy-BallRad<=BallY)&&(BallY<=yyy+BlockHight-1+BallRad) then 5270 dx=1:ddx=-ddx:BlockExist[idx]=0 5280 gosub 9600 ' collision action 5290 exit for 5300 end if 5310 end if 5320 next 5330 if bCollision=1 then exit for 5340 end if 5345 next 5360 end if 5400 tempX=BallX:tempY=BallY: 'for ball erase 5410 if (ddx=0)||(bCollision=1) then 5420 BallX=BallX+dx 5430 BallY=BallY+dy 5440 else 5450 ddxCount=ddxCount-1 5460 if ddxCount<0 then 5470 gosub 9400:' set ddxCount 5480 if dx<0 then 5482 if ddx<0 then BallX=BallX+dx else BallY=BallY+dy 5484 else 5486 if ddx<0 then BallY=BallY+dy else BallX=BallX+dx 5488 end if 5490 else 5500 BallX=BallX+dx 5510 BallY=BallY+dy 5520 end if 5530 end if 5540 xx=tempX:yy=tempY:gosub 4170 : 'ball erase 5550 xx=BallX:yy=BallY:gosub 4140 : 'ball disp 5560 return 8000 '-------- saveHiscore ------------ 8010 addr=0 8020 write addr,GameTitle:addr=addr+16 8030 for i=0 to HighScoreNum-1 8040 write addr,format("%D",HighScore[i]):addr=addr+16 8050 next 8060 return 8100 '-------- readHiscore ------------ 8110 addr=0 8120 if GameTitle=read(addr,strlen(GameTitle)) then 8125 addr=addr+16 8130 for i=0 to HighScoreNum-1 8140 HighScore[i]=val(read(addr,5)):addr=addr+16 8150 next 8160 end if 8170 return 9000 '---------get HiScore------------- 9010 HiScore=0:MinHiScore=100000 9020 for i=0 to HighScoreNum-1 9030 if HighScore[i]>HiScore then HiScore=HighScore[i] 9035 if MinHiScore>HighScore[i] then MinHiScore=HighScore[i] 9040 next 9050 return 9060 '--------HiScore Initial---------- 9070 for i=0 to HighScoreNum-1 9080 HighScore[i]=0 9090 next 9095 return 9100 '--------- Wall sound ----------- 9110 sound 1,"L8C4L16.":play 1:return 9200 '--------- Pad sound ------------ 9210 sound 2,"L8C5L16.":play 2:return 9300 '--------- Block sound ---------- 9310 sound 3,"L8C6L16.":play 3:return 9400 '---------- set ddxCount ------------ 9410 if ddx<0 then ddxAbs=-ddx else ddxAbs=ddx 9420 ddxCount=5-ddxAbs 9430 if ddxCount<1 then ddxCount=1 9440 return 9600 '----------- Block Collision Action -------- 9610 bCollision=1 9620 gosub 9300 :' sound 9630 xx=BallX:yy=BallY:gosub 4170 : 'ball erase 9640 fill xxx,yyy,xxx+BlockWidth-1,yyy+BlockHight-1,0 : 'Block erase 9650 xx=BallX:yy=BallY:gosub 4140 : 'ball disp 9660 Score=Score+10*Stage:gosub 4080 9670 BlockNum=BlockNum-1 9680 if BlockNum=0 then gameClear=1 9690 return 10000 '=========== DEMO ============= 10005 '----- SOUND DEFINE ----- 10010 S11="T760L8E5E5.E5.C5L4E5_G5.G4._C5L8.L4G4L8.L4E4_L8.L4A4B4L8A#4L4A4_" 10020 S21="T760L8F#4F4.F4.F4L4F4_B4..._E4L8.L4C4L8.L4A3_L8.L4C4D4L8C#4L4C4_" 10030 S31="T760L8D3D3.D3.D3L4D3_G3.G2._G3L8.L4E3L8.L4C3_L8.L4F3G3L8F#3L4F3_" 10040 ' 10050 S12="L6G4E5G5L4A5L8F5G5_.L4E5L8C5D5L4B4L8._C5L8.L4G4L8.L4E4_" 10060 S22="L6C4G4B4L4C5L8A4B4_.L4A4L8E4F4L4D4L8._E4L8.L4C4L8.L4A3_" 10070 S32="L6E3C4E4L4F4L8D4E4_.L4C4L8A3B3L4G3L8._G3L8.L4E3L8.L4C3_" 10080 ' 10090 S13="L8.L4A4B4L8A#4L4A4_L6G4E5G5L4A5L8F5G5_.L4E5L8C5D5L4B4L8._" 10100 S23="L8.L4C4D4L8C#4L4C4_L6C4G4B4L4C5L8A4B4_.L4A4L8E4F4L4D4L8._" 10110 S33="L8.L4F3G3L8F#3L4F3_L6E3C4E4L4F4L8D4E4_.L4C4L8A3B3L4G3L8._" 10120 ' 10130 S14="L4.L8G5F#5E#5L4D#5L8E5_L8.G#4A4C5.A4C5D5_" 10140 S24="L4.L8E5D#5C#5L4B4L8C5_L8.E4F4F#4.C4E4F4__" 10150 S34="L4C3L8.G3L4.C4________L4F3L8.C3L4C3F3____" 10160 ' 10170 S15="L4.L8G5F#5E#5L4D#5L8E5_L8.L4C6L8C6L4C6._" 10180 S25="L4.L8E5D#5C#5L4B4L8C5_L8.L4G5L8G5L4G5._" 10190 S35="L4C3L8.E3L4.L8G3C4____L2.L4.G3_" 10200 ' 10210 S16="L4.L8G5F#5E#5L4D#5L8E5_.G#4A4C5.A4C5D5_L4.D#5L8.D5L8._L4C5.L2.L8." 10220 S26="L4.L8E5D#5C#5L4B4L8C5_.E4F4F#4.C4E4F4_L4.G#4L8.L4F4L8._L4E4.L2._" 10230 S36="L4C3L8.G3L4.C4_F3L8.C3L4C3F3_L4C3G#3L8.L4A#3L8._L4C4L8..L2._" 10240 ' 10300 sound 1,S11+S12+S13+S14+S15+S16 10310 sound 2,S21+S22+S23+S24+S25+S26 10320 sound 3,S31+S32+S33+S34+S35+S36 10400 '----- MAKE SCREEN ------- 10410 cls 10430 Comment="PUSH B KEY" 10440 TitleX=(ScreenWidth-strlen(GameTitle)*FontWidth)/2 10450 TitleY=(ScreenHight-2*FontWidth)/3 10460 putStr TitleX,TitleY,GameTitle,1 10470 CommentX=(ScreenWidth-strlen(Comment)*FontWidth)/2 10480 putStr CommentX,TitleY*2,Comment,1 10490 '--------------- Wait --------------- 10495 keyBpushd=0 10500 while -1 10505 for i=0 to 20 10507 if keyB()=1 then keyBpushd=1:exit for 10510 if sound1status()=0 then play 1,2,3 10520 sleep 50 10525 next 10530 putStr CommentX,TitleY*2,Comment,1,xor,T 10535 if keyBpushd=1 then exit while 10550 end while 10560 sound 1,"L8." 10570 sound 2,"L8." 10580 sound 3,"L8." 10590 play 1,2,3 10600 return 11000 '=========== GAME OVER ============= 11005 if MinHiScore0 11290 end while 11295 sleep 1000 11300 '----- NEW GAME ------- 11310 gameOver=0:gameClear=0:Stage=1:Score=0 11320 return 11500 '=========== HIGH SCORE ============= 11510 for i=0 to HighScoreNum-1 11520 if HighScore[i]0 11810 end while 11820 sleep 1000 11830 '----- NEW GAME ------- 11840 gameOver=0:gameClear=0:Stage=1:Score=0 11850 return 12000 '=========== STAGE CLEAR ============= 12100 '----- MAKE SCREEN ------- 12110 cls 12120 Title="STAGE CLEAR" 12130 Comment="Score: "+format("%-5D",Score) 12140 TitleX=(ScreenWidth-strlen(Title)*FontWidth)/2 12150 TitleY=(ScreenHight-2*FontWidth)/3 12160 putStr TitleX,TitleY,Title,1 12170 CommentX=(ScreenWidth-strlen(Comment)*FontWidth)/2 12180 putStr CommentX,TitleY*2,Comment,1 12190 '----- SOUND ------- 12200 S11="T580L12G3C4E4G4C5E5L4G5E5_L12G#3C4D#4G#4C5D#5L4G#5E5_" 12205 S12="T580L12A#3D4F4A#4D5F5L4A#5L12A#5A#5A#5_L1C6_L4." 12210 S21="T580L4.L12.G3C4L4.C4_L4.L12.G3C4L4.C4_" 12215 S22="T580L4.L12.B3D4L4.L12D3D3D3_L1C3_L4." 12230 S31="T580L12C3E3G3C4E4G4L4E4G4_L12C3D#3F#3C4D#4F#4L4E4A4_" 12235 S32="T580L12D3F3A#3D4F4A#4L4F4L12D4D4D4_L1C4_L4." 12240 sound 1,S11+S12 12250 sound 2,S21+S22 12260 sound 3,S31+S32 12270 play 1,2,3 12280 while sound1status()<>0 12290 end while 12295 sleep 1000 12300 '----- NEW STAGE ------- 12310 gameClear=0:gameOver=0:Stage=Stage+1 12320 return ***program end***