aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_defines.h2
-rw-r--r--inc/cub3d_structs.h4
-rw-r--r--map/map_one.cub8
-rw-r--r--src/ft_find_item.c52
-rw-r--r--src/ft_get_traps.c2
-rw-r--r--src/ft_key_loop.c1
8 files changed, 64 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 476ed6b..33a509d 100644
--- a/Makefile
+++ b/Makefile
@@ -104,6 +104,7 @@ SRCS_NAME += ft_get_fps_count.c
SRCS_NAME += ft_get_heal_spawn.c
SRCS_NAME += ft_draw_heals.c
SRCS_NAME += ft_draw_heals_extra.c
+SRCS_NAME += ft_find_item.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 4f1bc72..84ce976 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -184,5 +184,6 @@ t_bmp_rgb ft_hex_to_rgb(uint32_t color);
uint32_t ft_darken(t_rgb rgb, t_cub *cl);
void ft_death_screen(t_cub *cl);
void ft_get_fps_count(clock_t delta_time, t_cub *cl);
+void ft_find_item(t_player *pl, t_map *ml, t_cub *cl);
# endif
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 237cdad..e82fef5 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -140,6 +140,7 @@ enum
# define FT_CHRST_MAP_NON_WALL "023456789NESWLT+"
# define FT_CHRST_COLLISION "123456789 "
# define FT_CHRST_DETECT "1L"
+# define FT_CHRST_ITEM "+!@"
/*
** ====== BMP ======
@@ -224,5 +225,6 @@ enum
*/
# define FT_PARSE_END_RET 25
+# define FT_HEAL_PACK_AMOUNT 10
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index e4936eb..dc2b411 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -113,8 +113,8 @@ typedef struct s_sprite
int32_t y;
int32_t tex_x;
int32_t tex_y;
- int32_t s_pos_x;
- int32_t s_pos_y;
+ uint64_t s_pos_x;
+ uint64_t s_pos_y;
double spritex;
double spritey;
int32_t spriteheight;
diff --git a/map/map_one.cub b/map/map_one.cub
index b06c818..15e49ee 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -12,14 +12,14 @@ F ./media/img/parquet.xpm
S3 ./media/img/pylon.xpm
S4 ./media/img/wood_chest.xpm
-
T ./media/img/spikes.xpm
SH 2
+
111111111111111111
-100000000000020201
-100000E00000000001
-100100000000030301
+10000000+0000+0001
+100000E000T0000001
+1001000000000+0001
10110000+111000001
111111111111110011
1000001 100001
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
new file mode 100644
index 0000000..782a24a
--- /dev/null
+++ b/src/ft_find_item.c
@@ -0,0 +1,52 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_find_item.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */
+/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static uint16_t
+ ft_fetch_heals_id(uint64_t pos_y, uint64_t pos_x, t_cub *cl)
+{
+ uint16_t id;
+
+ id = 0;
+ while (id <= 64)
+ {
+ if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x)
+ return (id);
+ id++;
+ }
+ return (0);
+}
+
+void
+ ft_find_item(t_player *pl, t_map *ml, t_cub *cl)
+{
+ uint16_t id;
+ if (ft_ischarset(FT_CHRST_ITEM,
+ ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x]))
+ {
+ if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+'
+ && pl->life < 100)
+ {
+ pl->life += FT_HEAL_PACK_AMOUNT;
+ pl->life = (pl->life > 100) ? (100) : (pl->life);
+ ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0';
+ id = ft_fetch_heals_id((uint64_t)pl->pos_y,
+ (uint64_t)pl->pos_x, cl);
+ cl->heals[id].s_pos_x = 0;
+ cl->heals[id].s_pos_y = 0;
+ /* TODO: ft_sfx_heal(3) */
+ }
+ }
+}
diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c
index 2d652f8..fef3179 100644
--- a/src/ft_get_traps.c
+++ b/src/ft_get_traps.c
@@ -19,7 +19,7 @@ void
{
size_t x;
size_t y;
- uint8_t i;
+ uint16_t i;
x = 1;
y = 1;
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 0108202..e0177e2 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -89,6 +89,7 @@ int
{
ft_sfx_footstep(cl);
ft_collision(old_y, old_x, cl->key_input[i], cl);
+ ft_find_item(&cl->plist, &cl->mlist, cl);
if (cl->mlist.isnlvl)
{
if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&