From ac94e9e937cae829632b27579c2562d3977381ba Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Tue, 29 Jul 2025 13:33:41 +0200 Subject: [PATCH] fix(player init): deleted old init_player function in favor of the new one --- src/main.c | 48 ++++++++++++++++----------------------------- src/player/player.h | 6 +++++- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/main.c b/src/main.c index 160952e..79eb323 100644 --- a/src/main.c +++ b/src/main.c @@ -6,12 +6,13 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/07/29 12:33:46 by tchampio ### ########.fr */ +/* Updated: 2025/07/29 13:28:35 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "../libft/includes/libft.h" #include "../mlx/mlx.h" +#include "player/player.h" #include "consts.h" #include "cub3d_data.h" #include "draw/drawutils.h" @@ -29,21 +30,6 @@ #include #include // BAD -void init_player(t_mapdata *mapdata, t_player *player) -{ - player->health = 100; - player->x = mapdata->startx * SIZE + ((float)SIZE / 2); - player->y = mapdata->starty * SIZE + ((float)SIZE / 2); - if (mapdata->map[mapdata->starty][mapdata->startx] == 'N') - player->yaw = M_PI; - else if (mapdata->map[mapdata->starty][mapdata->startx] == 'S') - player->yaw = 0; - else if (mapdata->map[mapdata->starty][mapdata->startx] == 'E') - player->yaw = M_PI / 2; - else if (mapdata->map[mapdata->starty][mapdata->startx] == 'W') - player->yaw = 3 * M_PI / 2; -} - bool touch(float px, float py, t_mapdata *map) { int x; @@ -56,20 +42,20 @@ bool touch(float px, float py, t_mapdata *map) return (false); } -void draw_line(t_cub3d_data *data, float start_angle) -{ - float cos_angle = cos(start_angle); - float sin_angle = sin(start_angle); - float ray_x = data->player.x; - float ray_y = data->player.y; - - while(!touch(ray_x, ray_y, data->map)) - { - my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xcc241b); - ray_x += sin_angle; - ray_y += cos_angle; - } -} +// void draw_line(t_cub3d_data *data, float start_angle) +// { +// float cos_angle = cos(start_angle); +// float sin_angle = sin(start_angle); +// float ray_x = data->player.x; +// float ray_y = data->player.y; +// +// while(!touch(ray_x, ray_y, data->map)) +// { +// my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xcc241b); +// ray_x += sin_angle; +// ray_y += cos_angle; +// } +// } t_cardinal_dir angle_cardinal_dir(float angle) { @@ -177,7 +163,7 @@ int main(int argc, char **argv) data.img_data->addr = mlx_get_data_addr(data.img_data->img, &data.img_data->bits_per_pixel, &data.img_data->line_length, &data.img_data->endian); - init_player(data.map, &(data.player)); + init_player(&data.player, data.map); mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data); mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, keyrelease_handler, &data); diff --git a/src/player/player.h b/src/player/player.h index 1fc189b..8ac8231 100644 --- a/src/player/player.h +++ b/src/player/player.h @@ -6,13 +6,15 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */ -/* Updated: 2025/07/29 12:01:02 by tchampio ### ########.fr */ +/* Updated: 2025/07/29 13:28:08 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PLAYER_H # define PLAYER_H +# include "../map/mapdata.h" + typedef struct s_vec2 { double x; @@ -32,4 +34,6 @@ typedef struct s_player t_vec2 movement; } t_player; +void init_player(t_player *player, t_mapdata *map); + #endif // PLAYER_H