summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--include/so_long.h5
-rw-r--r--src/map_utils.c31
3 files changed, 35 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 84d93f3..51de300 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LIBS = -Llibft -lft -lm -LMLX42/build -lmlx42 -ldl -lglfw -pthread
VPATH := src
SRC = main.c init.c loop.c input.c draw.c tilemap.c player_process.c \
- collision.c
+ collision.c map_utils.c
OBJ_DIR := obj
OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o))
diff --git a/include/so_long.h b/include/so_long.h
index bd40371..6834620 100644
--- a/include/so_long.h
+++ b/include/so_long.h
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/08 14:14:02 by dkaiser #+# #+# */
-/* Updated: 2024/05/14 12:41:08 by dkaiser ### ########.fr */
+/* Updated: 2024/05/14 13:52:05 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -84,7 +84,8 @@ void player_process(t_game *game);
int draw(t_game *game);
int draw_map(t_game *game);
void on_key_input(mlx_key_data_t event, void *params);
-
+t_vector grid_to_screen_pos(t_ivector grid_pos, t_ivector tile_size);
+t_ivector screen_to_grid_pos(t_vector screen_pos, t_ivector tile_size);
int check_collision(t_vector a_pos, t_vector a_size, t_vector b_pos,
t_vector b_size);
diff --git a/src/map_utils.c b/src/map_utils.c
new file mode 100644
index 0000000..54577a8
--- /dev/null
+++ b/src/map_utils.c
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* map_utils.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/05/14 13:19:34 by dkaiser #+# #+# */
+/* Updated: 2024/05/14 13:50:23 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "so_long.h"
+
+t_vector grid_to_screen_pos(t_ivector grid_pos, t_ivector tile_size)
+{
+ t_vector screen_pos;
+
+ screen_pos.x = grid_pos.x * tile_size.x;
+ screen_pos.y = grid_pos.y * tile_size.y;
+ return (screen_pos);
+}
+
+t_ivector screen_to_grid_pos(t_vector screen_pos, t_ivector tile_size)
+{
+ t_ivector grid_pos;
+
+ grid_pos.x = screen_pos.x / tile_size.x;
+ grid_pos.y = screen_pos.y / tile_size.y;
+ return (grid_pos);
+}