diff --git a/Makefile b/Makefile index d843487..726bec9 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ endif IFLAGS = -I./mlx -I./libft SOURCEFILES = \ + src/consts.c \ src/draw/draw_map.c \ src/draw/drawutils.c \ src/main.c \ diff --git a/README b/README index d9426ac..ebf9529 100644 --- a/README +++ b/README @@ -18,9 +18,9 @@ faire un systeme de "cheats" soit par un menu de debug soit par une ligne de com --[ Correspondances des angles / points cardinaux PI [ nord ] - | + 5 PI / 4 [NO] | 3 PI / 4 [NE] | 3 PI / 2 [ouest] ----------- PI / 2 [est] - | - | + | + 7 PI / 4 [SO] | PI / 4 [SE] 0 [ sud ] diff --git a/src/consts.c b/src/consts.c new file mode 100644 index 0000000..8b4b371 --- /dev/null +++ b/src/consts.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* consts.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/07/28 14:33:12 by kcolin #+# #+# */ +/* Updated: 2025/07/28 15:03:16 by kcolin ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "consts.h" +#include + +const float g_north = M_PI; +const float g_south = 0; +const float g_east = M_PI / 2; +const float g_west = 3 * M_PI / 2; +const float g_northwest = 5 * M_PI / 4; +const float g_northeast = 3 * M_PI / 4; +const float g_southwest = 7 * M_PI / 4; +const float g_southeast = M_PI / 4; diff --git a/src/consts.h b/src/consts.h index 80e0af2..329e3f9 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ -/* Updated: 2025/07/25 14:53:56 by tchampio ### ########.fr */ +/* Updated: 2025/07/28 15:03:19 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,19 @@ # define HEIGHT 800 # define WIDTH 800 + # define SIZE 64 # define MAP_SIZE 10 + +extern const float g_north; +extern const float g_south; +extern const float g_east; +extern const float g_west; +extern const float g_northwest; +extern const float g_northeast; +extern const float g_southwest; +extern const float g_southeast; + # define RESSOURCE_DIR "ressources" # define MOVEMENT_SPEED 6.4 # define ROTATION_SPEED 0.1 diff --git a/src/main.c b/src/main.c index 4a4a88d..fc7aee3 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,8 @@ #include "draw/drawutils.h" #include "map/map_checker.h" #include "draw/draw_map.h" +#include "map/mapdata.h" +#include "player/player.h" #include "utils/hooks.h" #include "utils/frees.h" #include @@ -29,8 +31,8 @@ void init_player(t_mapdata *mapdata, t_player *player) { player->health = 100; - player->x = mapdata->startx; - player->y = mapdata->starty; + player->x = mapdata->startx * SIZE; + player->y = mapdata->starty * SIZE; if (mapdata->map[mapdata->starty][mapdata->startx] == 'N') player->yaw = M_PI; else if (mapdata->map[mapdata->starty][mapdata->startx] == 'S') @@ -53,10 +55,10 @@ bool touch(float px, float py, t_mapdata *map) return (false); } -void draw_line(t_cub3d_data *data, float start_x) +void draw_line(t_cub3d_data *data, float start_angle) { - float cos_angle = cos(start_x); - float sin_angle = sin(start_x); + float cos_angle = cos(start_angle); + float sin_angle = sin(start_angle); float ray_x = data->player.x; float ray_y = data->player.y; @@ -68,19 +70,46 @@ void draw_line(t_cub3d_data *data, float start_x) } } +t_direction angle_dir(float angle) +{ + if (angle >= g_southwest || (angle > g_south && angle < g_southeast)) + return (SOUTH); + if (angle >= g_southeast && angle < g_northeast) + return (EAST); + if (angle >= g_northeast && angle < g_northwest) + return (NORTH); + return (WEST); +} + +t_direction player_dir(t_player player) +{ + return (angle_dir(player.yaw)); +} + int game_loop(t_cub3d_data *data) { mlx_destroy_image(data->mlx, data->img_data->img); data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT); - int column = 0; - float fraction = M_PI / 3 / WIDTH; - float start_angle = data->player.yaw - M_PI / 6; + if (player_dir(data->player) == SOUTH) + ft_printf("south\n"); + if (player_dir(data->player) == EAST) + ft_printf("east\n"); + if (player_dir(data->player) == NORTH) + ft_printf("north\n"); + if (player_dir(data->player) == WEST) + ft_printf("west\n"); + + float ray_angle = data->player.yaw - M_PI / 6; + float fraction = M_PI / 3 / WIDTH; + int column = 0; while (column < WIDTH) { - draw_line(data, start_angle); - start_angle += fraction; + // hline check + /* float ray_atan = atan(ray_angle); */ + draw_line(data, ray_angle); column++; + ray_angle += fraction; } draw_map(data->map, &data->player, data->img_data);