cub3d/src/draw/draw_map.c

93 lines
2.5 KiB
C
Raw Normal View History

2025-07-15 10:33:25 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_map.c :+: :+: :+: */
2025-07-15 10:33:25 +02:00
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
2025-07-15 10:33:25 +02:00
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:20:00 by kcolin #+# #+# */
2025-09-08 13:59:35 +02:00
/* Updated: 2025/09/08 13:58:59 by tchampio ### ########.fr */
2025-07-15 10:33:25 +02:00
/* */
/* ************************************************************************** */
#include "../map/mapdata.h"
#include "../player/player.h"
#include "drawutils.h"
2025-07-28 12:16:26 +02:00
#include "../consts.h"
#include "img_data.h"
2025-07-15 10:33:25 +02:00
void draw_2d_wall(unsigned int color, t_img_data *data,
2025-07-15 10:33:25 +02:00
int x, int y)
{
int i;
int j;
i = 0;
2025-07-28 12:16:26 +02:00
while (i < MAP_SIZE)
2025-07-15 10:33:25 +02:00
{
j = 0;
2025-07-28 12:16:26 +02:00
while (j < MAP_SIZE)
2025-07-15 10:33:25 +02:00
{
my_mlx_pixel_put(data, x + i, y + j, color);
j++;
}
i++;
}
}
void draw_player(unsigned int color, t_img_data *data,
int x, int y)
{
int i;
int j;
i = -(PLAYER_SIZE / 2);
while (i < (PLAYER_SIZE / 2))
{
j = -(PLAYER_SIZE / 2);
while (j < (PLAYER_SIZE / 2))
{
my_mlx_pixel_put(data, x + i, y + j, color);
j++;
}
i++;
}
}
void draw_heading(unsigned int color, t_img_data *data, t_player *player)
{
int x;
int y;
x = player->x * MAP_SIZE + player->dir_x * PLAYER_SIZE;
y = player->y * MAP_SIZE + player->dir_y * PLAYER_SIZE;
my_mlx_pixel_put(data, x, y, color);
}
void draw_map(t_mapdata *map, t_player *player, t_img_data *data)
2025-07-15 10:33:25 +02:00
{
int i;
int j;
i = 0;
while (map->map[i])
{
j = 0;
while (map->map[i][j])
{
if (map->map[i][j] == '1')
2025-07-28 12:16:26 +02:00
draw_2d_wall(map->f_color, data, MAP_SIZE * j, MAP_SIZE * i);
2025-07-15 10:33:25 +02:00
else if (map->map[i][j] == 'D' || map->map[i][j] == 'd')
2025-07-28 12:16:26 +02:00
draw_2d_wall(0x00FF2E63, data, MAP_SIZE * j, MAP_SIZE * i);
2025-07-15 10:33:25 +02:00
else if (map->map[i][j] == 's')
2025-07-28 12:16:26 +02:00
draw_2d_wall(0x00E84545, data, MAP_SIZE * j, MAP_SIZE * i);
2025-07-15 10:33:25 +02:00
else if (map->map[i][j] == 'M')
2025-07-28 12:16:26 +02:00
draw_2d_wall(0x00F4CE14, data, MAP_SIZE * j, MAP_SIZE * i);
2025-07-15 10:33:25 +02:00
j++;
}
i++;
}
draw_player(0x00FF0000, data, MAP_SIZE * player->x, MAP_SIZE * player->y);
draw_heading(0x00FFFFFF, data, player);
2025-07-15 10:33:25 +02:00
}