aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-31 14:59:53 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-31 14:59:53 +0200
commitf06a9f89bdbf5123fd00a79d350d599509d689df (patch)
tree396f94876a3d81f14c9cab3b06989c13cc8e6437
parentFixed that gangsta (diff)
download42-cub3d-f06a9f89bdbf5123fd00a79d350d599509d689df.tar.gz
42-cub3d-f06a9f89bdbf5123fd00a79d350d599509d689df.tar.bz2
42-cub3d-f06a9f89bdbf5123fd00a79d350d599509d689df.tar.xz
42-cub3d-f06a9f89bdbf5123fd00a79d350d599509d689df.tar.zst
42-cub3d-f06a9f89bdbf5123fd00a79d350d599509d689df.zip
Big gameplay
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_defines.h5
-rw-r--r--src/ft_damage_bad_boy.c45
-rw-r--r--src/ft_shoot.c41
5 files changed, 77 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 7b77c45..2e1f212 100644
--- a/Makefile
+++ b/Makefile
@@ -130,6 +130,7 @@ SRCS_NAME += ft_init_bad_boys.c
SRCS_NAME += ft_bad_boy_actions.c
SRCS_NAME += ft_select_bad_boy_action.c
SRCS_NAME += ft_collision.c
+SRCS_NAME += ft_damage_bad_boy.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index bb66ab1..f392354 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -248,6 +248,7 @@ void ft_bb_wait(t_bad_boy *bl, t_sprite *sl, t_map *ml);
void ft_bb_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml);
void ft_bb_fire(t_bad_boy *bl, t_sprite *sl, t_map *ml);
void ft_check_bad_boy_shoot(t_cub *cl);
+void ft_damage_bad_boy(t_cub *cl);
/*
** ====== DELETION ======
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 19caf31..42a74b2 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -303,9 +303,12 @@ enum
# define FT_WEAP_TWO_STRT_AMMO 30
# define FT_WEAP_THREE_STRT_AMMO 24
# define FT_WEAP_MAX_AMMO 1000
-# define FT_ENMY_STRT_LIFE 3
+# define FT_ENMY_STRT_LIFE 15
# define FT_ENMY_SIGHT_RANGE 7.0
# define FT_ENMY_DAMAGE_AMOUNT 54
+# define FT_W_ONE_DANAGE_AMOUNT 2
+# define FT_W_TWO_DANAGE_AMOUNT 1
+# define FT_W_THREE_DANAGE_AMOUNT 3
/*
** ====== OTHER ======
diff --git a/src/ft_damage_bad_boy.c b/src/ft_damage_bad_boy.c
new file mode 100644
index 0000000..c8a04fa
--- /dev/null
+++ b/src/ft_damage_bad_boy.c
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_damage_bad_boy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:22:32 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+
+static uint8_t
+ ft_get_bad_boy_id(t_cub *cl)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < cl->mlist.sprite_nbr[13])
+ {
+ if (cl->sprites[13][i].s_pos_x == cl->rlist.sqy &&
+ cl->sprites[13][i].s_pos_y == cl->rlist.sqx)
+ return (i);
+ i++;
+ }
+ return (0);
+}
+
+void
+ ft_damage_bad_boy(t_cub *cl)
+{
+ uint8_t id;
+
+ id = ft_get_bad_boy_id(cl);
+ if (cl->plist.handles_weapon == 0)
+ cl->bad_boy[id].life -= FT_W_ONE_DANAGE_AMOUNT;
+ else if (cl->plist.handles_weapon == 1)
+ cl->bad_boy[id].life -= FT_W_TWO_DANAGE_AMOUNT;
+ else if (cl->plist.handles_weapon == 2)
+ cl->bad_boy[id].life -= FT_W_THREE_DANAGE_AMOUNT;
+ /* TODO: sfx enemy scream and death */
+}
diff --git a/src/ft_shoot.c b/src/ft_shoot.c
index 7f23bfd..5342509 100644
--- a/src/ft_shoot.c
+++ b/src/ft_shoot.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_extra_keys.c :+: :+: :+: */
+/* ft_shoot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@@ -55,30 +55,41 @@ static int8_t
}
static void
+ ft_set_sq(t_cub *cl)
+{
+ if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
+ {
+ cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
+ cl->rlist.sqx += cl->mlist.x_step;
+ cl->rlist.side = 0;
+ }
+ else
+ {
+ cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
+ cl->rlist.sqy += cl->mlist.y_step;
+ cl->rlist.side = 1;
+ }
+}
+
+static void
ft_hitscan(t_cub *cl, uint16_t hit)
{
while (hit == 0)
{
- if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)
- {
- cl->rlist.x_side_dist += cl->rlist.x_delta_dist;
- cl->rlist.sqx += cl->mlist.x_step;
- cl->rlist.side = 0;
- }
- else
- {
- cl->rlist.y_side_dist += cl->rlist.y_delta_dist;
- cl->rlist.sqy += cl->mlist.y_step;
- cl->rlist.side = 1;
- }
+ ft_set_sq(cl);
if (ft_ischarset(FT_CHRST_SPRITES,
cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]) && ft_weap_range(cl))
{
hit = 1;
ft_hide_sprite(cl);
}
- else if (ft_ischarset("1",
- cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ else if (cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == 'e' &&
+ ft_weap_range(cl))
+ {
+ hit = 1;
+ ft_damage_bad_boy(cl);
+ }
+ else if (cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == '1')
hit = 1;
}
}