/*************************************************************************
 * bridge#.zes Entity Script
 * 
 * Author: KC
 * Date:   Feb 2003
 *
 * Desc:   Forget layers, bridges can work!!
 *
 * Usage:  for walking on and under
 *
 * Sprites: _Bridges.spt
 *         
 ************************************************************************/
#include <entity>
#include <general>
#include <core>

//==================================
//   Global Data
//==================================
new mainSpr[20];
new param;

//----------------------------------------
// Name: main()
//----------------------------------------
main()
{
	if (FirstRun())
	{
		SetActiveFlag("this",true);
		SetVisibleFlag("this",true);
		param = GetParam("this");
		if (param == '1')
		{
			mainSpr = "underbridge1";
		} 
		else if (param == '2')
		{
			mainSpr = "underbridge2";
		} 
		else if (param == '3')
		{
			mainSpr = "underbridge3";
		}
		else if (param == '4')
		{
			mainSpr = "underbridge4";
		} 
		else if (param == '5')
		{
			mainSpr = "underbridge5";
		}
		// Set some general parameters
		SetActiveDist("this", 500);
		SetType("this", otherType);
	}

	
	// Get the width and height of the Current animation
	new width  = GetWidth(mainSpr);
	new height = GetHeight(mainSpr);
	new x = GetX("this");
	new y = GetY("this");
   
	if (isVisible("this"))
	{
		if(GetGlobal(799) < 1)
		{
			PutSprite(mainSpr, x, y, 0);
			if(param == '2')
			{
				SetCollisionRect("this", 0, true, x, y, x + width, y + height);
			}
			else if(param == '3')
			{
				SetCollisionRect("this", 0, true, x, y, x + width, y + height);
			}
			else if(param == '4')
			{
				ClearCollisionRect("this", 0);
			}
			else if(param == '5')
			{
				ClearCollisionRect("this", 0);
			}
		}
		if(GetGlobal(799) >= 1)
		{
			PutSprite(mainSpr, x, y, 99999);
			if(param == '2')
			{
				ClearCollisionRect("this", 0);
			}
			else if(param == '3')
			{
				ClearCollisionRect("this", 0);
			}
			else if(param == '4')
			{
				SetCollisionRect("this", 0, true, x, y, x + width, y + height);
			}
			else if(param == '5')
			{
				SetCollisionRect("this", 0, true, x, y, x + width, y + height);
			}
		}
	}
}

