program ChangeBall ;

import "mod_grproc"
import "mod_key"
import "mod_joy"
import "mod_map"
import "mod_math"
import "mod_proc"
import "mod_rand"
import "mod_screen"
import "mod_scroll"
import "mod_sound"
import "mod_text"
import "mod_video"
import "mod_wm"
import "mod_file"

#include "jkey.lib"

global

//Variables

int Score;
int Lives;
int Points;
int GlobalX;
int GlobalY;
int InvincibleCounter;
int Song;
struct HighScore[3];
  int HiScore;
  int HiPoints;
end
int GameMode;
int Main_Menu_Selection;
int DelayCounter;
int ScoreCounter;
int DisplayHigh;
int Volume;

//Sound Pointers

int Bip;
int Bounce;
int Poff;
int Pop;
int Neotron;

begin

GameMode=1;
Full_Screen=true;
set_mode(320,240,16);
load_fpg("ball.fpg");
load("score.dat",HighScore);
jkeys_set_default_keys();
jkeys_controller();
VolumeControl();

Bip=load_wav("bip.wav");
Bounce=load_wav("bounce.wav");
Poff=load_wav("poff.wav");
Pop=load_wav("pop.wav");
Neotron=load_wav("neotron_zoom.wav");

Volume=40;

DelayCounter=0; repeat DelayCounter++; frame; until (DelayCounter==20);
FadeIn(160,90,0,50);
FadeIn(170,180,0,58);
play_wav(Neotron,0);
DelayCounter=0; repeat DelayCounter++; frame; until (DelayCounter==70);
repeat frame; if(rand(1,3)==1) Falling_SmallBall(rand(10,310)); end until (jkeys_state[_JKEY_SELECT] or jkeys_state[_JKEY_B])
let_me_alone();

loop

jkeys_set_default_keys();
jkeys_controller();
VolumeControl();

stop_wav(0);
stop_song();
Song=load_song("changeball_meny.ogg");
play_song(Song,99);

write(0,170,93,0,"Top Points :");
write_int(0,245,93,0,&HighScore[1].HiScore);

write(0,170,103,0,"Top Score :");
write_int(0,245,103,0,&HighScore[1].HiPoints);


write(0,170,123,0,"Top Points :");
write_int(0,245,123,0,&HighScore[2].HiScore);

write(0,170,133,0,"Top Score :");
write_int(0,245,133,0,&HighScore[2].HiPoints);


write(0,170,153,0,"Top Points :");
write_int(0,245,153,0,&HighScore[3].HiScore);

write(0,170,163,0,"Top Score :");
write_int(0,245,163,0,&HighScore[3].HiPoints);

x=10;
y=10;
repeat
  repeat
    Bkg_Tile2(x,y,6,1);
    x+=20;
  until (x>320);
  x=0;
  y+=20;
until (y>230);

TitleLogo(160,40,0,43);

Main_Menu_Option(100,-125,1,46);
Main_Menu_Option(130,-125,1,47);
Main_Menu_Option(160,-125,1,48);
Main_Menu_Option(190,-125,1,49);

Main_Menu_Selection=1;
Main_Menu_Selector(1,44);

DelayCounter=0; repeat DelayCounter++; frame; until (DelayCounter==35);

repeat
  if (jkeys_state[_JKEY_UP])
    Main_Menu_Selection--;
    play_wav(Bip,0);
  end
  if (jkeys_state[_JKEY_DOWN])
    Main_Menu_Selection++;
    play_wav(Bip,0);
  end
  frame;
  frame;
  frame;
  if (Main_Menu_Selection==0) Main_Menu_Selection=4; end
  if (Main_Menu_Selection==5) Main_Menu_Selection=1; end
until (jkeys_state[_JKEY_SELECT] or jkeys_state[_JKEY_B])
frame;

if (Main_Menu_Selection==1) GameMode=1; end
if (Main_Menu_Selection==2) GameMode=2; end
if (Main_Menu_Selection==3) GameMode=3; end
if (Main_Menu_Selection==4) exit("Quit",0); end



repeat frame; until(jkeys_state[_JKEY_SELECT] or jkeys_state[_JKEY_MENU] or jkeys_state[_JKEY_B])
if (jkeys_state[_JKEY_MENU]) exit("Quit",0); end

let_me_alone();
delete_text(0);
jkeys_set_default_keys();
jkeys_controller();
VolumeControl();

Points=0;
Score=0;
Lives=3;

x=10;
y=10;
repeat
  repeat
    Bkg_Tile(x,y,6,56);
    x+=20;
  until (x>320);
  x=0;
  y+=20;
until (y>230);

stop_song();
Song=load_song("changeball.ogg");
play_song(Song,99);

write(0,6,5,0,"Points :");
write_int(0,55,5,0,&Score);

write(0,106,5,0,"Score :");
write_int(0,155,5,0,&Points);

write(0,250,5,0,"Lives :");
write_int(0,295,5,0,&Lives);

Point(rand(10,310),rand(10,230),4);

ZoomText(160,70,0,40);
ZoomIn(160,120,3,2,500,50);
Player(160,120,4,1);
ScoreCounter=200;
ScoreTimer();
if (GameMode==1) RandomMode(); end

DisplayHigh=0;
repeat
  if (GameMode==1 and Score>HighScore[1].HiScore and DisplayHigh==0) ZoomText(160,120,0,57); DisplayHigh=1; end
  if (GameMode==2 and Score>HighScore[2].HiScore and DisplayHigh==0) ZoomText(160,120,0,57); DisplayHigh=1; end
  if (GameMode==3 and Score>HighScore[3].HiScore and DisplayHigh==0) ZoomText(160,120,0,57); DisplayHigh=1; end
  frame;
until(jkeys_state[_JKEY_MENU] or Lives==0)
let_me_alone();
delete_text(0);
jkeys_set_default_keys();
jkeys_controller();
VolumeControl();

if (GameMode==1 and Score>HighScore[1].HiScore)
  HighScore[1].HiScore=Score;
  HighScore[1].HiPoints=Points;
  save("score.dat",HighScore);
end
if (GameMode==2 and Score>HighScore[2].HiScore)
  HighScore[2].HiScore=Score;
  HighScore[2].HiPoints=Points;
  save("score.dat",HighScore);
end
if (GameMode==3 and Score>HighScore[3].HiScore)
  HighScore[3].HiScore=Score;
  HighScore[3].HiPoints=Points;
  save("score.dat",HighScore);
end


end
end


process Player(x,y,z,Mode);
private
int Counter;
int GravityDelay;
int X_Velocity;
int Y_Velocity;
begin
graph=2;
InvincibleCounter=30;

if (Mode==1)
  loop
    if (jkeys_state[_JKEY_LEFT]) x+=-5; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT]) x+=5; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP]) y+=-5; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN]) y+=5; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=5; play_wav(Bounce,0); end
    if (x>315) x+=-5; play_wav(Bounce,0); end
    if (y<5) y+=5; play_wav(Bounce,0); end
    if (y>235) y+=-5; play_wav(Bounce,0); end

    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,1);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==2)
  loop
    if (jkeys_state[_JKEY_LEFT] and X_Velocity>-10) X_Velocity-=2; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT] and X_Velocity<10) X_Velocity+=2; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP] and Y_Velocity>-10) Y_Velocity-=2; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN] and Y_Velocity<10) Y_Velocity+=2; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=5; x+=-X_Velocity; play_wav(Bounce,0); end
    if (x>315) x-=5; x-=X_Velocity; play_wav(Bounce,0); end
    if (y<5) y+=5; y+=-Y_Velocity; play_wav(Bounce,0); end
    if (y>235) y-=5; y-=Y_Velocity; play_wav(Bounce,0); end

    if (X_Velocity>0) X_Velocity--; end
    if (X_Velocity<0) X_Velocity++; end
    if (Y_Velocity>0) Y_Velocity--; end
    if (Y_Velocity<0) Y_Velocity++; end

    x+=X_Velocity;
    y+=Y_Velocity;
    
    GlobalX=x;
    GlobalY=y;
    
    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end    
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,2);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==3)
  loop
    if (jkeys_state[_JKEY_LEFT] and X_Velocity>-8) X_Velocity-=2; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT] and X_Velocity<8) X_Velocity+=2; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP] and Y_Velocity>-8) Y_Velocity-=1; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN] and Y_Velocity<8) Y_Velocity+=1; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=5; x+=-X_Velocity; play_wav(Bounce,0); end
    if (x>315) x-=5; x-=X_Velocity; play_wav(Bounce,0); end
    if (y<5) y+=5; Y_Velocity=5; play_wav(Bounce,0); end
    if (y>235) y-=5; Y_Velocity=-5; play_wav(Bounce,0); end

    if (X_Velocity>0) X_Velocity--; end
    if (X_Velocity<0) X_Velocity++; end
    
    GravityDelay++;
    if (Y_Velocity<6 and GravityDelay==2) Y_Velocity+=1; end
    if (GravityDelay>3) GravityDelay=0; end

    x+=X_Velocity;
    y+=Y_Velocity;
    
    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end    
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,3);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==4)
  loop
    if (jkeys_state[_JKEY_LEFT] and X_Velocity>-8) X_Velocity-=2; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT] and X_Velocity<8) X_Velocity+=2; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP] and Y_Velocity>-8) Y_Velocity-=1; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN] and Y_Velocity<8) Y_Velocity+=1; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=5; x+=-X_Velocity; play_wav(Bounce,0); end
    if (x>315) x-=5; x-=X_Velocity; play_wav(Bounce,0); end
    if (y<5) y+=5; Y_Velocity=5; play_wav(Bounce,0); end
    if (y>235) y-=5; Y_Velocity=-5; play_wav(Bounce,0); end

    if (X_Velocity>0) X_Velocity--; end
    if (X_Velocity<0) X_Velocity++; end
    
    GravityDelay++;
    if (Y_Velocity>-6 and GravityDelay==1) Y_Velocity-=1; end
    if (GravityDelay>2) GravityDelay=0; end   

    x+=X_Velocity;
    y+=Y_Velocity;
    
    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end    
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,3);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==5)
  loop
    if (jkeys_state[_JKEY_LEFT]) X_Velocity=-5; Y_Velocity=0; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT]) X_Velocity=5; Y_Velocity=0; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP]) Y_Velocity=-5; X_Velocity=0; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN]) Y_Velocity=5; X_Velocity=0; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=5; X_Velocity=5; play_wav(Bounce,0); end
    if (x>315) x-=5; X_Velocity=-5; play_wav(Bounce,0); end
    if (y<5) y+=5; Y_Velocity=5; play_wav(Bounce,0); end
    if (y>235) y-=5; Y_Velocity=-5; play_wav(Bounce,0); end

    x+=X_Velocity;
    y+=Y_Velocity;
    
    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end   
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,2);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==6)
  loop
    if (jkeys_state[_JKEY_LEFT]) x+=5; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_RIGHT]) x+=-5; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_UP]) y+=5; Particle_Trail(x,y-5,3,3,100,200); end
    if (jkeys_state[_JKEY_DOWN]) y+=-5; Particle_Trail(x,y+5,3,7,100,200); end

    if (x<5) x+=5; play_wav(Bounce,0); end
    if (x>315) x+=-5; play_wav(Bounce,0); end
    if (y<5) y+=5; play_wav(Bounce,0); end
    if (y>235) y+=-5; play_wav(Bounce,0); end

    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,1);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
if (Mode==7)
  loop
    if (jkeys_state[_JKEY_LEFT]) x+=-3; Particle_Trail(x+5,y,3,5,100,200); end
    if (jkeys_state[_JKEY_RIGHT]) x+=3; Particle_Trail(x-5,y,3,1,100,200); end
    if (jkeys_state[_JKEY_UP]) y+=-3; Particle_Trail(x,y+5,3,7,100,200); end
    if (jkeys_state[_JKEY_DOWN]) y+=3; Particle_Trail(x,y-5,3,3,100,200); end

    if (x<5) x+=3; play_wav(Bounce,0); end
    if (x>315) x+=-3; play_wav(Bounce,0); end
    if (y<5) y+=3; play_wav(Bounce,0); end
    if (y>235) y+=-3; play_wav(Bounce,0); end

    GlobalX=x;
    GlobalY=y;

    if (InvincibleCounter>0) alpha=150; InvincibleCounter--; end
    if (InvincibleCounter==0) alpha=255; end
    if (collision(type Enemy) and InvincibleCounter==0)
      play_wav(Poff,0);
      CreateSparks(x,y,z-1,255,20,rand(2,4),5,2);
      if (Lives>0)
        graph=0;
        Counter=0; repeat Counter++; frame; until (Counter==30);
        Lives--;
        Player(160,120,4,1);
        ZoomIn(160,120,3,2,500,50);
      end
      return;
    end
    frame;
  end
end
end


process RandomMode();
private
int Counter;
begin
Counter=200;
graph=45;
y=235;
flags=4;
loop
  Counter--;
  if (Counter==0)
    Counter=200;
    ZoomText(160,120,0,41);
    signal (type Player, s_kill);
    Player(GlobalX,GlobalY,4,rand(1,7));
  end
  x=Counter-100;
  frame;
end
end


process ScoreTimer();
begin
graph=51;
x=315;
y=140;
flags=4;
loop
  if (ScoreCounter>0) ScoreCounter--; end
  y=-ScoreCounter+340;
  frame;
end
end



process Enemy(x,y,z,Model,Direction);
private
int Counter;
begin
graph=7;
Shockwave(x,y,2,38);
loop
  if (Model==1)
    if (Direction==1) x-=1; Counter++; end
    if (Direction==2) x+=1; Counter++; end
    if (Direction==1)
      if (Counter==1) graph=24; end
      if (Counter==2) graph=25; end
      if (Counter==3) graph=26; end
      if (Counter==4) graph=27; end
      if (Counter==5) graph=28; end
      if (Counter==6) graph=29; end
      if (Counter==7) graph=30; end
      if (Counter==8) graph=31; end
      if (Counter==9) graph=32; end
      if (Counter==10) graph=33; end  
    end
    if (Direction==2)
      if (Counter==10) graph=24; end
      if (Counter==9) graph=25; end
      if (Counter==8) graph=26; end
      if (Counter==7) graph=27; end
      if (Counter==6) graph=28; end
      if (Counter==5) graph=29; end
      if (Counter==4) graph=30; end
      if (Counter==3) graph=31; end
      if (Counter==2) graph=32; end
      if (Counter==1) graph=33; end  
    end    
    if (Counter==11) Counter=1; end
    if (Direction==1 and x==4) Direction=2; end
    if (Direction==2 and x==316) Direction=1; end      
  end
  
  if (Model==2)
    if (Direction==1) y-=1; Counter++; end
    if (Direction==2) y+=1; Counter++; end
    if (Direction==1)
      flags=2;
      if (Counter==1) graph=14; end
      if (Counter==2) graph=15; end
      if (Counter==3) graph=16; end
      if (Counter==4) graph=17; end
      if (Counter==5) graph=18; end
      if (Counter==6) graph=19; end
      if (Counter==7) graph=20; end
      if (Counter==8) graph=21; end
      if (Counter==9) graph=22; end
      if (Counter==10) graph=23; end  
    end
    if (Direction==2)
      flags=2;
      if (Counter==10) graph=14; end
      if (Counter==9) graph=15; end
      if (Counter==8) graph=16; end
      if (Counter==7) graph=17; end
      if (Counter==6) graph=18; end
      if (Counter==5) graph=19; end
      if (Counter==4) graph=20; end
      if (Counter==3) graph=21; end
      if (Counter==2) graph=22; end
      if (Counter==1) graph=23; end  
    end    
    if (Counter==11) Counter=1; end
    if (Direction==1 and y==4) Direction=2; end
    if (Direction==2 and y==236) Direction=1; end      
  end
  frame(50);
end
end


process Point(x,y,z);
begin
graph=8;
Shockwave(x,y,2,13);
loop
  if (collision(type Player))
    play_wav(Pop,0);
    Score++;
    Points+=ScoreCounter;
    ScoreCounter=200;
    InvincibleCounter=10;
    Point(rand(10,310),rand(10,230),4);
    CreateSparks(x,y,z-1,255,20,rand(1,3),4,1);
    Enemy(rand(10,310),rand(10,230),4,rand(1,2),rand(1,2));
    if (GameMode==2)
      ZoomText(160,120,0,41);
      signal (type Player, s_kill);
      Player(GlobalX,GlobalY,4,rand(1,7));
    end
    return;
  end
  frame;
end
end



process Bkg_Tile(x,y,z,graph);
private
int AnimationCounter;
begin
loop

  if (GlobalX>x-10 and GlobalX<x+10)
    if (GlobalY>y-10 and GlobalY<y+10)
      AnimationCounter=12;
    end
  end

  if (AnimationCounter==0) if (collision(type Particle_Trail)) AnimationCounter=12; end end
  if (AnimationCounter==12 or AnimationCounter==11 or AnimationCounter==10) graph=52; end
  if (AnimationCounter==9 or AnimationCounter==8 or AnimationCounter==7) graph=53; end
  if (AnimationCounter==6 or AnimationCounter==5 or AnimationCounter==4) graph=54; end
  if (AnimationCounter==3 or AnimationCounter==2 or AnimationCounter==1) graph=55; end
  if (AnimationCounter==0) graph=56; end 
  if (AnimationCounter>0) AnimationCounter--; end
  frame;
end
end


process Bkg_Tile2(x,y,z,graph);
begin
alpha=100;
loop
  if (rand(1,100)<5) alpha=250; end
  if (alpha>100) alpha-=10; 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=33+rand(1,4); end
if (Model==2) graph=33+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-=10;
  if (Gravity<8) Gravity++; end
  if (EntryVelocity<Velocity) Velocity--; end
  frame;
until (alpha<40)
end


process Particle_Trail(x,y,z,Direction,size,alpha);
private
int Speed;
begin
if (rand(1,2)==1) return; end
graph=2+rand(1,4);
Speed=1;
repeat
  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
  alpha=alpha-20;
  x+=rand(-2,2);
  y+=rand(-2,2);
  frame;
until (alpha<80)
end


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



process ZoomIn(x,y,z,graph,Start,Speed);
begin
size=Start;
repeat
  size-=Speed;
  frame;
until (size==100);
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 FadeIn(x,y,z,graph);
begin
alpha=0;
repeat
  alpha+=10;
  frame;
until (alpha==250)
loop frame; end
end


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


process TitleLogo(x,y,z,graph);
begin
loop
  repeat
    size++;
    frame(50);
  until (size==110);
  repeat
    size--;
    frame(50);
  until (size==80);
end
end


process Main_Menu_Option(y,x,z,graph);
begin
loop
  if (x<100) x+=5; end
  if (x>100) x-=5; end

  if (Main_Menu_Selection==1 and graph==46) if (alpha<250) alpha+=5; end end
  if (Main_Menu_Selection==2 and graph==47) if (alpha<250) alpha+=5; end end
  if (Main_Menu_Selection==3 and graph==48) if (alpha<250) alpha+=5; end end
  if (Main_Menu_Selection==4 and graph==49) if (alpha<250) alpha+=5; end end

  if (Main_Menu_Selection!=1 and graph==46) if (alpha>200) alpha-=5; end end
  if (Main_Menu_Selection!=2 and graph==47) if (alpha>200) alpha-=5; end end
  if (Main_Menu_Selection!=3 and graph==48) if (alpha>200) alpha-=5; end end
  if (Main_Menu_Selection!=4 and graph==49) if (alpha>200) alpha-=5; end end
  frame;
end
end


process Main_Menu_Selector(z,graph);
private
int Mode;
int Counter;

begin
x=100;
y=290;
size=95;
loop
  if (Main_Menu_Selection==1) if (y<100) y+=4; end if (y>100) y-=4; end end
  if (Main_Menu_Selection==2) if (y<130) y+=4; end if (y>130) y-=4; end end
  if (Main_Menu_Selection==3) if (y<160) y+=4; end if (y>160) y-=4; end end
  if (Main_Menu_Selection==4) if (y<190) y+=4; end if (y>190) y-=4; end end

  if (Mode==0) size++; Counter++; end
  if (Mode==1) size+=-1; Counter++; end
  if (Counter==5 and Mode==0) Mode=1; Counter=0; end
  if (Counter==5 and Mode==1) Mode=0; Counter=0; end
  frame;
end
end


process Falling_SmallBall(x);
begin
y=-10;
z=1;
graph=2;
repeat
  y+=5;
  Particle_Trail(x,y-5,3,3,100,200);
  frame;
until(y==250);
end


process VolumeControl();
begin
  set_song_volume(Volume);
  set_wav_volume(0,Volume);
  loop
    if (jkeys_state[_JKEY_VOLDOWN])
      Volume-=2;
      if (Volume>127) Volume=127; End
      set_song_volume(Volume);
      set_wav_volume(0,Volume);
    end
    if (jkeys_state[_JKEY_VOLUP])
      Volume+=2;
      if (Volume<1) Volume=1; End
      set_song_volume(Volume);
      set_wav_volume(0,Volume);
    end
    frame;
  end
end