/*************************************************************************
 * _Achicken Entity Script
 * 
 * Author: Satanman
 * Date:   30/06/02
 *
 * Desc:   A Script for a simple attack chicken. 
 *
 *         this is just an add-on to the big chicken
 *         
 *
 * Usage:  called by the main chicken. it's in a seperate script because
 *		   there are several on screen at once, so it must be small
 *         there's a 1 in 50 chance of getting a special chicken
 *
 * Sprites: _Chickensheet.spt
 *         
 ************************************************************************/
#include <entity>
#include <general>
#include <animation>
#include <float>
#include <core>

//==================================
//   Global Data
//==================================

new float: timer;
new chickanim[20];
new width;
new height;
new Bcolour = 255;  //blue
new Rcolour = 255;  //red
new HasBeenActive = 0;

//----------------------------------------
// Name: main()
//----------------------------------------
main()
{
	if (FirstRun())
	{
		// Create the animations
		CreateAnim(6, chickanim);    // Flying animations

		if (random(100) == 1)
		{
			Bcolour = 0;
			SetSpeed("this", 128 );
			SetDamage("this", 500);   //Golden Chicken of justice!
		} else if (random(100) == 1)
		{
			Rcolour = 0;
			SetSpeed("this", 40 );
			SetDamage("this", -500);   //Perspex Chicken of healing!
		} else {
			SetSpeed("this", 60 );
			SetDamage("this", 100);   //they take off 1 heart in lttp... I think
		}

		new fly = CalculateAngle(GetX("this"),GetY("this"),GetX("player1"),GetY("player1"));
		SetMoveAngle("this", fly);

		if (GetMoveAngle("this") > 90 && GetMoveAngle("this") < 270)
		{
			SetDirection("this", east);
			AddAnimframe(chickanim, 0, 0, "_chickeneast1");  // Flying east
			AddAnimframe(chickanim, 0, 0, "_chickeneast2");
		} else {
			SetDirection("this", west);
			AddAnimframe(chickanim, 0, 0, "_chickenwest1");  // Flying west
			AddAnimframe(chickanim, 0, 0, "_chickenwest2");
		}
		

		// Set some general parameters
		SetActiveDist("this", 320);
		SetType("this", otherType); //any other suggestions for its type?
		SetCuttableFlag("this", false);   //immortal
		SetActiveInGroups("this", true); //bug fix - can cross group boundaries
		
		width  = GetAnimWidth(chickanim);
		height = GetAnimHeight(chickanim);

	}

	if (isActive("this"))
		HasBeenActive = 1;

	if (!isActive("this") && HasBeenActive == 1)
		DeleteEntity("this");

	// Check for a collision with the player
	CallFunction("_enemylib", true, "CheckForPlayer", "NULL");


	width  = GetAnimWidth(chickanim);
	height = GetAnimHeight(chickanim);



	// Move the chicken if the game is unpaused
	if (GetPauseLevel() == 0)
		AngleMove("this");

	new x = GetX("this");
	new y = GetY("this");

	// Draw the chicken and its shadow
	if (isVisible("this"))
	{
		DrawAnim(chickanim, x, y - 16, y + height, 0, Rcolour, 255, Bcolour);
		PutSprite("shadow1", (x + width / 2) - 8, y + height - 15, 2);
	}

	// Set a collision rectangle around the chicken
	SetCollisionRect("this", 0, false, x, y, x + width, y + height);
}