program EpicFreeFall ;

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"

global

//Variables
int GameOver;
int Score;
int Score2;
int HighScore;
int Selection;
int LogoCounter;
int ShowLogo;
int PlayerWin;

CONST
 	KEY_UP = 1;
    KEY_DOWN = 2;
    KEY_LEFT = 3;
    KEY_RIGHT = 4;
    KEY_A = 5;
    KEY_B = 6;
    KEY_X = 7;
    KEY_Y = 8;
    KEY_START = 9;
    KEY_CLOSE = 10;
	KEY_VOL_UP = 11;
	KEY_VOL_DOWN = 12;

    NUM_OF_KEYS_FOR_PLAYER = 12;

    PLAYER_1 = 1;
    PLAYER_2 = 2;

    NUM_OF_PLAYERS = 2;
GLOBAL
int player_key[NUM_OF_PLAYERS][NUM_OF_KEYS_FOR_PLAYER];
int player_key_state[NUM_OF_PLAYERS][NUM_OF_KEYS_FOR_PLAYER];

//Sound INT's
int Bip;
int Poff;
int Pop;
int Boing;
int Crumble;
int Turn;
int Song;
int Volume = 40;
int uc;
int dc;

begin
	
	
	Full_Screen=true;
	set_mode(320,240,16);
	
	load_fpg("freefall.fpg");
	sound_freq=44100;
	
	Bip=load_wav("Sound/bip.wav");
	Poff=load_wav("Sound/poff.wav");
	Pop=load_wav("Sound/pop.wav");
	Boing=load_wav("Sound/boing.wav");
	Crumble=load_wav("Sound/crumble.wav");
	Turn=load_wav("Sound/turn.wav");
	
	Song=load_song("Music/fdsfssfdd.ogg");
	
	load("score.dat",HighScore);
	ShowLogo=0;
	loop
	
		let_me_alone();
		delete_text(0);
		
		stop_song();
		play_song(Song,99);
		set_song_volume(Volume);
		
		Title(160,40,1);
		
		Background1(160,360,10,2);
		Background1(160,120,10,2);
		
		Background2(0,120,12,10);
		Background2(320,120,12,10);
		
		frame; frame; frame; frame; frame;
		frame; frame; frame; frame; frame;
		
		if (ShowLogo==0)
		  Logo(160,120,0,23);
		  Logo(170,190,0,24);
		 
		  LogoCounter=0; repeat LogoCounter++; frame; until(LogoCounter>40)
		  ShowLogo=1;
		end
		
		
		write(0,90,90,0,"Top Score :");
		write_int(0,170,90,0,&HighScore);
		
		Selection=1;
		
		Menu(160,130,1,20);
		Menu(160,170,1,21);
		Menu(160,210,1,22);
		Menu(160,235,0,41);

		set_default_keys();
	    signal( type controls, s_kill ); controls();
		controls();
		uc = 0;
		dc = 0;
		repeat
		  if ( player_key_state[PLAYER_1][KEY_UP] and uc > 2) play_wav(Bip,0); Selection--; uc = 0;
		  elseif (player_key_state[PLAYER_1][KEY_UP] and uc <= 2) uc += 1; 
		  end
		  if ( player_key_state[PLAYER_1][KEY_DOWN] and dc > 2) play_wav(Bip,0); Selection++; dc = 0;
		  elseif (player_key_state[PLAYER_1][KEY_DOWN] and dc <= 2) dc += 1;
		  end
		  if (Selection==4) Selection=1; end
		  if (Selection==0) Selection=3; end  
		  frame; 
		until( player_key_state[PLAYER_1][KEY_START]);
		
		if ( (player_key_state[PLAYER_1][KEY_START]) AND Selection==3) 
			frame; frame; frame; frame; frame; exit("Quit",0); 
		end
		frame; frame; frame; frame; frame;
		signal (type Title, s_kill);
		delete_text(0);
		
		LongBox();
		LongBox();
		LongBox();
		frame; frame; frame; frame; frame;
		SpawnObjects();
		
		if (Selection==1)
		  write_int(0,1,1,0,&Score);
		  Player(160,30,4,1);
		end
		if (Selection==2)
		  write_int(0,1,1,0,&Score);
		  write_int(0,270,1,0,&Score2);
		  Player(140,30,4,1);
		  Player2(180,30,4,25);
		end
		
		repeat
		  frame;
		until(player_key_state[PLAYER_1][KEY_START] or GameOver==1)
		
		if (Score>HighScore) HighScore=Score; end
		save("score.dat",HighScore);
		
		frame; frame; frame; frame; frame;
		if (Selection==2)
		  if (PlayerWin==1) Menu(160,120,1,26); end
		  if (PlayerWin==2) Menu(160,120,1,27); end
		repeat frame; until( player_key_state[PLAYER_1][KEY_START]);
		end
		
		GameOver=0;
		Score=0;
		Score2=0;
		PlayerWin=0;
		let_me_alone();
		
	
	end
end


FUNCTION set_default_keys()

BEGIN
    player_key[PLAYER_1][KEY_UP]=_up;
    player_key[PLAYER_1][KEY_DOWN]=_down;
    player_key[PLAYER_1][KEY_LEFT]=_left;
    player_key[PLAYER_1][KEY_RIGHT]=_right;
    player_key[PLAYER_1][KEY_A]=_q;
    player_key[PLAYER_1][KEY_B]=_w;
    player_key[PLAYER_1][KEY_X]=_e;
    player_key[PLAYER_1][KEY_Y]=_r;
    player_key[PLAYER_1][KEY_START]=_enter;
    player_key[PLAYER_1][KEY_CLOSE]=_esc;
	player_key[PLAYER_1][KEY_VOL_UP]=_b;
 	player_key[PLAYER_1][KEY_VOL_DOWN]=_n;

    player_key[PLAYER_2][KEY_UP]=_o;
    player_key[PLAYER_2][KEY_DOWN]=_l;
    player_key[PLAYER_2][KEY_LEFT]=_k;
    player_key[PLAYER_2][KEY_RIGHT]=_SEMICOLON;
    player_key[PLAYER_2][KEY_A]=_t;
    player_key[PLAYER_2][KEY_B]=_y;
    player_key[PLAYER_2][KEY_X]=_u;
    player_key[PLAYER_2][KEY_Y]=_i;
    player_key[PLAYER_2][KEY_START]=_enter;
    player_key[PLAYER_2][KEY_CLOSE]=_esc;
    player_key[PLAYER_2][KEY_VOL_UP]=_b;
 	player_key[PLAYER_2][KEY_VOL_DOWN]=_n;

END

process controls()
private
    p, k;
begin
    loop
        for ( p = 1; p <= NUM_OF_PLAYERS; p++)
            for ( k = 1; k <= NUM_OF_KEYS_FOR_PLAYER; k++)
                player_key_state[p][k] = key(player_key[p][k]);
            end
        end

        #define WIZ_UP          0
        #define WIZ_UP_LEFT     1
        #define WIZ_LEFT        2
        #define WIZ_DOWN_LEFT   3
        #define WIZ_DOWN        4
        #define WIZ_DOWN_RIGHT  5
        #define WIZ_RIGHT       6
        #define WIZ_UP_RIGHT    7

        #define WIZ_MENU        8
        #define WIZ_SELECT      9

        #define WIZ_L_BUTTON    10
        #define WIZ_R_BUTTON    11

        #define WIZ_A           12
        #define WIZ_B           13
        #define WIZ_X           14
        #define WIZ_Y           15

        #define WIZ_VOL_UP      16
        #define WIZ_VOL_DOWN    17

        /* Wiz */

        if (joy_number())
            player_key_state[PLAYER_1][KEY_UP]    |= joy_getbutton(0,WIZ_UP);
            player_key_state[PLAYER_1][KEY_DOWN]  |= joy_getbutton(0,WIZ_DOWN);
            player_key_state[PLAYER_1][KEY_LEFT]  |= joy_getbutton(0,WIZ_LEFT);
            player_key_state[PLAYER_1][KEY_RIGHT] |= joy_getbutton(0,WIZ_RIGHT);
            
            
            player_key_state[PLAYER_1][KEY_CLOSE] |= joy_getbutton(0,WIZ_SELECT);
            player_key_state[PLAYER_1][KEY_START] |= joy_getbutton(0,WIZ_MENU);
            player_key_state[PLAYER_1][KEY_VOL_UP] |= joy_getbutton(0,WIZ_VOL_UP);
            player_key_state[PLAYER_1][KEY_VOL_DOWN] |= joy_getbutton(0,WIZ_VOL_DOWN);
            
            player_key_state[PLAYER_2][KEY_LEFT]     |= joy_getbutton(0,WIZ_A);
            player_key_state[PLAYER_2][KEY_RIGHT]     |= joy_getbutton(0,WIZ_B);
            
        end
        if (player_key_state[PLAYER_1][KEY_VOL_DOWN])
	        Volume -= 2;
	        If (Volume > 127) Volume = 127; End
	        set_song_volume(Volume);
        end
        if (player_key_state[PLAYER_1][KEY_VOL_UP])
	        Volume += 2;
	        If (Volume < 1) Volume = 1; End
	        set_song_volume(Volume);
        end
        frame;
    end
end





process Player(x,y,z,graph);
private
int SpikeCounter;
int Slow;
begin

loop
	Slow = 0;
  y+=5;
  if (y>230) y=230; end

  if (collision(type Box))
    repeat
      frame(0);
      y--;
    until(collision(type Box)==0)
  end frame(0);

  if (collision(type LongBox))
    repeat
      frame(0);
      y--;
    until(collision(type LongBox)==0)
  end frame(0);
  
  if (collision(type BrokenBox))
    repeat
      frame(0);
      y--;
    until(collision(type BrokenBox)==0)
  end frame(0);
  
  if (collision(type BounceBox))
    repeat
      frame(0);
      y--;
    until(collision(type BounceBox)==0)
  end frame(0);

  if (collision(type RotateBox))
    repeat
      frame(0);
      y--;
    until(collision(type RotateBox)==0)
  end frame(0);

  if (collision(type RubberBox))
    repeat
      frame(0);
      Slow = 3;
      y--;
    until(collision(type RubberBox)==0)
  end frame(0);
  
  if (player_key_state[PLAYER_1][KEY_LEFT])
    x = x - (6-Slow);
    if (collision(type Box) or collision(type LongBox) or collision(type Spikes) or collision(type BrokenBox) or collision(type BounceBox) or collision(type RotateBox)) 
    	x = x + (6-Slow);
    end	
   
  end
  
  if (player_key_state[PLAYER_1][KEY_RIGHT])
    x = x + (6-Slow);
    if (collision(type Box) or collision(type LongBox) or collision(type Spikes) or collision(type BrokenBox) or collision(type BounceBox) or collision(type RotateBox)) 
    	x = x - (6-Slow);
    end
  end
  
  if (x<10) x=10; end
  if (x>310) x=310; end

  if (x>0 and x<80) set_panning(0,255,0); set_panning(1,255,0); set_panning(2,255,0); end
  if (x>80 and x<160) set_panning(0,200,50); set_panning(1,200,50); set_panning(2,200,50); end
  if (x>160 and x<240) set_panning(0,50,200); set_panning(1,50,200); set_panning(2,20,200); end
  if (x>240 and x<320) set_panning(0,0,255); set_panning(1,0,255); set_panning(2,0,255); end

  if (collision(type Spikes)) SpikeCounter++; end
  if (SpikeCounter>3)
    graph=0;
    play_wav(Poff,0);
    Shockwave(x,y,z-1,37);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    frame; frame; frame; frame; frame;
    GameOver=1;
    PlayerWin=2;
    return;
  end

  if (y<-20)
    graph=0;
    play_wav(Poff,0);
    Shockwave(x,y,z-1,37);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    Particle_Splash(x,y,z-1,3);
    frame; frame; frame; frame; frame;
    GameOver=1;
    PlayerWin=2;
    return;
  end

  Score+=1;

  frame;
end
end



process Player2(x,y,z,graph);
private
int SpikeCounter;
int Slow;
begin

loop
  Slow = 0;
  y+=5;
  if (y>230) y=230; end

  if (collision(type Box))
    repeat
      frame(0);
      y--;
    until(collision(type Box)==0)
  end frame(0);

  if (collision(type LongBox))
    repeat
      frame(0);
      y--;
    until(collision(type LongBox)==0)
  end frame(0);
  
  if (collision(type BrokenBox))
    repeat
      frame(0);
      y--;
    until(collision(type BrokenBox)==0)
  end frame(0);
  
  if (collision(type BounceBox))
    repeat
      frame(0);
      y--;
    until(collision(type BounceBox)==0)
  end frame(0);

  if (collision(type RotateBox))
    repeat
      frame(0);
      y--;
    until(collision(type RotateBox)==0)
  end frame(0);
  
  if (collision(type RubberBox))
    repeat
      frame(0);
      Slow = 3;
      y--;
    until(collision(type RubberBox)==0)
  end frame(0);

  if (player_key_state[PLAYER_2][KEY_LEFT])
    x = x - (6-Slow);
    if (collision(type Box) or collision(type LongBox) or collision(type Spikes) or collision(type BrokenBox) or collision(type BounceBox) or collision(type RotateBox)) 
     x = x + (6-Slow);
    end
    frame(0);
  end
  
  if (player_key_state[PLAYER_2][KEY_RIGHT])
    x = x + (6-Slow);
    if (collision(type Box) or collision(type LongBox) or collision(type Spikes) or collision(type BrokenBox) or collision(type BounceBox) or collision(type RotateBox)) 
    	x = x - (6-Slow);
    end
    frame(0);
  end
  
  if (x<10) x=10; end
  if (x>310) x=310; end

  if (collision(type Spikes)) SpikeCounter++; end
  if (SpikeCounter>3)
    graph=0;
    play_wav(Poff,0);
    Shockwave(x,y,z-1,38);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    frame; frame; frame; frame; frame;
    GameOver=1;
    PlayerWin=1;
    return;
  end

  if (y<-20)
    graph=0;
    play_wav(Poff,0);
    Shockwave(x,y,z-1,38);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    Particle_Splash(x,y,z-1,4);
    frame; frame; frame; frame; frame;
    GameOver=1;
    PlayerWin=1;
    return;
  end

  Score2+=1;

  frame;
end
end





process SpawnObjects();
begin

Box();
Box();
LongBox();
LongBox();

loop

  if (rand(1,8)==1) Box(); end
  if (rand(1,12)==1) LongBox(); end
  if (rand(1,28)==1) RubberBox(); end
  if (rand(1,28)==1) Spikes(); end
  if (rand(1,28)==1) BrokenBox(); end
  if (rand(1,35)==1) BounceBox(); end
  if (rand(1,30)==1) RotateBox(); end
  if (rand(1,20)==1) Point1(); end
  if (rand(1,50)==1) Point2(); end
              
  frame;
end
end



process Spikes();
private
int Counter;
begin
graph=8;
z=4;

repeat
  x=rand(10,310);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=7;
repeat
  y-=5;
  frame;
until(y<-50)
end



process Box();
private
int Counter;
begin
graph=4;
z=4;

repeat
  x=rand(10,310);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=3;
repeat
  y-=5;
  frame;
until(y<-50)
end



process LongBox();
private
int Counter;
begin
graph=6;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=5;
repeat
  y-=5;
  frame;
until(y<-50)
end

process RubberBox();
private
int Counter;
begin
graph=43;
z=4;

repeat
  x=rand(10,310);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=42;
repeat
  y-=5;
  frame;
until(y<-50)
end


process BrokenBox();
private
int Counter;
int Destroy;
int Acceleration;
begin
graph=6;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=11;
repeat
  y-=5;
  if (Destroy==0 and collision(type Player) or collision(type Player2)) Destroy=1; play_wav(Crumble,0); end
  if (Destroy==1)
    Particle_Fade(x+rand(-56,56),y+rand(0,16),1,rand(1,8),1);
    Particle_Fade(x+rand(-56,56),y+rand(0,16),1,rand(1,8),1);
    Acceleration++;
    y+=Acceleration;
    alpha-=20;
  end
  frame;
until(y<-50 or alpha<0)
end



process BounceBox();
private
int Counter;
int BounceCounter;
begin
graph=17;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=16;
repeat
  y-=5;
  if (BounceCounter==0 and collision(type Player) or collision(type Player2)) play_wav(Boing,0); BounceCounter=6; end
  if (BounceCounter>0)
    BounceCounter--;
    if (BounceCounter<6 and BounceCounter>3) y+=3; end
    if (BounceCounter<3 and BounceCounter>0) y-=3; end    
  end
  frame;
until(y<-50 or alpha<0)
end



process RotateBox();
private
int Counter;
int Rotate;
int Direction;
begin
graph=17;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

Direction=rand(1,2);
if (Direction==1) graph=19; end
if (Direction==2) graph=18; end
repeat
  y-=5;
  if (Rotate==0 and collision(type Player) or collision(type Player2)) play_wav(Turn,0); Rotate=1; end
  if (Rotate==1)
    if (Direction==1)
      if (Angle<90000) angle+=5000; end
    end
    if (Direction==2)
      if (Angle>-90000) angle-=5000; end
    end    
  end
  frame;
until(y<-50 or alpha<0)
end



process Point1();
private
int Counter;
begin
graph=32;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=28;
repeat
  y-=5;
  if (collision(type Player))
    play_wav(Pop,0);
    Shockwave(x,y,z-1,35);
    Display_Score(x,y,z-1,39);
    Score+=50;
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    return;
  end
  if (collision(type Player2))
    play_wav(Pop,0);
    Shockwave(x,y,z-1,35);
    Display_Score(x,y,z-1,39);
    Score2+=50;
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    Particle_Splash(x,y,z-1,1); Particle_Splash(x,y,z-1,1);
    return;
  end
  frame;
until(y<-50)
end



process Point2();
private
int Counter;
begin
graph=32;
z=4;

repeat
  x=rand(10,320);
  y=rand(280,480);
  Counter++;
  if (Counter==20) return; end
  frame(0);
until(collision(type Box)==0 and collision(type RubberBox)==0 and collision(type LongBox)==0 and collision(type Spikes)==0 and collision(type BrokenBox)==0 and collision(type BounceBox)==0 and collision(type RotateBox)==0 and collision(type Point1)==0 and collision(type Point2)==0)

graph=29;
repeat
  y-=5;
  if (collision(type Player))
    play_wav(Pop,0);
    Display_Score(x,y,z-1,40);
    Shockwave(x,y,z-1,36);
    Score+=500;
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    return;
  end
  if (collision(type Player2))
    play_wav(Pop,0);
    Display_Score(x,y,z-1,40);
    Shockwave(x,y,z-1,36);
    Score2+=50;
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    Particle_Splash(x,y,z-1,2); Particle_Splash(x,y,z-1,2);
    return;
  end
  frame;
until(y<-50)
end



process Background1(x,y,z,graph);
begin
loop
  y-=5;
  if (y==-120) y=360; end
  frame;
end
end


process Background2(x,y,z,graph);
begin
loop
  x+=2;
  if (x==480) x=-160; end
  frame;
end
end


process Title(x,y,z);
private
int Counter;
int Counter2;
begin
graph=9;
size=0;
alpha=0;

repeat
  size+=10;
  alpha+=25;
  frame;
until(size==100)

repeat
  Counter2++;
  Counter++;
  if (Counter>0 and Counter<20) size+=1; end
  if (Counter>20 and Counter<40) size-=1; end
  if (Counter==41) Counter=0; end
  frame(50);
until(counter2>50)

loop
  Counter++;
  if (Counter>0 and Counter<20) size+=1; end
  if (Counter>20 and Counter<40) size-=1; end
  if (Counter==41) Counter=0; end
  frame(50);
  if (player_key_state[PLAYER_1][KEY_START])
    Counter=0;
    repeat
      size-=10;
      alpha-=30;
      Counter++;
      frame;
    until(Counter==10)
    return;
  end
end
end


process Particle_Splash(x,y,z,Mode);
private
int Speed;
int DownSpeed;
int Direction;
begin
alpha=200;
flags=16;
if (Mode==1) graph=30; end
if (Mode==2) graph=31; end
if (Mode==3) graph=33; end
if (Mode==4) graph=34; end
DownSpeed=rand(-8,-4);
Speed=rand(-2,2);
if (Mode==3 or Mode==4) Direction=rand(1,2); flags=rand(1,3); end
repeat
  x+=Speed;
  y+=DownSpeed;
  if (DownSpeed<4) DownSpeed++; end
  alpha-=10;
  
  if (Mode==3 or Mode==4)
    if (Direction==1) angle+=5000; end
    if (Direction==2) angle-=5000; end
  end
  
  frame;
until(alpha<0)
end



process Particle_Fade(x,y,z,Direction,Mode);
private
int Speed;
int Rotation;
begin
if (Mode==1 or Mode==2) alpha=100; end
Speed=rand(1,3);
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
  if (Mode==1) alpha=alpha-10; end
  if (Mode==2) alpha=alpha-20; end
  x+=rand(-2,2);
  y+=rand(-2,2);
  if (Mode==1)
    if (alpha>120 and alpha<150) graph=12; end
    if (alpha>80 and alpha<120) graph=13; end
    if (alpha>40 and alpha<80) graph=14; end
    if (alpha>0 and alpha<40) graph=15; end
  end
  frame;
until (alpha==20)
end


process Menu(x,y,z,graph);
private
int Counter;
begin
alpha=0;
size=0;
repeat
  size+=10;
  alpha+=25;
  frame;
until(size==100)

loop
  if (graph==20 and Selection==1) alpha=255; end
  if (graph==21 and Selection==2) alpha=255; end
  if (graph==22 and Selection==3) alpha=255; end
  if (graph==26) alpha=255; end
  if (graph==41) alpha=255; end    
  if (graph==27) alpha=255; end  
  if (alpha>100) alpha-=5; end

  if (player_key_state[PLAYER_1][KEY_START])
    Counter=0;
    repeat
      size-=10;
      alpha-=30;
      Counter++;
      frame;
    until(Counter==10)
    return;
  end
  
  frame(50);
end
end



process Logo(x,y,z,graph);
private
int Counter;
begin

alpha=0;
size=0;
repeat
  size+=10;
  alpha+=25;
  frame;
until(size==100)

repeat
  Counter++;
  frame;
until(counter>20)

repeat
  size-=10;
  alpha-=25;
  frame;
until(size==0)

end



process Shockwave(x,y,z,graph);
begin
alpha=120;
size=0;
repeat
  size+=20;
  alpha-=20;
  frame;
until (alpha==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