modified scaling minimap
This commit is contained in:
parent
54f61ee4b0
commit
fc318fc851
4 changed files with 60 additions and 43 deletions
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 17:00:59 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/19 13:31:42 by marvin ### ########.fr */
|
||||
/* Updated: 2024/11/19 13:54:46 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
# define FOV 0.66 // Width of the view plane (unit: cases)
|
||||
|
||||
# define MINIMAP_SCALE 8 // Size of a case on the minimap.
|
||||
# define MINIMAP_SIZE_INVERT 4 // The minimap takes 1/N of the window.
|
||||
# define MINIMAP_COLOR_WALL 0xFFAF33 // Color of the walls on the minimap
|
||||
# define MINIMAP_COLOR_EMPTY 0xFFFC33 // Color of the empty cases on the minimap
|
||||
# define MINIMAP_COLOR_PLAYER 0x0000FF // Color of the player on the minimap
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/15 11:41:15 by grobledo #+# #+# */
|
||||
/* Updated: 2024/11/19 13:20:54 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/11/19 13:59:36 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -17,14 +17,29 @@
|
|||
#include "map.h"
|
||||
#include "global.h"
|
||||
|
||||
static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x);
|
||||
static void draw_minimap_player(u_int32_t *img_data);
|
||||
static void draw_minimap_player_fov(u_int32_t *img_data);
|
||||
static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x,
|
||||
double scale);
|
||||
static void draw_minimap_player(u_int32_t *img_data, double scale);
|
||||
static void draw_minimap_player_fov(u_int32_t *img_data, double scale);
|
||||
|
||||
static double scale_calcul(void)
|
||||
{
|
||||
const int minimap_width = SCREEN_WIDTH / MINIMAP_SIZE_INVERT;
|
||||
const int minimap_height = SCREEN_HEIGHT / MINIMAP_SIZE_INVERT;
|
||||
const double scale_x = (double)minimap_width / g_map.width;
|
||||
const double scale_y = (double)minimap_height / g_map.height;
|
||||
|
||||
if (scale_x < scale_y)
|
||||
return (scale_x);
|
||||
else
|
||||
return (scale_y);
|
||||
}
|
||||
|
||||
void draw_minimap(u_int32_t *img_data)
|
||||
{
|
||||
unsigned int map_x;
|
||||
unsigned int map_y;
|
||||
const double scale = scale_calcul();
|
||||
|
||||
map_x = 0;
|
||||
map_y = 0;
|
||||
|
@ -33,26 +48,27 @@ void draw_minimap(u_int32_t *img_data)
|
|||
map_x = 0;
|
||||
while (map_x < g_map.height)
|
||||
{
|
||||
draw_minimap_wall(img_data, map_x, map_y);
|
||||
draw_minimap_wall(img_data, map_x, map_y, scale);
|
||||
map_x++;
|
||||
}
|
||||
map_y++;
|
||||
}
|
||||
draw_minimap_player(img_data);
|
||||
draw_minimap_player(img_data, scale);
|
||||
}
|
||||
|
||||
static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x)
|
||||
static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x,
|
||||
double scale)
|
||||
{
|
||||
const int map_case = map_y * g_map.width + map_x;
|
||||
int pixel_x;
|
||||
int pixel_y;
|
||||
int pixel;
|
||||
|
||||
pixel_y = map_y * MINIMAP_SCALE;
|
||||
while (pixel_y < (map_y + 1) * MINIMAP_SCALE)
|
||||
pixel_y = map_y * scale;
|
||||
while (pixel_y < (map_y + 1) * scale)
|
||||
{
|
||||
pixel_x = map_x * MINIMAP_SCALE;
|
||||
while (pixel_x < (map_x + 1) * MINIMAP_SCALE)
|
||||
pixel_x = map_x * scale;
|
||||
while (pixel_x < (map_x + 1) * scale)
|
||||
{
|
||||
if (pixel_x < SCREEN_WIDTH && pixel_y < SCREEN_HEIGHT)
|
||||
{
|
||||
|
@ -69,45 +85,45 @@ static void draw_minimap_wall(uint32_t *img_data, int map_y, int map_x)
|
|||
}
|
||||
}
|
||||
|
||||
static void draw_minimap_player(u_int32_t *img_data)
|
||||
static void draw_minimap_player(u_int32_t *img_data, double scale)
|
||||
{
|
||||
const t_point_int player = {
|
||||
g_map.player.pos.x * MINIMAP_SCALE,
|
||||
g_map.player.pos.y * MINIMAP_SCALE,
|
||||
g_map.player.pos.x * scale,
|
||||
g_map.player.pos.y * scale,
|
||||
};
|
||||
t_point_int pixel;
|
||||
int pixel_i;
|
||||
|
||||
draw_minimap_player_fov(img_data);
|
||||
pixel.x = player.x - HITBOX * MINIMAP_SCALE;
|
||||
while (++pixel.x < player.x + HITBOX * MINIMAP_SCALE)
|
||||
draw_minimap_player_fov(img_data, scale);
|
||||
pixel.x = player.x - HITBOX * scale;
|
||||
while (++pixel.x < player.x + HITBOX * scale)
|
||||
{
|
||||
pixel.y = player.y - HITBOX * MINIMAP_SCALE;
|
||||
while (++pixel.y < player.y + HITBOX * MINIMAP_SCALE)
|
||||
pixel.y = player.y - HITBOX * scale;
|
||||
while (++pixel.y < player.y + HITBOX * scale)
|
||||
{
|
||||
pixel_i = pixel.y * SCREEN_WIDTH + pixel.x;
|
||||
if (pixel.x < SCREEN_WIDTH && pixel.y < SCREEN_HEIGHT
|
||||
&& distance_between_int(player, pixel) < HITBOX * MINIMAP_SCALE)
|
||||
&& distance_between_int(player, pixel) < HITBOX * scale)
|
||||
img_data[pixel_i] = MINIMAP_COLOR_PLAYER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_minimap_player_fov(u_int32_t *img_data)
|
||||
static void draw_minimap_player_fov(u_int32_t *img_data, double scale)
|
||||
{
|
||||
const double fov_angle = atan(FOV);
|
||||
const t_point_int player = {
|
||||
g_map.player.pos.x * MINIMAP_SCALE,
|
||||
g_map.player.pos.y * MINIMAP_SCALE,
|
||||
g_map.player.pos.x * scale,
|
||||
g_map.player.pos.y * scale,
|
||||
};
|
||||
t_point_int p;
|
||||
int p_i;
|
||||
|
||||
p.x = player.x - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1;
|
||||
while (++p.x < player.x + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE)
|
||||
p.x = player.x - MINIMAP_DISTANCE_FOV * scale - 1;
|
||||
while (++p.x < player.x + MINIMAP_DISTANCE_FOV * scale)
|
||||
{
|
||||
p.y = player.y - MINIMAP_DISTANCE_FOV * MINIMAP_SCALE - 1;
|
||||
while (++p.y < player.y + MINIMAP_DISTANCE_FOV * MINIMAP_SCALE)
|
||||
p.y = player.y - MINIMAP_DISTANCE_FOV * scale - 1;
|
||||
while (++p.y < player.y + MINIMAP_DISTANCE_FOV * scale)
|
||||
{
|
||||
p_i = p.y * SCREEN_WIDTH + p.x;
|
||||
if (p_i >= 0 && p_i < SCREEN_HEIGHT * SCREEN_WIDTH)
|
||||
|
@ -115,7 +131,8 @@ static void draw_minimap_player_fov(u_int32_t *img_data)
|
|||
- fov_angle, g_map.player.rot + fov_angle))
|
||||
draw_transparent_pixel(&img_data[p_i],
|
||||
MINIMAP_COLOR_PLAYER, MINIMAP_OPACITY_FOV
|
||||
- (distance_between(pixel_to_pos(p), g_map.player.pos)
|
||||
- (distance_between(pixel_to_pos(p, scale),
|
||||
g_map.player.pos)
|
||||
/ MINIMAP_DISTANCE_FOV * MINIMAP_OPACITY_FOV));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/19 13:01:34 by mcolonna #+# #+# */
|
||||
/* Updated: 2024/11/19 13:26:01 by mcolonna ### ########.fr */
|
||||
/* Updated: 2024/11/19 13:51:57 by mcolonna ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -30,11 +30,11 @@ static inline double distance_between_int(t_point_int a, t_point_int b)
|
|||
)));
|
||||
}
|
||||
|
||||
static inline t_point_double pixel_to_pos(t_point_int pixel)
|
||||
static inline t_point_double pixel_to_pos(t_point_int pixel, double scale)
|
||||
{
|
||||
return ((t_point_double){
|
||||
(double)pixel.x / MINIMAP_SCALE,
|
||||
(double)pixel.y / MINIMAP_SCALE,
|
||||
(double)pixel.x / scale,
|
||||
(double)pixel.y / scale,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@ EA textures/east.xpm
|
|||
NO textures/north.xpm
|
||||
SO textures/south.xpm
|
||||
WE textures/west.xpm
|
||||
111111111
|
||||
100000001
|
||||
100010001
|
||||
100000001
|
||||
1000N0001
|
||||
100000001
|
||||
100000001
|
||||
100000001
|
||||
111111111
|
||||
111111111111111111111111111111111111111111111
|
||||
100000001100000001100000001100000001100000001
|
||||
100010000000000001100000001100000001100000001
|
||||
100000001100000000000000001100000001100000001
|
||||
1000N0001100000001100000001100000001100000001
|
||||
100000001100000001100000000000000001100000001
|
||||
100000001100000001100000001100000000000000001
|
||||
100000001100000001100000001100000001100000001
|
||||
111111111111111111111111111111111111111111111
|
||||
|
|
Loading…
Add table
Reference in a new issue