/*
 * funcs.cpp
 *
 *  Created on: 2010.04.16.
 *      Author: Szabó László
 */

#include "funcs.hpp"

SDL_Surface* load( std::string filename ){

	SDL_Surface* temp = NULL;
	SDL_Surface* rpic = NULL;

	temp = IMG_Load( filename.c_str() );

	if( temp != NULL ){
		rpic = SDL_DisplayFormat( temp );
		SDL_FreeSurface( temp );
	}

	SDL_SetColorKey( rpic, SDL_SRCCOLORKEY, SDL_MapRGB( rpic->format, 0, 0xFF, 0xFF ) );

	return rpic;
}

void apply( int x, int y, SDL_Surface* src, SDL_Surface* dest, SDL_Rect* clip ){
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;

	SDL_BlitSurface( src, clip, dest, &offset );
}

bool collision( SDL_Rect A, SDL_Rect B ){

	if( A.y + A.h < B.y ) return false;
	if( A.y > B.y + B.h ) return false;
	if( A.x >= B.x + B.w ) return false;
	if( A.x + A.w <= B.x ) return false;

	return true;
}
