added minimap

This commit is contained in:
Gregory Robledo 2024-11-15 15:39:12 +01:00
parent 96cc9096cd
commit 57b099d013
5 changed files with 110 additions and 8 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* const.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */
/* Updated: 2024/11/12 17:56:05 by mcolonna ### ########.fr */
/* Updated: 2024/11/15 14:58:24 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,4 +27,5 @@
# define FOV 0.66 // Width of the view plane (unit: cases)
# define MINIMAP_SCALE 8
#endif

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* map.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:59:04 by mcolonna #+# #+# */
/* Updated: 2024/11/12 15:10:07 by mcolonna ### ########.fr */
/* Updated: 2024/11/15 14:56:55 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
@ -157,4 +157,8 @@ bool check_map(const t_map *map);
/// @return Wanted case.
const t_map_case *map_get_case(const t_map *map, int x, int y);
void create_minimap(u_int32_t *img_data);
void draw_minimap(uint32_t *img_data, int map_x, int map_y);
void minimap_player(u_int32_t *img_data);
#endif

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 16:57:40 by mcolonna #+# #+# */
/* Updated: 2024/11/07 18:44:01 by mcolonna ### ########.fr */
/* Updated: 2024/11/15 12:47:03 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,3 +79,6 @@ int main(int argc, char *argv[])
free(g_mlx);
return (g_return_value);
}

93
src/minimap.c Normal file
View file

@ -0,0 +1,93 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minimap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */
/* Updated: 2024/11/15 15:10:06 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/global.h"
#include "../include/const.h"
// g_map.width
// g_map.height
// g_map.player.pos.x
// g_map.player.pos.y
// g_map.cases[y * g_map.width + x].wall == WALL / EMPTY
void create_minimap(u_int32_t *img_data)
{
unsigned int map_x;
unsigned int map_y;
map_x = 0;
map_y = 0;
while (map_y < g_map.width)
{
map_x = 0;
while (map_x < g_map.height)
{
draw_minimap(img_data, map_x, map_y);
map_x++;
}
map_y++;
}
minimap_player(img_data);
}
void draw_minimap(uint32_t *img_data, int map_y, int map_x)
{
int pixel_x;
int pixel_y;
int i;
int j;
i = 0;
while (i++ < MINIMAP_SCALE)
{
j = 0;
while (j++ < MINIMAP_SCALE)
{
pixel_y = map_y * MINIMAP_SCALE + j;
pixel_x = map_x * MINIMAP_SCALE + i;
if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT)
{
if (g_map.cases[map_y * g_map.width + map_x].wall == WALL)
img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFAF33;
else if (g_map.cases[map_y * g_map.width + map_x].wall == EMPTY && g_map.cases[map_y * g_map.width + map_x].inside)
img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFFFC33;
}
}
}
}
void minimap_player(u_int32_t *img_data)
{
int player_x;
int player_y;
int pixel_x;
int pixel_y;
int i;
int j;
i = -2;
player_x = g_map.player.pos.x * MINIMAP_SCALE;
player_y = g_map.player.pos.y * MINIMAP_SCALE;
while(i++ < 2)
{
j = -2;
while(j++ < 2)
{
pixel_x = player_x + i;
pixel_y = player_y + j;
if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT)
img_data[pixel_y * SCREEN_WIDTH + pixel_x] = 0xFF0000;
}
}
}

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* By: grobledo <grobledo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/14 14:55:05 by grobledo #+# #+# */
/* Updated: 2024/11/13 18:33:00 by mcolonna ### ########.fr */
/* Updated: 2024/11/15 13:00:52 by grobledo ### ########.fr */
/* */
/* ************************************************************************** */
@ -118,5 +118,6 @@ int render(u_int32_t *img_data)
draw_vertical_line(img_data, &ray);
ray.x++;
}
create_minimap(img_data);
return (0);
}