SYNC ON : SYNC RATE 0 : HIDE MOUSE
SET DISPLAY MODE 320,260,32
 
SET TEXT SIZE 12 : SET TEXT FONT "MT Extra"
SYNC : CENTER TEXT 160,120,"Loading..." : SYNC
 
RANDOMIZE TIMER()
SET IMAGE COLORKEY 0,0,0
 
RETICLE=1
INK 0,0 : BOX 1,1,34,18
INK RGB(0,165,0),0
LINE 12,1,15,4 : LINE 13,1,16,4
LINE 22,1,19,4 : LINE 23,1,20,4
LINE 15,8,13,10 : LINE 16,8,14,10
LINE 19,8,21,10 : LINE 20,8,22,10
INK RGB(0,255,0),0
DOT 7,4 : DOT 8,4 : DOT 9,4
DOT 10,5 : DOT 10,6 : DOT 10,7
DOT 9,8 : DOT 8,8 : DOT 7,8
DOT 6,7 : DOT 6,6 : DOT 6,5
DOT 26,4 : DOT 27,4 : DOT 28,4
DOT 29,5 : DOT 29,6 : DOT 29,7
DOT 28,8 : DOT 27,8 : DOT 26,8
DOT 25,7 : DOT 25,6 : DOT 25,5
DOT 7,12 : DOT 8,12 : DOT 7,13 : DOT 8,13
DOT 27,12 : DOT 28,12 : DOT 27,13 : DOT 28,13
DOT 6,14 : DOT 4,15 : DOT 29,14 : DOT 31,15
DOT 2,16 : DOT 3,16 : DOT 2,17 : DOT 3,17
DOT 32,16 : DOT 33,16 : DOT 32,17 : DOT 33,17
DOT 15,4 : DOT 16,4 : DOT 19,4 : DOT 20,4
DOT 13,10 : DOT 14,10 : DOT 21,10 : DOT 22,10
INK RGB(0,165,0),0
DOT 6,12 : DOT 6,13 : DOT 5,14 : DOT 5,15
DOT 29,12 : DOT 29,13 : DOT 30,14 : DOT 30,15
DOT 2,15 : DOT 3,15 : DOT 4,16 : DOT 4,17
DOT 3,18 : DOT 2,18 : DOT 1,17 : DOT 1,16
DOT 32,15 : DOT 33,15 : DOT 34,16 : DOT 34,17
DOT 33,18 : DOT 32,18 : DOT 31,17 : DOT 31,16
DOT 7,11 : DOT 8,11 : DOT 9,11
DOT 7,14 : DOT 8,14 : DOT 9,14
DOT 9,12 : DOT 10,12 : DOT 10,13 : DOT 9,13
DOT 26,11 : DOT 27,11 : DOT 28,11
DOT 26,14 : DOT 27,14 : DOT 28,14
DOT 25,12 : DOT 26,12 : DOT 26,13 : DOT 25,13
GET IMAGE RETICLE,1,1,34,18,1
 
WALLS=2
INK RGB(200,200,200),0
BOX 1,1,64,64
INK RGB(180,180,180),0
FOR I=1 TO 50
   LINEX=RND(64)
   LINEY1=RND(32)
   LINEY2=RND(32)+LINEY1
   LINE LINEX,LINEY1,LINEX,LINEY2
NEXT I
INK RGB(130,130,130),0
ELLIPSE 32,32,24,24
ELLIPSE 32,32,23,23
INK RGB(255,255,255),0
CIRCLE 32,32,22
GET IMAGE WALLS,1,1,64,64,0
 
PILLAR=3
FOR I=1 TO 64
   FOR J=1 TO 64
      COLR=RND(80)+175
      INK RGB(COLR,COLR,COLR),0
      DOT J,I
   NEXT J
NEXT I
GET IMAGE PILLAR,1,1,64,64,0
 
FLOOR=4
INK RGB(25,40,20),0
BOX 1,1,64,64
FOR I=1 TO 20
   IF RND(1)=1 : INK RGB(60,60,20),0 : ELSE : INK RGB(20,20,60),0 : ENDIF
   DOT RND(64),RND(64)
NEXT I
INK RGB(15,30,15),0
LINE 1,1,1,64 : LINE 22,1,22,64
LINE 44,1,44,64 : LINE 1,20,64,20
LINE 1,42,64,42 : LINE 1,64,64,64
GET IMAGE FLOOR,1,1,64,64,0
 
EXPLODE=5
SET IMAGE COLORKEY 255,0,255
INK RGB(255,0,255),0
BOX 1,1,32,32
INK RGB(180,180,0),0
FOR I=1 TO 16 STEP 2
   CIRCLE 16,16,I
NEXT I
GET IMAGE EXPLODE,1,1,32,32,0
 
MakeDrone("Class1",1,-30,0,0)
MakeDrone("Class1",2,30,0,-20)
MakeDrone("Class1",3,0,0,30)
 
MAKE OBJECT CYLINDER 4,10 : TEXTURE OBJECT 4,PILLAR : POSITION OBJECT 4,30,0,30
SET OBJECT COLLISION ON 4
 
MAKE OBJECT BOX 5,150,1,150 : TEXTURE OBJECT 5,FLOOR : POSITION OBJECT 5,0,5.5,0
SET OBJECT COLLISION ON 5
 
MAKE OBJECT BOX 6,1,10,150 : TEXTURE OBJECT 6,WALLS : POSITION OBJECT 6,-75.5,0,0
SET OBJECT COLLISION ON 6
 
MAKE OBJECT BOX 7,1,10,150 : TEXTURE OBJECT 7,WALLS : POSITION OBJECT 7,75.5,0,0
SET OBJECT COLLISION ON 7
 
MAKE OBJECT BOX 8,150,10,1 : TEXTURE OBJECT 8,WALLS : POSITION OBJECT 8,0,0,75.5
SET OBJECT COLLISION ON 8
 
MAKE OBJECT BOX 9,150,10,1 : TEXTURE OBJECT 9,WALLS : POSITION OBJECT 9,0,0,-75.5
SET OBJECT COLLISION ON 9
 
MAKE OBJECT BOX 10,150,1,150 : TEXTURE OBJECT 10,FLOOR : POSITION OBJECT 10,0,-5.5,0
SET OBJECT COLLISION ON 10
 
MAKE OBJECT CYLINDER 11,10 : TEXTURE OBJECT 11,PILLAR : POSITION OBJECT 11,-30,0,30
SET OBJECT COLLISION ON 11
 
MAKE OBJECT CYLINDER 12,10 : TEXTURE OBJECT 12,PILLAR : POSITION OBJECT 12,-30,0,-30
SET OBJECT COLLISION ON 12
 
MAKE OBJECT CYLINDER 13,10 : TEXTURE OBJECT 13,PILLAR : POSITION OBJECT 13,30,0,-30
SET OBJECT COLLISION ON 13
 
GLOBAL EXPO=1
MAKE PARTICLES EXPO,EXPLODE,1,3
HIDE PARTICLES EXPO
SET PARTICLE GRAVITY EXPO,10
SET PARTICLE VELOCITY EXPO,0
SET PARTICLE LIFE EXPO,20
 
GLOBAL PLR=14 : GLOBAL PLRX#=0.0 : GLOBAL PLRY#=0.0
GLOBAL PLRZ#=-30.0 : GLOBAL PLRA#=0.0 : GLOBAL HOVER#=90.0
GLOBAL SCORE=0 : GLOBAL SHIELDS=100 : GLOBAL ENERGY=100
GLOBAL CONCS=8 : THEIGHT=TEXT HEIGHT("ANYTHING")
GLOBAL LASER$="LASER LEVEL 1" : GLOBAL LASERS=2
GLOBAL PLRSHOT=800 : GLOBAL DRONESHOT=120 : GLOBAL PLRCONCS=1200
GLOBAL DEADZONE=TIMER() : GLOBAL CONCZONE=TIMER()
GLOBAL BOMBTIME=TIMER() : GLOBAL CONCSIDE=1
 
MAKE OBJECT CUBE PLR,5
SET OBJECT COLLISION ON PLR
SET OBJECT CULL PLR,1
POSITION OBJECT PLR,PLRX#,PLRY#,PLRZ#
 
INK RGB(0,180,0),0
 
QUADS1=MakePowerup("Quads",-15,0,-10)
ENERGY1=MakePowerup("Energy",0,0,0)
SHIELDS1=MakePowerup("Shields",35,0,-10)
 
TYPE DronesA
   SHOOTING AS INTEGER
   STATE AS INTEGER
   LOS AS INTEGER
   SPEED AS FLOAT
   DAMMAGE AS FLOAT
   INTEGRITY AS FLOAT
   REFLEX AS FLOAT
   DESTX AS FLOAT
   DESTZ AS FLOAT
   XLOCKSTATE AS INTEGER
   ZLOCKSTATE AS INTEGER
ENDTYPE
 
GLOBAL DIM DRONESTAT(3) AS DronesA
FOR I=1 TO 3
   DRONESTAT(I).SHOOTING=0
   DRONESTAT(I).STATE=1
   DRONESTAT(I).LOS=0
   DRONESTAT(I).SPEED=(RND(2)/10)+0.1
   DRONESTAT(I).DAMMAGE=RND(512)/100
   DRONESTAT(I).INTEGRITY=100
   DRONESTAT(I).REFLEX=RND(5)/10
   DRONESTAT(I).DESTX=(RND(80)-40)
   DRONESTAT(I).DESTZ=(RND(80)-40)
   DRONESTAT(I).XLOCKSTATE=0
   DRONESTAT(I).ZLOCKSTATE=0
NEXT I
 
TYPE DroneShot
   SPEED AS FLOAT
   POSX AS FLOAT
   POSY AS FLOAT
   POSZ AS FLOAT
   ANGLE AS FLOAT
ENDTYPE
 
GLOBAL DIM DBULLET(600) AS DroneShot
FOR I=1 TO 600
   DBULLET(I).SPEED=RND(5)/10+0.3
   DBULLET(I).POSX=0.0
   DBULLET(I).POSY=0.0
   DBULLET(I).POSZ=0.0
   DBULLET(I).ANGLE=0.0
NEXT I
 
TYPE PlayerShot
   ID AS INTEGER
   POSX AS FLOAT
   POSY AS FLOAT
   POSZ AS FLOAT
   ANGLE AS FLOAT
ENDTYPE
 
GLOBAL DIM PBULLET(2000) AS PlayerShot
FOR I=800 TO 2000
   PBULLET(I).ID=1
   PBULLET(I).POSX=0.0
   PBULLET(I).POSY=PLRY#
   PBULLET(I).POSZ=0.0
   PBULLET(I).ANGLE=PLRA#
NEXT I
 
DO
   IF KEYSTATE(32)=1
      PLRX#=NEWXVALUE(PLRX#,PLRA#,0.2)
      PLRZ#=NEWZVALUE(PLRZ#,PLRA#,0.2)
   ENDIF
   IF KEYSTATE(18)=1
      PLRX#=NEWXVALUE(PLRX#,PLRA#,-0.2)
      PLRZ#=NEWZVALUE(PLRZ#,PLRA#,-0.2)
   ENDIF
   IF KEYSTATE(42)=1
      PLRX#=NEWXVALUE(PLRX#,WRAPVALUE(PLRA#-90),0.2)
      PLRZ#=NEWZVALUE(PLRZ#,WRAPVALUE(PLRA#-90),0.2)
   ENDIF
   IF KEYSTATE(33)=1
      PLRX#=NEWXVALUE(PLRX#,WRAPVALUE(PLRA#+90),0.2)
      PLRZ#=NEWZVALUE(PLRZ#,WRAPVALUE(PLRA#+90),0.2)
   ENDIF
   IF KEYSTATE(17)=1 THEN INC PLRY#,0.15
   IF KEYSTATE(46)=1 THEN DEC PLRY#,0.15
 
   IF MOUSECLICK()=1 THEN Shooting(1)
   IF MOUSECLICK()=2 THEN Shooting(2)
   IF MOUSECLICK()=3 THEN Shooting(1) : Shooting(2)
 
   PLRA#=WRAPVALUE(PLRA#+(MOUSEMOVEX()*0.2))
 
   INC HOVER#,3
   HOVER#=WRAPVALUE(HOVER#)
   PLRY#=PLRY#+(SIN(HOVER#)/33)
 
   POSITION OBJECT PLR,PLRX#,PLRY#,PLRZ#
   YROTATE OBJECT PLR,PLRA#
 
   SlidingCollision()
   FOR I=800 TO 2000 : HandlePlayerBullets(I) : NEXT I
   FOR I=120 TO 790 : HandleDroneBullets(I) : NEXT I
   FOR I=1 TO 3
      IF OBJECT EXIST(I)=1 THEN HandleDrone(I)
   NEXT I
 
   `IF OBJECT EXIST(1)=0 AND OBJECT EXIST(2)=0 AND OBJECT EXIST(3)=0 THEN Ending()
 
   IF OBJECT EXIST(QUADS1)=1 THEN YROTATE OBJECT QUADS1,OBJECT ANGLE Y(QUADS1)+2.5
   IF OBJECT EXIST(QUADS1)=1 THEN IF OBJECT COLLISION(PLR,QUADS1)=1 THEN GotItem("Quads")
   IF OBJECT EXIST(ENERGY1)=1 THEN YROTATE OBJECT ENERGY1,OBJECT ANGLE Y(ENERGY1)+5
   IF OBJECT EXIST(ENERGY1)=1 THEN IF OBJECT COLLISION(PLR,ENERGY1)=1 THEN GotItem("Energy")
   IF OBJECT EXIST(SHIELDS1)=1 THEN IF OBJECT COLLISION(PLR,SHIELDS1)=1 THEN GotItem("Shields")
 
   SET CAMERA TO OBJECT ORIENTATION PLR
   POSITION CAMERA PLRX#,PLRY#,PLRZ#
 
   TEXT SCREEN WIDTH()-(TEXT WIDTH("SCORE: "+STR$(SCORE))+5),5,"SCORE: "+STR$(SCORE)
   TEXT 5,SCREEN HEIGHT()-(TEXT HEIGHT("ANYTHING")*2),"SHIELDS: "+STR$(SHIELDS)
   TEXT 5,SCREEN HEIGHT()-TEXT HEIGHT("ANYTHING"),"ENERGY: "+STR$(ENERGY)
   TEXT SCREEN WIDTH()-(TEXT WIDTH(LASER$)+5),SCREEN HEIGHT()-(THEIGHT*2),LASER$
   TEXT SCREEN WIDTH()-(TEXT WIDTH("0 CONCSN MISSLES")+5),SCREEN HEIGHT()-THEIGHT,STR$(CONCS)+" CONCSN MISSLES"
 
   PASTE IMAGE RETICLE,(SCREEN WIDTH()/2)-17,(SCREEN HEIGHT()/2)-9,1
 
   SYNC
LOOP
 
FUNCTION SlidingCollision()
   W=OBJECT COLLISION(PLR,0)
   IF W>0
      IF ABS(PLRX#-OBJECT POSITION X(W))<OBJECT SIZE X(W)/2
         IF ABS(PLRY#-OBJECT POSITION Y(W))<OBJECT SIZE Y(W)/2
            IF PLRZ#<OBJECT POSITION Z(W) THEN DEC PLRZ#,0.20000000000000000000000001
            IF PLRZ#>OBJECT POSITION Z(W) THEN INC PLRZ#,0.20000000000000000000000001
         ENDIF
      ENDIF
      IF ABS(PLRZ#-OBJECT POSITION Z(W))<OBJECT SIZE Z(W)/2
         IF ABS(PLRY#-OBJECT POSITION Y(W))<OBJECT SIZE Y(W)/2
            IF PLRX#<OBJECT POSITION X(W) THEN DEC PLRX#,0.20000000000000000000000001
            IF PLRX#>OBJECT POSITION X(W) THEN INC PLRX#,0.20000000000000000000000001
         ENDIF
      ENDIF
      IF ABS(PLRX#-OBJECT POSITION X(W))<(OBJECT SIZE X(W)/2)-0.1 AND ABS(PLRZ#-OBJECT POSITION Z(W))<(OBJECT SIZE Z(W)/2)-0.1
         IF PLRY#>OBJECT POSITION Y(W) THEN INC PLRY#,0.15000000000000000000000001
         IF PLRY#<OBJECT POSITION Y(W) THEN DEC PLRY#,0.15000000000000000000000001
      ENDIF
   ENDIF
ENDFUNCTION
 
FUNCTION Shooting(m)
   IF m=1
      IF ENERGY>0
         IF TIMER()-DEADZONE>=300
            IF LASERS=2 THEN MakeFlack("Laser")
            IF LASERS=4 THEN MakeFlack("Quads")
            DEC ENERGY : DEADZONE=TIMER()
         ENDIF
      ELSE
         PostMessage("ENERGY DEPLETED")
      ENDIF
   ENDIF
   IF m=2
      IF CONCS>0
         IF TIMER()-CONCZONE>=500 THEN MakeFlack("Conc") : DEC CONCS : CONCZONE=TIMER()
      ELSE
         PostMessage("CONCUSSION MISSLES DEPLETED")
      ENDIF
   ENDIF
ENDFUNCTION
 
FUNCTION PostMessage(m$)
   CENTER TEXT SCREEN WIDTH()/2,5,m$
ENDFUNCTION
 
FUNCTION MakeDrone(d$,ObNum,dX#,dY#,dZ#)
   SELECT d$
      CASE "Class1"
         MAKE OBJECT SPHERE ObNum,4.5
         COLOR OBJECT ObNum,RGB(200,50,0)
         SCALE OBJECT ObNum,70,40,100
         MAKE OBJECT CONE (ObNum+1),5
         XROTATE OBJECT (ObNum+1),-90
         SCALE OBJECT (ObNum+1),80,70,60
         MAKE MESH FROM OBJECT 1,ObNum+1
         DELETE OBJECT (ObNum+1)
         ADD LIMB ObNum,1,1
         DELETE MESH 1
         OFFSET LIMB ObNum,1,0,0,-3
         COLOR LIMB ObNum,1,RGB(200,50,0)
         SET LIMB SMOOTHING ObNum,1,100
         MAKE OBJECT CYLINDER (ObNum+1),1
         SCALE OBJECT (ObNum+1),100,200,100
         ZROTATE OBJECT (ObNum+1),-105
         MAKE MESH FROM OBJECT 1,(ObNum+1)
         DELETE OBJECT (ObNum+1)
         ADD LIMB ObNum,2,1
         DELETE MESH 1
         OFFSET LIMB ObNum,2,2.7,-1,0.5
         COLOR LIMB ObNum,2,RGB(50,50,50)
         MAKE OBJECT CYLINDER (ObNum+1),1
         SCALE OBJECT (ObNum+1),100,200,100
         ZROTATE OBJECT (ObNum+1),-255
         MAKE MESH FROM OBJECT 1,ObNum+1
         DELETE OBJECT (ObNum+1)
         ADD LIMB ObNum,3,1
         DELETE MESH 1
         OFFSET LIMB ObNum,3,-2.7,-1,0.5
         COLOR LIMB ObNum,3,RGB(50,50,50)
         MAKE OBJECT CONE (ObNum+1),2
         XROTATE OBJECT (ObNum+1),-90
         MAKE MESH FROM OBJECT 1,(ObNum+1)
         DELETE OBJECT (ObNum+1)
         ADD LIMB ObNum,4,1
         DELETE MESH 1
         OFFSET LIMB ObNum,4,3.5,-1.25,0.5
         COLOR LIMB ObNum,4,RGB(200,50,0)
         MAKE OBJECT CONE (ObNum+1),2
         XROTATE OBJECT (ObNum+1),-90
         MAKE MESH FROM OBJECT 1,(ObNum+1)
         DELETE OBJECT (ObNum+1)
         ADD LIMB ObNum,5,1
         DELETE MESH 1
         OFFSET LIMB ObNum,5,-3.5,-1.25,0.5
         COLOR LIMB ObNum,5,RGB(200,50,0)
         SET OBJECT CULL ObNum,0
      ENDCASE
   ENDSELECT
   POSITION OBJECT ObNum,dX#,dY#,dZ#
   SET OBJECT COLLISION ON ObNum
ENDFUNCTION
 
FUNCTION MakeFlack(f$)
   Flack=GetFreeBullet(800)
   Flacky=Flack+1
   SELECT f$
      CASE "Laser"
         INC PLRSHOT
         MAKE OBJECT SPHERE Flack,0.5,2,4
         MAKE OBJECT SPHERE Flacky,0.5,2,4
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,1,1
         DELETE MESH 1
         OFFSET LIMB Flack,1,3,0,0
         COLOR LIMB Flack,1,RGB(255,0,0)
         COLOR OBJECT Flack,RGB(255,0,0)
         SET OBJECT DIFFUSE Flack,RGB(255,0,0)
         SET OBJECT EMISSIVE Flack,RGB(160,0,0)
         SET OBJECT SPECULAR Flack,RGB(255,255,0)
         SCALE OBJECT Flack,100,100,1000
         PBULLET(Flack).ID=1
         PBULLET(Flack).ANGLE=OBJECT ANGLE Y(PLR)
         PBULLET(Flack).POSX=OBJECT POSITION X(PLR)
         PBULLET(Flack).POSY=OBJECT POSITION Y(PLR)
         PBULLET(Flack).POSZ=OBJECT POSITION Z(PLR)
         YROTATE OBJECT Flack,PBULLET(Flack).ANGLE
         POSITION OBJECT Flack,PBULLET(Flack).POSX,PBULLET(Flack).POSY,PBULLET(Flack).POSZ
         MOVE OBJECT Flack,OBJECT SIZE Z(Flack)/2
         MOVE OBJECT LEFT Flack,1.8
      ENDCASE
      CASE "Quads"
         INC PLRSHOT
         MAKE OBJECT SPHERE Flack,0.5,2,4
         MAKE OBJECT SPHERE Flacky,0.5,2,4
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,1,1
         DELETE MESH 1
         OFFSET LIMB Flack,1,3,0,0
         COLOR LIMB Flack,1,RGB(255,0,0)
         MAKE OBJECT SPHERE Flacky,0.5,2,4
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,2,1
         DELETE MESH 1
         OFFSET LIMB Flack,2,5,-1,0.2
         COLOR LIMB Flack,2,RGB(255,0,0)
         MAKE OBJECT SPHERE Flacky,0.5,2,4
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,3,1
         DELETE MESH 1
         OFFSET LIMB Flack,3,-2,-1,0.2
         COLOR LIMB Flack,3,RGB(255,0,0)
         COLOR OBJECT Flack,RGB(255,0,0)
         SET OBJECT DIFFUSE Flack,RGB(255,0,0)
         SET OBJECT EMISSIVE Flack,RGB(160,0,0)
         SET OBJECT SPECULAR Flack,RGB(255,255,0)
         SCALE OBJECT Flack,100,100,1000
         PBULLET(Flack).ID=1
         PBULLET(Flack).ANGLE=OBJECT ANGLE Y(PLR)
         PBULLET(Flack).POSX=OBJECT POSITION X(PLR)
         PBULLET(Flack).POSY=OBJECT POSITION Y(PLR)
         PBULLET(Flack).POSZ=OBJECT POSITION Z(PLR)
         YROTATE OBJECT Flack,PBULLET(Flack).ANGLE
         POSITION OBJECT Flack,PBULLET(Flack).POSX,PBULLET(Flack).POSY,PBULLET(Flack).POSZ
         MOVE OBJECT Flack,OBJECT SIZE Z(Flack)/2
         MOVE OBJECT LEFT Flack,1.8
      ENDCASE
      CASE "Conc"
         MAKE OBJECT PLAIN Flack,0.1,0.1
         MAKE OBJECT CYLINDER Flacky,0.5
         XROTATE OBJECT Flacky,90
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,1,1
         DELETE MESH 1
         COLOR LIMB Flack,1,RGB(160,160,160)
         MAKE OBJECT CONE Flacky,0.7
         SCALE OBJECT Flacky,100,150,100
         XROTATE OBJECT Flacky,90
         MAKE MESH FROM OBJECT 1,Flacky
         DELETE OBJECT Flacky
         ADD LIMB Flack,2,1
         DELETE MESH 1
         OFFSET LIMB Flack,2,0,0,1
         COLOR LIMB Flack,2,RGB(160,160,160)
         SET OBJECT CULL Flack,0
         PBULLET(Flack).ID=2
         PBULLET(Flack).ANGLE=OBJECT ANGLE Y(PLR)
         PBULLET(Flack).POSX=OBJECT POSITION X(PLR)
         PBULLET(Flack).POSY=OBJECT POSITION Y(PLR)+1
         PBULLET(Flack).POSZ=OBJECT POSITION Z(PLR)
         YROTATE OBJECT Flack,PBULLET(Flack).ANGLE
         POSITION OBJECT Flack,PBULLET(Flack).POSX,PBULLET(Flack).POSY,PBULLET(Flack).POSZ
         MOVE OBJECT Flack,OBJECT SIZE Z(Flack)/2
         IF CONCSIDE=1 THEN MOVE OBJECT LEFT Flack,2
         IF CONCSIDE=2 THEN MOVE OBJECT RIGHT Flack,2
         CONCSIDE=CONCSIDE*-1
         INC CONCSIDE,3
      ENDCASE
   ENDSELECT
   SET OBJECT COLLISION ON Flack
ENDFUNCTION Flack
 
FUNCTION MakePowerup(t$,tX#,tY#,tZ#)
   ItmNum=0
   FOR I=1 TO 9999 STEP 2
      IF OBJECT EXIST(I)<>1 THEN ItmNum=I
      IF ItmNum<>0 THEN BREAK
   NEXT I
   SELECT t$
      CASE "Quads"
         MAKE OBJECT BOX ItmNum,1.5,0.125,0.75
         COLOR OBJECT ItmNum,RGB(50,50,50)
         MAKE OBJECT BOX (ItmNum+1),1.5,0.125,1
         ZROTATE OBJECT (ItmNum+1),45
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,1,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,1,-1,-0.5,0
         COLOR LIMB ItmNum,1,RGB(50,50,50)
         MAKE OBJECT BOX (ItmNum+1),1.5,0.125,1
         ZROTATE OBJECT (ItmNum+1),-45
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,2,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,2,1,-0.5,0
         COLOR LIMB ItmNum,2,RGB(50,50,50)
         MAKE OBJECT CYLINDER (ItmNum+1),1.3
         SCALE OBJECT (ItmNum+1),20,120,20
         XROTATE OBJECT (ItmNum+1),90
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,3,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,3,-1,-0.5,-0.45
         COLOR LIMB ItmNum,3,RGB(50,50,50)
         MAKE OBJECT CYLINDER (ItmNum+1),1.3
         SCALE OBJECT (ItmNum+1),20,120,20
         XROTATE OBJECT (ItmNum+1),90
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,4,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,4,-1.5,-0.95,-0.45
         COLOR LIMB ItmNum,4,RGB(50,50,50)
         MAKE OBJECT CYLINDER (ItmNum+1),1.3
         SCALE OBJECT (ItmNum+1),20,120,20
         XROTATE OBJECT (ItmNum+1),90
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,5,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,5,1,-0.5,-0.45
         COLOR LIMB ItmNum,5,RGB(50,50,50)
         MAKE OBJECT CYLINDER (ItmNum+1),1.3
         SCALE OBJECT (ItmNum+1),20,120,20
         XROTATE OBJECT (ItmNum+1),90
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,6,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,6,1.5,-0.95,-0.45
         COLOR LIMB ItmNum,6,RGB(50,50,50)
         SET OBJECT CULL ItmNum,0
      ENDCASE
      CASE "Energy"
         MAKE OBJECT SPHERE ItmNum,1,2,4
         SCALE OBJECT ItmNum,200,200,100
         COLOR OBJECT ItmNum,RGB(255,255,0)
         MAKE OBJECT SPHERE (ItmNum+1),0.3,2,4
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,1,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,1,0.7,0.7,0
         COLOR LIMB ItmNum,1,RGB(255,255,0)
         MAKE OBJECT SPHERE (ItmNum+1),0.3,2,4
         MAKE MESH FROM OBJECT 1,(ItmNum+1)
         DELETE OBJECT (ItmNum+1)
         ADD LIMB ItmNum,2,1
         DELETE MESH 1
         OFFSET LIMB ItmNum,2,-0.7,0.7,0
         COLOR LIMB ItmNum,2,RGB(255,255,0)
      ENDCASE
      CASE "Shields"
         MAKE OBJECT SPHERE ItmNum,3,6,12
         COLOR OBJECT ItmNum,RGB(0,0,255)
         SET OBJECT DIFFUSE ItmNum,RGB(0,0,255)
         SET OBJECT EMISSIVE ItmNum,RGB(0,0,150)
         SET OBJECT SPECULAR ItmNum,RGB(255,255,255)
      ENDCASE
   ENDSELECT
   POSITION OBJECT ItmNum,tX#,tY#,tZ#
   XROTATE OBJECT ItmNum,350
ENDFUNCTION ItmNum
 
FUNCTION HandleDrone(r)
   rx#=OBJECT POSITION X(r)
   ry#=OBJECT POSITION Y(r)
   rz#=OBJECT POSITION Z(r)
   ra#=OBJECT ANGLE Y(r)
 
   IF OBJECT EXIST(100+r)<>1
      MAKE OBJECT CUBE (100+r),1
      HIDE OBJECT (100+r)
      SET OBJECT COLLISION OFF (100+r)
   ENDIF
   IF OBJECT EXIST(100+r)=1
      POSITION OBJECT (100+r),rx#,ry#,rz#
      YROTATE OBJECT (100+r),ra#
      MOVE OBJECT (100+r),50
   ENDIF
 
   rsx#=OBJECT POSITION X(100+r)
   rsz#=OBJECT POSITION Z(100+r)
 
   DRONESTAT(r).LOS=INTERSECT OBJECT(PLR,rsx#,ry#,rsz#,rx#,ry#,rz#)
   DRONESTAT(r).SPEED=(RND(2)/10)+0.1
 
   IF ABS(PLRX#-rx#)<20 AND ABS(PLRZ#-rz#)<10
      DRONESTAT(r).STATE=3
   ELSE
      DRONESTAT(r).STATE=1
   ENDIF
 
   SELECT DRONESTAT(r).STATE
      CASE 1
         IF RND(60)=2
            DRONESTAT(r).DESTX=rx#+(RND(50)-25)
            DRONESTAT(r).DESTZ=rz#+(RND(50)-25)
         ENDIF
         DRONESTAT(r).SHOOTING=0
      ENDCASE
 
      CASE 2
         DRONESTAT(r).DESTX=NEWXVALUE(rx#,WRAPVALUE(PLRA#*-1),DRONESTAT(r).SPEED)
         DRONESTAT(r).DESTZ=NEWZVALUE(rz#,WRAPVALUE(PLRA#*-1),DRONESTAT(r).SPEED)
         DRONESTAT(r).SHOOTING=0
      ENDCASE
 
      CASE 3
         DRONESTAT(r).DESTX=PLRX#
         DRONESTAT(r).DESTZ=PLRZ#
         DRONESTAT(r).SHOOTING=1
      ENDCASE
   ENDSELECT
 
   IF DRONESTAT(r).LOS <> 0
      DRONESTAT(r).STATE=3
      DRONESTAT(r).SHOOTING=1
   ELSE
      DRONESTAT(r).STATE=1
      DRONESTAT(r).SHOOTING=0
   ENDIF
 
   IF OBJECT COLLISION(r,0)<>0
      w=OBJECT COLLISION(r,0)
      wx#=OBJECT POSITION X(w)
      wz#=OBJECT POSITION Z(w)
      wsx#=OBJECT SIZE X(w)
      wsz#=OBJECT SIZE Z(w)
      IF ABS(rx#-wx#)<wsx#/2
         IF rz#>wz#
            IF ra#>=90 AND ra#<=270
               DRONESTAT(r).ZLOCKSTATE=1
            ELSE
               DRONESTAT(r).ZLOCKSTATE=0
            ENDIF
         ENDIF
         IF rz#<wz#
            IF ra#>=270 OR ra#<=90
               DRONESTAT(r).ZLOCKSTATE=1
            ELSE
               DRONESTAT(r).ZLOCKSTATE=0
            ENDIF
         ENDIF
      ENDIF
      IF ABS(rz#-wz#)<wsz#/2
         IF rx#>wx#
            IF ra#>=180
               DRONESTAT(r).XLOCKSTATE=1
            ELSE
               DRONESTAT(r).XLOCKSTATE=0
            ENDIF
         ENDIF
         IF rx#<wx#
            IF ra#>=0 AND ra#<=180
               DRONESTAT(r).XLOCKSTATE=1
            ELSE
               DRONESTAT(r).XLOCKSTATE=0
            ENDIF
         ENDIF
      ENDIF
      POSITION OBJECT r,rx#,OBJECT POSITION Y(r),rz#
   ELSE
      DRONESTAT(r).XLOCKSTATE=0
      DRONESTAT(r).ZLOCKSTATE=0
   ENDIF
 
   IF OBJECT EXIST(110+r)<>1
      MAKE OBJECT PLAIN (110+r),1,1
      HIDE OBJECT (110+r)
      SET OBJECT COLLISION OFF (110+r)
   ENDIF
 
   POSITION OBJECT (110+r),DRONESTAT(r).DESTX,ry#,DRONESTAT(r).DESTZ
   POINT OBJECT (110+r),rx#,ry#,rz# : YROTATE OBJECT (110+r),WRAPVALUE(OBJECT ANGLE Y(110+r)*-1)
 
   ra#=CURVEANGLE(OBJECT ANGLE Y(110+r),ra#,100)
 
   ra#=WRAPVALUE(ra#)
   IF DRONESTAT(r).XLOCKSTATE=0 THEN rx#=NEWXVALUE(rx#,ra#,DRONESTAT(r).SPEED)
   IF DRONESTAT(r).ZLOCKSTATE=0 THEN rz#=NEWZVALUE(rz#,ra#,DRONESTAT(r).SPEED)
 
   POSITION OBJECT r,rx#,ry#,rz#
   YROTATE OBJECT r,ra#
 
   IF DRONESTAT(r).SHOOTING=1
      IF RND(100)=1 THEN Shoot(r)
   ENDIF
ENDFUNCTION
 
FUNCTION GotItem(i$)
   OK=1
   SELECT i$
      CASE "Quads"
         LASER$="QUAD LASER LEVEL 1"
         LASERS=4
      ENDCASE
      CASE "Energy"
         IF (ENERGY+9)<200
            INC ENERGY,9
         ELSE
            PostMessage("ENERGY LIMIT 200") : OK=0
         ENDIF
      ENDCASE
      CASE "Shields"
         IF (SHIELDS+9)<200
            INC SHIELDS,9
         ELSE
            PostMessage("SHIELDS LIMIT 200") : OK=0
         ENDIF
      ENDCASE
   ENDSELECT
   IF OK=1 THEN DELETE OBJECT OBJECT COLLISION(PLR,0)
ENDFUNCTION
 
FUNCTION Shoot(d)
   IF DRONESHOT<800
      INC DRONESHOT
      p=GetFreeBullet(120)
      pcx1#=LIMB POSITION X(d,4)
      pcy1#=LIMB POSITION Y(d,4)
      pcz1#=LIMB POSITION Z(d,4)
      pcx2#=LIMB POSITION X(d,5)
      pcy2#=LIMB POSITION Y(d,5)
      pcz2#=LIMB POSITION Z(d,5)
      IF OBJECT EXIST(p)<>1
         MAKE OBJECT SPHERE p,2.5,5,5
         COLOR OBJECT p,RGB(255,0,0)
         SET OBJECT EMISSIVE p,RGB(255,0,0)
         SET OBJECT SPECULAR p,RGB(255,60,60)
         SET OBJECT COLLISION ON p
         IF RND(1)=0
            POSITION OBJECT p,pcx1#,pcy1#,pcz1#
         ELSE
            POSITION OBJECT p,pcx2#,pcy2#,pcz2#
         ENDIF
         DBULLET(p).POSX=OBJECT POSITION X(p)
         DBULLET(p).POSY=OBJECT POSITION Y(p)
         DBULLET(p).POSZ=OBJECT POSITION Z(p)
         YROTATE OBJECT p,OBJECT ANGLE Y(d)
      ENDIF
   ENDIF
ENDFUNCTION
 
FUNCTION HandleDroneBullets(p)
   IF OBJECT EXIST(p)=1
      DBULLET(p).ANGLE=OBJECT ANGLE Y(p)
      DBULLET(p).POSX=OBJECT POSITION X(p)
      DBULLET(p).POSY=OBJECT POSITION Y(p)
      DBULLET(p).POSZ=OBJECT POSITION Z(p)
      DBULLET(p).POSX=NEWXVALUE(DBULLET(p).POSX,DBULLET(p).ANGLE,DBULLET(p).SPEED)
      DBULLET(p).POSZ=NEWZVALUE(DBULLET(p).POSZ,DBULLET(p).ANGLE,DBULLET(p).SPEED)
 
      IF OBJECT COLLISION(p,0)<>0 AND OBJECT COLLISION(p,0)<>1 AND OBJECT COLLISION(p,0)<>2 AND OBJECT COLLISION(p,0)<>3
         IF OBJECT COLLISION(p,PLR)=1 THEN DEC SHIELDS,RND(6)+7
         DELETE OBJECT p : DEC DRONESHOT : EXITFUNCTION
      ENDIF
 
      POSITION OBJECT p,DBULLET(p).POSX,DBULLET(p).POSY,DBULLET(p).POSZ
   ENDIF
ENDFUNCTION
 
FUNCTION HandlePlayerBullets(p)
   IF OBJECT EXIST(p)=1
      IF PBULLET(p).ID=1
         IF OBJECT COLLISION(p,0)<>0 AND OBJECT COLLISION(p,0)<>PLR
            IF LASERS=2
               IF OBJECT COLLISION(p,0)=1 OR OBJECT COLLISION(p,0)=2 OR OBJECT COLLISION(p,0)=3
                  IF (DRONESTAT(OBJECT COLLISION(p,0)).INTEGRITY-60)>0
                     DEC DRONESTAT(OBJECT COLLISION(p,0)).INTEGRITY,60
                  ELSE
                     POSITION OBJECT OBJECT COLLISION(p,0),0,50,0
                     INC SCORE,200
                  ENDIF
               ENDIF
            ELSE
               IF OBJECT COLLISION(p,0)=1 OR OBJECT COLLISION(p,0)=2 OR OBJECT COLLISION(p,0)=3
                  POSITION OBJECT OBJECT COLLISION(p,0),0,50,0
                  INC SCORE,200
               ENDIF
            ENDIF
 
            DELETE OBJECT p
            EXITFUNCTION
         ENDIF
 
         MOVE OBJECT p,0.7
      ENDIF
      IF PBULLET(p).ID=2
         IF OBJECT COLLISION(p,0)<>0 AND OBJECT COLLISION(p,0)<>PLR
            IF OBJECT COLLISION(p,0)=1 OR OBJECT COLLISION(p,0)=2 OR OBJECT COLLISION(p,0)=3
               DELETE OBJECT OBJECT COLLISION(p,0)
               INC SCORE,200
            ENDIF
 
            Explosion(OBJECT POSITION X(p),OBJECT POSITION Y(p),OBJECT POSITION Z(p))
            DELETE OBJECT p
            EXITFUNCTION
         ENDIF
 
         MOVE OBJECT p,0.5
      ENDIF
   ENDIF
ENDFUNCTION
 
FUNCTION Explosion(xpos#,ypos#,zpos#)
   SET PARTICLE EMISSIONS EXPO,5
   POSITION PARTICLES EXPO,xpos#,ypos#,zpos#
   IF TIMER()-BOMBTIME>=100 THEN SET PARTICLE EMISSIONS EXPO,0 : BOMBTIME=TIMER()
ENDFUNCTION
 
FUNCTION GetFreeBullet(s)
   Obj=s
   REPEAT
      INC Obj,2
   UNTIL OBJECT EXIST(Obj)=0
ENDFUNCTION Obj