aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_missing_defines.c6
-rw-r--r--src/ft_check_missing_sfx.c6
-rw-r--r--src/ft_del_sfx_cmd.c2
-rw-r--r--src/ft_del_sprites_lists.c2
-rw-r--r--src/ft_del_tex.c4
-rw-r--r--src/ft_draw_weapons_extra.c1
-rw-r--r--src/ft_find_item.c14
-rw-r--r--src/ft_get_weapon_spawn.c6
-rw-r--r--src/ft_init_lists.c2
-rw-r--r--src/ft_init_sfx.c26
-rw-r--r--src/ft_init_weaps.c4
-rw-r--r--src/ft_sfx_weapon_three.c67
-rw-r--r--src/ft_tex_init.c5
-rw-r--r--src/ft_tex_weap_init.c8
14 files changed, 139 insertions, 14 deletions
diff --git a/src/ft_check_missing_defines.c b/src/ft_check_missing_defines.c
index 2e365b8..d5d56b9 100644
--- a/src/ft_check_missing_defines.c
+++ b/src/ft_check_missing_defines.c
@@ -57,11 +57,17 @@ int
if (ft_check_not_found(FT_WEAPON_TWO_PATH) < 0 ||
ft_check_ext(FT_WEAPON_TWO_PATH, ".xpm") < 0)
return (ft_missing_error(FT_ERR_MISS_W_TWO, clist));
+ if (ft_check_not_found(FT_WEAPON_THREE_PATH) < 0 ||
+ ft_check_ext(FT_WEAPON_THREE_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_W_THREE, clist));
if (ft_check_not_found(FT_WEAPON_ONE_FIRE_PATH) < 0 ||
ft_check_ext(FT_WEAPON_ONE_FIRE_PATH, ".xpm") < 0)
return (ft_missing_error(FT_ERR_MISS_W_ONE_FIRE, clist));
if (ft_check_not_found(FT_WEAPON_TWO_FIRE_PATH) < 0 ||
ft_check_ext(FT_WEAPON_TWO_FIRE_PATH, ".xpm") < 0)
return (ft_missing_error(FT_ERR_MISS_W_TWO_FIRE, clist));
+ if (ft_check_not_found(FT_WEAPON_THREE_FIRE_PATH) < 0 ||
+ ft_check_ext(FT_WEAPON_THREE_FIRE_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_W_THREE_FIRE, clist));
return (ft_check_missing_number_defines(clist));
}
diff --git a/src/ft_check_missing_sfx.c b/src/ft_check_missing_sfx.c
index f8a32b1..1273457 100644
--- a/src/ft_check_missing_sfx.c
+++ b/src/ft_check_missing_sfx.c
@@ -28,6 +28,12 @@ static int
if (ft_check_not_found(FT_SFX_W_TWO_FIRE_PATH) < 0 ||
ft_check_ext(FT_SFX_W_TWO_FIRE_PATH, ".wav") < 0)
return (ft_missing_error(FT_ERR_MISS_SFX_W_TWO_FIRE, clist));
+ if (ft_check_not_found(FT_SFX_W_THREE_LOAD_PATH) < 0 ||
+ ft_check_ext(FT_SFX_W_THREE_LOAD_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_W_THREE_LOAD, clist));
+ if (ft_check_not_found(FT_SFX_W_THREE_FIRE_PATH) < 0 ||
+ ft_check_ext(FT_SFX_W_THREE_FIRE_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_W_THREE_FIRE, clist));
return (0);
}
diff --git a/src/ft_del_sfx_cmd.c b/src/ft_del_sfx_cmd.c
index b5c5fdf..701bfa9 100644
--- a/src/ft_del_sfx_cmd.c
+++ b/src/ft_del_sfx_cmd.c
@@ -20,7 +20,7 @@ void
uint8_t i;
i = 0;
- while (i < 10)
+ while (i < 12)
{
ft_memdel((void*)&clist->sfx[i].cmd);
i++;
diff --git a/src/ft_del_sprites_lists.c b/src/ft_del_sprites_lists.c
index 72e5fa9..bb382e6 100644
--- a/src/ft_del_sprites_lists.c
+++ b/src/ft_del_sprites_lists.c
@@ -27,7 +27,7 @@ void
}
ft_memdel((void*)&clist->sprites);
i = 0;
- while (i < 2)
+ while (i < 3)
{
ft_memdel((void*)&clist->weaps[i]);
i++;
diff --git a/src/ft_del_tex.c b/src/ft_del_tex.c
index 839387a..55eff72 100644
--- a/src/ft_del_tex.c
+++ b/src/ft_del_tex.c
@@ -48,7 +48,7 @@ static void
int8_t i;
i = 0;
- while (i < 4)
+ while (i < 6)
{
if (cl->tweap[i].img)
mlx_destroy_image(cl->wlist.wlx, cl->tweap[i].img);
@@ -75,6 +75,8 @@ static void
mlx_destroy_image(cl->wlist.wlx, cl->tlist[18].img);
if (cl->tlist[19].img)
mlx_destroy_image(cl->wlist.wlx, cl->tlist[19].img);
+ if (cl->tlist[20].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[20].img);
}
void
diff --git a/src/ft_draw_weapons_extra.c b/src/ft_draw_weapons_extra.c
index 781598f..ed3ed53 100644
--- a/src/ft_draw_weapons_extra.c
+++ b/src/ft_draw_weapons_extra.c
@@ -38,4 +38,5 @@ void
{
ft_calc_weapon(0, cl);
ft_calc_weapon(1, cl);
+ ft_calc_weapon(2, cl);
}
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index 56e1351..c95fa0a 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -36,13 +36,23 @@ static void
if (ft_ischarset(FT_CHRST_WEAPONS, map_char))
{
- weap_id = (map_char == '!') ? (0) : (1);
+ weap_id = 0;
+ if (map_char == '@')
+ weap_id = 1;
+ else if (map_char == '#')
+ weap_id = 2;
cl->mlist.map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0';
cl->weaps[weap_id][0].s_pos_x = 0;
cl->weaps[weap_id][0].s_pos_y = 0;
pl->has_weapon[weap_id] = 1;
pl->handles_weapon = (weap_id == 1) ? (2) : (weap_id);
- cl->sfx[((weap_id == 1) ? (2) : (weap_id)) + 6].sfx_play(cl->sfx);
+ pl->handles_weapon = (weap_id == 2) ? (4) : (weap_id);
+ if (weap_id == 0)
+ cl->sfx[6].sfx_play(cl->sfx);
+ else if (weap_id == 1)
+ cl->sfx[8].sfx_play(cl->sfx);
+ else if (weap_id == 2)
+ cl->sfx[10].sfx_play(cl->sfx);
}
}
diff --git a/src/ft_get_weapon_spawn.c b/src/ft_get_weapon_spawn.c
index a54d2b6..1ed4c7d 100644
--- a/src/ft_get_weapon_spawn.c
+++ b/src/ft_get_weapon_spawn.c
@@ -22,8 +22,10 @@ static void
{
if (id == 0)
ft_map_error(FT_ERR_TOO_MUCH_W_ONE, clist);
- else
+ else if (id == 1)
ft_map_error(FT_ERR_TOO_MUCH_W_TWO, clist);
+ else
+ ft_map_error(FT_ERR_TOO_MUCH_W_THREE, clist);
}
clist->weaps[id][0].s_pos_x = x;
clist->weaps[id][0].s_pos_y = y;
@@ -47,6 +49,8 @@ void
ft_get_weapon_id_spawn(0, y, x, clist);
else if (clist->mlist.map[y][x] == '@')
ft_get_weapon_id_spawn(1, y, x, clist);
+ else if (clist->mlist.map[y][x] == '#')
+ ft_get_weapon_id_spawn(2, y, x, clist);
x++;
}
x = 1;
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index e94e688..dbf944d 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -33,6 +33,7 @@ t_rgb
** -1: no weapon
** 0: weapon one
** 2: weapon two
+** 4: weapon two
*/
t_player
@@ -52,6 +53,7 @@ t_player
plist.plane_y = 0.66;
plist.has_weapon[0] = 0;
plist.has_weapon[1] = 0;
+ plist.has_weapon[2] = 0;
plist.handles_weapon = -1;
plist.life = FT_STRT_LIFE;
plist.fire = 0;
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 6fc8504..202e647 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -32,6 +32,8 @@
** 7: weapon one fire
** 8: weapon two load
** 9: weapon two fire
+** 10: weapon three load
+** 11: weapon three fire
*/
static int8_t
@@ -56,10 +58,18 @@ static void
pthread_create(&cl->sfx[3].tid, NULL, ft_sfx_pain_thread, &cl->sfx);
pthread_create(&cl->sfx[4].tid, NULL, ft_sfx_trap_thread, &cl->sfx);
pthread_create(&cl->sfx[5].tid, NULL, ft_sfx_heal_thread, &cl->sfx);
- pthread_create(&cl->sfx[6].tid, NULL, ft_sfx_weapon_one_load_thread, &cl->sfx);
- pthread_create(&cl->sfx[7].tid, NULL, ft_sfx_weapon_one_fire_thread, &cl->sfx);
- pthread_create(&cl->sfx[8].tid, NULL, ft_sfx_weapon_two_load_thread, &cl->sfx);
- pthread_create(&cl->sfx[9].tid, NULL, ft_sfx_weapon_two_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[6].tid, NULL,
+ ft_sfx_weapon_one_load_thread, &cl->sfx);
+ pthread_create(&cl->sfx[7].tid, NULL,
+ ft_sfx_weapon_one_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[8].tid, NULL,
+ ft_sfx_weapon_two_load_thread, &cl->sfx);
+ pthread_create(&cl->sfx[9].tid, NULL,
+ ft_sfx_weapon_two_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[10].tid, NULL,
+ ft_sfx_weapon_three_load_thread, &cl->sfx);
+ pthread_create(&cl->sfx[11].tid, NULL,
+ ft_sfx_weapon_three_fire_thread, &cl->sfx);
}
static void
@@ -75,6 +85,8 @@ static void
cl->sfx[7].sfx_play = ft_sfx_weapon_one_fire;
cl->sfx[8].sfx_play = ft_sfx_weapon_two_load;
cl->sfx[9].sfx_play = ft_sfx_weapon_two_fire;
+ cl->sfx[10].sfx_play = ft_sfx_weapon_three_load;
+ cl->sfx[11].sfx_play = ft_sfx_weapon_three_fire;
}
int8_t
@@ -92,10 +104,12 @@ int8_t
ft_init_sfx_cmd(&cl->sfx[6].cmd, FT_SFX_W_ONE_LOAD_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[7].cmd, FT_SFX_W_ONE_FIRE_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[8].cmd, FT_SFX_W_TWO_LOAD_PATH) < 0 ||
- ft_init_sfx_cmd(&cl->sfx[9].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0)
+ ft_init_sfx_cmd(&cl->sfx[9].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0 ||
+ ft_init_sfx_cmd(&cl->sfx[10].cmd, FT_SFX_W_THREE_LOAD_PATH) < 0 ||
+ ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0)
return (-1);
i = -1;
- while (++i < 10)
+ while (++i < 12)
pthread_mutex_init(&cl->sfx[i].mutex, NULL);
ft_init_sfx_pthreads(cl);
ft_init_sfx_funptr(cl);
diff --git a/src/ft_init_weaps.c b/src/ft_init_weaps.c
index 242b62d..f3f7452 100644
--- a/src/ft_init_weaps.c
+++ b/src/ft_init_weaps.c
@@ -21,10 +21,10 @@ int8_t
{
uint8_t i;
- if (!(*weaps = (t_sprite**)ft_calloc(2, sizeof(t_sprite*))))
+ if (!(*weaps = (t_sprite**)ft_calloc(3, sizeof(t_sprite*))))
return (-1);
i = 0;
- while (i < 2)
+ while (i < 3)
{
if (!(*((*weaps) + i) = (t_sprite*)ft_calloc(1, sizeof(t_sprite))))
return (-1);
diff --git a/src/ft_sfx_weapon_three.c b/src/ft_sfx_weapon_three.c
new file mode 100644
index 0000000..a737230
--- /dev/null
+++ b/src/ft_sfx_weapon_three.c
@@ -0,0 +1,67 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_weapon_three.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */
+/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+void
+ *ft_sfx_weapon_three_load_thread(void *vargp)
+{
+ t_sfx *sfx;
+
+ if (FT_OS == 1)
+ pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ else
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ sfx = (t_sfx *)vargp;
+ pthread_mutex_lock(&sfx[10].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[10].mutex);
+ if (system(sfx[10].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_three_load(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[10].mutex);
+}
+
+void
+ *ft_sfx_weapon_three_fire_thread(void *vargp)
+{
+ t_sfx *sfx;
+
+ if (FT_OS == 1)
+ pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ else
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ sfx = (t_sfx *)vargp;
+ pthread_mutex_lock(&sfx[11].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[11].mutex);
+ if (system(sfx[11].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_three_fire(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[11].mutex);
+}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 89a4d77..effe6a1 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -38,6 +38,7 @@
** 17: heal pack
** 18: weapon one sprite
** 19: weapon two sprite
+** 20: weapon two sprite
*/
static void
@@ -73,6 +74,10 @@ static void
FT_WEAPON_TWO_SPR_PATH, &cl->tlist[19].img_w, &cl->tlist[19].img_h);
cl->tlist[19].ptr = mlx_get_data_addr(cl->tlist[19].img,
&cl->tlist[19].bpp, &cl->tlist[19].sizeline, &cl->tlist[19].endian);
+ cl->tlist[20].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_WEAPON_THREE_SPR_PATH, &cl->tlist[20].img_w, &cl->tlist[20].img_h);
+ cl->tlist[20].ptr = mlx_get_data_addr(cl->tlist[20].img,
+ &cl->tlist[20].bpp, &cl->tlist[20].sizeline, &cl->tlist[20].endian);
cl->walltexgood = 1;
if (cl->mlist.sprite_var > 1)
ft_next_sprite_init(cl);
diff --git a/src/ft_tex_weap_init.c b/src/ft_tex_weap_init.c
index d0bf835..ab8ed53 100644
--- a/src/ft_tex_weap_init.c
+++ b/src/ft_tex_weap_init.c
@@ -41,4 +41,12 @@ void
FT_WEAPON_TWO_FIRE_PATH, &cl->tweap[3].img_w, &cl->tweap[3].img_h);
cl->tweap[3].ptr = mlx_get_data_addr(cl->tweap[3].img,
&cl->tweap[3].bpp, &cl->tweap[3].sizeline, &cl->tweap[3].endian);
+ cl->tweap[4].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_WEAPON_THREE_PATH, &cl->tweap[4].img_w, &cl->tweap[4].img_h);
+ cl->tweap[4].ptr = mlx_get_data_addr(cl->tweap[4].img,
+ &cl->tweap[4].bpp, &cl->tweap[4].sizeline, &cl->tweap[4].endian);
+ cl->tweap[5].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_WEAPON_THREE_FIRE_PATH, &cl->tweap[5].img_w, &cl->tweap[5].img_h);
+ cl->tweap[5].ptr = mlx_get_data_addr(cl->tweap[5].img,
+ &cl->tweap[5].bpp, &cl->tweap[5].sizeline, &cl->tweap[5].endian);
}