namespace ExampleEnemy{

	npc script ExampleEnemyMinimal_NPCANIM{
		using namespace NPCAnim;
		
		// Constants for the enemy's animation offsets
		enum{
			ANIM_NEUTRAL = 0,
			ANIM_ATTACKING = 1
		};
		
		void run(int enemyid){
			// First create a new AnimHandler object, aptr. This will hold
			// all the data used for NPCAnim.zh's animation handling.
			// It will then be assigned to one of the enemy's Misc[] indices so
			// anything can access it off of the enemy.
			AnimHandler aptr = new AnimHandler(this);
			
			
			// Add animations to aptr with this function. Do this once at the start of the script.
			// In this case, the tile positions of both animations are relative to the enemy's original tile,
			// So ANIM_NEUTRAL uses 0 and ANIM_ATTACKING uses 8. You can use 
			// absolute tile numbers if you want with the ADF_NORELATIVE flag
			aptr->AddAnim(ANIM_NEUTRAL, 0, 4, 4, ADF_NORESET);
			aptr->AddAnim(ANIM_ATTACKING, 8, 4, 2, ADF_NORESET);
		
			// Resizes the enemy's tile size and hitbox.
			// The last four args are pixels shaved off each side of the hitbox.
			// It's generally best for the enemy's hitbox to be a little 
			// smaller than its sprite to account for empty space in the corners.
			aptr->SetHitbox(2, 2, {3, 3, 3, 3});
			
			int attack; // The current attack used by the enemy
			int attackCooldown = 96; // The delay before the enemy can use another attack
			
			while(true){
				// While the enemy isn't attacking, give it some other movement pattern.
				// The most basic is just moving straight towards Link every frame.
				int angleLink = Angle(this->X+8, this->Y+8, Link->X, Link->Y);
				this->MoveAtAngle(angleLink, 0.3);
			
				// Count down the attack cooldown to 0
				if(attackCooldown)
					--attackCooldown;
				// If it's 0, check against a random number for some variance
				else if(Rand(16)==0){
					// Now the attack phase begins. Choose an attack to use
					attack = Choose(0, 1);
					switch(attack){
						// ATTACK 0: Triple fireball
						case 0:
						{
							aptr->PlayAnim(ANIM_ATTACKING); 
							Custom_Waitframe(this, 16);
							// Offset the weapon angle in a loop to fire a triple shot
							for(int i=-1; i<=1; ++i){
								// FireEWeaponAtHero() creates an eweapon that moves towards Link
								// See std_functions.zh for this and other similar weapon firing functions
								eweapon e = FireEWeaponAtHero(EW_FIREBALL, this->X+8, this->Y+8, true, 250, this->WeaponDamage, -1, SFX_FIREBALL);
								// To offset the angle based on the for loop, add to e->DegAngle
								e->DegAngle += i*30;
							}
							Custom_Waitframe(this, 16);
							break;
						}
						// ATTACK 1: Dash at Link
						case 1:
						{
							aptr->PlayAnim(ANIM_ATTACKING); 
							// Store the angle between the enemy and Link, then wait for a bit
							int ang = Angle(this->X+8, this->Y+8, Link->X, Link->Y);
							Custom_Waitframe(this, 32);
							// For 32 frames, move at that angle
							for(int i=0; i<32; ++i){
								this->MoveAtAngle(ang, 2.5);
								Custom_Waitframe(this);
							}
							Custom_Waitframe(this, 16);
							break;
						}
					}
					// Reset the enemy's animation to neutral
					aptr->PlayAnim(ANIM_NEUTRAL); 
					// Make it wait another 96 frames before it can attack again
					attackCooldown = 96;
				}
			
				Custom_Waitframe(this);
			}
		}
		// Custom waitframe wrapper for the enemy
		// Checks if the enemy should die and plays its death animation
		// Can optionally run for multiple frames
		void Custom_Waitframe(npc this, int frames=1){
			for(int i=0; i<frames; ++i){
				if(this->HP<=0)
				{
					// Pull the AnimHandler off the enemy and run the death animation
					AnimHandler aptr = GetAnimHandler(this);
					aptr->PlayDeathAnim();
				}
				Waitframe(this);
			}
		}
	}
}