'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'         Blue Meanies By Nick (c) August 2001.
'            A Shockwave/Fanatix program..
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
open window 400,400

  high=15000    : Rem Highscore.
label outerloop
  score=0      : Rem Score.
  plx=320      : Rem Player X Co-ordinate.
  ply=480      : Rem Player Y Co-ordinate.
  dead=3       : Rem Player Lives variable.
  xmove=0      : Rem Inertia movement for player. 
waveclear=1    : Rem generate new attack wave when set.
dim xshot(5)  : Rem player x-bullet.
dim yshot(5)  : Rem player y-bullet.
dim sstat(5)  : Rem player shot status.

dim enstate(8): Rem Enemy alive or dead!
  dim enemx(8): Rem Enemy X position
  dim enemy(8): Rem Enemy Y position
dim efstate(10): Rem Enemy bullet status! 
  dim ebulx(10): Rem Enemy X bullet
  dim ebuly(10): Rem Enemy Y bullet
  dim enh(8)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                    Main Game Loop!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gosub menu

repeat
      setdispbuf dw
      dw=1-dw
      setdrawbuf dw
      clear window
      if waveclear=1 gosub newwave
      gosub background
      if dead>0 gosub joypad
      gosub drawplayerbullets
      gosub drawplayer
      gosub drawenemys
      gosub enemyfire
      gosub playerbulcol   
      if (shock=0) and (dead>0) gosub enemybulcol
      gosub wavecheck   
      gosub scorepannel
      if dead=-1 text 210,240,"GAME UNDER - PRESS (X)"
j=peek("port1")
until ((j=16384) and (dead=-1))
pause 1
goto outerloop


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                   Game Subroutines:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label enemybulcol
for a=1 to 10
 if (efstate(a)>0) and (ebuly(a)>=450) and (ebuly(a)<=480) then
  if (ebulx(a)>=plx) and (ebulx(a)<=plx+30)then
     efstate(a)=0 
     dead=dead-1
     shock=255   
     rdf=255
     grf=255
     blf=255
     a=20
  end if
  
 end if
next a

return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'      Check to see if new attack wave is needed!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label wavecheck
waveclear=1
for a=1 to 8
 if enstate(a)<>300 waveclear=0
next a
if waveclear=1 score=score+500 
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Check for collisions between player bullets and enemys
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label playerbulcol
for a=1 to 5
   if (sstat(a)=1) then 
   for b=1 to 8
    if (enstate(b)<250) and (xshot(a)>=enemx(b)-10) and (xshot(a)<=enemx(b)+20) and (yshot(a)>=enemy(b)-15) and (yshot(a)<=enemy(b)+15) then
  sstat(a)=0
  score=score+10
  enstate(b)=enstate(b)+20
  if enstate(b)>250 score=score+100
  if enstate(b)>250 enstate(b)=340
 end if
   next b
   end if
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'            Enemy Bullet Handling subroutine
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label enemyfire

for a=1 to 8
if enstate(a)<250 then 
  if (enemx(a)>=plx-5) and (enemx(a)<=plx+5) gosub nwes
end if
next a

for a=1 to 10
  if efstate(a)=1 then
    ebuly(a)=ebuly(a)+10
    setrgb 1,ran(250),ran(250),ran(250)
    if ebuly(a)>520 efstate(a)=0
    fill rectangle ebulx(a),ebuly(a) to ebulx(a)+4,ebuly(a)+10
  
  end if
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                     New enemy shot!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label nwes
for b=1 to 10
 if efstate(b)=0 then  
  ebulx(b)=enemx(a)
  ebuly(b)=enemy(a)
  setrgb 1,ran(55),100+ran(155),100+ran(155)
  circle enemx(a),enemy(a)+20,5+ran(30)
  enh(a)=255
  blf=blf+40
  efstate(b)=1
  b=31
 end if
 next b
a=a+20
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                 Set up new attack wave!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label newwave
xdiv=4+ran(4)
ydiv=4+ran(4)
yin=-300
waveclear=0
for a=1 to 8
  enstate(a)=0
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'           Draw And Update Enemy Attack Wave!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label drawenemys
'setrgb 1,0,0,blu*3
setrgb 2,0,0,blu*3
setrgb 3,0,0,100+blu*5
aw=aw+.05
awvex=300+(250*sin(aw/6))
awvey=yin+100+(99*cos(aw/6))
if yin<0 yin=yin+1

for a=1 to 8

 enemx(a)=100*sin(aw+(a*4)/xdiv)+awvex
 enemy(a)=100*sin(aw-(a*4)/ydiv)+awvey
if enstate(a)<250 then
setrgb 1,0,0,blu*3

 gtriangle enemx(a)+20,enemy(a)+15 to enemx(a)-10,enemy(a)+15 to enemx(a)+5,enemy(a)-15
setrgb 1,enstate(a),0,enh(a)
if enh(a)>0 enh(a)=enh(a)-20
 fill rectangle enemx(a),enemy(a) to enemx(a)+10,enemy(a)+10
end if
if enstate(a)>300 then
 setrgb 1,255,255,255 
 fill circle enemx(a),enemy(a),enstate(a)-300
 blf=blf+100
 grf=grf+100
 rdf=rdf+100
 enstate(a)=enstate(a)-5
 
end if
next a

return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   Draws the players bullets and checks if on screen!
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

label drawplayerbullets
for a=1 to 5
  if sstat(a)=1 then
    setrgb 1,40+ran(200),40+ran(200),40+ran(200)
    fill rectangle xshot(a),yshot(a) to xshot(a)+6,yshot(a)+6
    yshot(a)=yshot(a)-15
    if yshot(a)<0 sstat(a)=0
  end if
next a
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   Update player movement variables and read joypad:
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
label joypad
'16384=fire
'32=right
'128=left
ply=480
  if and(peek("port1"),128)=128 xmove=-6 
  if and(peek("port1"),32)=32 xmove=6
  if and(peek("port1"),16384)=16384 and bldelay=0 gosub newbullet
  if bldelay>0 bldelay=bldelay-1
  plx=plx+xmove
  
  if xmove>0 xmove=xmove-1
  if xmove<0 xmove=xmove+1
  
  if plx<20 plx=20
  if plx>585 plx=585
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' See if there are any free player bullets and allocate 1
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
label newbullet
for a=1 to 5
  
  if sstat(a)=0 then 
     setrgb 1,10+ran(200),10+ran(200),10+ran(200)
     circle plx+14,ply-35,6+ran(5)
     xshot(a)=plx+11+ran(2)
     yshot(a)=ply-35
     sstat(a)=1
     bldelay=3
     ply=ply+1+ran(3)
     rdf=rdf+10
     grf=grf+10
     blf=blf+10
     a=11

  end if
next a
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'                 Draw Player 1 Graphic!
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
label drawplayer
    setrgb 1,255,55,255
    setrgb 2,255,55,255
if shock >0 then 
rdf=shock
grf=shock
blf=shock
    setrgb 1,shock,shock,shock
    setrgb 2,shock,shock,shock
end if
if dead>0 then     
    setrgb 3,0,0,0
    gtriangle plx,ply-30 to plx+30,ply-30 to plx+15,ply
    setrgb 1,255,255,255
    fill rectangle plx+10,ply-20 to plx+20,ply-25
end if
if dead=0 then
     fill circle plx,ply,shock
end if
    
    if shock>0 shock=shock-5
    if shock<0 shock=0
    if dead=0 and shock=0 dead=-1
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'           Update Background Plasma colours!
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

label background
   bgnds=bgnds+.1
   red=rdf+(25+25*sin(bgnds/5))
   grn=grf+(20+20*sin(bgnds/7))
   blu=blf+(20+20*sin(bgnds/3))
   if blf>0 blf=0
   if rdf>0 rdf=0
   if grf>0 grf=0
      setrgb 1,red,0,0
      setrgb 2,0,grn,0
      setrgb 3,0,0,blu
     gtriangle 0,0 to 640,520 to 0,520
     gtriangle 0,0 to 640,520 to 640,0 
return

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This simple subroutine just updates the score pannel.
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

label scorepannel
dead2=dead
if score>high high=score
if dead2<0 dead2=0
  setrgb 1,100,255,100
  text 70,500,"SCORE: "+str$(score)+"   HIGHSCORE: "+str$(high)+"   SHIELDS LEFT:"+str$(dead2)

return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Self Contained Menu Subroutine.. The selection Number
' Is returned in the variable CHOICE
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label menu
choice=1
nochoice=1
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'               Variable initialisation:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


mtitle$="BLUE MEANIES! BY SHOCKWAVE/FANATIX"
mxchoice=5 : rem amount of choices possible
delay=4 : rem delay in reading port in frames
ystart=150 : rem position to draw menu from
dim choice$(mxchoice)

'     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'     %% ARRAY DEFINITIONS FOR MENU CHOICES: %%
'     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

choice$(1)="          START NEW GAME!"
choice$(2)="         VIEW INSTRUCTIONS"
choice$(3)="    VIEW HIGH SCORE AND SCORING"

choice$(4)="       VIEW CREDITS+CONTACTS"
choice$(5)="            QUIT  GAME!"

mdb=0
repeat

'Double buffer!

    setdispbuf mdb
    mdb=1-mdb
    setdrawbuf mdb
    clear window

'       %%%%%%%%%%%%%%%%%%%%%
'       %% Draw Background %%
'       %%%%%%%%%%%%%%%%%%%%%

    setrgb 1,0,0,10 
    setrgb 2,0,0,140
    setrgb 3,0,0,140
    gtriangle 0,0 to 640,510 to 0,510
setrgb 2,0,0,10
    gtriangle 0,0 to 640,0 to 640,510
    z=z+5
    if z>=0 z=z-160

    for meb=z to 510 step 160
    for mea=0 to 640 step 160
    setrgb 1,15,15,60+(meb/3)

  fill rectangle mea,meb to mea+80,meb+80 
  fill rectangle mea+80,meb+80 to mea+160,meb+160 

next mea
next meb

'            %%%%%%%%%%%%%%%
'            %% title bar %%
'            %%%%%%%%%%%%%%%

   setrgb 1,0,0,0
   fill rectangle 160,40 to 510,70
   setrgb 1,50,50,100
   fill rectangle 150,30 to 500,60
   setrgb 1,0,0,0
   text 154,54,mtitle$
   setrgb 1,255,255,255
   text 153,49,mtitle$

'        %%%%%%%%%%%%%%%%%%%%%
'        %% DRAW SELECTIONS %%
'        %%%%%%%%%%%%%%%%%%%%%
if nochoice=1 then
myy=ystart
for mea=1 to mxchoice
  setrgb 1,0,0,0
  fill rectangle 160,myy+10 to 510,myy+45
  setrgb 1,50,50,100
  if choice=mea setrgb 1,80,80,130
  fill rectangle 150,myy to 500,myy+35

  setrgb 1,0,0,0
  text 152,myy+23,choice$(mea)

  setrgb 1,155,155,255
  if choice=mea setrgb 1,255,255,255
  text 150,myy+21,choice$(mea)

  myy=myy+58
next mea

'Instructions

setrgb 1,255,255,255
text 147,510,"USE JOYPAD UP DOWN AND (X) TO SELECT"
end if
'Read D-pad

  menjpad=0
  portflag=portflag+1
  if portflag>delay portflag=1
  if portflag=1 menjpad=peek("port1")
if nochoice=1 then
  if menjpad=16 choice=choice-1
  if menjpad=64 choice=choice+1
  if choice<1 choice=1
  if choice>mxchoice choice=mxchoice
end if
if menjpad=16384 nochoice=nochoice+1
if nochoice>1 nochoice=0
if nochoice=0 then
 if choice=2 gosub instructions
 if choice=3 gosub scoring
 if choice=4 gosub credcont
 if choice=5 exit
end if
until ((menjpad=16384) and (choice=1))

return

label instructions

text 140,100,"===== Blue Meanies Instructions ====="
text 140,120,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,140,"USE THE D-PAD LEFT AND RIGHT TO MOVE!"
text 140,160,"USE THE (X) BUTTON  TO  FIRE CANNONS!"
text 140,180,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,200,"ZAP THE BLUE MEANIES!! THEY ARE AFTER"
text 140,220,"YOU, AND THEY ARE TRYING  TO BOMB YOU"
text 140,240,"          OUT OF THE SKY!!!!"
text 140,260,"THIER CRAFT ARE BULLET  PROOF BUT YOU"
text 140,280,"CAN HEAT UP THIER PLASMA BOMB WEAPONS"
text 140,300,"SYSTEM SO IT EXPLODES... THE MORE YOU"
text 140,320,"SHOOT IT THE HOTTER IT WILL GET UNTIL"
text 140,340,"EVENTUALLY... K A B O O M ! ! ! ! ! !"
text 140,360,"YOU HAVE 3 SHIELDS, ONCE THEY ARE ALL"
text 140,380,"       GONE YOU CAN BE KILLED.       "
text 140,400,"  IT TAKES APPROXIMATELY 15 HITS TO  "
text 140,420,"       BLOW UP A BLUE MEANIE!!       "
text 140,460,"ONCE YOU HAVE DESTROYED A WAVE OF THE"
text 140,480," BLUE MEANIES BE CAREFUL AS MORE ARE"
text 140,500," SURE TO COME!!! ( (X) TO GO BACK! )"

return

label scoring

text 140,160,"TODAYS HIGH SCORE IS A WHOPPING "+str$(high)
text 140,200,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,220,"  HERE ARE  THE SCORING  TABLES FOR  "
text 140,240,"            BLUE MEANIES!!           "
text 140,260,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,300,"SCORE ONE HIT:              10 POINTS"
text 140,320,"DESTROY A MEANIE :         100 POINTS"
text 140,340,"DESTROY WHOLE ATTACK WAVE: 500 POINTS"
text 140,380,"         PRESS (X) TO GO BACK"

return

label credcont

text 140,160,"   BLUE MEANIES  WAS PROGRAMED BY:   "
text 140,200,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,220," NICK SIMPSON AKA. SHOCKWAVE/FANATIX "
text 140,240," (C) SEPTEMBER 2001. PUBLIC DOMAIN.. "
text 140,260,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
text 140,300,"IF THIS IS DISTRUBUTED  IN  ANY  WAY,"
text 140,320,"  THE DOCCUMNTATION IS TO REMAIN IN  "
text 140,340,"IT'S ENTIRETY. HERE'S MY EMAIL ADDY:-"
text 140,380,"NICKSIMPSON007@AOL.COM (CODERS ONLY!)"

return

