aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-02-02 18:37:10 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-02-02 18:37:10 +0100
commit88c8592fa835c7c5a010f69e80e09a8e38caa09f (patch)
treef2371c512957931e6446a9bedacc79ac815e7e6f
parentChanged variable name (diff)
download42-cub3d-88c8592fa835c7c5a010f69e80e09a8e38caa09f.tar.gz
42-cub3d-88c8592fa835c7c5a010f69e80e09a8e38caa09f.tar.bz2
42-cub3d-88c8592fa835c7c5a010f69e80e09a8e38caa09f.tar.xz
42-cub3d-88c8592fa835c7c5a010f69e80e09a8e38caa09f.tar.zst
42-cub3d-88c8592fa835c7c5a010f69e80e09a8e38caa09f.zip
Added player list
-rw-r--r--inc/cub3d.h7
-rw-r--r--src/ft_exit.c1
-rw-r--r--src/ft_init_lists.c17
-rw-r--r--src/ft_print_list.c25
4 files changed, 37 insertions, 13 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 2fd6396..923e877 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -57,8 +57,15 @@ typedef struct s_cub
size_t line_chk;
uint8_t isspawn;
struct s_win *wlist;
+ struct s_player *plist;
} t_cub;
+typedef struct s_player
+{
+ size_t pos_x;
+ size_t pos_y;
+} t_player;
+
t_win *ft_init_win(void);
t_cub *ft_init_cub(void);
int ft_key_event(int keycode, void *param);
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 1e926ce..5e7cd3f 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -28,6 +28,7 @@ static void
ft_memdel((void**)&clist->sprite_path);
ft_memdel((void**)&clist->mapl);
ft_free_words(clist->map);
+ ft_memdel((void**)&clist->plist);
if (!clist->wlist->inited)
ft_memdel((void**)&clist->wlist->winptr);
ft_memdel((void**)&clist->wlist->wlx);
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index f81e256..b7602ab 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -17,6 +17,18 @@
#include <stddef.h>
#include <stdlib.h>
+t_player
+ *ft_init_player(void)
+{
+ t_player *plist;
+
+ if (!(plist = (t_player*)malloc(sizeof(t_player))))
+ return (NULL);
+ plist->pos_x = 0;
+ plist->pos_y = 0;
+ return (plist);
+}
+
t_win
*ft_init_win(void)
{
@@ -36,7 +48,7 @@ t_win
t_cub
*ft_init_cub(void)
{
- t_cub *clist;
+ t_cub *clist;
if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
return (NULL);
@@ -47,7 +59,8 @@ t_cub
!(clist->sprite_path = (char*)ft_calloc(1, sizeof(char))) ||
!(clist->mapl = (char*)ft_calloc(1, sizeof(char))) ||
!(clist->map = (char**)ft_calloc(2, sizeof(char*))) ||
- !(clist->map[0] = (char*)ft_calloc(1, sizeof(char))))
+ !(clist->map[0] = (char*)ft_calloc(1, sizeof(char))) ||
+ !(clist->plist = ft_init_player()))
return (NULL);
clist->map[1] = 0;
clist->f_color = -1;
diff --git a/src/ft_print_list.c b/src/ft_print_list.c
index b86d915..45ef1fe 100644
--- a/src/ft_print_list.c
+++ b/src/ft_print_list.c
@@ -19,22 +19,25 @@ void
{
size_t i;
- ft_printf("x size [%d]\n", clist->wlist->x_size);
- ft_printf("y size [%d]\n", clist->wlist->y_size);
- ft_printf("North - [%s]\n", clist->no_tex_path);
- ft_printf("South - [%s]\n", clist->so_tex_path);
- ft_printf("West -- [%s]\n", clist->we_tex_path);
- ft_printf("East -- [%s]\n", clist->ea_tex_path);
- ft_printf("Sprite [%s]\n", clist->sprite_path);
- ft_printf("F color [%d]\n", clist->f_color);
- ft_printf("C color [%d]\n", clist->c_color);
+ ft_printf("x size ----- [%d]\n", clist->wlist->x_size);
+ ft_printf("y size ----- [%d]\n", clist->wlist->y_size);
+ ft_printf("North ------ [%s]\n", clist->no_tex_path);
+ ft_printf("South ------ [%s]\n", clist->so_tex_path);
+ ft_printf("West ------- [%s]\n", clist->we_tex_path);
+ ft_printf("East ------- [%s]\n", clist->ea_tex_path);
+ ft_printf("Sprite ----- [%s]\n", clist->sprite_path);
+ ft_printf("F color ---- [%d]\n", clist->f_color);
+ ft_printf("C color ---- [%d]\n", clist->c_color);
i = 0;
ft_printf("Map\n----\n");
while (clist->map[i])
{
- ft_printf("%2zu [%s]\n", i + 1, clist->map[i]);
+ ft_printf("%2zu -- [%s]\n", i + 1, clist->map[i]);
i++;
}
- ft_printf("Map width [%zu]\n", clist->map_w);
+ ft_printf("Map width -- [%zu]\n", clist->map_w);
+ ft_printf("----\n");
+ ft_printf("Player pos X [%zu]\n", clist->plist->pos_x);
+ ft_printf("Player pos Y [%zu]\n", clist->plist->pos_y);
ft_printf("----------------------\n");
}