/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   game_hud.c                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: qmennen <qmennen@student.codam.nl>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2025/05/28 14:26:29 by qmennen           #+#    #+#             */
/*   Updated: 2025/06/03 19:22:47 by qmennen          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "game.h"

static int	battery_color(float battery)
{
	if (battery > 0.5f)
		return (0x00FF0066);
	else if (battery > 0.25f)
		return (0xFFFF0066);
	else
		return (0xFF000066);
}

static void	draw_battery(mlx_image_t *img, float battery)
{
	int		x;
	int		y;

	x = 1340;
	while (x < 1350)
	{
		y = 265;
		while (y < 285)
		{
			mlx_put_pixel(img, x, y, battery_color(battery));
			y++;
		}
		x++;
	}
	x = 1350;
	while (x < 1450)
	{
		y = 250;
		while (y < 300)
		{
			mlx_put_pixel(img, x, y, battery_color(battery));
			y++;
		}
		x++;
	}
}

void	handle_battery(t_game *game)
{
	game->player->battery -= game->screen->mlx->delta_time / 50;
	if (game->player->battery < 0)
	{
		game->player->battery = 0;
		game->manager->state = GAME_STATE_MENU;
		// game_terminate(game);
	}
	draw_battery(game->screen->minimap, game->player->battery);
}

void	handle_record(t_game *game)
{
	static int	flash = 0;
	int			x;
	int			y;

	flash = (int) mlx_get_time() % 2;
	y = -15;
	while (y <= 15)
	{
		x = -15;
		while (x <= 15)
		{
			if (x * x + y * y <= 225)
			{
				if (flash)
					mlx_put_pixel(
						game->screen->hud, 1530 + x, 212 + y, 0xFF000055);
				else
					mlx_put_pixel(
						game->screen->hud, 1530 + x, 212 + y, 0x00000066);
			}
			x++;
		}
		y++;
	}
}
