/***********************************************
 * Elec1 
 * 
 * Author: Pikachu19192
 * Date:   1/11/2003
 *
 * Desc:  Its an enemy that can only be killed by the level 2 sword
 *
 * Usage:	Place as an entity
 *         
 ***********************************************/
#include <entity>
#include <general>
#include <animation>
#include <float>
#include <core>
#include <counter>
new Elec[20];
new LastImage[20];
new DeadAnim[20];
new float: HitCount;
new width;
new height;
new x;
new y;
main()
{
	if (FirstRun())
	{
		CreateAnim(5, Elec); 
		AddAnimframe(Elec, 0, 0, "Elec1");  
		AddAnimframe(Elec, 0, 0, "Elec1a");
		LastImage = "Elec1";
		
		
		
   
   
		
		SetActiveDist("this", 320);
		SetType("this", enemyType);
		SetItem("this","Nothing");
		SetDamage("this", 50);
		width  = GetAnimWidth(Elec);
	    height = GetAnimHeight(Elec);
		x = GetX("this");
		y = GetY("this");
	    SetHealth("this", 50);
		SetMaxHealth("this", 50);
		CreateAnim(8, DeadAnim);
		CallFunction("_enemylib", true, "CreateDeathAnim", "s", DeadAnim );
		SetCollisionRect("this", 0, true, x, y, x + width, y + height);
	}

	
	// Check for a collision with the player
	if (Collide("this", "player1"))
	{
		PlaySound("LinkElectrified.wav");
		// Call the BeginHit() function in the player script
		CallFunction("player1", false, "BeginHit", "nnn", x, y, GetDamage("this"));
	}

    // Call a function for the enemy depending on its state
   switch( GetState("this") )
      {
     case standing:
      	 Stand();
     case dying:
     	Die();
     case hit:
     	Hit();
     
    
     
      }
}
//----------------------------------------
// Name:Stand()
//----------------------------------------
Stand()
{
if(isVisible("this")&& isActive("this"))
	{
    DrawAnim(Elec, x, y, y + height,9999);
	}
if(isVisible("this") && !isActive("this"))
{
PutSprite("Elec1gone", x, y, y + height,9999);
}
}

//----------------------------------------
// Name: HitByWeapon(wtype[], damage, x, y)
//----------------------------------------
public HitByWeapon(wtype[], damage, x, y)
{    
    new state = GetState("this");
   if (state == dying)
      	return;
	if ( !strcmp( wtype, "sword" )&& damage >= 100 )
	{
		
		CallFunction("_enemylib", true, "BeginHit", "nnn", damage, x, y );
	
	}
		if ( !strcmp( wtype, "sword" )&& damage <= 50 )
	{
		PlaySound("LinkElectrified.wav");
		// Call the BeginHit() function in the player script
		CallFunction("player1", false, "BeginHit", "nnn", x, y, GetDamage("this"));
	}

	
}
//----------------------------------------
// Name: Hit()
//----------------------------------------
Hit()
{
	new colors[5][3] = { {19,125,19}, {253,211,65}, {225,88,5}, {32,211,238}, {238,32,32} };
	new width  = GetAnimWidth(Elec);
	new height = GetAnimHeight(Elec);

	// Move the enemy if the game is completely unpaused
	if (GetPauseLevel() == 0)
	{
		AngleMove("this");
		AngleCollide("this", 5, 5, 126, 0, width / 2, height / 2);
	}

	new x = GetX("this");
	new y = GetY("this");

	// Draw the enemy
	if (isVisible("this"))
	{
		DrawAnim(Elec, x, y, y + height, 0, colors[ floatround(HitCount * 20.0) % 5 ][0], \
			colors[ floatround(HitCount * 20.0) % 5 ][1], \
			colors[ floatround(HitCount * 20.0) % 5 ][2], 255, 0, 100);

		
	}

	// Check the hit counter
	HitCount += GetTimeDelta();

	if (HitCount >= 0.23)
	{
		// Leave the Hit state
		SetState("this", standing); 
	
	}
}

//----------------------------------------
// Name: Die()
//----------------------------------------
Die()
{		
	// Draw the enemy standing still
	if (GetAnimCount(DeadAnim) < 5)
		Stand( true );   	

	// Overlay the death animation over the enemy
	CallFunction("_enemylib", true, "HandleDying", "ss", DeadAnim, LastImage);   
	SetHealth("this", 0);
}
 