Program rheroes;

import "mod_m7";
import "mod_blendop";
import "mod_debug";
import "mod_dir";
import "mod_draw";
import "mod_file";
import "mod_grproc";
import "mod_joy";
import "mod_key";
import "mod_map";
import "mod_math";
import "mod_mouse";
import "mod_multi";
import "mod_proc";
import "mod_rand";
import "mod_regex";
import "mod_say";
import "mod_screen";
import "mod_scroll";
import "mod_sound";
import "mod_string";
import "mod_sys";
import "mod_text";
import "mod_time";
import "mod_timers";
import "mod_video";
import "mod_wm";

Global
	snd;
	fuente;
	lider=1;
	wavs[10];
	voces[142];
	rings;
	x_anterior;
	y_anterior;

Begin
	rand_seed(time());
	set_mode(640,480,32);
	load_fpg("rheroes.fpg");
	fuente=load_fnt("1.fnt");
	from x=1 to 4;
		wavs[x]=load_wav(x+".wav");
	end
	from x=1 to 142;
		voces[x]=load_wav("voces\ ("+x+").wav");
	end
	graph=1;
	x=320; y=240; z=10;
	play_song(load_song("1.ogg"),-1);
	from alpha=0 to 255 step 10; frame; end
	titulo();
	from z=10 to 1 step -1; size++; frame(300); end
	bichos();
	frame(3000);
	write(fuente,320,240,4,"PRES BETWEEN TO STAR!!!11");
	while(!key(_enter))
		if(key(_esc)) exit(); end
		frame;
	end
	graph=get_screen();
	let_me_alone();
	delete_text(all_text);
	size=100;
	from alpha=255 to 0 step -10; size++; frame; end
	frame(3000);
	graph=new_map(640,480,32);
	drawing_map(0,graph);
	drawing_color(rgb(0,0,0));
	draw_box(0,0,640,480);
	alpha=255;
	
	play_song(load_song("2.ogg"),-1);
	put_screen(0,1);
	start_mode7(0,0,21,22,0,240);
	m7[0].height=20;
	m7[0].camera=camara();
	voces();
	jugador();
	follower(1);
	follower(2);
	
	from x_anterior=0 to 10000 step 10;
		y_anterior=y_anterior+(rand(-10,10));
		ring(y_anterior,x_anterior);
	end
	esmeralda(y_anterior,x_anterior+500);
	marcador();
	from alpha=255 to 0 step -20; frame; end
	
	while(!key(_esc)) frame; end
	exit();
End

Process titulo();
Begin
	graph=2;
	x=320; y=150; alpha=0;
	from alpha=0 to 255 step 10; y+=4; frame; end
	while(exists(father)) frame; end
End

Process bichos();
Begin
	z=-1;
	graph=3;
	x=320;
	y=600;
	while(y>400) y-=rand(5,10); frame; end
	while(exists(father)) frame; end
End

Process camara();
Private
	vel;
	pulsando;
Begin
	ctype=c_m7;
	angle=-90000;
	while(exists(father))
		//graph=10+lider;
		//if(key(_left)) angle+=3000; end
		//if(key(_right)) angle-=3000; end
		if(key(_left)) x+=3; end
		if(key(_right)) x-=3; end
		if(key(_up)) vel+=2; end
		if(key(_down)) vel-=2; end
		if(key(_space))
			if(pulsando==0)
				lider+=1;
				if(lider==4) lider=1; end
				stop_wav(-1);
				snd=play_wav(wavs[1+lider],0);
				pulsando=1;
			end
		else
			pulsando=0;
		end
		if(vel!=0)
			if(vel>0) vel--; else vel++; end
			if(vel>(rings/50)+1) vel=(rings/50)+1; end
			if(vel<-((rings/50)+1)) vel=-((rings/50)+1); end
			advance(vel); 
		end
		frame;
	end
End

Process jugador();
Begin
	graph=11;
	x=320; y=350;
	size=50;
	loop
		graph=10+lider;
		frame;
	end
End

Process follower(num);
Begin
	size=50;
	if(num==1)
		x=250;
	else
		x=390;
	end
	y=400;
	loop
		graph=10+num+lider;
		if(graph>13) graph-=3; end
		frame;
	end
End

Process ring(x,y);
Begin
	graph=31;
	ctype=c_m7;
	height=10;
	loop
		angle+=1000;
		if(get_dist(m7[0].camera)<8) break; end
		frame;
	end
	play_wav(wavs[1],0);
	rings++;
	from alpha=255 to 0 step -10; frame; end
End

Process esmeralda(x,y);
Begin
	graph=32;
	ctype=c_m7;
	height=10;
	loop
		angle+=1000;
		if(get_dist(m7[0].camera)<8) break; end
		frame;
	end
	play_wav(wavs[1],0);
	from alpha=255 to 0 step -10; frame; end
	//let_me_alone();
	yourpresidentnow();
	//main();
	return;
End

Process marcador();
Begin
	graph=4;
	x=320;
	y=240;
	z=-10;
	write_int(fuente,90,85,0,&rings);
	loop
		frame;
	end
End

Process voces();
Begin
	loop
		//frame(3000);
		snd=play_wav(voces[rand(1,142)],0);
		while(is_playing_wav(snd)) frame; end
		frame;
	end
End

Process yourpresidentnow();
Begin
	graph=5;
	x=320; y=240; z=-100;
	size=0;
	while(size<100)
		size++;
		frame;
	end
	loop
		from size=100 to 120; frame; end
		from size=120 to 80 step -1; frame; end
		frame;
	end
End