
#include "collide.h"

char		collide (float x1_old, float y1_old, float x1_new, float y1_new, float w1_min, float w1_max, float h1_min, float h1_max, float x2_old, float y2_old, float x2_new, float y2_new, float w2_min, float w2_max, float h2_min, float h2_max)
{
	float	x1_max;
	float	x1_min;
	float	x2_max;
	float	x2_min;
	float	y1_max;
	float	y1_min;
	float	y2_max;
	float	y2_min;
	char	flag;

	if (x1_old < x1_new)
	{
		x1_max = x1_new;
		x1_min = x1_old;
	}
	else
	{
		x1_max = x1_old;
		x1_min = x1_new;
	}

	if (x2_old < x2_new)
	{
		x2_max = x2_new;
		x2_min = x2_old;
	}
	else
	{
		x2_max = x2_old;
		x2_min = x2_new;
	}

	if (y1_old < y1_new)
	{
		y1_max = y1_new;
		y1_min = y1_old;
	}
	else
	{
		y1_max = y1_old;
		y1_min = y1_new;
	}

	if (y2_old < y2_new)
	{
		y2_max = y2_new;
		y2_min = y2_old;
	}
	else
	{
		y2_max = y2_old;
		y2_min = y2_new;
	}

	flag = 0;

	if (x1_max + w1_max > x2_min + w2_min && x1_min + w1_min < x2_max + w2_max)
	{
		if (y1_new + h1_max > y2_min + h2_min && y1_old + h1_max <= y2_max + h2_min)
			flag |= COLLIDE_TOP;
		if (y1_new + h1_min < y2_max + h2_max && y1_old + h1_min >= y2_min + h2_max)
			flag |= COLLIDE_BOTTOM;
	}

	if (y1_max + h1_max > y2_min + h2_min && y1_min + h1_min < y2_max + h2_max)
	{
		if (x1_new + w1_max > x2_min + w2_min && x1_old + w1_max <= x2_max + w2_min)
			flag |= COLLIDE_LEFT;
		if (x1_new + w1_min < x2_max + w2_max && x1_old + w1_min >= x2_min + w2_max)
			flag |= COLLIDE_RIGHT;
	}

	return flag;
}

/*
char		collide (float x1_old, float y1_old, float x1_new, float y1_new, float w1, float h1, float x2_old, float y2_old, float x2_new, float y2_new, float w2, float h2)
{
	float	x1_max;
	float	x1_min;
	float	x2_max;
	float	x2_min;
	float	y1_max;
	float	y1_min;
	float	y2_max;
	float	y2_min;
	char	flag;

	if (x1_old < x1_new)
	{
		x1_max = x1_new;
		x1_min = x1_old;
	}
	else
	{
		x1_max = x1_old;
		x1_min = x1_new;
	}

	if (x2_old < x2_new)
	{
		x2_max = x2_new;
		x2_min = x2_old;
	}
	else
	{
		x2_max = x2_old;
		x2_min = x2_new;
	}

	if (y1_old < y1_new)
	{
		y1_max = y1_new;
		y1_min = y1_old;
	}
	else
	{
		y1_max = y1_old;
		y1_min = y1_new;
	}

	if (y2_old < y2_new)
	{
		y2_max = y2_new;
		y2_min = y2_old;
	}
	else
	{
		y2_max = y2_old;
		y2_min = y2_new;
	}

	flag = 0;

	if (x1_max + w1_max > x2_min + w2_min && x1_min + w1_min < x2_max + w2_max)
	{
		if (y1_new + h1_max > y2_min + h2_min && y1_old + h1_max <= y2_max + h2_min)
			flag |= COLLIDE_TOP;
		if (y1_new + h1_min < y2_max + h2_max && y1_old + h1_min >= y2_min + h2_max)
			flag |= COLLIDE_BOTTOM;
	}

	if (y1_max + h1_max > y2_min + h2_min && y1_min + h1_min < y2_max + h2_max)
	{
		if (x1_new + w1_max > x2_min + w2_min && x1_old + w1_max <= x2_max + w2_min)
			flag |= COLLIDE_LEFT;
		if (x1_new + w1_min < x2_max + w2_max && x1_old + w1_min >= x2_min + w2_max)
			flag |= COLLIDE_RIGHT;
	}

	return flag;
}
*/
