// class definition stuff for sprite.
// all variables are private members of the class.

#include "Sprite.h"
#include <math.h>


void Sprite::drawPartIMG(SDL_Surface *img, SDL_Surface *screen, int x, int y, int width, int height, int x2, int y2)
{
	SDL_Rect dest;
	dest.x = x;
	dest.y = y;
	
	SDL_Rect dest2;
	dest2.x = x2;
	dest2.y = y2;
	dest2.w = width;
	dest2.h = height;

	SDL_BlitSurface(img, &dest2, screen, &dest);
}

void Sprite::drawIMG(SDL_Surface *img, SDL_Surface *screen, int x, int y)
{
	SDL_Rect dest;
	dest.x = x;
	dest.y = y;
	SDL_BlitSurface(img, NULL, screen, &dest);
}



bool Sprite::inRange(double distance, int enemyType)
{
	switch (enemyType)
	{
		case 1: //zombie
	    if (distance <= 300) //if you're closer than 200 pixels away zombie can see you.
			  closeEnough = true;
			else
				closeEnough = false;
			break;
	}

	return closeEnough;
}



double Sprite::getDistance(int x1, int y1, int x2, int y2)
{
	//gets the distance between sprites and returns that value


	distanceX = (double)x2 - (double) x1;
	distanceY = (double)y2 - (double)y1;
	distance = sqrt(pow(distanceX, 2) + pow(distanceY,2));

	return distance;
}


SDL_Surface* Sprite::loadIMG(const char* image)
{
	SDL_Surface *fileToLoad, *imageToReturn;
	
	fileToLoad = SDL_LoadBMP(image);
	imageToReturn = SDL_DisplayFormat(fileToLoad);
	SDL_FreeSurface(fileToLoad);

	return imageToReturn;
  
}

