REM Variables:
REM ----------------------------
declara_variables:
global onum as integer
global DT#
global tiempo_actual as float
global nivel_actual

type cuadro
   objeto as integer
   objetoR as integer
   posx as float
   posz as float
   mat as integer
   fade as float
endtype

type jug
   objeto as integer
   posx as float
   posz as float
   movimiento as integer
   bhit as integer
   maxbombas as integer
   lastbomba as integer
   powbomba as integer
 	vel as float
 	slide as float
 	fade as float
 	muerto as float
 	vivo as integer
 	vidas as integer
 	autobomba as integer
endtype

type bomba
   objeto as integer
   activa as integer
   inflando as integer
   initim as integer
   duracion as integer
   chocada as integer
endtype

type map
	limites as integer
	modocam as integer
	camzoom as float
	maxtiempo as integer
	agua1 as integer
	agua2 as integer
	salida as integer
endtype

type explo
	objeto as integer
	activa as integer
	cuadro as float
	posx as float
	posz as float
endtype

type enem
	objeto as integer
	activo as integer
	tipo as integer
	sentido as integer
	posx as float
	posz as float
	vel as float
	lrot as integer
	fading as float
endtype

type spri
	img as integer
	activo as integer
	duracion as float
	tiempo as float
	posx as integer
	posy as integer
endtype

type imgs
	jugar as integer
	opciones as integer
	ayuda as integer
	creditos as integer
	salir as integer
	punto as integer
	mouse as integer
	ld as integer
	agua as integer
	titulo as integer
	res as integer
	r1 as integer
	r2 as integer
	r3 as integer
	atras as integer
	f1 as integer
 	f2 as integer
 	f3 as integer
 	crs as integer
 	gover as integer
 	egame as integer
 	ins as integer
 	ctr as integer
 	hup as integer
 	gtz as integer
endtype

type pup
	objeto as integer
	tipo as integer
endtype


global img as imgs

global snd_exp1 as integer
global snd_bmb1 as integer
global snd_idl1 as integer
global snd_idl2 as integer
global snd_menu as integer
global mus_menu as integer

global img_bar as integer
global img_go as integer
global img_hurry as integer
global img_time as integer
global img_des as integer

global powerup as pup


global jugando as integer
global mapa as map

dim sprites(50) as spri
dim img_exp1(18) as integer
dim bombas(10) as bomba
dim jugador(1) as jug
dim cuadros(12,34) as cuadro
dim explos(300) as explo
dim enemigos(50) as enem
dim pre_enem(10) as integer
dim col_tiles(6) as integer
return

REM FUNCIONES:
REM ----------------------------

function cargar_modelo(nombre as string)
   inc onum
   load object nombre,onum
endfunction onum

function clonar_modelo(origen as integer)
   inc onum
   clone object onum,origen
endfunction onum


function get_cuadro(pos as float)
   pos=abs(pos)
   pos=pos+8
   while pos>16
      pos=pos-16
      inc cuadx
   endwhile
endfunction cuadx

function get_resto_cuad#(cuadro as integer,pos as float)
   resultado#=(cuadro*16)-abs(pos)
endfunction resultado#

function distancia(o1 as integer,o2 as integer)
   x1#=object position x(o1)
   z1#=object position z(o1)
   x2#=object position x(o2)
   z2#=object position z(o2)
   resultado#=sqrt( ((x2#-x1#)*(x2#-x1#)) + ((z2#-z1#)*(z2#-z1#)) )
endfunction resultado#


function crear_sprite(x as integer,y as integer,img as integer,dur as integer)
	for i = 0 to 50
		if sprites(i).activo=0 then exit
	next i

	sprites(i).posx=x
	sprites(i).posy=y
	sprites(i).activo=1
	sprites(i).img=img
	sprites(i).duracion=dur
	sprites(i).tiempo=0
endfunction

function controlar_sprites()
	for i = 0 to 50
		if sprites(i).activo=1
			sprite 50+i,sprites(i).posx,sprites(i).posy,sprites(i).img
			show sprite 50+i
			sprites(i).tiempo=sprites(i).tiempo+(1*DT#)
			
			sprites(i).duracion=sprites(i).duracion-(1*DT#)
			
			alph#=(sprites(i).tiempo*255)/sprites(i).duracion
			alph#=255-(alph#*2)
			
			if alph#<0 then alph#=0
			
			if sprites(i).tiempo<sprites(i).duracion
				set sprite alpha 50+i,alph#
			else
				sprites(i).activo=0
				hide sprite 50+i
			endif
			
		endif
	next i
endfunction

function preparar_nivel()
	stop music 1
	stop sound snd_idl1
	stop music 2
	stop music mus_menu
	
	for i = 1 to 40
		if sprite exist(i)
			delete sprite i
		endif
	next i
	
	jugador(1).posx=0
	jugador(1).posz=0
	jugador(1).fade=0
	jugador(1).muerto=0
	jugador(1).vivo=1
	
	delete object jugador(1).objeto
	jugador(1).objeto=cargar_modelo("media\bman.x")
	
	rotate object jugador(1).objeto,0,180,0
	for i = 0 to 10
		bombas(i).activa=0
		hide object bombas(i).objeto
	next i
	
	for i = 0 to 200
		explos(i).activa=0
		hide object explos(i).objeto
	next i
	
	for i= 0 to 50
		enemigos(i).activo=0
		
		if enemigos(i).objeto>0
			if object exist(enemigos(i).objeto)
				delete object enemigos(i).objeto
			endif
		endif

		enemigos(i).objeto=0
	next i
endfunction

function borrar_sprites()
	for i = 1 to 100 
		if sprite exist(i)
			delete sprite i
		endif
	next i
endfunction
 