diff --git a/Makefile b/Makefile index f3ba90c..e94eac0 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,6 @@ SRC =main.c \ render/init_graphics.c \ render/render_canvas.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 \ diff --git a/inc/main.h b/inc/main.h index a39344e..48cfe6d 100644 --- a/inc/main.h +++ b/inc/main.h @@ -24,7 +24,6 @@ # include "player.h" # include # include "textures.h" -# include "mini_map.h" # include "raycast.h" # include #endif diff --git a/inc/mini_map.h b/inc/mini_map.h deleted file mode 100644 index 3a33d70..0000000 --- a/inc/mini_map.h +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mini_map.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: chguerre pos_y][(int)(p->pos_x + p->dir_x * (speed + pad))] != '1') + if (map[(int)p->pos_y][(int)(p->pos_x + p->dir_x * speed)] != '1') p->pos_x += p->dir_x * speed; - if (map[(int)(p->pos_y + p->dir_y * (speed + pad))][(int)p->pos_x] != '1') + if (map[(int)(p->pos_y + p->dir_y * speed)][(int)p->pos_x] != '1') p->pos_y += p->dir_y * speed; return (0); } -int move_down(t_player *p, char **map, double speed, double pad) +int move_down(t_player *p, char **map, double speed) { - if (map[(int)p->pos_y][(int)(p->pos_x - p->dir_x * (speed + pad))] != '1') + if (map[(int)p->pos_y][(int)(p->pos_x - p->dir_x * speed)] != '1') p->pos_x -= p->dir_x * speed; - if (map[(int)(p->pos_y - p->dir_y * (speed + pad))][(int)p->pos_x] != '1') + if (map[(int)(p->pos_y - p->dir_y * speed)][(int)p->pos_x] != '1') p->pos_y -= p->dir_y * speed; return (0); } -int move_rigth(t_player *p, char **map, double speed, double pad) +int move_rigth(t_player *p, char **map, double speed) { - if (map[(int)p->pos_y][(int)(p->pos_x + p->plane_x * (speed + pad))] != '1') + if (map[(int)p->pos_y][(int)(p->pos_x + p->plane_x * speed)] != '1') p->pos_x += p->plane_x * speed; - if (map[(int)(p->pos_y + p->plane_y * (speed + pad))][(int)p->pos_x] != '1') + if (map[(int)(p->pos_y + p->plane_y * speed)][(int)p->pos_x] != '1') p->pos_y += p->plane_y * speed; return (0); } -int move_left(t_player *p, char **map, double speed, double pad) +int move_left(t_player *p, char **map, double speed) { - if (map[(int)p->pos_y][(int)(p->pos_x - p->plane_x * (speed + pad))] != '1') + if (map[(int)p->pos_y][(int)(p->pos_x - p->plane_x * speed)] != '1') p->pos_x -= p->plane_x * speed; - if (map[(int)(p->pos_y - p->plane_y * speed - pad)][(int)p->pos_x] != '1') + if (map[(int)(p->pos_y - p->plane_y * speed)][(int)p->pos_x] != '1') p->pos_y -= p->plane_y * speed; return (0); } @@ -51,12 +51,12 @@ int move_left(t_player *p, char **map, double speed, double pad) int move_player(t_player *p, char **map, t_game *game) { if (p->key_w) - move_up(p, map, p->move_speed * game->delta_time, 0.30); + move_up(p, map, p->move_speed * game->delta_time); if (p->key_s) - move_down(p, map, p->move_speed * game->delta_time, 0.30); + move_down(p, map, p->move_speed * game->delta_time); if (p->key_d) - move_rigth(p, map, p->move_speed * game->delta_time, 0.30); + move_rigth(p, map, p->move_speed * game->delta_time); if (p->key_a) - move_left(p, map, p->move_speed * game->delta_time, 0.30); + move_left(p, map, p->move_speed * game->delta_time); return (0); } diff --git a/src/engine/raycast/raycast.c b/src/engine/raycast/raycast.c index e02b9f8..8ff9efc 100644 --- a/src/engine/raycast/raycast.c +++ b/src/engine/raycast/raycast.c @@ -55,6 +55,15 @@ void setup_dda(t_game *game, t_ray *ray) set_sidestep(game, ray); } +static int check_limits(t_game *game, t_ray *ray) +{ + if (ray->map_y < 0 || ray->map_y >= game->map_height) + return (1); + else if (ray->map_x < 0 || ray->map_x >= ft_strlen(game->map[ray->map_y])) + return (1); + return (0); +} + void dda(t_game *game, t_ray *ray) { setup_dda(game, ray); @@ -72,6 +81,8 @@ void dda(t_game *game, t_ray *ray) ray->map_y += ray->step_y; ray->side = 1; } + if (check_limits(game, ray) != 0) + break ; if (game->map[ray->map_y][ray->map_x] == '1') ray->hit = 1; } diff --git a/src/minimap/mini_map.c b/src/minimap/mini_map.c deleted file mode 100644 index ba07a2b..0000000 --- a/src/minimap/mini_map.c +++ /dev/null @@ -1,110 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mini_map.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ch +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2026/11/12 17:24:29 by ch #+# #+# */ -/* Updated: 2026/11/16 20:07:37 by rpinheir ### ########.ch */ -/* */ -/* ************************************************************************** */ - -#include "main.h" - -void draw_background_map(t_game *game, t_minimap *m) -{ - int x; - int y; - - y = 0; - while (y < m->height * m->tile_size) - { - x = 0; - while (x < m->width * m->tile_size) - { - put_pixel(MINI_OFFSET_X + x, MINI_OFFSET_Y + y, GRAY_MEDIUM, game); - x++; - } - y++; - } -} - -void draw_square_tile(t_game *game, t_minimap *m, double pos_x, double pos_y) -{ - int x; - int y; - int pixel_x; - int pixel_y; - - y = 0; - while (y < m->tile_size) - { - x = 0; - while (x < m->tile_size) - { - pixel_x = pos_x + x; - pixel_y = pos_y + y; - if (pixel_x >= 0 && pixel_x <= WIDTH - && pixel_y >= 0 && pixel_y <= HEIGHT) - put_pixel(pixel_x, pixel_y, m->color_tile, game); - x++; - } - y++; - } -} - -double *posicion_minimapa(t_game *game, t_minimap *m, double mini_pos[2]) -{ - mini_pos[0] = (double)MINI_OFFSET_X + (game->player.pos_x - * (double)m->tile_size); - mini_pos[1] = (double)MINI_OFFSET_Y + (game->player.pos_y - * (double)m->tile_size); - return (mini_pos); -} - -void draw_map(t_game *game, t_minimap *m, int map_width, int map_height) -{ - int mx; - int my; - int pos_x; - int pos_y; - - my = 0; - while (my < map_height) - { - mx = 0; - while (mx < map_width && game->map[my][mx]) - { - m->color_tile = select_color(game->map[my][mx], - game->player.orientation); - pos_x = MINI_OFFSET_X + (mx * m->tile_size); - pos_y = MINI_OFFSET_Y + (my * m->tile_size); - draw_square_tile(game, m, pos_x, pos_y); - mx++; - } - my++; - } -} - -void generate_minimap(t_game *game) -{ - double mini_pos[2]; - t_line line; - t_minimap mini_map; - - ft_bzero(&line, sizeof(line)); - ft_bzero(&mini_map, sizeof(mini_map)); - calculate_size(game, &mini_map); - mini_map.tile_size = size_tile(mini_map.width, mini_map.height); - if (mini_map.tile_size < 3) - mini_map.tile_size = 3; - if (mini_map.tile_size > 12) - mini_map.tile_size = 12; - draw_background_map(game, &mini_map); - draw_map(game, &mini_map, mini_map.width, mini_map.height); - posicion_minimapa(game, &mini_map, mini_pos); - 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); -} diff --git a/src/minimap/mini_player.c b/src/minimap/mini_player.c deleted file mode 100644 index 5d55fd7..0000000 --- a/src/minimap/mini_player.c +++ /dev/null @@ -1,80 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* mini_player.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: chguerre step) - { - put_pixel((int)round(line->curr_x), - (int)round(line->curr_y), color, game); - line->curr_x += line->inc_x; - line->curr_y += line->inc_y; - i++; - } -} - -void draw_line(t_game *game, t_line *line, int color) -{ - line->dx = line->x1 - line->x0; - line->dy = line->y1 - line->y0; - if (abs((int)line->dx) > abs((int)line->dy)) - line->step = abs((int)line->dx); - else - line->step = abs((int)line->dy); - if (line->step == 0) - { - put_pixel(line->x0, line->x0, 0xFFFF00, game); - return ; - } - line->inc_x = line->dx / (float)line->step; - 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); -} - -void draw_minimap_player(t_game *game, int px, int py, t_minimap *m) -{ - float size; - int x; - int y; - - size = m->tile_size * 0.7; - y = -size / 2; - while (y < size / 2) - { - x = -size / 2; - while (x < size / 2) - { - put_pixel(px + x, py + y, 0x00FF0000, game); - x++; - } - y++; - } -} diff --git a/src/minimap/ray_minimap.c b/src/minimap/ray_minimap.c deleted file mode 100644 index fd52abe..0000000 --- a/src/minimap/ray_minimap.c +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ray_minimap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: chguerre 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; - } -} diff --git a/src/minimap/utils_minimap.c b/src/minimap/utils_minimap.c deleted file mode 100644 index b797895..0000000 --- a/src/minimap/utils_minimap.c +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* utils_minimap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: chguerre map[h]) - { - w = ft_strlen(game->map[h]); - if (w > w_max) - w_max = w; - h++; - } - m->height = h; - m->width = w_max; -} diff --git a/src/parsing/check_order.c b/src/parsing/check_order.c index c03e4c3..fc4449b 100644 --- a/src/parsing/check_order.c +++ b/src/parsing/check_order.c @@ -79,5 +79,6 @@ int dup_buffer(t_game *game, int fd) } if (!game->config || !game->map) return (ft_putendl_fd("Error\nempty map or header", 2), 1); + game->map_height = count_len; return (0); } diff --git a/src/render/render_canvas.c b/src/render/render_canvas.c index c2854e4..fcf7eb7 100644 --- a/src/render/render_canvas.c +++ b/src/render/render_canvas.c @@ -33,12 +33,9 @@ void draw_square(t_game *game, int x, int y, int size) return ; } -// -50 to hide textures - void create_canvas(t_game *game) { ft_bzero(game->screen.addr, HEIGHT * game->screen.size_line); draw_background(game); cast_rays(game); - generate_minimap(game); }