aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_convert_keycode.c2
-rw-r--r--src/ft_init_lists.c2
-rw-r--r--src/ft_key_events.c7
-rw-r--r--src/ft_switch_weapons.c30
4 files changed, 39 insertions, 2 deletions
diff --git a/src/ft_convert_keycode.c b/src/ft_convert_keycode.c
index a152cfa..22e6169 100644
--- a/src/ft_convert_keycode.c
+++ b/src/ft_convert_keycode.c
@@ -33,5 +33,7 @@ int32_t
keycode = (tmp_code == FT_TAB_KEY) ? (FT_TAB_KEY) : (keycode);
keycode = (tmp_code == FT_RET_KEY) ? (FT_RET_KEY) : (keycode);
keycode = (tmp_code == FT_SPC_KEY) ? (FT_SPC_KEY) : (keycode);
+ keycode = (tmp_code == FT_ONE_KEY) ? (FT_ONE_KEY) : (keycode);
+ keycode = (tmp_code == FT_TWO_KEY) ? (FT_TWO_KEY) : (keycode);
return (keycode);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index dbf4e8f..efb243b 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -32,7 +32,7 @@ t_rgb
** --------------
** -1: no weapon
** 0: weapon one
-** 1: weapon two
+** 2: weapon two
*/
t_player
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index edacc42..52ef477 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -10,7 +10,6 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
#include <stdint.h>
@@ -38,6 +37,12 @@ int
return (ft_f1_key(clist));
else if (keycode == FT_SPC_KEY && clist->plist.handles_weapon > -1)
return (ft_space_key(clist));
+ else if (keycode == FT_ONE_KEY && clist->plist.fire == 0
+ && clist->plist.has_weapon[0] == 1 && clist->plist.handles_weapon != 0)
+ return (ft_switch_weap_one(clist));
+ else if (keycode == FT_TWO_KEY && clist->plist.fire == 0
+ && clist->plist.has_weapon[1] == 1 && clist->plist.handles_weapon != 2)
+ return (ft_switch_weap_two(clist));
ft_insert_key(keycode, clist);
return (0);
}
diff --git a/src/ft_switch_weapons.c b/src/ft_switch_weapons.c
new file mode 100644
index 0000000..186f7be
--- /dev/null
+++ b/src/ft_switch_weapons.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_switch_weapons.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:55 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:55 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+int8_t
+ ft_switch_weap_one(t_cub *cl)
+{
+ cl->sfx[6].sfx_play(cl->sfx);
+ cl->plist.handles_weapon = 0;
+ return (0);
+}
+
+int8_t
+ ft_switch_weap_two(t_cub *cl)
+{
+ cl->sfx[8].sfx_play(cl->sfx);
+ cl->plist.handles_weapon = 2;
+ return (0);
+}