*********** Space Invaders ************* Code by Fryer E-mail R.Fryer@BTInternet.com Game ideas and testing by Cas Improvements to the game: Improved movement of players ship (slightly harder, looks better) Invaders can dive down the screen (Start diving on the 2nd/3rd level) Extra life every 1000 bug fixed (dont have to get exactly 1000/2000 etc) Reduced Slowdown on higher levels (i hope, havn't seen any yet) Pause/Exit game option added (some say u should have a way to quit) Diving invaders home in on player (and return to origional position) Controls: D-pad Left/Right X - Fire/Start game(continue when game paused) O - Exit to editor when game paused Start - Pause game Scores: Blue - 10 pts Red - 20 pts If invader is diving down screen add 20 pts Bonus ship - 100 pts Extra life every 1000 pts *******************The Code****************** OPEN WINDOW 640,512 DIM as(40),sx(100),sy(100),dropx(20),dropy(20),drop(20) setup() LABEL loop SETDISPBUF ss CLEAR WINDOW j=PEEK("port1") IF os=0 THEN xmax=0 xmin=640 count=0 SETRGB 1,200,0,0 SETRGB 2,200,0,200 SETRGB 3,200,0,200 FOR y=1 TO 4 IF y=2 SETRGB 1,0,0,200 FOR x=1 TO 8 xy=x+y*8 c=as(xy) IF c>0 THEN ax=60*x+xoffset IF c>1 THEN as(xy)=as(xy)+10 mad=12 IF y=1 THEN SETRGB 1,200-c,0,0 ELSE SETRGB 1,0,0,200-c END IF SETRGB 2,200-c,0,200-c SETRGB 3,200-c,0,200-c ELSE mad=0 xmax=max(ax,xmax) xmin=min(ax,xmin) END IF ax=ax+RAN(mad) ay=40*y+yoffset+RAN(mad) IF diver=xy THEN bomb=INT(RAN(40)) ay=ay+dive ax=ax+dxoff IF axsx dxoff=dxoff-1 IF dxoff>0 dxoff=MIN(dxoff,512-dive) IF dxoff<0 dxoff=MAX(dxoff,dive-512) IF ay>512 ay=ay-512 IF ABS(sx-ax)<10 AND ay>400 AND ay<450 AND shipstatus=0 shipstatus=2 ELSE ay=ay-c bomb=INT(RAN(200)) IF shipstatus=0 AND lives>0 THEN IF (ABS(sx-ax)<10 AND ay>400) OR ay>450 THEN shipstatus=2 lives=1 END IF END IF END IF IF ABS(mx-ax)<20 AND ABS(my-ay)<6 AND mf=1 and c=1 THEN mf=0 my=400 as(xy)=2 oldscore=score IF y=1 score=score+20 IF y>1 score=score+10 IF diver=xy score=score+20 IF INT(score/1000)>INT(oldscore/1000) lives=lives+1 END IF GTRIANGLE ax,ay-10 TO ax-20,ay TO ax+20,ay GTRIANGLE ax-20,ay TO ax-15,ay TO ax-legs,ay+10 GTRIANGLE ax+20,ay TO ax+15,ay TO ax+legs,ay+10 IF c>1 THEN IF y=1 THEN SETRGB 1,200,0,0 ELSE SETRGB 1,0,0,200 END IF SETRGB 2,200,0,200 SETRGB 3,200,0,200 END IF IF c>150 as(xy)=0 count=count+1 dv=INT(RAN(1000) IF diver=0 AND dv=50 AND score>420 THEN dxoff=0 diver=xy dive=0 END IF IF bomb=20 AND drop(drop)=0 AND shipstatus=0 AND ay>0 THEN drop(drop)=1 dropx(drop)=ax dropy(drop)=ay+10 drop=drop+1 IF drop>dropmax drop=1 END IF END IF NEXT x NEXT y IF diver>0 dive=dive+ymove IF dive>512 diver=0 IF xmin<40 OR xmax>600 THEN xmove=-xmove IF lives>0 yoffset=yoffset+ymove IF count<20 AND yoffset=34 AND bonus=0 bonus=1 END IF xoffset=xoffset+xmove IF yoffset<0 yoffset=yoffset+ymove legs=legs+legmove IF legs=25 OR legs=10 legmove=-legmove SETRGB 1,255,255,255 FOR i=1 TO dropmax IF drop(i)=1 THEN dx=dropx(i):dy=dropy(i) IF dy>400 AND dy<450 AND ABS(sx-dx)<10 AND shipstatus=0 THEN drop(i)=0 shipstatus=2 END IF LINE dx,dy TO dx,dy-10 dy=dy+6 IF dy>500 THEN drop(i)=0 ELSE dropy(i)=dy END IF END IF NEXT i END IF FOR i=1 TO 100 sy(i)=sy(i)+8 IF sy(i)>512 sy(i)=0 DOT sx(i),sy(i) NEXT i IF bonus>0 THEN SETRGB 1,255*ss,255*ss,255*ss IF bonusflag=0 GTRIANGLE bonus,40 TO bonus-25,50 TO bonus+25,50 IF bonusflag=1 TEXT bonus-20,48,"100" bonus=bonus+3 IF bonus>640 THEN bonus=0 bonusflag=0 END IF IF ABS(mx-bonus)<25 AND ABS(my-50)<5 AND bonusflag=0 THEN oldscore=score score=score+100 IF INT(score/1000)>INT(oldscore/1000) lives=lives+1 bonusflag=1 END IF END IF IF lives>0 THEN SETRGB 3,100,0,0 SETRGB 2,100,0,0 SETRGB 1,0,0,200 FOR i=1 TO lives-1 GTRIANGLE 40+i*12,460 TO 36+i*12,480 TO 44+i*12,480 NEXT i IF shipstatus>0 THEN SETRGB 3,100-shipstatus,0,0 SETRGB 2,100-shipstatus,0,0 shipstatus=shipstatus+2 END IF ox=sx msx=msx+AND(j,32)/16-AND(j,128)/64 msx=MAX(MIN(msx,6),-6) IF msx>0 msx=msx-.66 IF msx<0 msx=msx+.66 IF ABS(msx)>.66 sx=sx+msx sx=MAX(MIN(sx,600),40) o=ox-sx sr=sr+1 IF sr>10 sr=sr-20 SETRGB 1,200,200,0 GTRIANGLE sx,440 TO sx-4-shipstatus,460+ss*6 TO sx+4+shipstatus,460+ss*6 SETRGB 1,0,0,200-shipstatus GTRIANGLE sx,410+shipstatus TO sx+15,450-o TO sx-15,450+o SETRGB 1,0,200-shipstatus*2,0 GTRIANGLE sx,400+shipstatus TO sx-5-ABS(sr),420 TO sx+5+ABS(sr),420 IF shipstatus=100 THEN shipstatus=0 lives=lives-1 sx=320 END IF IF count=0 LEVEL() END IF SETRGB 1,0,255,0 IF lives>0 AND shipstatus=0 THEN IF mf=0 AND AND(j,16384)>0 THEN mf=1 mx=sx my=390 END IF IF mf=0 line sx,400 TO sx,390 END IF IF mf=1 THEN my=my-8 LINE mx,my TO mx,my+10 SETRGB 1,0,120,0 LINE mx,my+10 TO mx,my+30 SETRGB 1,0,50,0 LINE mx,my+30 TO mx,my+50 IF my<8 mf=0 END IF IF lives=0 THEN SETRGB 1,255*ss,255*ss,255*ss IF os=0 THEN TEXT 100,104,"Space Invaders by Fryer Game ideas by Cas" TEXT 150,250,"Press FIRE to play START to exit" END IF IF AND(j,16384)>0 THEN os=1 IF score>hiscore hiscore=score score=0 h$=STR$(hiscore) END IF IF AND(j,16384)=0 AND os=1 THEN os=0 newgame() END IF END IF SETRGB 1,255,255,0 TEXT 100,20,"SCORE:"+STR$(score) TEXT 420,20,"HISCORE:"+h$ SETDRAWBUF ss ss=1-ss IF AND(j,8)=0 GOTO loop TEXT 200,300,"x - continue o - exit" rt=0 LABEL option j=PEEK("port1") IF AND(j,16384)>0 rt=1 IF AND(j,16384)=0 AND rt=1 GOTO loop IF AND(j,8192)>0 END GOTO option SUB newgame() lives=3 sx=320 mf=0 reset() xmove=2 xoffset=40 yoffset=-180 FOR i=1 TO 20 drop(i)=0 NEXT i shipstatus=0 dropmax=2 bonus=0 bonusflag=0 dive=0 diver=0 END SUB SUB level() reset() xmove=ABS(xmove)+.5 dropmax=MIN(dropmax+1,16) xoffset=40 yoffset=-180 diver=0 IF bonusflag=1 THEN bonusflag=0 bonus=0 END IF END SUB SUB setup() reset() FOR i=1 TO 100 sx(i)=RAN(640):sy(i)=RAN(512) NEXT i legs=20 legmove=1 xoffset=40 yoffset=-180 ymove=2 xmove=2 dropmax=0 drop=1 FOR i=1 TO 20 drop(i)=0 NEXT i score=0 hiscore=0 h$=STR$(hiscore) lives=0 sr=0 ss=1 END SUB SUB reset() FOR x=1 TO 8 FOR y=1 TO 4 xy=x+y*8 as(xy)=1 NEXT y NEXT x as(9)=0:as(12)=0:as(13)=0:as(16)=0 END SUB