aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-18 22:21:29 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-18 22:21:29 +0100
commit8fda101ccda5c23bfd9cd604f0c3124a9b83aa1d (patch)
treeeaf3adca241ec77c8af19adbfdf5871e305c6d01 /src
parentWorks fine (diff)
download42-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
Diffstat (limited to '')
-rw-r--r--src/ft_find_item.c52
-rw-r--r--src/ft_get_traps.c2
-rw-r--r--src/ft_key_loop.c1
3 files changed, 54 insertions, 1 deletions
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 &&