Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ SRC =main.c \
minimap/mini_map.c \
minimap/mini_player.c \
minimap/utils_minimap.c \
minimap/ray_minimap.c \
\
parsing/check_order.c \
parsing/parse_prep.c \
parsing/validation.c \
parsing/config/headers.c \
parsing/config/headers_values.c \
parsing/config/validation.c \
parsing/map/parse_map.c
parsing/map/parse_map.c
OBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o))

################################################################################
Expand Down
4 changes: 3 additions & 1 deletion inc/mini_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/11/16 12:43:25 by chguerre #+# #+# */
/* Updated: 2026/11/17 22:53:42 by chguerre ### ########.fr */
/* Updated: 2026/11/18 18:40:41 by chguerre ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,4 +16,6 @@
unsigned int select_color(char c, char orientation);
void calculate_size(t_game *game, t_minimap *m);
int size_tile(int map_width, int map_height);
void draw_minimap_pov(t_game *game, t_minimap *m);

#endif //MINI_MAP_H
1 change: 1 addition & 0 deletions inc/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ void draw_minimap_player(t_game *game, int px, int py, t_minimap *m);
void mini_dir_player(t_game *game, t_line *line, t_minimap *m);
void update_movement(t_game *game);
int move_player(t_player *p, char **map, t_game *game);
void draw_line(t_game *game, t_line *line, int color);

#endif // PLAYER_H
5 changes: 3 additions & 2 deletions inc/raycast.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* raycast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rpinheir <rpinheir@student.42lausanne.ch> +#+ +:+ +#+ */
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/11/16 19:46:51 by rpinheir #+# #+# */
/* Updated: 2026/11/17 13:25:10 by rpinheir ### ########.ch */
/* Updated: 2026/11/18 18:18:56 by chguerre ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -16,5 +16,6 @@

void cast_rays(t_game *game);
void draw_walls(t_game *game, t_ray *ray, int x);
void dda(t_game *game, t_ray *ray);

#endif
3 changes: 2 additions & 1 deletion src/minimap/mini_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void generate_minimap(t_game *game)
draw_background_map(game, &mini_map);
draw_map(game, &mini_map, mini_map.width, mini_map.height);
posicion_minimapa(game, &mini_map, mini_pos);
draw_minimap_player(game, mini_pos[0], mini_pos[1], &mini_map);
mini_dir_player(game, &line, &mini_map);
draw_minimap_pov(game, &mini_map);
draw_minimap_player(game, mini_pos[0], mini_pos[1], &mini_map);
}
25 changes: 15 additions & 10 deletions src/minimap/mini_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/11/14 17:27:26 by chguerre #+# #+# */
/* Updated: 2026/11/17 23:51:22 by chguerre ### ########.fr */
/* Updated: 2026/11/18 19:37:01 by chguerre ### ########.fr */
/* */
/* ************************************************************************** */

#include "main.h"

static void draw_line(t_game *game, t_line *line, int color)
void paint_line(t_game *game, t_line *line, int color)
{
int i;

Expand All @@ -27,15 +27,8 @@ static void draw_line(t_game *game, t_line *line, int color)
}
}

void mini_dir_player(t_game *game, t_line *line, t_minimap *m)
void draw_line(t_game *game, t_line *line, int color)
{
t_player *player;

player = &game->player;
line->x0 = (double)MINI_OFFSET_X + (player->pos_x * (double)m->tile_size);
line->y0 = (double)MINI_OFFSET_Y + (player->pos_y * (double)m->tile_size);
line->x1 = line->x0 + player->dir_x * (m->tile_size * 1.1);
line->y1 = line->y0 + player->dir_y * (m->tile_size * 1.1);
line->dx = line->x1 - line->x0;
line->dy = line->y1 - line->y0;
if (abs((int)line->dx) > abs((int)line->dy))
Expand All @@ -51,6 +44,18 @@ void mini_dir_player(t_game *game, t_line *line, t_minimap *m)
line->inc_y = line->dy / (float)line->step;
line->curr_x = line->x0;
line->curr_y = line->y0;
paint_line(game, line, color);
}

void mini_dir_player(t_game *game, t_line *line, t_minimap *m)
{
t_player *player;

player = &game->player;
line->x0 = (double)MINI_OFFSET_X + (player->pos_x * (double)m->tile_size);
line->y0 = (double)MINI_OFFSET_Y + (player->pos_y * (double)m->tile_size);
line->x1 = line->x0 + player->dir_x * (m->tile_size * 1.1);
line->y1 = line->y0 + player->dir_y * (m->tile_size * 1.1);
draw_line(game, line, 0xFFFF00);
}

Expand Down
55 changes: 55 additions & 0 deletions src/minimap/ray_minimap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ray_minimap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/11/18 17:58:44 by chguerre #+# #+# */
/* Updated: 2026/11/18 19:36:33 by chguerre ### ########.fr */
/* */
/* ************************************************************************** */

#include "main.h"

void get_ray_mini_hit(t_game *g, t_ray *m_ray, double *hit_x, double *hit_y)
{
if (m_ray->side == 0)
{
*hit_x = m_ray->map_x + (m_ray->step_x < 0);
*hit_y = g->player.pos_y + m_ray->perp_wall_dist * m_ray->ray_dir_y;
}
else
{
*hit_y = m_ray->map_y + (m_ray->step_y < 0);
*hit_x = g->player.pos_x + m_ray->perp_wall_dist * m_ray->ray_dir_x;
}
}

void draw_minimap_pov(t_game *game, t_minimap *m)
{
t_ray r_mini;
t_line l;
double hit[2];
int x;

l.x0 = MINI_OFFSET_X + game->player.pos_x * m->tile_size;
l.y0 = MINI_OFFSET_Y + game->player.pos_y * m->tile_size;
ft_bzero(&r_mini, sizeof(t_ray));
x = 0;
while (x < WIDTH)
{
r_mini.hit = 0;
r_mini.camera_x = 2.0 * x / WIDTH - 1;
r_mini.ray_dir_x = game->player.dir_x + game->player.plane_x
* r_mini.camera_x;
r_mini.ray_dir_y = game->player.dir_y + game->player.plane_y
* r_mini.camera_x;
dda(game, &r_mini);
get_ray_mini_hit(game, &r_mini, &hit[0], &hit[1]);
l.x1 = MINI_OFFSET_X + hit[0] * m->tile_size;
l.y1 = MINI_OFFSET_Y + hit[1] * m->tile_size;
draw_line(game, &l, 0xFFFF00);
x += 16;
}
}
Loading