#include "player.h"
#include "graphics.h"
#include "healthkit.h"
#include "stage.h"
#include "mouse.h"

gxSprite healthkitSprite;
Healthkit healthkit;

void InitHealthkit ()
{
	gxLoadBmp( "medkit.tga", &healthkitSprite, 0 );
	healthkit.X  = rand()%stages[currentStage].width;
	healthkit.Y  = rand()%stages[currentStage].height;
	healthkit.directionx = rand()%10 -5;
	healthkit.directiony = rand()%10 -5;
	healthkit.active = true;
}


void UpdateHealthkit ()
{
	// Healthkit Movement
	healthkit.X  += healthkit.directionx;
	healthkit.Y  += healthkit.directiony;


	if ( healthkit.X > stages[currentStage].width || healthkit.X < 0 )
	{
		healthkit.directionx = -healthkit.directionx;
	}
	if ( healthkit.Y > stages[currentStage].height - 31 || healthkit.Y < 0 )
	{
		healthkit.directiony = -healthkit.directiony;
	}
	//Get Healthkit
	if ( healthkit.X+16 <= player.X +64 && healthkit.X+16 >= player.X )
	{
		if ( healthkit.Y+16 <= player.Y +64 && healthkit.Y+16 >= player.Y )
		{
			if ( healthkit.active == true && player.health < 100 )
			{
				player.health += 10;
				if (player.health >= 100 )
				{
					player.health = 100;
				}
				healthkit.respawntime = 150;
				healthkit.active = false;

			}
		}
	}
	// Healthkit Reset
	if (healthkit.active == false )
	{
		healthkit.respawntime -= 1;
	}
	if ( healthkit.respawntime == 0 )
	{
	healthkit.active = true;
	}
	if ( healthkit.active == true && player.health < 100 )
	{
		gxDrawSpriteAlpha( healthkit.X-xAxis, healthkit.Y-yAxis, &healthkitSprite, 255 );
	}
}