program ChangeBall ;

global

//Variables

int Score;
int Lives;
int GlobalX;
int GlobalY;
int GlobalAngle;
int InvincibleCounter;
int Song;
int Resolution_X;
int Resolution_Y;
int SpawnNew;
int TractorBeamOn;
int BonusWeapon;
int GravityMine_Y;
int GravityMine_X;
int GravityMineOn;
int MissileOn;
int ShieldPower;
int BlackHoleOn;
int TwinMissileOn;
int MenuOption;
int MenuOption2;
struct HighScore[6];
  int HiScore;
end
int IntroDelay;

//Sound INTs

int Neotron;
int Bip;
int Explode1;
int Explode2;
int Spawn;
int Beam;
int Photon;
int GravityMine;
int Burner;
int Rocket;
int Menu1;
int Sweep;
int Shield1;
int Shield2;

begin


Full_Screen=true;
set_mode(320,240,16);
load_fpg("rocks.fpg");
load("score.dat",HighScore);

Neotron=load_wav("Sound/neotron_zoom.wav");
Bip=load_wav("Sound/bip.wav");
Explode1=load_wav("Sound/explode1.wav");
Explode2=load_wav("Sound/explode2.wav");
Spawn=load_wav("Sound/spawn.wav");
Beam=load_wav("Sound/beam.wav");
Photon=load_wav("Sound/photon.wav");
GravityMine=load_wav("Sound/gravitymine.wav");
Burner=load_wav("Sound/burner.wav");
Rocket=load_wav("Sound/rocket.wav");
Menu1=load_wav("Sound/menu1.wav");
Sweep=load_wav("Sound/sweep.wav");
Shield1=load_wav("Sound/shield1.wav");
Shield2=load_wav("Sound/shield2.wav");

frame;

FadeIn(160,50,1,166,0,5,1);
FadeIn(170,190,1,167,0,5,1);

play_wav(Neotron,0);

IntroDelay=0; repeat IntroDelay++; frame; until(IntroDelay==100);
IntroShip(-40,120,0,79);
IntroDelay=0; repeat IntroDelay++; frame; until(IntroDelay==140);
GravityMineOn=0;


loop

let_me_alone();
delete_text(0);
frame; frame; frame; frame;

MenuBackGround();
Sweep();
MenuPart(160,40,4,160,0);
MenuPart(160,200,4,163,0);

repeat frame; until(key(_esc) or key(_enter) or key(_space))
if (key(_esc)) exit("Quit",0); end
play_wav(Menu1,0);
frame; frame; frame; frame;
let_me_alone();

loop

Score=0;
Lives=3;
ShieldPower=160;
BlackHoleOn=0;

//LevelMenu

MenuBackGround();
Sweep();
MenuPart(160,40,4,134,0);
MenuInfo(160,200,4,103,1);

MenuPart(35,120,4,115,1); frame;
MenuPart(85,120,4,118,1); frame;
MenuPart(135,120,4,121,1); frame;
MenuPart(185,120,4,124,1); frame;
MenuPart(235,120,4,127,1); frame;
MenuPart(285,120,4,130,1); frame;

write_int(0,15,150,0,&HighScore[1].HiScore);
write_int(0,65,150,0,&HighScore[2].HiScore);
write_int(0,115,150,0,&HighScore[3].HiScore);
write_int(0,165,150,0,&HighScore[4].HiScore);
write_int(0,215,150,0,&HighScore[5].HiScore);
write_int(0,265,150,0,&HighScore[6].HiScore);

if (HighScore[1].HiScore<10000 or HighScore[2].HiScore<10000)
  MenuPart(235,120,3,155,0);
end
if (HighScore[3].HiScore<10000 or HighScore[4].HiScore<10000)
  MenuPart(285,120,3,155,0);
end

MenuSelector(35,120,2,133,1);
MenuOption=1;


repeat
  if (key(_left)) play_wav(Bip,0); MenuOption--; end
  if (Key(_right)) play_wav(Bip,0); MenuOption++; end

  if (HighScore[1].HiScore<10000 or HighScore[2].HiScore<10000)
    if (MenuOption==5) MenuOption=1; end
    if (MenuOption==0) MenuOption=4; end
  end
  if (HighScore[3].HiScore<10000 or HighScore[4].HiScore<10000)
    if (HighScore[1].HiScore=>10000 and HighScore[2].HiScore=>10000)
      if (MenuOption==6) MenuOption=1; end
      if (MenuOption==0) MenuOption=5; end  
    end
  end
  if (HighScore[3].HiScore=>10000 and HighScore[4].HiScore=>10000)
    if (MenuOption==7) MenuOption=1; end
    if (MenuOption==0) MenuOption=6; end  
  end

  frame; frame;
until(key(_esc) or key(_enter) or key(_space))
play_wav(Menu1,0);

if (key(_esc)) break; end

let_me_alone();
delete_text(0);
frame; frame; frame; frame;

//ShipMenu

MenuBackGround();
Sweep();
MenuPart(160,40,4,87,0); frame;
MenuInfo(160,200,4,103,2);

MenuPart(55,120,4,90,1); frame;
MenuPart(125,120,4,93,1); frame;
MenuPart(195,120,4,96,1); frame;
MenuPart(265,120,4,99,1); frame;

MenuSelector(55,120,2,102,2);
MenuOption2=1;

repeat
  if (key(_left)) play_wav(Bip,0); MenuOption2--; end
  if (Key(_right)) play_wav(Bip,0); MenuOption2++; end
  if (MenuOption2==5) MenuOption2=1; end
  if (MenuOption2==0) MenuOption2=4; end

  frame; frame;
until(key(_enter) or key(_space))
play_wav(Menu1,0);

frame; frame; frame; frame;
let_me_alone();

switch(MenuOption)
  case 1: Level1(); end
  case 2: Level2(); end
  case 3: Level3(); end
  case 4: Level4(); end
  case 5: Level5(); end
  case 6: Level6(); end
end

Song=load_song("Music/rymdklot.ogg");
play_song(Song,99);

repeat frame; until(key(_esc) or Lives==0)
signal(type Player, s_kill);
stop_song();
play_wav(Menu1,0);
frame; frame; frame; frame;
MenuPart(160,120,0,156,0);
repeat frame; until(key(_esc) or key(_enter) or key(_space))
frame; frame; frame; frame;

if (MenuOption==1 and Score>HighScore[1].HiScore)
  HighScore[1].HiScore=Score;
  save("score.dat",HighScore);
end
if (MenuOption==2 and Score>HighScore[2].HiScore)
  HighScore[2].HiScore=Score;
  save("score.dat",HighScore);
end
if (MenuOption==3 and Score>HighScore[3].HiScore)
  HighScore[3].HiScore=Score;
  save("score.dat",HighScore);
end
if (MenuOption==4 and Score>HighScore[4].HiScore)
  HighScore[4].HiScore=Score;
  save("score.dat",HighScore);
end
if (MenuOption==5 and Score>HighScore[5].HiScore)
  HighScore[5].HiScore=Score;
  save("score.dat",HighScore);
end
if (MenuOption==6 and Score>HighScore[6].HiScore)
  HighScore[6].HiScore=Score;
  save("score.dat",HighScore);
end
delete_text(0);
let_me_alone();
end
end
end


process MenuSelector(x,y,z,graph,Mode);
begin
size=0;
alpha=0;
repeat
  alpha+=20;
  size+=5;
  frame;
until (size==100);

if (Mode==1)
  loop
    if (rand(1,40)==1) alpha=250; end
    if (alpha>200) alpha-=5; end
    if (MenuOption==1 and x>35) x--; end
    if (MenuOption==1 and x<35) x++; end
    if (MenuOption==2 and x>85) x--; end
    if (MenuOption==2 and x<85) x++; end
    if (MenuOption==3 and x>135) x--; end
    if (MenuOption==3 and x<135) x++; end
    if (MenuOption==4 and x>185) x--; end
    if (MenuOption==4 and x<185) x++; end
    if (MenuOption==5 and x>235) x--; end
    if (MenuOption==5 and x<235) x++; end
    if (MenuOption==6 and x>285) x--; end
    if (MenuOption==6 and x<285) x++; end
        
    frame(10);
  end
end

if (Mode==2)
  loop
    if (rand(1,40)==1) alpha=250; end
    if (alpha>200) alpha-=5; end
    if (MenuOption2==1 and x>55) x--; end
    if (MenuOption2==1 and x<55) x++; end
    if (MenuOption2==2 and x>125) x--; end
    if (MenuOption2==2 and x<125) x++; end
    if (MenuOption2==3 and x>195) x--; end
    if (MenuOption2==3 and x<195) x++; end
    if (MenuOption2==4 and x>265) x--; end
    if (MenuOption2==4 and x<265) x++; end
    frame(10);
  end
end

end


process MenuPart(x,y,z,graph,Mode);
private
int StartGraph;
begin
size=0;
alpha=0;
StartGraph=graph;
repeat
  alpha+=20;
  size+=5;
  frame;
until (size==100);
if (Mode==1)
  loop
    if (rand(1,40)==1) alpha=250; end
    if (alpha>200) alpha-=5; end
    graph=StartGraph;
    if (rand(0,60)<5) graph=StartGraph+1; end
    if (rand(0,60)<2) graph=StartGraph+2; end
    frame;
  end
end
if (Mode==0)
  loop
    frame;
  end
end
end


process MenuInfo(x,y,z,graph,Mode);
private
int StartGraph;
begin
size=0;
alpha=0;
StartGraph=graph;
repeat
  alpha+=20;
  size+=5;
  frame;
until (size==100);

if (Mode==1)
  loop
    if (MenuOption==1) StartGraph=137; end
    if (MenuOption==2) StartGraph=140; end
    if (MenuOption==3) StartGraph=143; end
    if (MenuOption==4) StartGraph=146; end
    if (MenuOption==5) StartGraph=149; end
    if (MenuOption==6) StartGraph=152; end
          
    if (rand(1,40)==1) alpha=250; end
    if (alpha>200) alpha-=5; end
    graph=StartGraph;
    if (rand(0,60)<5) graph=StartGraph+1; end
    if (rand(0,60)<2) graph=StartGraph+2; end   
    frame;
  end
end

if (Mode==2)
  loop
    if (MenuOption2==1) StartGraph=103; end
    if (MenuOption2==2) StartGraph=106; end
    if (MenuOption2==3) StartGraph=109; end
    if (MenuOption2==4) StartGraph=112; end
      
    if (rand(1,40)==1) alpha=250; end
    if (alpha>200) alpha-=5; end
    graph=StartGraph;
    if (rand(0,60)<5) graph=StartGraph+1; end
    if (rand(0,60)<2) graph=StartGraph+2; end   
    frame;
  end
end
end



process MenuBackGround();
begin

x=10; y=10;
repeat
  repeat
    MenuBkgTile(x,y,8);
    x+=20;
  until (x>330);
  x=0;
  y+=20;
until (y>250);

end


process Level1();
begin

//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);
Moving_Background(160,120,12,15,1);
Moving_Background(-160,120,12,15,1);

Asteroid(30,30,3,rand(50,100),18,rand(1,8),1);

if (MenuOption2==1) Player(160,120,4,1); end
if (MenuOption2==2) Player(160,120,4,2); end
if (MenuOption2==3) Player(160,120,4,3); end
if (MenuOption2==4) Player(160,120,4,4); end

SpawnAsteroids();

end


process Level2();
private
int AnimationCounter;
begin

//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);
Moving_Background(160,120,12,15,1);
Moving_Background(-160,120,12,15,1);

Base(160,120,10);

Asteroid(230,230,3,rand(50,100),19,rand(1,8),1);

if (MenuOption2==1) Player(160,60,4,1); end
if (MenuOption2==2) Player(160,60,4,2); end
if (MenuOption2==3) Player(160,60,4,3); end
if (MenuOption2==4) Player(160,60,4,4); end

SpawnAsteroids();

loop
  AnimationCounter++;
  if (AnimationCounter==10) LightSpark(145,80,9,66); LightSpark(175,80,9,66); end
  if (AnimationCounter==20) LightSpark(145,86,9,66); LightSpark(175,86,9,66); end  
  if (AnimationCounter==30) LightSpark(145,90,9,66); LightSpark(175,90,9,66); end
  if (AnimationCounter==40) LightSpark(145,96,9,66); LightSpark(175,96,9,66); end
  if (AnimationCounter==50) AnimationCounter=0; end  
  frame; 
end

end


process Level3();
begin

//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);
Moving_Background(160,120,12,15,1);
Moving_Background(-160,120,12,15,1);

DisplayObject(20,120,7,69,1);
DisplayObject(300,120,7,70,1);

Asteroid(330,30,3,rand(50,100),20,rand(1,8),1);

if (MenuOption2==1) Player(160,120,4,1); end
if (MenuOption2==2) Player(160,120,4,2); end
if (MenuOption2==3) Player(160,120,4,3); end
if (MenuOption2==4) Player(160,120,4,4); end

SpawnAsteroids();

loop
  if (rand(1,30)==1) Explode2(20+rand(-7,7),120+rand(-100,100),6,30); end
  if (rand(1,30)==1) Explode2(300+rand(-7,7),120+rand(-100,100),6,30); end
  if (rand(1,40)==1) PlanetMissile(20+rand(-7,7),120+rand(-100,100),5,71,1); end
  if (rand(1,40)==1) PlanetMissile(300+rand(-7,7),120+rand(-100,100),5,71,2); end  
  frame; 
end


end


process Level4();
begin

BlackHoleOn=1;
//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);
Moving_Background(160,120,12,67,2);
Moving_Background(160,120,10,68,3);
BlackHoleMiddle(160,120,9);

Asteroid(30,30,3,rand(50,100),18,rand(1,8),1);

if (MenuOption2==1) Player(160,60,4,1); end
if (MenuOption2==2) Player(160,60,4,2); end
if (MenuOption2==3) Player(160,60,4,3); end
if (MenuOption2==4) Player(160,60,4,4); end

SpawnAsteroids();


end



process Level5();
begin

//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);
Moving_Background(160,120,12,15,1);
Moving_Background(-160,120,12,15,1);
Moving_Background(160,120,2,73,4);
Moving_Background(-160,120,2,73,4);
Moving_Background(160,120,10,74,5);
Moving_Background(480,120,10,74,5);

DisplayObject(160,120,1,75,2);

Asteroid(30,30,3,rand(50,100),18,rand(1,8),1);

if (MenuOption2==1) Player(160,60,4,1); end
if (MenuOption2==2) Player(160,60,4,2); end
if (MenuOption2==3) Player(160,60,4,3); end
if (MenuOption2==4) Player(160,60,4,4); end

SpawnAsteroids();

end



process Level6();
begin

//Song=load_song("Changeball.ogg");
//play_song(Song,0);

write(0,6,5,0,"Score :");
write_int(0,55,5,0,&Score);
write(0,125,5,0,"Lives :");
write_int(0,170,5,0,&Lives);
write(0,200,5,0,"Special Weapon :");

ShowBonusWeapon(310,9,0);

Display_Background(160,120,11,1);

x=10; y=10;
repeat
  repeat
    BkgDot(x,y,8);
    x+=20;
  until (x>330);
  x=0;
  y+=20;
until (y>250);

Asteroid(230,230,3,rand(50,100),19,rand(1,8),1);

if (MenuOption2==1) Player(160,120,4,1); end
if (MenuOption2==2) Player(160,120,4,2); end
if (MenuOption2==3) Player(160,120,4,3); end
if (MenuOption2==4) Player(160,120,4,4); end

SpawnAsteroids();

end



process Player(x,y,z,Mode);
private
int Counter;
int X_Velocity;
int Y_Velocity;
int Speed;
int FireCounter;
int ShieldOn;
int StartX;
int StartY;
begin
play_wav(Spawn,0);
InvincibleCounter=40;
size=50;
ShieldOn=1;
Shield(x,y,z-2,Mode);
ShieldBreaker(x,y,z,angle,2);
ShieldPower=160;
ShieldBar(160,235,0);
StartX=x;
StartY=y;
if (Mode==1)
  graph=2;
  loop
    if (key(_left)) angle+=15000; end
    if (key(_right)) angle-=15000; end
    
    if (key(_up) and Speed<=6)
      play_wav(Burner,0);
      Speed+=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end
    if (key(_down) and Speed=>0)
      Speed-=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end

    if (key(_Control) and FireCounter==0) Shoot(x,y,z+1,angle); FireCounter=8; end
    if (FireCounter>0) FireCounter--; end 
    if (key(_Space) and ShieldOn==1) ShieldOn=0; ShieldBreaker(x,y,z,angle,1); signal(type Shield, s_kill); end
    if (Key(_Alt))
      if(BonusWeapon==1 and TractorBeamOn==0) TractorBeam1(x,y,z-1,angle,Speed); end
      if(BonusWeapon==2 and GravityMineOn==0) GravityMine(x,y,z); end
      if(BonusWeapon==3 and MissileOn==0) Missile(x,y,z+1,angle); end
      if(BonusWeapon==4 and TwinMissileOn==0) TwinMissile(x,y,z+1,angle,1); TwinMissile(x,y,z+1,angle,2); end
    end
    
    frame(0);
    if (collision(type BeamPickUp)) BonusWeapon=1; end frame(0);
    if (collision(type GravityMinePickup)) BonusWeapon=2; end    
    if (collision(type MissilePickUp)) BonusWeapon=3; end 
    if (collision(type TwinMissilePickUp)) BonusWeapon=4; end 
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end

    advance(Speed);

    if (Speed>0) Speed--; end
    if (ShieldPower<-160)
      ShieldBreaker(x,y,z,angle,1);
      signal(type Shield, s_kill);
      signal(type ShieldBar, s_kill);
      ShieldPower=160;
   end
    
    GlobalX=x;
    GlobalY=y;
    GlobalAngle=angle;
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    
    if (collision(type Asteroid) or collision(type AttackShip) or collision(type Base) or collision(type Explode3) and InvincibleCounter==0)
      BonusWeapon=0;
      play_wav(Explode2,0);
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      GravityMineOn=0;
      TractorBeamOn=0;
      CreateSparks(x,y,z-1,255,50,rand(2,4),5,2);
      Explode(x,y,z-2,100);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end

    if (collision(type BlackHoleMiddle) and InvincibleCounter==0)
      BonusWeapon=0;
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      TractorBeamOn=0;
      repeat
        if (BlackHoleOn==1 and x<160) x+=2; end
        if (BlackHoleOn==1 and x>160) x-=2; end
        if (BlackHoleOn==1 and y<120) y+=2; end
        if (BlackHoleOn==1 and y>120) y-=2; end
        size-=2;
        frame;
      until(size==0)
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end
    frame;
  end
end

if (Mode==2)
  graph=77;
  loop
    if (key(_left)) angle+=10000; end
    if (key(_right)) angle-=10000; end
    
    if (key(_up) and Speed<=4)
      play_wav(Burner,0);
      Speed+=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end
    if (key(_down) and Speed=>0)
      Speed-=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end

    if (key(_Control) and FireCounter==0) Shoot(x,y,z+1,angle); FireCounter=8; end
    if (FireCounter>0) FireCounter--; end 
    if (key(_Space) and ShieldOn==1) ShieldOn=0; ShieldBreaker(x,y,z,angle,1); signal(type Shield, s_kill); end
    if (Key(_Alt))
      if(BonusWeapon==1 and TractorBeamOn==0) TractorBeam1(x,y,z-1,angle,Speed); end
      if(BonusWeapon==2 and GravityMineOn==0) GravityMine(x,y,z); end
      if(BonusWeapon==3 and MissileOn==0) Missile(x,y,z+1,angle); end
      if(BonusWeapon==4 and TwinMissileOn==0) TwinMissile(x,y,z+1,angle,1); TwinMissile(x,y,z+1,angle,2); end
    end
    
    frame(0);
    if (collision(type BeamPickUp)) BonusWeapon=1; end frame(0);
    if (collision(type GravityMinePickup)) BonusWeapon=2; end    
    if (collision(type MissilePickUp)) BonusWeapon=3; end 
    if (collision(type TwinMissilePickUp)) BonusWeapon=4; end 
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end

    advance(Speed);

    if (Speed>0) Speed--; end
    if (ShieldPower<-160)
      ShieldBreaker(x,y,z,angle,1);
      signal(type Shield, s_kill);
      signal(type ShieldBar, s_kill);
      ShieldPower=160;
   end
    
    GlobalX=x;
    GlobalY=y;
    GlobalAngle=angle;
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    
    if (collision(type Asteroid) or collision(type AttackShip) or collision(type Base) or collision(type Explode3) and InvincibleCounter==0)
      BonusWeapon=0;
      play_wav(Explode2,0);
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      GravityMineOn=0;
      TractorBeamOn=0;
      CreateSparks(x,y,z-1,255,50,rand(2,4),5,2);
      Explode(x,y,z-2,100);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end

    if (collision(type BlackHoleMiddle) and InvincibleCounter==0)
      BonusWeapon=0;
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      TractorBeamOn=0;
      repeat
        if (BlackHoleOn==1 and x<160) x+=2; end
        if (BlackHoleOn==1 and x>160) x-=2; end
        if (BlackHoleOn==1 and y<120) y+=2; end
        if (BlackHoleOn==1 and y>120) y-=2; end
        size-=2;
        frame;
      until(size==0)
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end
    frame;
  end
end

if (Mode==3)
  graph=78;
  loop
    if (key(_left)) angle+=10000; end
    if (key(_right)) angle-=10000; end
    
    if (key(_up) and Speed<=6)
      play_wav(Burner,0);
      Speed+=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end
    if (key(_down) and Speed=>0)
      Speed-=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end

    if (key(_Control) and FireCounter==0) Shoot(x,y,z+1,angle); FireCounter=8; end
    if (FireCounter>0) FireCounter--; end 
    if (key(_Space) and ShieldOn==1) ShieldOn=0; ShieldBreaker(x,y,z,angle,1); signal(type Shield, s_kill); end
    if (Key(_Alt))
      if(BonusWeapon==1 and TractorBeamOn==0) TractorBeam1(x,y,z-1,angle,Speed); end
      if(BonusWeapon==2 and GravityMineOn==0) GravityMine(x,y,z); end
      if(BonusWeapon==3 and MissileOn==0) Missile(x,y,z+1,angle); end
      if(BonusWeapon==4 and TwinMissileOn==0) TwinMissile(x,y,z+1,angle,1); TwinMissile(x,y,z+1,angle,2); end
    end
    
    frame(0);
    if (collision(type BeamPickUp)) BonusWeapon=1; end frame(0);
    if (collision(type GravityMinePickup)) BonusWeapon=2; end    
    if (collision(type MissilePickUp)) BonusWeapon=3; end 
    if (collision(type TwinMissilePickUp)) BonusWeapon=4; end 
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end

    advance(Speed);

    if (Speed>0) Speed--; end
    if (ShieldPower<-160)
      ShieldBreaker(x,y,z,angle,1);
      signal(type Shield, s_kill);
      signal(type ShieldBar, s_kill);
      ShieldPower=160;
   end
    
    GlobalX=x;
    GlobalY=y;
    GlobalAngle=angle;
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    
    if (collision(type Asteroid) or collision(type AttackShip) or collision(type Base) or collision(type Explode3) and InvincibleCounter==0)
      BonusWeapon=0;
      play_wav(Explode2,0);
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      GravityMineOn=0;
      TractorBeamOn=0;
      CreateSparks(x,y,z-1,255,50,rand(2,4),5,2);
      Explode(x,y,z-2,100);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end

    if (collision(type BlackHoleMiddle) and InvincibleCounter==0)
      BonusWeapon=0;
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      TractorBeamOn=0;
      repeat
        if (BlackHoleOn==1 and x<160) x+=2; end
        if (BlackHoleOn==1 and x>160) x-=2; end
        if (BlackHoleOn==1 and y<120) y+=2; end
        if (BlackHoleOn==1 and y>120) y-=2; end
        size-=2;
        frame;
      until(size==0)
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end
    frame;
  end
end

if (Mode==4)
  graph=79;
  loop
    if (key(_left)) angle+=15000; end
    if (key(_right)) angle-=15000; end
    
    if (key(_up) and Speed<=4)
      play_wav(Burner,0);
      Speed+=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end
    if (key(_down) and Speed=>0)
      Speed-=2;
      Particle_Trail(x,y,3,angle,100,200,3);
      Particle_Trail(x,y,3,angle,100,200,3);
    end

    if (key(_Control) and FireCounter==0) Shoot(x,y,z+1,angle); FireCounter=8; end
    if (FireCounter>0) FireCounter--; end 
    if (key(_Space) and ShieldOn==1) ShieldOn=0; ShieldBreaker(x,y,z,angle,1); signal(type Shield, s_kill); end
    if (Key(_Alt))
      if(BonusWeapon==1 and TractorBeamOn==0) TractorBeam1(x,y,z-1,angle,Speed); end
      if(BonusWeapon==2 and GravityMineOn==0) GravityMine(x,y,z); end
      if(BonusWeapon==3 and MissileOn==0) Missile(x,y,z+1,angle); end
      if(BonusWeapon==4 and TwinMissileOn==0) TwinMissile(x,y,z+1,angle,1); TwinMissile(x,y,z+1,angle,2); end
    end
    
    frame(0);
    if (collision(type BeamPickUp)) BonusWeapon=1; end frame(0);
    if (collision(type GravityMinePickup)) BonusWeapon=2; end    
    if (collision(type MissilePickUp)) BonusWeapon=3; end 
    if (collision(type TwinMissilePickUp)) BonusWeapon=4; end 
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end

    advance(Speed);

    if (Speed>0) Speed--; end
    if (ShieldPower<-160)
      ShieldBreaker(x,y,z,angle,1);
      signal(type Shield, s_kill);
      signal(type ShieldBar, s_kill);
      ShieldPower=160;
   end
    
    GlobalX=x;
    GlobalY=y;
    GlobalAngle=angle;
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    
    if (collision(type Asteroid) or collision(type AttackShip) or collision(type Base) or collision(type Explode3) and InvincibleCounter==0)
      BonusWeapon=0;
      play_wav(Explode2,0);
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      GravityMineOn=0;
      TractorBeamOn=0;
      CreateSparks(x,y,z-1,255,50,rand(2,4),5,2);
      Explode(x,y,z-2,100);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end

    if (collision(type BlackHoleMiddle) and InvincibleCounter==0)
      BonusWeapon=0;
      signal(type Shield, s_kill);
      signal(type TractorBeam1, s_kill);
      signal(type GravityMine, s_kill);
      TractorBeamOn=0;
      repeat
        if (BlackHoleOn==1 and x<160) x+=2; end
        if (BlackHoleOn==1 and x>160) x-=2; end
        if (BlackHoleOn==1 and y<120) y+=2; end
        if (BlackHoleOn==1 and y>120) y-=2; end
        size-=2;
        frame;
      until(size==0)
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(StartX,StartY,4,Mode);
        ZoomIn(StartX,StartY,3,2,500,50);
      end
      return;
    end
    frame;
  end
end

end


process ShowBonusWeapon(x,y,z);
begin
loop
  if (BonusWeapon==0) graph=0; end
  if (BonusWeapon==1) graph=44; end
  if (BonusWeapon==2) graph=43; end
  if (BonusWeapon==3) graph=47; end
  if (BonusWeapon==4) graph=76; end
  frame;
end
end


process AttackShip(x,y,z);
private
int Counter;
begin
graph=63;
repeat
  Counter++;
  advance(Counter);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  frame;
until(Counter==6)
loop
  advance(6);
  if (y>GlobalY) angle-=5000; end
  if (y<GlobalY) angle+=5000; end  
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) or collision(type Explode))
    play_wav(Explode1,0);
    frame;
    Score+=100;
    Explode(x,y,z-2,100);
    return;
  end
  frame;
end
end


process Missile(x,y,z,angle);
private
int Counter;
begin
play_wav(Rocket,0);
MissileOn=1;
graph=48;

repeat
  Counter++;
  advance(Counter);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  frame;
until(Counter==7)

repeat
  advance(7);
  angle=GlobalAngle;
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  frame;
until(collision(type Asteroid) or collision(type Base))
Explode(x,y,z-2,100);
frame;
MissileOn=0;
end



process TwinMissile(x,y,z,angle,Mode);
private
int Counter;
begin
play_wav(Rocket,0);
frame;
play_wav(Rocket,0);
TwinMissileOn=1;
graph=48;

if (Mode==1) angle+=5000; end
if (Mode==2) angle-=5000; end

repeat
  Counter++;
  advance(Counter);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  TwinMissileOn=1;
  frame;
until(Counter==7)

repeat
  advance(7);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  Particle_Trail(x,y,3,angle,100,200,3);
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  TwinMissileOn=1;
  frame;
until(collision(type Asteroid) or collision(type Base))
Explode(x,y,z-2,100);
frame;
TwinMissileOn=0;
end



process GravityMine(x,y,z);
private
int Counter;
int Counter2;
begin
play_wav(GravityMine,0);
size=75;
graph=46;
GravityMineOn=1;
GravityMine_X=x;
GravityMine_Y=y;
repeat
  if (Counter2==10) Counter2=0; TotalZoomIn(x,y,z+2,14,100,10,1); end
  Counter2++;
  Counter++;
  angle+=4000;
  frame;
until(Counter==100)
GravityMineOn=0;
end


process BeamPickUp(x,y,z,graph);
begin
loop
  if (collision(type Player)) ZoomOut(x,y,z-1,graph,100,200,10,2); frame; return; end
  frame;
end
end


process GravityMinePickUp(x,y,z,graph);
begin
loop
  if (collision(type Player)) ZoomOut(x,y,z-1,graph,100,200,10,2); frame; return; end
  frame;
end
end


process MissilePickUp(x,y,z,graph);
begin
loop
  if (collision(type Player)) ZoomOut(x,y,z-1,graph,100,200,10,2); frame; return; end
  frame;
end
end


process TwinMissilePickUp(x,y,z,graph);
begin
loop
  if (collision(type Player)) ZoomOut(x,y,z-1,graph,100,200,10,2); frame; return; end
  frame;
end
end


process TractorBeam1(x,y,z,angle,Speed);
begin
play_wav(Beam,0);
TractorBeamOn=1;
flags=16;
graph=45;
alpha=0;
size=0;
repeat
  alpha+=10;
  size+=5;
  if (key(_left)) angle+=15000; end
  if (key(_right)) angle-=15000; end
  if (key(_up) and Speed<=6) Speed+=2; end
  if (key(_down) and Speed=>0) Speed-=2; end
    
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  
  if (BlackHoleOn==1 and x<160) y+=1; end
  if (BlackHoleOn==1 and x>160) y-=1; end
  if (BlackHoleOn==1 and y<120) x-=1; end
  if (BlackHoleOn==1 and y>120) x+=1; end

  advance(Speed);
  if (Speed>0) Speed--; end

  frame;
  
until(alpha>200);

repeat
  alpha-=10;
  size-=5;
  if (key(_left)) angle+=15000; end
  if (key(_right)) angle-=15000; end
  if (key(_up) and Speed<=6) Speed+=2; end
  if (key(_down) and Speed=>0) Speed-=2; end
    
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  
  if (BlackHoleOn==1 and x<160) y+=1; end
  if (BlackHoleOn==1 and x>160) y-=1; end
  if (BlackHoleOn==1 and y<120) x-=1; end
  if (BlackHoleOn==1 and y>120) x+=1; end

  advance(Speed);
  if (Speed>0) Speed--; end
  
  frame;
until(alpha<0);

TractorBeamOn=0;
end




process Shield(x,y,z,Mode);
private
int Speed;
begin
graph=41;
alpha=0;
flags=16;
priority=1;
if (Mode==1)
  loop
    if (key(_left)) angle+=15000; end
    if (key(_right)) angle-=15000; end
    if (key(_up) and Speed<=6) Speed+=2; end
    if (key(_down) and Speed=>0) Speed-=2; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    advance(Speed);
    if (Speed>0) Speed--; end
    
    if (collision(type Asteroid) or collision(type PlanetMissile)) play_wav(Shield1,0); alpha=200; ShieldPower-=20; end
    if (alpha>0) alpha-=20; end
    
    frame;
  end
end

if (Mode==2)
  loop
    if (key(_left)) angle+=10000; end
    if (key(_right)) angle-=10000; end
    if (key(_up) and Speed<=4) Speed+=2; end
    if (key(_down) and Speed=>0) Speed-=2; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    advance(Speed);
    if (Speed>0) Speed--; end
    
    if (collision(type Asteroid) or collision(type PlanetMissile)) play_wav(Shield1,0); alpha=200; ShieldPower-=20; end
    if (alpha>0) alpha-=20; end
    
    frame;
  end
end

if (Mode==3)
  loop
    if (key(_left)) angle+=10000; end
    if (key(_right)) angle-=10000; end
    if (key(_up) and Speed<=6) Speed+=2; end
    if (key(_down) and Speed=>0) Speed-=2; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    advance(Speed);
    if (Speed>0) Speed--; end
    
    if (collision(type Asteroid) or collision(type PlanetMissile)) play_wav(Shield1,0); alpha=200; ShieldPower-=20; end
    if (alpha>0) alpha-=20; end
    
    frame;
  end
end

if (Mode==4)
  loop
    if (key(_left)) angle+=15000; end
    if (key(_right)) angle-=15000; end
    if (key(_up) and Speed<=4) Speed+=2; end
    if (key(_down) and Speed=>0) Speed-=2; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (BlackHoleOn==1 and x<160) y+=1; end
    if (BlackHoleOn==1 and x>160) y-=1; end
    if (BlackHoleOn==1 and y<120) x-=1; end
    if (BlackHoleOn==1 and y>120) x+=1; end

    advance(Speed);
    if (Speed>0) Speed--; end
    
    if (collision(type Asteroid) or collision(type PlanetMissile)) play_wav(Shield1,0); alpha=200; ShieldPower-=20; end
    if (alpha>0) alpha-=20; end
    
    frame;
  end
end

end


process ShieldBreaker(x,y,z,angle,Mode);
private
int Speed;
begin
if (Mode==1)
  play_wav(Shield2,0);
  graph=42;
  alpha=0;
  flags=16;
  priority=1;
  size=20;
  repeat
    alpha+=10;
    frame;
  until(alpha==200)
  repeat
    angle+=10000;
    size+=5;
    frame;
  until(size==100)
end
if (Mode==2)
  graph=41;
  alpha=100;
  flags=16;
  priority=1;
  size=80;
  repeat
    size+=5;
    frame(50);
    alpha-=5;
  until(size==170)
end
end


process Asteroid(x,y,z,size,graph,Direction, Mode);
private
int Speed;
int Model;
begin
if (Mode==1)
  Speed=rand(1,2);
  Model=rand(1,2);
  loop
    if (Direction==1) x-=Speed; end
    if (Direction==2) x-=Speed; y-=Speed; end
    if (Direction==3) y-=Speed; end
    if (Direction==4) x+=Speed; y-=Speed; end
    if (Direction==5) x+=Speed; end
    if (Direction==6) x+=Speed; y+=Speed; end
    if (Direction==7) y+=Speed; end
    if (Direction==8) x-=Speed; y+=Speed; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) or collision(type Explode) or collision(type BlackHoleMiddle))
      play_wav(Explode1,0);
      switch(graph)
      case 18:
        frame;
        Score+=10;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,6,4,3);
        if (rand(1,20)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,size,21,2,2);
          Asteroid(x,y,z,size,22,4,2);
          Asteroid(x,y,z,size,23,6,2);
          Asteroid(x,y,z,size,24,8,2);
        end
        if (Model==2)
          Asteroid(x,y,z,size,21,1,2);
          Asteroid(x,y,z,size,22,3,2);
          Asteroid(x,y,z,size,23,5,2);
          Asteroid(x,y,z,size,24,7,2);
        end
        frame;
        return;
      end

      case 19:
        frame;
        Score+=10;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,6,4,4);
        if (rand(1,20)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,size,33,2,2);
          Asteroid(x,y,z,size,34,4,2);
          Asteroid(x,y,z,size,35,6,2);
          Asteroid(x,y,z,size,36,8,2);
        end
        if (Model==2)
          Asteroid(x,y,z,size,33,1,2);
          Asteroid(x,y,z,size,34,3,2);
          Asteroid(x,y,z,size,35,5,2);
          Asteroid(x,y,z,size,36,7,2);
        end
        frame;
        return;
      end

      case 20:
        frame;
        Score+=10;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,6,4,3);
        if (rand(1,20)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,size,37,2,2);
          Asteroid(x,y,z,size,38,4,2);
          Asteroid(x,y,z,size,39,6,2);
          Asteroid(x,y,z,size,40,8,2);
        end
        if (Model==2)
          Asteroid(x,y,z,size,37,1,2);
          Asteroid(x,y,z,size,38,3,2);
          Asteroid(x,y,z,size,39,5,2);
          Asteroid(x,y,z,size,40,7,2);
        end
        frame;
        return;
      end
      case 62:
        frame;
        Score+=10;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,6,4,3);
        if (rand(1,30)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        AttackShip(x,y,z+1);
        if (Model==1)
          Asteroid(x,y,z,size,21,2,2);
          Asteroid(x,y,z,size,22,4,2);
          Asteroid(x,y,z,size,23,6,2);
          Asteroid(x,y,z,size,24,8,2);
        end
        if (Model==2)
          Asteroid(x,y,z,size,21,1,2);
          Asteroid(x,y,z,size,22,3,2);
          Asteroid(x,y,z,size,23,5,2);
          Asteroid(x,y,z,size,24,7,2);
        end
        frame;
        return;
      end
    end
  end
  
  frame(0);
  if (collision(type Shield) or collision(type ShieldBreaker) or collision(type Base))
    frame(0);
    switch(Direction)
      case 1: Direction=5; end
      case 2: Direction=6; end
      case 3: Direction=7; end
      case 4: Direction=8; end
      case 5: Direction=1; end
      case 6: Direction=2; end
      case 7: Direction=3; end
      case 8: Direction=4; end
    end
  end
    
  if (GravityMineOn==1 and x<GravityMine_X) x+=2; end
  if (GravityMineOn==1 and x>GravityMine_X) x-=2; end
  if (GravityMineOn==1 and y<GravityMine_Y) y+=2; end
  if (GravityMineOn==1 and y>GravityMine_Y) y-=2; end

  if (BlackHoleOn==1 and x<160) y+=1; end
  if (BlackHoleOn==1 and x>160) y-=1; end
  if (BlackHoleOn==1 and y<120) x-=1; end
  if (BlackHoleOn==1 and y>120) x+=1; end
         
  if (Model==1) angle+=1000; end
  if (Model==2) angle-=1000; end
  frame;
  end
end
 
if (Mode==2)
  Speed=rand(1,2);
  Model=rand(1,2);
  loop
    if (Direction==1) x-=Speed; end
    if (Direction==2) x-=Speed; y-=Speed; end
    if (Direction==3) y-=Speed; end
    if (Direction==4) x+=Speed; y-=Speed; end
    if (Direction==5) x+=Speed; end
    if (Direction==6) x+=Speed; y+=Speed; end
    if (Direction==7) y+=Speed; end
    if (Direction==8) x-=Speed; y+=Speed; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
  if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) or collision(type Explode) or collision(type BlackHoleMiddle))
    play_wav(Explode1,0);
    switch(graph)
      case 21,22,23,24:
        frame;
        Score+=20;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,5,3,3);
        if (rand(1,30)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,50,21,2,3);
          Asteroid(x,y,z,50,22,4,3);
          Asteroid(x,y,z,50,23,6,3);
          Asteroid(x,y,z,50,24,8,3);
        end
        if (Model==2)
          Asteroid(x,y,z,50,21,1,3);
          Asteroid(x,y,z,50,22,3,3);
          Asteroid(x,y,z,50,23,5,3);
          Asteroid(x,y,z,50,24,7,3);
        end
        return;
      end
    
      case 33,34,35,36:
        frame;
        Score+=20;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,10,5,3,4);
        if (rand(1,20)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,50,33,2,3);
          Asteroid(x,y,z,50,34,4,3);
          Asteroid(x,y,z,50,35,6,3);
          Asteroid(x,y,z,50,36,8,3);
        end
        if (Model==2)
          Asteroid(x,y,z,50,33,1,3);
          Asteroid(x,y,z,50,34,3,3);
          Asteroid(x,y,z,50,35,5,3);
          Asteroid(x,y,z,50,36,7,3);
        end
        return;
      end
    
      case 37,38,39,40:
        frame;
        Score+=20;
        Shockwave(x,y,2,14);
        CreateSparks(x,y,z,255,20,5,3,3);
        if (rand(1,20)==1)
          switch(rand(1,4))
            case 1: BeamPickUp(x,y,z,44); end
            case 2: GravityMinePickUp(x,y,z,43); end
            case 3: MissilePickUp(x,y,z,47); end
            case 4: TwinMissilePickUp(x,y,z,76); end
          end
        end
        if (Model==1)
          Asteroid(x,y,z,50,37,2,3);
          Asteroid(x,y,z,50,38,4,3);
          Asteroid(x,y,z,50,39,6,3);
          Asteroid(x,y,z,50,40,8,3);
        end
        if (Model==2)
          Asteroid(x,y,z,50,37,1,3);
          Asteroid(x,y,z,50,38,3,3);
          Asteroid(x,y,z,50,39,5,3);
          Asteroid(x,y,z,50,40,7,3);
        end
        return;
      end
    end 
  end

  frame(0);
  if (collision(type Shield) or collision(type ShieldBreaker) or collision(type Base))
    frame(0);
    switch(Direction)
      case 1: Direction=5; end
      case 2: Direction=6; end
      case 3: Direction=7; end
      case 4: Direction=8; end
      case 5: Direction=1; end
      case 6: Direction=2; end
      case 7: Direction=3; end
      case 8: Direction=4; end
    end
  end

  if (GravityMineOn==1 and x<GravityMine_X) x+=2; end
  if (GravityMineOn==1 and x>GravityMine_X) x-=2; end
  if (GravityMineOn==1 and y<GravityMine_Y) y+=2; end
  if (GravityMineOn==1 and y>GravityMine_Y) y-=2; end

  if (BlackHoleOn==1 and x<160) y+=1; end
  if (BlackHoleOn==1 and x>160) y-=1; end
  if (BlackHoleOn==1 and y<120) x-=1; end
  if (BlackHoleOn==1 and y>120) x+=1; end
         
  if (Model==1) angle+=1000; end
  if (Model==2) angle-=1000; end
  frame;
  end 
end

if (Mode==3)
  Speed=rand(1,2);
  Model=rand(1,2);
  loop
    if (Direction==1) x-=Speed; end
    if (Direction==2) x-=Speed; y-=Speed; end
    if (Direction==3) y-=Speed; end
    if (Direction==4) x+=Speed; y-=Speed; end
    if (Direction==5) x+=Speed; end
    if (Direction==6) x+=Speed; y+=Speed; end
    if (Direction==7) y+=Speed; end
    if (Direction==8) x-=Speed; y+=Speed; end
    
    if (x<0) x=320; end
    if (x>320) x=0; end
    if (y<0) y=240; end
    if (y>240) y=0; end
    
    if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) or collision(type Explode) or collision(type BlackHoleMiddle))
      play_wav(Explode1,0);
      frame;
      Score+=30;
      SpawnNew++;
      Shockwave(x,y,2,14);
      CreateSparks(x,y,z,255,10,2,1,3);
      if (rand(1,30)==1)
        switch(rand(1,4))
          case 1: BeamPickUp(x,y,z,44); end
          case 2: GravityMinePickUp(x,y,z,43); end
          case 3: MissilePickUp(x,y,z,47); end
          case 4: TwinMissilePickUp(x,y,z,76); end
        end
      end
      return;
    end
    
  frame(0);
  if (collision(type Shield) or collision(type ShieldBreaker) or collision(type Base))
    frame(0);
    switch(Direction)
      case 1: Direction=5; end
      case 2: Direction=6; end
      case 3: Direction=7; end
      case 4: Direction=8; end
      case 5: Direction=1; end
      case 6: Direction=2; end
      case 7: Direction=3; end
      case 8: Direction=4; end
    end
  end

  if (GravityMineOn==1 and x<GravityMine_X) x+=2; end
  if (GravityMineOn==1 and x>GravityMine_X) x-=2; end
  if (GravityMineOn==1 and y<GravityMine_Y) y+=2; end
  if (GravityMineOn==1 and y>GravityMine_Y) y-=2; end

  if (BlackHoleOn==1 and x<160) y+=1; end
  if (BlackHoleOn==1 and x>160) y-=1; end
  if (BlackHoleOn==1 and y<120) x-=1; end
  if (BlackHoleOn==1 and y>120) x+=1; end
         
  if (Model==1) angle+=1000; end
  if (Model==2) angle-=1000; end
  frame;
  end 
end

end


process SpawnAsteroids();
private
int Model;
int Side;
begin
loop
  if (SpawnNew>10)
    SpawnNew=0;
    Model=rand(1,4);
    Side=rand(1,4);
    
    if (Side==1)
      if (Model==1) Asteroid(rand(10,310),-10,3,rand(50,100),18,7,1); end
      if (Model==2) Asteroid(rand(10,310),-10,3,rand(50,100),19,7,1); end
      if (Model==3) Asteroid(rand(10,310),-10,3,rand(50,100),20,7,1); end
      if (Model==4) Asteroid(rand(10,310),-10,3,100,62,rand(1,8),1); end
    end
    if (Side==2)
      if (Model==1) Asteroid(330,rand(10,230),3,rand(50,100),18,1,1); end
      if (Model==2) Asteroid(330,rand(10,230),3,rand(50,100),19,1,1); end
      if (Model==3) Asteroid(330,rand(10,230),3,rand(50,100),20,1,1); end
      if (Model==4) Asteroid(330,rand(10,230),3,100,62,rand(1,8),1); end
    end  
    if (Side==3)
      if (Model==1) Asteroid(rand(10,310),250,3,rand(50,100),18,3,1); end
      if (Model==2) Asteroid(rand(10,310),250,3,rand(50,100),19,3,1); end
      if (Model==3) Asteroid(rand(10,310),250,3,rand(50,100),20,3,1); end
      if (Model==4) Asteroid(rand(10,310),250,3,100,62,rand(1,8),1); end
    end
    if (Side==4)
      if (Model==1) Asteroid(-10,rand(10,230),3,rand(50,100),18,5,1); end
      if (Model==2) Asteroid(-10,rand(10,230),3,rand(50,100),19,5,1); end
      if (Model==3) Asteroid(-10,rand(10,230),3,rand(50,100),20,5,1); end
      if (Model==4) Asteroid(-10,rand(10,230),3,100,62,rand(1,8),1); end
    end    
  end
  frame;
end
end



process Shoot(x,y,z,angle);
private
int Fade;
begin
play_wav(Photon,0);
graph=8;
flags=16;
Fade=25;
alpha=200;
advance(10);
repeat
  Particle_Trail(x,y,z+1,angle,100,200,9);
  if (x<0) x=320; end
  if (x>320) x=0; end
  if (y<0) y=240; end
  if (y>240) y=0; end
  Fade--;
  advance(10);
  if (collision(type Asteroid) or collision(type Base) or collision(type PlanetMissile) or collision(type AttackShip))
    frame;
    Shockwave(x,y,2,13);
    CreateSparks(x,y,z+1,200,20,2,6,2);
    return;
  end
  frame;
until (Fade==0)
Shockwave(x,y,2,13);
CreateSparks(x,y,z+1,200,20,2,6,2);
end



process BkgDot(x,y,z);
private
int StartX;
int StartY;
begin
graph=72;
alpha=100;
StartX=x;
StartY=y;
loop
  if (fget_dist(x,y,GlobalX,GlobalY)<50) alpha=150; end
  if (fget_dist(x,y,GlobalX,GlobalY)<30) alpha=200; end
  if (fget_dist(x,y,GlobalX,GlobalY)<10) alpha=250; end
  if (alpha>100) alpha-=5; end
  if (alpha<100) alpha+=5; end
  frame;
end
end


process MenuBkgTile(x,y,z);
private
int StartX;
int StartY;
begin

switch(rand(1,6))
  case 1: graph=81; end
  case 2: graph=82; end
  case 3: graph=83; end
  case 4: graph=84; end
  case 5: graph=85; end
  case 6: graph=86; end
end
alpha=100;
StartX=x;
StartY=y;
loop
  if (rand(1,50)==1) alpha=200; end
  if (alpha>100) alpha-=5; end
  frame;
end
end


process CreateSparks(x,y,z,alpha,Amount,Velocity,StartVelocity,Model);
private
int Counter;
begin
Counter=0;
repeat
  Counter++;
  Spark(x,y,z,alpha,Velocity,StartVelocity,Model);
until (Counter==Amount)
end


process Spark(x,y,z,alpha,Velocity,EntryVelocity,Model);
private
int Counter;
int Direction;
int Gravity;
begin
Gravity=-7;
if (Model==1) graph=2+rand(1,4); end
if (Model==2) graph=8+rand(1,4); end
if (Model==3) graph=24+rand(1,4); end
if (Model==4) graph=28+rand(1,4); end
Direction=rand(1,8);
repeat    
  if (Direction==1) x-=Velocity; end
  if (Direction==2) x-=Velocity; y-=Velocity; end
  if (Direction==3) y-=Velocity; end
  if (Direction==4) x+=Velocity; y-=Velocity; end
  if (Direction==5) x+=Velocity; end
  if (Direction==6) x+=Velocity; y+=Velocity; end
  if (Direction==7) y+=Velocity; end
  if (Direction==8) x-=Velocity; y+=Velocity; end
  
  x+=rand(-3,3);
  y+=rand(-3,3);
  alpha-=8;
  if (Gravity<8) Gravity++; end
  if (EntryVelocity<Velocity) Velocity--; end
  frame;
until (alpha<20)
end


process Particle_Trail(x,y,z,angle,size,alpha,graph);
private
int Speed;
begin
graph=Graph+rand(0,1);
Speed=rand(1,3);
flags=16;
advance(-10);
repeat
  advance(Speed);
  alpha=alpha-10;
  x+=rand(-2,2);
  y+=rand(-2,2);
  frame;
until (alpha==20)
end


process Shockwave(x,y,z,graph);
begin
alpha=120;
size=0;
repeat
  size+=20;
  alpha-=20;
  frame;
until (alpha==0);
end


process ZoomIn(x,y,z,graph,Start,Speed);
begin
size=Start;
repeat
  size-=Speed;
  frame;
until (size==100);
end


process FadeIn(x,y,z,graph,Start,Speed,Mode);
begin
alpha=Start;
repeat
  alpha+=Speed;
  frame;
until (alpha>255);

repeat
  if (Mode==1)
    if (GravityMineOn==1 and y>120) y-=4; size-=5; end
    if (GravityMineOn==1 and y<120) y+=4; size-=5; end
  end
  frame;
until (size<0);

end


process ZoomOut(x,y,z,graph,Start,Stop,Speed,Mode);
begin
size=Start;
if (Mode==2) alpha=200; end
repeat
  if (Mode==2) alpha-=Speed; end
  size+=Speed;
  frame;
until (size==Stop or alpha<0);
end


process TotalZoomIn(x,y,z,graph,Start,Speed,Mode);
begin
size=Start;
if (Mode==1) alpha=200; flags=16; end
repeat
  if (Mode==1) alpha-=30; end
  size-=Speed;
  frame;
until (size==0);
end


process Display_Score(x,y,z,graph);
private
int Counter;
begin
repeat
  y=y-Counter;
  Counter=Counter+1;
  alpha=250-Counter*10;
  frame;
until (Counter==10)
end


process ZoomText(x,y,z,graph);
private
int Counter;
begin
repeat
  Counter=Counter+10;
  size=50+Counter;
  alpha=251-Counter;
  frame;
until (Counter==150)
end


process Display_Background(x,y,z,graph);
begin
alpha=200;
loop frame; end
end


process Moving_Background(x,y,z,graph,Mode);
begin
if (Mode==1)
  alpha=150;
  repeat
    x+=2;
    frame;
  until(x==480)
  Moving_Background(-160,120,12,15,1);
end
if (Mode==2)
  alpha=255;
  loop
    angle+=2000;
    if (angle==360000) angle=0; end
    frame;
  end
end
if (Mode==3)
  alpha=150;
  loop
    angle+=4000;
    if (angle==360000) angle=0; end
    frame;
  end
end
if (Mode==4)
  repeat
    x+=2;
    frame;
  until(x==480)
  Moving_Background(-160,120,2,73,4);
end
if (Mode==5)
  repeat
    x-=1;
    frame;
  until(x==-480)
  Moving_Background(480,120,10,74,5);
end
end


process Explode(x,y,z,size);
private
int Animation;
begin
alpha=200;
repeat
  Animation=Animation+1;
  graph=48+Animation;
  frame;
until (Animation==13)
end


process Explode2(x,y,z,size);
private
int Animation;
begin
alpha=200;
repeat
  Animation=Animation+1;
  graph=48+Animation;
  frame;
until (Animation==13)
end


process Explode3(x,y,z,size);
private
int Animation;
begin
alpha=200;
repeat
  Animation=Animation+1;
  graph=48+Animation;
  frame;
until (Animation==13)
end


process Base(x,y,z);
begin
graph=64;
loop frame; end
end


process DisplayObject(x,y,z,graph,Mode);
begin
if (Mode==1) loop frame; end end
if (Mode==2)
  alpha=100;
  loop frame; end
end
end


process ShieldBar(x,y,z);
begin
graph=65;
alpha=100;
loop
  x=ShieldPower;
  frame;
end
end


process LightSpark(x,y,z,graph);
begin
alpha=200;
repeat
  alpha-=10;
  size+=10;
  frame(50);
until(alpha==0)
end


process BlackHoleMiddle(x,y,z);
begin
graph=68;
size=50;
flags=32;
loop
  angle+=5000;
  if (angle==360000) angle=0; end
  frame;
end
end


process PlanetMissile(x,y,z,graph,Mode);
begin
size=0;

if (Mode==1)
  repeat
    if (x<160) size+=4; end
    if (x>160) size-=4; end    
    x+=4;
    if (collision(type Shield) and size>100)
      repeat
        x-=2;
        angle-=5000;
        frame;
      until (angle==-45000)
      Explode(x,y,z,50);
      return;
    end
    if (collision(type Player) and size>100) Explode3(x,y,z,50); return; end
    if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) and size>95) Score+=20; Explode(x,y,z,50); return; end
    frame;
  until(x=>300)
Explode2(x,y,z,100);
return;
end

if (Mode==2)
  flags=1;
  repeat
    if (x>160) size+=4; end
    if (x<160) size-=4; end    
    x-=4;
    if (collision(type Shield) and size>100)
      repeat
        x+=2;
        angle+=5000;
        frame;
      until (angle==45000)
      Explode(x,y,z,50);
      return;
    end
    if (collision(type Player) and size>100) Explode3(x,y,z,50); return; end 
    if (collision(type Shoot) or collision(type ShieldBreaker) or collision(type TractorBeam1) or collision(type Missile) and size>95) Explode(x,y,z,50); Score+=20; return; end
    frame;
  until(x<=20)
Explode2(x,y,z,100);
return;
end
end


process Sweep();
private
int Counter;
int DelayCounter;
begin
play_wav(Sweep,0);
x=-20;
y=120;
z=7;
graph=159;
alpha=150;
flags=16;
loop
  Counter++;
  if (Counter==4) Counter=0; DropSweep(x+5,y,z); end
  x+=5;
  frame(50);
  if (x>340)
    x=-20;
    repeat
      DelayCounter++;
      frame;
    until (DelayCounter==50)
    play_wav(Sweep,0);
    DelayCounter=0;
  end
end
end


process DropSweep(x,y,z);
begin
graph=159;
alpha=150;
flags=16;
repeat
  alpha-=5;
  frame;
until(alpha<0)
end


process IntroShip(x,y,z,graph);
begin
repeat
  x+=5;
  if (x==160) GravityMine(x,y,z); end
  frame;
until(x>360)
end