/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "game/core.h"
#include "game/game.h"

static int collision_id_princess(sfml_t *sfml, int id_princess)
{
	uint8_t *map = sfml->scene->level->map;
	int x = sfml->scene->player->x;
	int y = sfml->scene->player->y;
	int width = sfml->scene->level->width;

	if (map[(x + 8 >> 6) + (y + 8 >> 6) * width] == id_princess)
		return ((x + 8 >> 6) + (y + 8 >> 6) * width);
	if (map[(x + 8 >> 6) + (y + 64 >> 6) * width] == id_princess)
		return ((x + 8 >> 6) + (y + 64 >> 6) * width);
	if (map[(x + 56 >> 6) + (y + 8 >> 6) * width] == id_princess)
		return ((x + 54 >> 6) + (y + 8 >> 6) * width);
	if (map[(x + 56 >> 6) + (y + 64 >> 6) * width] == id_princess)
		return ((x + 54 >> 6) + (y + 64 >> 6) * width);
	return (-1);
}

void collision_princess(sfml_t *sfml)
{
	int locate;

	locate = collision_id_princess(sfml, ID_FAKE_PRINCESS);
	if (locate >= 0){
		sfml->scene->level->map[locate] = ' ';
		sfml->scene->player->action = PLAYER_DEAD;
		sfml->scene->player->dead_counter = 0;
		sfml->scene->message_active |= MESSAGE_FAKE_PRINCESS;
	}
	if (collision_id_princess(sfml, ID_PRINCESS) >= 0)
		sfml->scene->player->action |= PLAYER_WIN;
}
