diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 22:21:29 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 22:21:29 +0100 |
commit | 8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d (patch) | |
tree | eaf3adca241ec77c8af19adbfdf5871e305c6d01 | |
parent | Works fine (diff) | |
download | 42-cub3d-8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d.tar.gz 42-cub3d-8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d.tar.bz2 42-cub3d-8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d.tar.xz 42-cub3d-8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d.tar.zst 42-cub3d-8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d.zip |
ok bav
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_defines.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 4 | ||||
-rw-r--r-- | map/map_one.cub | 8 | ||||
-rw-r--r-- | src/ft_find_item.c | 52 | ||||
-rw-r--r-- | src/ft_get_traps.c | 2 | ||||
-rw-r--r-- | src/ft_key_loop.c | 1 |
8 files changed, 64 insertions, 7 deletions
@@ -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 && |