aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_warp_level.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_warp_level.c')
-rw-r--r--src/ft_warp_level.c101
1 files changed, 32 insertions, 69 deletions
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 107e709..5055445 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -12,56 +12,42 @@
#include <libft.h>
#include <cub3d.h>
-#include <mlx.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
-#include <unistd.h>
#include <signal.h>
#include <pthread.h>
static void
- ft_del_map(t_map *ml)
-{
- ft_memdel((void*)&ml->filename);
- ft_memdel((void*)&ml->no_tex_path);
- ft_memdel((void*)&ml->so_tex_path);
- ft_memdel((void*)&ml->ea_tex_path);
- ft_memdel((void*)&ml->we_tex_path);
- ft_memdel((void*)&ml->nl_tex_path);
- ft_memdel((void*)&ml->fl_tex_path);
- ft_memdel((void*)&ml->ce_tex_path);
- ft_memdel((void*)&ml->nlevel_path);
- ft_memdel((void*)&ml->skybox_path);
- ft_memdel((void*)&ml->traps_path);
- ft_memdel((void*)&ml->music_path);
- ft_memdel((void*)&ml->music_cmd);
- ft_memdel((void*)&ml->mapl);
- ft_free_sprites(ml->sprite_path);
- ft_free_words(ml->map);
-}
-
-static void
ft_player_keepings(t_cub *cl)
{
- int8_t tmp_life;
- uint8_t tmp_has[2];
- int8_t tmp_handles;
+ int16_t tmp_life;
+ uint8_t tmp_has[3];
+ uint16_t tmp_ammo[3];
+ int8_t tmp_handles;
tmp_life = cl->plist.life;
tmp_has[0] = cl->plist.has_weapon[0];
tmp_has[1] = cl->plist.has_weapon[1];
+ tmp_has[2] = cl->plist.has_weapon[2];
+ tmp_ammo[0] = cl->plist.ammo[0];
+ tmp_ammo[1] = cl->plist.ammo[1];
+ tmp_ammo[2] = cl->plist.ammo[2];
tmp_handles = cl->plist.handles_weapon;
cl->plist = ft_init_player();
if (!cl->isdead)
cl->plist.life = tmp_life;
cl->plist.has_weapon[0] = tmp_has[0];
cl->plist.has_weapon[1] = tmp_has[1];
+ cl->plist.has_weapon[2] = tmp_has[2];
+ cl->plist.ammo[0] = tmp_ammo[0];
+ cl->plist.ammo[1] = tmp_ammo[1];
+ cl->plist.ammo[2] = tmp_ammo[2];
cl->plist.handles_weapon = tmp_handles;
}
-static void
- ft_del_some(t_cub *cl)
+static int8_t
+ ft_reinit_some(t_cub *cl)
{
int8_t i;
@@ -69,42 +55,22 @@ static void
cl->f_rgb = ft_init_rgb();
cl->c_rgb = ft_init_rgb();
cl->rlist = ft_init_s_ray();
- i = -1;
- while (++i < 5)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);
- if (cl->mlist.isnlvl && cl->tlist[5].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img);
- if (cl->mlist.isftex && cl->tlist[6].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img);
- if (cl->mlist.isctex && cl->tlist[7].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img);
- if (cl->mlist.istraps && cl->tlist[15].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img);
- if (cl->tlist[16].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img);
- if (cl->mlist.isheals && cl->tlist[17].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img);
- if (cl->mlist.isweapon[0] && cl->tlist[18].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[18].img);
- if (cl->mlist.isweapon[1] && cl->tlist[19].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[19].img);
- if (cl->tweap[0].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tweap[0].img);
- if (cl->tweap[1].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tweap[1].img);
- if (cl->tweap[2].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tweap[2].img);
- if (cl->tweap[3].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tweap[3].img);
- ft_del_extra_sprites(cl);
- i = -1;
- while (++i < 11)
- if (cl->tnum[i].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tnum[i].img);
- i = -1;
- while (++i < 8)
- ft_memdel((void*)&cl->sprites[i]);
- ft_memdel((void*)&cl->sprites);
+ ft_del_tex(cl);
+ ft_del_map(&cl->mlist);
+ ft_del_sprites_lists(cl);
+ if (ft_init_sprites(&cl->sprites) < 0)
+ return (-1);
+ if (ft_init_weaps(&cl->weaps) < 0)
+ return (-1);
+ if (ft_init_map(&cl->mlist) < 0)
+ return (-1);
+ i = 0;
+ while (i < 5)
+ {
+ cl->key_input[i] = -1;
+ i++;
+ }
+ return (0);
}
static void
@@ -140,11 +106,7 @@ int8_t
ft_sprintf(next_path, "%s", path);
if ((isoldmus = cl->mlist.ismusic))
tmp_mup = ft_strdup(cl->mlist.music_path);
- ft_del_some(cl);
- ft_del_map(&cl->mlist);
- if (ft_init_sprites(&cl->sprites) < 0)
- return (-1);
- if (ft_init_map(&cl->mlist) < 0)
+ if (ft_reinit_some(cl) < 0)
return (-1);
ft_parse_map(next_path, cl);
ft_treat_music(isoldmus, tmp_mup, cl);
@@ -153,6 +115,7 @@ int8_t
ft_memdel((void*)&tmp_mup);
ft_wall_tex_init(cl);
ft_weap_tex_init(cl);
+ ft_num_tex_init(cl);
ft_memdel((void*)&next_path);
return (0);
}