
#include "mobile.h"

void	mobile_bounce (struct s_mobile* mobile, enum e_mobile_bounce bounce)
{
	switch (bounce)
	{
		case MOBILE_BOUNCE_HORZ:
			mobile->direction = 2 * MOBILE_PI - mobile->direction;
		break;

		case MOBILE_BOUNCE_VERT:
			mobile->direction = MOBILE_PI - mobile->direction;
		break;
	}
}

void	mobile_compose (struct s_mobile* mobile, float direction, float speed)
{
	float	x;
	float	y;

	x = cos (mobile->direction) * mobile->speed + cos (direction) * speed;
	y = sin (mobile->direction) * mobile->speed + sin (direction) * speed;

	mobile->direction = atan2f (y, x);
	mobile->speed = sqrt (x * x + y * y);
}

void	mobile_define (struct s_mobile* mobile, float x, float y, float direction, float speed)
{
	mobile->direction = direction;
	mobile->speed = speed;
	mobile->x = x;
	mobile->y = y;
}

void	mobile_deviate (struct s_mobile* mobile, float direction, float speed)
{
	float	x;
	float	y;

	x = cos (mobile->direction) * mobile->speed + cos (direction) * speed;
	y = sin (mobile->direction) * mobile->speed + sin (direction) * speed;

	mobile->direction = atan2f (y, x);
}

void	mobile_move (struct s_mobile* mobile, float factor)
{
	mobile->x += cos (mobile->direction) * mobile->speed * factor;
	mobile->y += sin (mobile->direction) * mobile->speed * factor;
}

float	mobile_speed_x (struct s_mobile* mobile)
{
	return cos (mobile->direction) * mobile->speed;
}

float	mobile_speed_y (struct s_mobile* mobile)
{
	return sin (mobile->direction) * mobile->speed;
}
