OPTION explicit

'$include: 'al/al.bi'
'$include: 'al/alut.bi'

declare sub UnloadResources()
DECLARE SUB LineyBorder ()

'OpenAL Stuff
dim shared Buffer as ALuint   ' buffer to hold audio data.
dim shared BufferK as ALuint   ' buffer to hold audio data.
dim shared BufferJ as ALuint   ' buffer to hold audio data.
dim shared BufferH as ALuint   ' buffer to hold audio data.
dim shared BufferX as ALuint   ' buffer to hold audio data.
dim shared Source as ALuint   ' source for the sound to come from.
dim shared SourceK as ALuint   ' source for the sound to come from.
dim shared SourceJ as ALuint   ' source for the sound to come from.
dim shared SourceH as ALuint   ' source for the sound to come from.
dim shared SourceX as ALuint   ' source for the sound to come from.
dim SourcePos(3) as ALfloat   ' 3D position of the sound source.
dim SourceVel(3) as ALfloat   ' 3D velocity of the sound source.
dim SourcePosK(3) as ALfloat   ' 3D position of the sound source.
dim SourceVelK(3) as ALfloat   ' 3D velocity of the sound source.
dim SourcePosJ(3) as ALfloat   ' 3D position of the sound source.
dim SourceVelJ(3) as ALfloat   ' 3D velocity of the sound source.
dim SourcePosH(3) as ALfloat   ' 3D position of the sound source.
dim SourceVelH(3) as ALfloat   ' 3D velocity of the sound source.
dim SourcePosX(3) as ALfloat   ' 3D position of the sound source.
dim SourceVelX(3) as ALfloat   ' 3D velocity of the sound source.
dim ListenerPos(3) as ALfloat ' 3D position of the listener.
dim ListenerVel(3) as ALfloat ' 3D velocity of the listener.
dim ListenerOri(6) as ALfloat ' Listener orientation.

dim wavFormat as ALenum
dim wavSize as ALsizei
dim wavFreq as ALsizei
dim wavData as any ptr
dim wavLoop as ALboolean

dim curPitch as ALfloat

dim done as integer
dim ALy as integer
dim tmr as single
dim kbin as string

'Parsec 2 Stuff
dim shared as double Delay, d, z, y, x, blue, green, red, Tehollo
dim as string yaled, i, a
dim shared as double zlmn, zlmnv, Laser, lql, Sl1, Sl2, Sl3, lqv, lq1
dim shared as double EnemySpeed
dim shared as double Level, Cash, EngineHeat, Dead, Kills, zf, ExL1, ExL2, quitz
dim shared as double UltimateVictory, PassLevel, Shield, NumEnemies, we, wf
dim shared as double ShipX, ShipY, ShipXv, ShipYv, ShipA, ShipAv
dim shared as double Sm, Lb, LaserZ, tq1, tq2, tq3, Sf1, Sf2, r
dim shared as short Temble, ShipASlow, ShipAvSlow

'OpenAL Init
alutInit(0, 0)

alGenBuffers(1, @Buffer)
alGenBuffers(1, @BufferK)
alGenBuffers(1, @BufferJ)
alGenBuffers(1, @BufferH)
alGenBuffers(1, @BufferX)
if alGetError <> AL_NO_ERROR then
   print "failed!"
   alutExit
   end
end if

alutLoadWAVFile("sound/Warp.wav", @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData(Buffer, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV(wavFormat, wavData, wavSize, wavFreq)

alutLoadWAVFile("sound/Shield.wav", @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData(BufferK, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV(wavFormat, wavData, wavSize, wavFreq)

alutLoadWAVFile("sound/Laser.wav", @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData(BufferJ, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV(wavFormat, wavData, wavSize, wavFreq)

alutLoadWAVFile("sound/Hit.wav", @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData(BufferH, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV(wavFormat, wavData, wavSize, wavFreq)

alutLoadWAVFile("sound/Explosion.wav", @wavFormat, @wavData, @wavSize, @wavFreq, @wavLoop)
alBufferData(BufferX, wavFormat, wavData, wavSize, wavFreq)
alutUnloadWAV(wavFormat, wavData, wavSize, wavFreq)

if alGetError <> AL_NO_ERROR then
   print "failed!"
   alutExit
   end
end if

alGenSources(1, @Source)
alGenSources(1, @SourceK)
alGenSources(1, @SourceJ)
alGenSources(1, @SourceH)
alGenSources(1, @SourceX)

if alGetError <> AL_NO_ERROR then
   print "failed!"
   alutExit
   end
end if

' configure source and listener 3-d info.
for z = 0 to 2

 SourcePos(z) = 0.0      ' x
 SourceVel(z) = 0.0      ' x
 SourcePosK(z) = 0.0      ' x
 SourceVelK(z) = 0.0      ' x
 SourcePosJ(z) = 0.0      ' x
 SourceVelJ(z) = 0.0      ' x
 SourcePosH(z) = 0.0      ' x
 SourceVelH(z) = 0.0      ' x
 SourcePosX(z) = 0.0      ' x
 SourceVelX(z) = 0.0      ' x

next z

curPitch = 1.0
alSourcei (Source,   AL_BUFFER,     Buffer)
alSourcef (Source,   AL_PITCH,      curPitch)
alSourcef (Source,   AL_GAIN,       1.0)
alSourcefv(Source,   AL_POSITION,   @SourcePos(0))
alSourcefv(Source,   AL_VELOCITY,   @SourceVel(0))
alSourcei (Source,   AL_LOOPING,    wavLoop)

alSourcei (SourceK,   AL_BUFFER,     BufferK)
alSourcef (SourceK,   AL_PITCH,      curPitch)
alSourcef (SourceK,   AL_GAIN,       1.0)
alSourcefv(SourceK,   AL_POSITION,   @SourcePos(0))
alSourcefv(SourceK,   AL_VELOCITY,   @SourceVel(0))
alSourcei (SourceK,   AL_LOOPING,    wavLoop)

alSourcei (SourceJ,   AL_BUFFER,     BufferJ)
alSourcef (SourceJ,   AL_PITCH,      curPitch)
alSourcef (SourceJ,   AL_GAIN,       1.0)
alSourcefv(SourceJ,   AL_POSITION,   @SourcePos(0))
alSourcefv(SourceJ,   AL_VELOCITY,   @SourceVel(0))
alSourcei (SourceJ,   AL_LOOPING,    wavLoop)

alSourcei (SourceH,   AL_BUFFER,     BufferH)
alSourcef (SourceH,   AL_PITCH,      curPitch)
alSourcef (SourceH,   AL_GAIN,       1.0)
alSourcefv(SourceH,   AL_POSITION,   @SourcePos(0))
alSourcefv(SourceH,   AL_VELOCITY,   @SourceVel(0))
alSourcei (SourceH,   AL_LOOPING,    wavLoop)

alSourcei (SourceX,   AL_BUFFER,     BufferX)
alSourcef (SourceX,   AL_PITCH,      curPitch)
alSourcef (SourceX,   AL_GAIN,       1.0)
alSourcefv(SourceX,   AL_POSITION,   @SourcePos(0))
alSourcefv(SourceX,   AL_VELOCITY,   @SourceVel(0))
alSourcei (SourceX,   AL_LOOPING,    wavLoop)

if alGetError <> AL_NO_ERROR then
   print "failed!"
   UnloadResources
   alutExit
   end
end if

ListenerPos(0) = 0.0    ' x
ListenerPos(1) = 0.0    ' y
ListenerPos(2) = 0.0    ' z

ListenerVel(0) = 0.0    ' x
ListenerVel(1) = 0.0    ' y
ListenerVel(2) = 0.0    ' z

ListenerOri(0) = 0.0    ' at(x)
ListenerOri(1) = 0.0    ' at(y)
ListenerOri(2) = -1.0   ' at(z)
ListenerOri(3) = 0.0    ' up(x)
ListenerOri(4) = 0.0    ' up(y)
ListenerOri(5) = 1.0    ' up(z)

alListenerfv(AL_POSITION, @ListenerPos(0))
alListenerfv(AL_VELOCITY, @ListenerVel(0))
alListenerfv(AL_ORIENTATION, @ListenerOri(0))


if alGetError <> AL_NO_ERROR then
   print "failed!"
   UnloadResources
   alutExit
   end
end if

sub UnloadResources()
   
   alDeleteBuffers(1, @Buffer)
   alDeleteSources(1, @Source)
   alDeleteBuffers(1, @BufferK)
   alDeleteSources(1, @SourceK)
   alDeleteBuffers(1, @BufferJ)
   alDeleteSources(1, @SourceJ)
   alDeleteBuffers(1, @BufferH)
   alDeleteSources(1, @SourceH)
   alDeleteBuffers(1, @BufferX)
   alDeleteSources(1, @SourceX)
   
end sub

Temble = 45

alSourcei(Source, AL_LOOPING, AL_FALSE): alSourcePlay(Source)

Screen 17,8,2,1
setmouse 1,1,0

cls

screenset 1,0

FOR z = 0 TO 63

 blue = INT((1 / 63 * z) * 63)
 green = INT((1 / 63 * z) * 63)
 red = INT((1 / 63 * z) * 63)
 IF Delay >= 0 THEN PALETTE z, 65536 * blue + 256 * green + red

 blue = INT((1 / 63 * z) * 63)
 green = INT((1 / 63 * z) * 12)
 red = INT((1 / 63 * z) * 24)
 IF Delay >= 0 THEN PALETTE z + 64, 65536 * blue + 256 * green + red

 blue = INT((1 / 63 * z) * 15)
 green = INT((1 / 63 * z) * 63)
 red = INT((1 / 63 * z) * 24)
 IF Delay >= 0 THEN PALETTE z + 128, 65536 * blue + 256 * green + red

 blue = INT((1 / 63 * z) * 19)
 green = INT((1 / 63 * z) * 34)
 red = INT((1 / 63 * z) * 56)
 IF Delay >= 0 THEN PALETTE z + 192, 65536 * blue + 256 * green + red

NEXT z

PRINT "* P * A * R * S * E * C * 2 *"
PRINT " (By Jonny Tweed in 2006)"
PRINT
PRINT "  Delay?  (E.g., 1) ";

DIM PRImT$(14)

PRImT$(0) = "Easy Keys:                              "
PRImT$(1) = " Arrow Keys . Thrusters                 "
PRImT$(2) = " Space Bar  . Lasers à                  "
PRImT$(3) = " Enter      . Charge Shields à          "
PRImT$(4) = " Backspace  . Go to the Next Level á    "
PRImT$(5) = " =          . Cool Engines â            "
PRImT$(6) = " p or Pause . Pause                     "
PRImT$(7) = " Escape     . Quits                     "
PRImT$(8) = "                                        "
PRImT$(9) = "Hard Keys:                              "
PRImT$(10) = " Read the instructions...               "
PRImT$(11) = "ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ"
PRImT$(12) = " à   ... Engines may overheat.          "
PRImT$(13) = " á   ... All space mines must be dead.  "
PRImT$(14) = " â   ... Drains shield energy           "

FOR y = 0 TO 14
 FOR x = 1 TO 40
  LOCATE 7 + y, x
  IF MID$(PRImT$(y), x, 1) > CHR$(127) THEN Tehollo = 162 ELSE Tehollo = 215
  IF y = 0 OR y = 9 THEN Tehollo = 50
  IF y = 11 THEN Tehollo = 90
  COLOR Tehollo + x - y * 1.75
  PRINT MID$(PRImT$(y), x, 1);
 NEXT x
NEXT y

LOCATE 4, 21

WHILE i <> CHR$(13)

 FOR x = 0 TO 8 * LEN("* P * A * R * S * E * C * 2 x  ")
  FOR y = 0 TO 16*2
   IF POINT(x, y) > 0 THEN PSET (x, y), 100 + (20 * COS(x + zlmn) * SIN(y))
  NEXT y
 NEXT x

 FOR x = 0 TO 152
  FOR y = 23*2 TO 31*2
   IF POINT(x, y) > 0 THEN PSET (x, y), 100 + (20 * COS(x + zlmn) * SIN(y))
  NEXT y
 NEXT x

 FOR x = 160 TO 224
  FOR y = 23*2 TO 31*2
   IF POINT(x, y) > 0 THEN PSET (x, y), 163 + (20 * COS(x + zlmn) * SIN(y))
  NEXT y
 NEXT x

 IF zlmn >= 25 THEN zlmnv = -.12
 IF zlmn <= 0 THEN zlmnv = .12
 zlmn = zlmn + zlmnv
 i = INKEY$
 IF i >= "0" AND i <= "9" AND LEN(yaled$) < 8 THEN yaled$ = yaled$ + i: PRINT i;
 IF i = "-" AND LEN(yaled$) = 0 THEN yaled$ = yaled$ + i: PRINT i;
 IF i = CHR$(8) AND LEN(yaled$) > 0 THEN
  yaled$ = LEFT$(yaled$, LEN(yaled$) - 1)
  LOCATE CSRLIN, POS(0) - 1
  PRINT " ";
  LOCATE CSRLIN, POS(0) - 1
 END IF
 IF i = chr$(27) OR i = "q" or i = chr$(255)+"k" THEN UnloadResources: alutExit: END
 
 WAIT &h3DA, 8: flip
 
WEND

Delay = VAL(yaled$)
IF Delay < 0 THEN PALETTE

CONST NumStars = 8000

DIM as double StarX(NumStars), StarY(NumStars), StarXv(NumStars)
DIM as double ShieldAnimation(9000), GameOverPic(1000)

DIM PreCos1(20)

FOR z = 1 TO 20
 PreCos1(z) = ABS(COS(z) * 5)
NEXT z


Delay = ABS(Delay)

DIM as double EnemyX(35), EnemyY(35)
DIM as double EnemyXv(35), EnemyYv(35)
DIM as double EnemyLX(35), EnemyLY(35)
DIM EnemyHealth(35)

DIM as double Explosion(0, 500, 4)
' $DYNAMIC
DIM as double EExploX(35, 400), EExploY(35, 400), EExploXv(35, 400), EExploYv(35, 400)
DIM as double EExploAge(35)

1 REM [Go back here after you die and want to play again.]

alSourceStop(Source)

Level = 0: Cash = 0: EngineHeat = 0: Dead = 0
UltimateVictory = 0: PassLevel = 0: Shield = 100

2 REM [Return here after level completion.]


CLS : Kills = 0: a$ = "": PassLevel = 0

IF Level = 0 THEN
 NumEnemies = 1
 EnemySpeed = .01
END IF

IF Level = 1 THEN
 NumEnemies = 3
 EnemySpeed = .02
END IF

IF Level = 2 THEN
 NumEnemies = 5
 EnemySpeed = .03
END IF

IF Level = 3 THEN
 NumEnemies = 7
 EnemySpeed = .04
END IF

IF Level = 4 THEN
 NumEnemies = 9
 EnemySpeed = .05
END IF

IF Level = 5 THEN
 NumEnemies = 10
 EnemySpeed = .06
END IF

IF Level = 6 THEN
 NumEnemies = 13
 EnemySpeed = .065
END IF

IF Level = 7 THEN
 NumEnemies = 16
 EnemySpeed = .07
END IF

IF Level = 8 THEN
 NumEnemies = 20
 EnemySpeed = .08
END IF

IF Level = 9 THEN
 NumEnemies = 25
 EnemySpeed = .1
END IF

IF Level = 10 THEN
 NumEnemies = 35
 EnemySpeed = .15
END IF

IF Delay = 0 THEN Delay = 1
IF NumEnemies = 0 THEN NumEnemies = 10
IF EnemySpeed = 0 THEN EnemySpeed = .05
IF NumEnemies > 38 THEN NumEnemies = 38

LineyBorder

FOR z = 1 TO NumStars
 StarX(z) = INT(RND * 1000)
 StarY(z) = INT(RND * (149+200)) + 25
 StarXv(z) = RND * 5.3 + 1
NEXT z

ShipX = 200: ShipY = 200: ShipXv = 0: ShipYv = 0: ShipA = 1: ShipAv = 1
Sm = 1: ShipASlow = 1: ShipAvSlow = 1

IF Shield < 100 THEN Shield = 100

FOR z = 1 TO NumEnemies
 EnemyHealth(z) = 31
 EnemyXv(z) = RND * 5 - 2.5
 EnemyYv(z) = RND * 5 - 2.5
 EnemyX(z) = RND * 20 + 180+320
 EnemyY(z) = RND * 150 + 150
NEXT z

WHILE i <> "q" AND i <> chr$(27)

 i = INKEY$
 
 WAIT &h3DA, 8: flip

 FOR z = 1 TO Delay
  d = COS(z) * SIN(z)
 NEXT z

 ShipX = ShipX + ShipXv
 ShipY = ShipY + ShipYv
 ShipA = ShipA + ShipAv
 ShipASlow = ShipASlow + ShipAvSlow
 
 IF ShipA = 40 THEN ShipAv = -1
 IF ShipA = 0 THEN ShipAv = 1

 IF ShipASlow = 400 THEN ShipAvSlow = -1
 IF ShipASlow = 0 THEN ShipAvSlow = 1

 IF i = "d" OR i = CHR$(255) + "K" THEN ShipXv = ShipXv - Sm
 IF i = "e" THEN ShipXv = ShipXv - Sm: ShipYv = ShipYv - Sm
 IF i = "r" OR i = CHR$(255) + "H" THEN ShipYv = ShipYv - Sm
 IF i = "t" THEN ShipXv = ShipXv + Sm: ShipYv = ShipYv - Sm
 IF i = "g" OR i = CHR$(255) + "M" THEN ShipXv = ShipXv + Sm
 IF i = "b" THEN ShipXv = ShipXv + Sm: ShipYv = ShipYv + Sm
 IF i = "v" OR i = CHR$(255) + "P" THEN ShipYv = ShipYv + Sm
 IF i = "c" THEN ShipXv = ShipXv - Sm: ShipYv = ShipYv + Sm
 IF i = "f" THEN ShipXv = ShipXv * .6: ShipYv = ShipYv * .6

 IF i = "j" OR i = " " THEN
  IF Laser < 9 THEN
   Laser = Laser + 3: EngineHeat = EngineHeat + 5
   if Laser = 2 then alSourcei(SourceJ, AL_LOOPING, AL_TRUE): alSourcePlay(SourceJ)
  end if 
 END IF
 IF i = "k" OR i = CHR$(13) THEN
  IF Shield < 200 THEN
   Shield = Shield + 5: EngineHeat = EngineHeat + 8
   alSourcei(SourceK, AL_LOOPING, AL_FALSE): alSourcePlay(SourceK)
  end if 
 END IF
 IF i = "h" OR i = "=" THEN
  IF Shield > 10 AND EngineHeat > 6 THEN
   Shield = Shield - 10: EngineHeat = EngineHeat - 6
   alSourcei(SourceH, AL_LOOPING, AL_FALSE): alSourcePlay(SourceH)
  end if 
 END IF

 IF i = "p" THEN

  FOR z = 0 TO 63

   blue = INT((1 / 63 * z) * 31)
   green = INT((1 / 63 * z) * 31)
   red = INT((1 / 63 * z) * 31)
   PALETTE z, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 31)
   green = INT((1 / 63 * z) * 6)
   red = INT((1 / 63 * z) * 12)
   PALETTE z + 64, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 7)
   green = INT((1 / 63 * z) * 32)
   red = INT((1 / 63 * z) * 12)
   PALETTE z + 128, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 9)
   green = INT((1 / 63 * z) * 17)
   red = INT((1 / 63 * z) * 28)
   PALETTE z + 192, 65536 * blue + 256 * green + red
   
   'if z / 2 = int(z/2) then 
   WAIT &h3DA, 8: flip

  NEXT z

  WHILE INKEY$ = ""
  WEND
 
  FOR z = 0 TO 63

   blue = INT((1 / 63 * z) * 63)
   green = INT((1 / 63 * z) * 63)
   red = INT((1 / 63 * z) * 63)
   PALETTE z, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 63)
   green = INT((1 / 63 * z) * 12)
   red = INT((1 / 63 * z) * 24)
   PALETTE z + 64, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 15)
   green = INT((1 / 63 * z) * 63)
   red = INT((1 / 63 * z) * 24)
   PALETTE z + 128, 65536 * blue + 256 * green + red

   blue = INT((1 / 63 * z) * 19)
   green = INT((1 / 63 * z) * 34)
   red = INT((1 / 63 * z) * 56)
   PALETTE z + 192, 65536 * blue + 256 * green + red
   
   WAIT &h3DA, 8: flip

  NEXT z

 END IF

 IF i = "l" OR i = "" then
  if a$ <> "" THEN
   Level = Level + 1
   IF Level = 11 THEN UltimateVictory = 1
   PassLevel = 1
   i = "q"
  end if 
 END IF

 IF ShipX <= 73 THEN ShipX = 73: ShipXv = ABS(ShipXv) * .5: Lb = 1
 IF ShipY <= 35 THEN ShipY = 35: ShipYv = ABS(ShipYv) * .5: Lb = 1
 IF ShipX >= 248+320 THEN ShipX = 248+320: ShipXv = 0 - ShipXv * .5: Lb = 1
 IF ShipY >= 163+200 THEN ShipY = 163+200: ShipYv = 0 - ShipYv * .5: Lb = 1

 FOR z = 1 TO NumEnemies
 
  IF EnemyHealth(z) > 0 THEN

   IF EnemyX(z) < 70 THEN EnemyX(z) = 70: EnemyXv(z) = ABS(EnemyXv(z)) * .5: Lb = 1
   IF EnemyY(z) < 35 THEN EnemyY(z) = 35: EnemyYv(z) = ABS(EnemyYv(z)) * .5: Lb = 1
   IF EnemyX(z) > 248+320 THEN EnemyX(z) = 248+320: EnemyXv(z) = 0 - EnemyXv(z) * .5: Lb = 1
   IF EnemyY(z) > 163+200 THEN EnemyY(z) = 163+200: EnemyYv(z) = 0 - EnemyYv(z) * .5: Lb = 1

   IF EnemyX(z) - 9 < ShipX AND EnemyX(z) + 9 > ShipX AND EnemyY(z) - 9 < ShipY AND EnemyY(z) + 9 > ShipY THEN
    Shield = Shield - 2
    alSourcei(SourceH, AL_LOOPING, AL_FALSE): alSourcePlay(SourceH)
   END IF
  
   EnemyX(z) = EnemyX(z) + EnemyXv(z)
   EnemyY(z) = EnemyY(z) + EnemyYv(z)

   IF EnemyX(z) < ShipX THEN EnemyXv(z) = EnemyXv(z) + EnemySpeed
   IF EnemyX(z) > ShipX THEN EnemyXv(z) = EnemyXv(z) - EnemySpeed
   IF EnemyY(z) < ShipY THEN EnemyYv(z) = EnemyYv(z) + EnemySpeed
   IF EnemyY(z) > ShipY THEN EnemyYv(z) = EnemyYv(z) - EnemySpeed
  
   CIRCLE (EnemyLX(z), EnemyLY(z)), 8, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 7, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 6, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 5, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 4, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 3, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 2, 0
   CIRCLE (EnemyLX(z), EnemyLY(z)), 1, 0

 
   CIRCLE (EnemyX(z), EnemyY(z)), 8, EnemyHealth(z) * .65 + 20
   CIRCLE (EnemyX(z), EnemyY(z)), 7, EnemyHealth(z) * .7 + 20
   CIRCLE (EnemyX(z), EnemyY(z)), 6, EnemyHealth(z) * 1.8 + 64
   CIRCLE (EnemyX(z), EnemyY(z)), 5, EnemyHealth(z) * 2 + 64
   CIRCLE (EnemyX(z), EnemyY(z)), 4, EnemyHealth(z) * 1.7 + 64
   CIRCLE (EnemyX(z), EnemyY(z)), 3, EnemyHealth(z) * 1.5 + 64
   CIRCLE (EnemyX(z), EnemyY(z)), 2, EnemyHealth(z) * 1.4 + 64
   CIRCLE (EnemyX(z), EnemyY(z)), 1, EnemyHealth(z) * 1.35 + 64

   EnemyLX(z) = EnemyX(z): EnemyLY(z) = EnemyY(z)

   IF Laser > 0 AND EnemyX(z) > ShipX AND ShipY - 5 < EnemyY(z) AND ShipY + 5 > EnemyY(z) THEN
    EnemyHealth(z) = EnemyHealth(z) - Laser
    
    alSourcei(SourceH, AL_LOOPING, AL_FALSE): alSourcePlay(SourceH)
   
    IF EnemyHealth(z) <= 0 THEN
     FOR zf = 1 TO 400
      EExploX(z, zf) = EnemyLX(z)
      EExploY(z, zf) = EnemyLY(z)
      EExploXv(z, zf) = (RND * 8) - 4
      EExploYv(z, zf) = (RND * 8) - 4
     NEXT zf
     Cash = Cash + 3: Kills = Kills + 1: EExploAge(z) = 400
     alSourcei(SourceX, AL_LOOPING, AL_FALSE): alSourcePlay(SourceX)
    END IF

   END IF
 
  ELSE

   FOR zf = 1 TO EExploAge(z)
    ExL1 = EExploX(z, zf) - EExploXv(z, zf): ExL2 = EExploY(z, zf) - EExploYv(z, zf)
    IF ExL1 > 60 AND ExL1 < 258+320 AND ExL2 > 25 AND ExL2 < 173+200 THEN
     PSET (ExL1, ExL2), 0
    END IF
    IF EExploX(z, zf) > 60 AND EExploX(z, zf) < 258+320 AND EExploY(z, zf) > 25 AND EExploY(z, zf) < 173+200 THEN
     PSET (EExploX(z, zf), EExploY(z, zf)), INT(RND * 255)
    END IF
    EExploX(z, zf) = EExploX(z, zf) + EExploXv(z, zf)
    EExploY(z, zf) = EExploY(z, zf) + EExploYv(z, zf)
   NEXT zf

   IF EExploAge(z) > 10 THEN EExploAge(z) = EExploAge(z) - 1
                                                           
  END IF


 NEXT z

 IF Lb > 0 THEN Lb = Lb - 1: LineyBorder

 IF a$ <> "" THEN PUT (79, 79*2+1), GameOverPic, XOR

 FOR z = 1 TO NumStars
  StarX(z) = StarX(z) - StarXv(z)
  IF StarX(z) < 0 THEN StarX(z) = StarX(z) + 1000
  IF StarX(z) + StarXv(z) > 60 AND StarX(z) + StarXv(z) < 258+320 THEN PSET (StarX(z) + StarXv(z), StarY(z)), 0
  IF StarX(z) > 60 AND StarX(z) < 258+320 THEN PSET (StarX(z), StarY(z)), StarXv(z) * 10
 NEXT z

 IF Kills = NumEnemies THEN
  LOCATE 11, 11
  COLOR 248 - lq1
  a$ = "-!VICTORY!-"
  if ShipA / 3 = int(ShipA/3) then PRINT a$
  GET (80, 80*2)-(LEN(a$) * 8 + 80, 88*2), GameOverPic
 END IF

 FOR z = 1 TO 20
 
  LINE (Sl1 + 10, Sl2)-((Sl1 - 10) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 11) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 12) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 13) + PreCos1(z), Sl2 + z - 10), 0

 NEXT z

 IF Laser + 1 > 0 THEN
  FOR z = 0 - (Laser + 1) * .5 TO (Laser + 1) * .5
   LINE (Sl1, Sl2 + z)-(258+320, Sl2), 0
  NEXT z
 END IF
 
 IF Laser = 0 THEN Laser = -1: alSourceStop(SourceJ)

 CIRCLE (Sl1 - 2, Sl2), Sl3, 0

 FOR z = 1 TO 20

  LINE (ShipX + 10, ShipY)-((ShipX - 10) + PreCos1(z), ShipY + z - 10), ABS(z - 5) * 2 + 200
  PSET ((ShipX - 11) + PreCos1(z), ShipY + z - 10), ABS(z - 10) * 3 + 24 + ShipA
  PSET ((ShipX - 12) + PreCos1(z), ShipY + z - 10), z * 2 + 114 + ShipA
  PSET ((ShipX - 13) + PreCos1(z), ShipY + z - 10), z * 2 + 84 + ShipA

 NEXT z

 IF Laser > 0 THEN
  FOR z = 0 - Laser * .5 TO Laser * .5
   LINE (ShipX, ShipY + z)-(258+320, ShipY), ShipA + (INT(RND * EngineHeat) + 73) + z * 1.5
  NEXT z
 LaserZ = Laser
 Laser = Laser - 1
 END IF

 PSET (ShipX, ShipY), 210
 PSET (ShipX - 1, ShipY - 1), 220
 PSET (ShipX - 1, ShipY), 230
 PSET (ShipX - 1, ShipY + 1), 240
 PSET (ShipX - 2, ShipY), 250
 PSET (ShipX + 1, ShipY - 1), 190
 PSET (ShipX + 1, ShipY), 180
 PSET (ShipX + 1, ShipY + 1), 170
 PSET (ShipX + 2, ShipY), 160
 PSET (ShipX, ShipY - 1), 150
 PSET (ShipX, ShipY + 1), 140
 PSET (ShipX, ShipY - 2), 130
 PSET (ShipX, ShipY + 2), 120
 
 Sl3 = 1 + ShipA * (Shield * .0025)

 WHILE Sl3 > 10
  Sl3 = Sl3 - 1
 WEND

 CIRCLE (ShipX - 2, ShipY), Sl3, ShipA * 5

 Sl1 = ShipX: Sl2 = ShipY

 IF EngineHeat > 0 THEN EngineHeat = EngineHeat - .25
 IF EngineHeat > 63 THEN Dead = 1: i = "q": alSourcei(SourceX, AL_LOOPING, AL_FALSE): alSourcePlay(SourceX)
 IF Shield < 0 THEN Dead = 1: i = "q": alSourcei(SourceX, AL_LOOPING, AL_FALSE): alSourcePlay(SourceX)

 LINE (0, 0)-(34, 399 - 6 * EngineHeat), 0, BF
 
 FOR z = 1 TO 34
  LINE (z, 399 - 6 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2)) * .35
  LINE (z, 399 - 5.8 * EngineHeat)-(34 - z, 399), EngineHeat * (ABS(COS(z / 10) * 2.1)) * .35
  LINE (z, 399 - 5.6 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2.2)) * .35
  LINE (34 - z, 399 - 5.4 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2.3)) * .35
 NEXT z
 
 'LINE (285, 10)-(315, 40), 0, BF

 FOR z = 1 TO Shield STEP .25
  tq1 = (COS(z * (.025 * ShipA)) * (.15 * Shield)) * (.025 * ShipA) + 622
  tq2 = (SIN(z * (.025 * ShipA)) * (.15 * Shield)) * (.05 * ShipA) + 150+Temble
 
  while tq1 > 639
   tq1 = tq1 - 1
  WEND
 
  WHILE tq1 < 285+320
   tq1 = tq1 + 1
  WEND

  WHILE tq2*2-150 > 399
   tq2 = tq2 - 1
  WEND

  WHILE tq2*2-148 < 101
   tq2 = tq2 + 1
  WEND

  tq3 = Shield * .2 + 128 + (ShipA * .75) + (z * .2)
  line (tq1, tq2*2-150)-(tq1, tq2*2-148), tq3
  
 NEXT z

 GET (285+320, 100)-(639, 398), ShieldAnimation
 PUT (285+320, 101), ShieldAnimation, AND

 COLOR int(ShipASlow * .5)
 LOCATE 2, INT(285 / 8) + 2+40
 PRINT RIGHT$(STR$(Cash), LEN(STR$(Cash)))
 COLOR int(ShipASlow * .49)
 LOCATE 1, INT(285 / 8) + 2+40
 PRINT "$"

 COLOR 50 - int(.1 * ShipASlow)
 LOCATE 3, INT(285 / 8) + 2+40
 PRINT "---"

 COLOR 255 - int(ShipASlow * .5)
 LOCATE 5, INT(285 / 8) + 2+40
 PRINT Level + 1
 COLOR 255 - int(ShipASlow * .49)
 LOCATE 4, INT(285 / 8) + 2+40
 PRINT "Lvl"

 COLOR int(ShipASlow * .1)
 LOCATE 6, INT(285 / 8) + 2+40
 PRINT "---"


WEND

i = "": Laser = 0: alSourceStop(SourceJ)

IF Dead = 1 THEN
 
 IF Laser + 1 > 0 THEN
  FOR z = 0 - (Laser + 1) * .5 TO (Laser + 1) * .5
   LINE (Sl1, Sl2 + z)-(258+320, Sl2), 0
  NEXT z
 END IF
 
 FOR z = 1 TO 20

  LINE (Sl1 + 10, Sl2)-((Sl1 - 10) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 11) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 12) + PreCos1(z), Sl2 + z - 10), 0
  PSET ((Sl1 - 13) + PreCos1(z), Sl2 + z - 10), 0

 NEXT z

 CIRCLE (Sl1 - 2, Sl2), 5 + Sl3 * .125, 0

 FOR z = 1 TO 500
  Explosion(0, z, 1) = Sl1
  Explosion(0, z, 2) = Sl2
  Explosion(0, z, 3) = (RND * 8) - 4
  Explosion(0, z, 4) = (RND * 8) - 4
 NEXT z
 
 WHILE i <> "q" AND i <> chr$(27)

  i = INKEY$
  
  WAIT &h3DA, 8: flip
 
  ShipA = ShipA + ShipAv

  IF ShipA = 40 THEN ShipAv = -1
  IF ShipA = 0 THEN ShipAv = 1

  FOR z = 1 TO 500
   ExL1 = Explosion(0, z, 1) - Explosion(0, z, 3): ExL2 = Explosion(0, z, 2) - Explosion(0, z, 4)
   IF ExL1 > 60 AND ExL1 < 258+320 AND ExL2 > 25 AND ExL2 < 173+200 THEN
    PSET (ExL1, ExL2), 0
   END IF
   IF Explosion(0, z, 1) > 60 AND Explosion(0, z, 1) < 258+320 AND Explosion(0, z, 2) > 25 AND Explosion(0, z, 2) < 173+200 THEN
    PSET (Explosion(0, z, 1), Explosion(0, z, 2)), INT(RND * 255)
    Sf1 = Sf1 + 1
    Sf2 = Sf2 + .1
   END IF
   Explosion(0, z, 1) = Explosion(0, z, 1) + Explosion(0, z, 3)
   Explosion(0, z, 2) = Explosion(0, z, 2) + Explosion(0, z, 4)
   Sf1 = Sf1 + .03
  NEXT z

  Sf1 = 37: r = r + 1

  FOR z = 1 TO NumStars
   StarX(z) = StarX(z) - StarXv(z)
   IF StarX(z) < 0 THEN StarX(z) = StarX(z) + 1000
   IF StarX(z) + StarXv(z) > 60 AND StarX(z) + StarXv(z) < 258+320 THEN PSET (StarX(z) + StarXv(z), StarY(z)), 0
   IF StarX(z) > 60 AND StarX(z) < 258+320 THEN PSET (StarX(z), StarY(z)), StarXv(z) * 10
  NEXT z

  IF a$ <> "" THEN PUT (79, 80*2-1), GameOverPic, XOR

  IF EngineHeat > 0 THEN EngineHeat = EngineHeat - .5

  LINE (0, 0)-(34, 399 - 6 * EngineHeat), 0, BF

  FOR z = 1 TO 34
   LINE (z, 399 - 6 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2)) * .5
   LINE (z, 399 - 5.8 * EngineHeat)-(34 - z, 399), EngineHeat * (ABS(COS(z / 10) * 2.1)) * .5
   LINE (z, 399 - 5.6 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2.2)) * .5
   LINE (34 - z, 399 - 5.4 * EngineHeat)-(z, 399), EngineHeat * (ABS(COS(z / 10) * 2.3)) * .5
  NEXT z


  FOR z = 1 TO Delay
   d = COS(z) * SIN(z)
  NEXT z
  
  lq1 = lq1 + lqv
  IF lq1 = 0 THEN lqv = 1
  IF lq1 = 30 THEN lqv = -1
  LOCATE 11, 11
  COLOR 248 - lq1
  a$ = "* G A M E * O V E R *"
  if ShipA/3 = int(ShipA/3) then PRINT a$
  GET (80, 160)-(LEN(a$) * 8 + 80, 88*2), GameOverPic

  IF r = 4 THEN
   GET (285+320, 100)-(639, 198+200), ShieldAnimation
   PUT (285+320, 101), ShieldAnimation, AND
   r = 1
  END IF
 
  FOR z = 1 TO NumEnemies

   IF EnemyHealth(z) > 0 THEN

    IF EnemyX(z) < 70 THEN EnemyX(z) = 70: EnemyXv(z) = ABS(EnemyXv(z)) * .5: Lb = 1
    IF EnemyY(z) < 35 THEN EnemyY(z) = 35: EnemyYv(z) = ABS(EnemyYv(z)) * .5: Lb = 1
    IF EnemyX(z) > 248+320 THEN EnemyX(z) = 248+320: EnemyXv(z) = 0 - EnemyXv(z) * .5: Lb = 1
    IF EnemyY(z) > 163+200 THEN EnemyY(z) = 163+200: EnemyYv(z) = 0 - EnemyYv(z) * .5: Lb = 1

    EnemyX(z) = EnemyX(z) + EnemyXv(z)
    EnemyY(z) = EnemyY(z) + EnemyYv(z)
 
    CIRCLE (EnemyLX(z), EnemyLY(z)), 8, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 7, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 6, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 5, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 4, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 3, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 2, 0
    CIRCLE (EnemyLX(z), EnemyLY(z)), 1, 0


    CIRCLE (EnemyX(z), EnemyY(z)), 8, EnemyHealth(z) * .65 + 20
    CIRCLE (EnemyX(z), EnemyY(z)), 7, EnemyHealth(z) * .7 + 20
    CIRCLE (EnemyX(z), EnemyY(z)), 6, EnemyHealth(z) * 1.8 + 64
    CIRCLE (EnemyX(z), EnemyY(z)), 5, EnemyHealth(z) * 2 + 64
    CIRCLE (EnemyX(z), EnemyY(z)), 4, EnemyHealth(z) * 1.7 + 64
    CIRCLE (EnemyX(z), EnemyY(z)), 3, EnemyHealth(z) * 1.5 + 64
    CIRCLE (EnemyX(z), EnemyY(z)), 2, EnemyHealth(z) * 1.4 + 64
    CIRCLE (EnemyX(z), EnemyY(z)), 1, EnemyHealth(z) * 1.35 + 64

    EnemyLX(z) = EnemyX(z): EnemyLY(z) = EnemyY(z)

    IF Laser > 0 AND EnemyX(z) > ShipX AND ShipY - 5 < EnemyY(z) AND ShipY + 5 > EnemyY(z) THEN
     EnemyHealth(z) = EnemyHealth(z) - Laser
  
     IF EnemyHealth(z) <= 0 THEN
      FOR zf = 1 TO 400
       EExploX(z, zf) = EnemyLX(z)
       EExploY(z, zf) = EnemyLY(z)
       EExploXv(z, zf) = (RND * 8) - 4
       EExploYv(z, zf) = (RND * 8) - 4
      NEXT zf
      EExploAge(z) = 400
     END IF

    END IF

   ELSE

    FOR zf = 1 TO EExploAge(z)
     ExL1 = EExploX(z, zf) - EExploXv(z, zf): ExL2 = EExploY(z, zf) - EExploYv(z, zf)
     IF ExL1 > 60 AND ExL1 < 258+320 AND ExL2 > 25 AND ExL2 < 173+200 THEN
      PSET (ExL1, ExL2), 0
     END IF
     IF EExploX(z, zf) > 60 AND EExploX(z, zf) < 258+320 AND EExploY(z, zf) > 25 AND EExploY(z, zf) < 173+200 THEN
      PSET (EExploX(z, zf), EExploY(z, zf)), INT(RND * 255)
     END IF
     EExploX(z, zf) = EExploX(z, zf) + EExploXv(z, zf)
     EExploY(z, zf) = EExploY(z, zf) + EExploYv(z, zf)
    NEXT zf

    IF EExploAge(z) > 10 THEN EExploAge(z) = EExploAge(z) - 1

   END IF

  NEXT z

  COLOR int(ShipASlow * .4)
  LOCATE 2, INT(285 / 8) + 2+40
  PRINT RIGHT$(STR$(Cash), LEN(STR$(Cash)))
  COLOR int(ShipASlow * .39)
  LOCATE 1, INT(285 / 8) + 2+40
  PRINT "$"

  COLOR 50 - int(.105 * ShipASlow)
  LOCATE 3, INT(285 / 8) + 2+40
  PRINT "---"

  COLOR 255 - int(ShipASlow * .4)
  LOCATE 5, INT(285 / 8) + 2+40
  PRINT Level + 1
  COLOR 255 - int(ShipASlow * .39)
  LOCATE 4, INT(285 / 8) + 2+40
  PRINT "Lvl"

  COLOR int(ShipASlow * .09)
  LOCATE 6, INT(285 / 8) + 2+40
  PRINT "---"
 
  ShipA = ShipA + ShipAv: ShipASlow = ShipASlow + ShipAvSlow

  IF ShipA = 40 THEN ShipAv = -1
  IF ShipA = 0 THEN ShipAv = 1
  IF ShipASlow = 400 THEN ShipAvSlow = -1
  IF ShipASlow = 0 THEN ShipAvSlow = 1
 
 WEND

END IF

IF PassLevel = 1 THEN
    
 alSourcei(Source, AL_LOOPING, AL_TRUE): alSourcePlay(Source)
  
 FOR x = 1 TO 200
  FOR y = 1 TO 100
   LINE (0, 0)-(COS(x) * (y * 1.6) + 160+320, SIN(x) * y + 100+200), x + y
  NEXT y
 
  if x/2 = int(x/2) then WAIT &h3DA, 8: flip
  FOR z = 1 TO Delay: d = INT(RND * 100): NEXT z
 NEXT x
 FOR x = 0 TO 639
  LINE (0, 200 / 639 * x)-(x, 399), 0
   
  if x/8 = int(x/8) then WAIT &h3DA, 8: flip

  FOR z = 1 TO Delay: d = INT(RND * 100): NEXT z
 NEXT x
 FOR x = 0 TO 639
  LINE (x, 200 / 639 * x)-(x, 399), 0
  
  if x/8 = int(x/8) then WAIT &h3DA, 8: flip

  FOR z = 1 TO Delay: d = INT(RND * 100): NEXT z
 NEXT x
 FOR x = 0 TO 639
  LINE (639, 399)-(639 - x, 0), 0
  
  if x/8 = int(x/8) then WAIT &h3DA, 8: flip

  FOR z = 1 TO Delay: d = INT(RND * 100): NEXT
 NEXT x
 
 WAIT &h3DA, 8: flip
 
 alSourceStop(Source)
 
END IF

IF UltimateVictory = 1 THEN
 WHILE INKEY$ <> "q"
  COLOR INT(RND * 255)
  PRINT "Ultimate Victory!"
  we = INT(RND * 639): wf = INT(RND * 399)
  FOR x = 1 TO 639
   FOR y = 1 TO 399
    FOR z = 1 TO 10
     PSET (COS(x) * y + we, SIN(z) * y + wf), z
    NEXT z
   NEXT y
  NEXT x
  COLOR INT(RND * 255)
  PRINT "$$$"
  WAIT &h3DA, 8: flip
 WEND
 PassLevel = 0
END IF

IF PassLevel = 1 THEN 2

CLS

PRINT "Play again? (Y/N)";

FOR y = 0 TO 14
 FOR x = 1 TO 40
  LOCATE 7 + y, x
  IF MID$(PRImT$(y), x, 1) > CHR$(127) THEN Tehollo = 162 ELSE Tehollo = 215
  IF y = 0 OR y = 9 THEN Tehollo = 50
  IF y = 11 THEN Tehollo = 90
  COLOR Tehollo + x - y * 1.75
  PRINT MID$(PRImT$(y), x, 1);
 NEXT x
NEXT y

quitz = 0: zlmn = 0: zlmnv = .12
alSourcei(Source, AL_LOOPING, AL_FALSE): alSourcePlay(Source)

WHILE quitz = 0

 WAIT &h3DA, 8: flip
 
 FOR x = 0 TO 88
  FOR y = 0 TO 15
   IF POINT(x, y) > 0 THEN PSET (x, y), 100 + (20 * COS(x + zlmn) * SIN(y))
  NEXT y
 NEXT x

 FOR x = 96 TO 136
  FOR y = 0 TO 15
   IF POINT(x, y) > 0 THEN PSET (x, y), 43 + (20 * COS(x + zlmn) * SIN(y))
  NEXT y
 NEXT x

 IF zlmn >= 25 THEN zlmnv = -.12
 IF zlmn <= 0 THEN zlmnv = .12
 zlmn = zlmn + zlmnv

 i = INKEY$
 IF i = "y" OR i = "Y" THEN quitz = 99
 IF i = "n" OR i = "N" or i = chr$(27) THEN quitz = -99
WEND

IF quitz = 99 THEN 1

UnloadResources: alutExit

REM $STATIC
SUB LineyBorder

 FOR z = 0 TO 24
  LINE (59 - z, 24 - z)-(320 + 259 + z, 200 + 174 + z), 64 - ABS(COS(z / 10 + 20) * 63), B
 NEXT z

END SUB

