From fa3cb8da4a50abdc0490ab796c752a3cdc2a8296 Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Tue, 29 Jul 2025 12:14:44 +0200 Subject: [PATCH] fix(player): reworked angles for player and added player initialization --- src/consts.c | 2 +- src/consts.h | 5 ++++ src/player/player.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ src/player/player.h | 8 ++++-- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/player/player.c diff --git a/src/consts.c b/src/consts.c index 8b4b371..fdedb24 100644 --- a/src/consts.c +++ b/src/consts.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/28 14:33:12 by kcolin #+# #+# */ -/* Updated: 2025/07/28 15:03:16 by kcolin ### ########.fr */ +/* Updated: 2025/07/29 12:01:33 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/consts.h b/src/consts.h index c1a9a3c..7f61e8d 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,7 +6,11 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ +<<<<<<< Updated upstream /* Updated: 2025/07/29 11:42:20 by kcolin ### ########.fr */ +======= +/* Updated: 2025/07/29 12:02:08 by tchampio ### ########.fr */ +>>>>>>> Stashed changes /* */ /* ************************************************************************** */ @@ -31,6 +35,7 @@ extern const float g_southeast; # define RESSOURCE_DIR "ressources" # define MOVEMENT_SPEED 6.4 # define ROTATION_SPEED 0.1 +# define PLANE_VALUE 0.66 # ifdef BONUS # define COMPILED_TEXT "Compiled with bonuses" # else diff --git a/src/player/player.c b/src/player/player.c new file mode 100644 index 0000000..8ef7243 --- /dev/null +++ b/src/player/player.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* player.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio dir_x = 0; + player->dir_y = -1; + player->plane_x = PLANE_VALUE; + player->plane_y = 0; + } + else + { + player->dir_x = 0; + player->dir_y = 1; + player->plane_x = -PLANE_VALUE; + player->plane_y = 0; + } +} +// north south +void init_lat(t_player *player, char dir) +{ + if (dir == 'E') + { + player->dir_x = 1; + player->dir_y = 0; + player->plane_x = 0; + player->plane_y = PLANE_VALUE; + } + else + { + player->dir_x = -1; + player->dir_y = 0; + player->plane_x = 0; + player->plane_y = -PLANE_VALUE; + } +} + +void init_player(t_player *player, t_mapdata *map) +{ + char dir; + + dir = map->map[map->starty][map->startx]; + player->x = map->startx + 0.5; + player->y = map->starty + 0.5; + player->health = 100; + player->points = 500; + if (dir == 'N' || dir == 'S') + init_lon(player, dir); + else + init_lat(player, dir); +} diff --git a/src/player/player.h b/src/player/player.h index 24563e0..1fc189b 100644 --- a/src/player/player.h +++ b/src/player/player.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */ -/* Updated: 2025/07/24 14:07:09 by tchampio ### ########.fr */ +/* Updated: 2025/07/29 12:01:02 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,12 @@ typedef struct s_player { double x; double y; - double yaw; + double dir_x; + double dir_y; + double plane_x; + double plane_y; int health; + int points; t_vec2 movement; } t_player;