aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_check_map_line.c3
-rw-r--r--src/ft_check_missing.c128
-rw-r--r--src/ft_check_missing_defines.c93
-rw-r--r--src/ft_check_missing_sfx.c65
-rw-r--r--src/ft_convert_keycode.c1
-rw-r--r--src/ft_del_map.c36
-rw-r--r--src/ft_del_sfx_cmd.c (renamed from src/ft_del_extra_sprites.c)19
-rw-r--r--src/ft_del_sprites_lists.c (renamed from src/ft_darken_rgb.c)39
-rw-r--r--src/ft_del_tex.c107
-rw-r--r--src/ft_draw_ammo_back.c90
-rw-r--r--src/ft_draw_ammo_bar.c138
-rw-r--r--src/ft_draw_ammo_caption.c94
-rw-r--r--src/ft_draw_circle.c1
-rw-r--r--src/ft_draw_handweap.c31
-rw-r--r--src/ft_draw_heals.c25
-rw-r--r--src/ft_draw_heals_extra.c3
-rw-r--r--src/ft_draw_health_caption.c95
-rw-r--r--src/ft_draw_hud.c67
-rw-r--r--src/ft_draw_life_bar.c118
-rw-r--r--src/ft_draw_map.c2
-rw-r--r--src/ft_draw_map_back.c90
-rw-r--r--src/ft_draw_sprite.c26
-rw-r--r--src/ft_draw_sprite_extra.c2
-rw-r--r--src/ft_draw_square.c1
-rw-r--r--src/ft_draw_textures.c30
-rw-r--r--src/ft_draw_traps.c27
-rw-r--r--src/ft_draw_traps_extra.c3
-rw-r--r--src/ft_draw_verline.c1
-rw-r--r--src/ft_draw_weapons.c27
-rw-r--r--src/ft_draw_weapons_extra.c3
-rw-r--r--src/ft_exit.c98
-rw-r--r--src/ft_extra_keys.c12
-rw-r--r--src/ft_find_item.c31
-rw-r--r--src/ft_floor_cast.c28
-rw-r--r--src/ft_free_words.c2
-rw-r--r--src/ft_get_map.c11
-rw-r--r--src/ft_get_player_spawn.c5
-rw-r--r--src/ft_get_spawns.c (renamed from src/ft_get_topsp.c)24
-rw-r--r--src/ft_get_sprite.c1
-rw-r--r--src/ft_get_sprite_spawns.c1
-rw-r--r--src/ft_get_weapon_spawn.c6
-rw-r--r--src/ft_hooks_and_loops.c2
-rw-r--r--src/ft_init_lists.c23
-rw-r--r--src/ft_init_map.c8
-rw-r--r--src/ft_init_sfx.c51
-rw-r--r--src/ft_init_sprites.c2
-rw-r--r--src/ft_init_weaps.c34
-rw-r--r--src/ft_init_winlx.c1
-rw-r--r--src/ft_key_events.c3
-rw-r--r--src/ft_key_loop.c41
-rw-r--r--src/ft_parse_map.c4
-rw-r--r--src/ft_raycasting.c47
-rw-r--r--src/ft_rgb_to_hex.c9
-rw-r--r--src/ft_save_to_bmp.c4
-rw-r--r--src/ft_set_minimap_scale.c8
-rw-r--r--src/ft_sfx_ooa.c41
-rw-r--r--src/ft_sfx_weapon_three.c67
-rw-r--r--src/ft_suffer_animation.c45
-rw-r--r--src/ft_switch_weapons.c8
-rw-r--r--src/ft_tex_init.c133
-rw-r--r--src/ft_tex_num_init.c90
-rw-r--r--src/ft_tex_sprites_extra_init.c35
-rw-r--r--src/ft_tex_weap_init.c13
-rw-r--r--src/ft_treat_args.c26
-rw-r--r--src/ft_warp_level.c101
-rw-r--r--src/main.c6
66 files changed, 1630 insertions, 756 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c
index 9419ab2..44580db 100644
--- a/src/ft_check_map_line.c
+++ b/src/ft_check_map_line.c
@@ -39,9 +39,6 @@ static int8_t
}
cl->mlist.istraps = (line[i] == 'T') ? (1) : (cl->mlist.istraps);
cl->mlist.isheals = (line[i] == '+') ? (1) : (cl->mlist.isheals);
- cl->mlist.isweapon[0] = (line[i] == '!') ? (1) : (cl->mlist.isweapon[0]);
- cl->mlist.isweapon[1] = (line[i] == '@') ? (1) : (cl->mlist.isweapon[1]);
- ft_get_topsp(line[i], cl);
return (0);
}
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index fb2da64..2b49d2e 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -12,49 +12,18 @@
#include <libft.h>
#include <cub3d.h>
-#include <unistd.h>
static int
- ft_check_missing_sfx(t_cub *clist)
-{
- if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0 ||
- ft_check_ext(FT_SFX_DEATH_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_DEATH, clist));
- if (ft_check_not_found(FT_SFX_N_LVL_PATH) < 0 ||
- ft_check_ext(FT_SFX_N_LVL_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_N_LVL, clist));
- if (ft_check_not_found(FT_SFX_SCR_ONE_PATH) < 0 ||
- ft_check_ext(FT_SFX_SCR_ONE_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_SCR_ONE, clist));
- if (ft_check_not_found(FT_SFX_SCR_TWO_PATH) < 0 ||
- ft_check_ext(FT_SFX_SCR_TWO_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_SCR_TWO, clist));
- if (ft_check_not_found(FT_SFX_TRAP_PATH) < 0 ||
- ft_check_ext(FT_SFX_TRAP_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_TRAP, clist));
- if (ft_check_not_found(FT_SFX_HEAL_PATH) < 0 ||
- ft_check_ext(FT_SFX_HEAL_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_HEAL, clist));
- if (ft_check_not_found(FT_SFX_W_ONE_LOAD_PATH) < 0 ||
- ft_check_ext(FT_SFX_W_ONE_LOAD_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_LOAD, clist));
- if (ft_check_not_found(FT_SFX_W_ONE_FIRE_PATH) < 0 ||
- ft_check_ext(FT_SFX_W_ONE_FIRE_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_FIRE, clist));
- if (ft_check_not_found(FT_SFX_W_TWO_LOAD_PATH) < 0 ||
- ft_check_ext(FT_SFX_W_TWO_LOAD_PATH, ".wav") < 0)
- return (ft_missing_error(FT_ERR_MISS_SFX_W_TWO_LOAD, clist));
- 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));
- return (0);
-}
-
-static int
- ft_check_missing_sprites(t_cub *clist)
+ ft_check_missing_bonus(t_cub *clist)
{
int8_t i;
+ if (clist->mlist.isnlvl && !clist->mlist.nl_tex_path[0])
+ return (ft_missing_error(FT_ERR_MISS_NLVL, clist));
+ else if (clist->mlist.isnlvl && !clist->mlist.nlevel_path[0])
+ return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));
+ if (clist->mlist.istraps && !clist->mlist.traps_path[0])
+ return (ft_missing_error(FT_ERR_MISS_TRAP, clist));
if (ft_check_not_found(FT_WEAPON_ONE_SPR_PATH) < 0 ||
ft_check_ext(FT_WEAPON_ONE_SPR_PATH, ".xpm") < 0)
return (ft_missing_error(FT_ERR_MISS_W_ONE_SPR, clist));
@@ -71,79 +40,6 @@ static int
return (ft_missing_error(FT_ERR_MISS_SPRITE, clist));
i++;
}
- return (ft_check_missing_sfx(clist));
-}
-
-static int
- ft_check_missing_tex_defines(t_cub *clist)
-{
- if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 ||
- ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0)
- return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist));
- if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 ||
- ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0)
- return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist));
- if (ft_check_not_found(FT_WEAPON_ONE_PATH) < 0 ||
- ft_check_ext(FT_WEAPON_ONE_PATH, ".xpm") < 0)
- return (ft_missing_error(FT_ERR_MISS_W_ONE, clist));
- 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_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_ZER_PATH) < 0 ||
- ft_check_ext(FT_ZER_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_ONE_PATH) < 0 ||
- ft_check_ext(FT_ONE_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_TWO_PATH) < 0 ||
- ft_check_ext(FT_TWO_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_THR_PATH) < 0 ||
- ft_check_ext(FT_THR_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_FOU_PATH) < 0 ||
- ft_check_ext(FT_FOU_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_FIV_PATH) < 0 ||
- ft_check_ext(FT_FIV_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_SIX_PATH) < 0 ||
- ft_check_ext(FT_SIX_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_SEV_PATH) < 0 ||
- ft_check_ext(FT_SEV_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_EIG_PATH) < 0 ||
- ft_check_ext(FT_EIG_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_NIN_PATH) < 0 ||
- ft_check_ext(FT_NIN_PATH, ".xpm") < 0 ||
- ft_check_not_found(FT_PER_PATH) < 0 ||
- ft_check_ext(FT_PER_PATH, ".xpm") < 0)
- return (ft_missing_error(FT_ERR_MISS_NUMBER, clist));
- return (ft_check_missing_sprites(clist));
-}
-
-static int
- ft_check_missing_norme(t_cub *clist)
-{
- if (!clist->mlist.isftex)
- {
- if (clist->f_rgb.r == -1 || clist->f_rgb.g == -1
- || clist->f_rgb.b == -1)
- return (ft_missing_error(FT_ERR_MISS_FLOOR_C, clist));
- }
- if (!clist->mlist.isctex)
- {
- if (clist->c_rgb.r == -1 || clist->c_rgb.g == -1
- || clist->c_rgb.b == -1)
- return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist));
- }
- if (clist->plist.pos_x == 0 || clist->plist.pos_y == 0)
- return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist));
- else if (clist->mlist.isnlvl && !clist->mlist.nl_tex_path[0])
- return (ft_missing_error(FT_ERR_MISS_NLVL, clist));
- else if (clist->mlist.isnlvl && !clist->mlist.nlevel_path[0])
- return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));
- if (clist->mlist.istraps && !clist->mlist.traps_path[0])
- return (ft_missing_error(FT_ERR_MISS_TRAP, clist));
return (ft_check_missing_tex_defines(clist));
}
@@ -162,5 +58,13 @@ int
return (ft_missing_error(FT_ERR_MISS_SPRITE, clist));
else if (clist->wlist.x_size == 0 || clist->wlist.y_size == 0)
return (ft_missing_error(FT_ERR_MISS_RESOLUTION, clist));
- return (ft_check_missing_norme(clist));
+ if (clist->plist.pos_x == 0 || clist->plist.pos_y == 0)
+ return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist));
+ if (!clist->mlist.isftex && (clist->f_rgb.r == -1 || clist->f_rgb.g == -1
+ || clist->f_rgb.b == -1))
+ return (ft_missing_error(FT_ERR_MISS_FLOOR_C, clist));
+ if (!clist->mlist.isctex && (clist->c_rgb.r == -1 || clist->c_rgb.g == -1
+ || clist->c_rgb.b == -1))
+ return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist));
+ return (ft_check_missing_bonus(clist));
}
diff --git a/src/ft_check_missing_defines.c b/src/ft_check_missing_defines.c
new file mode 100644
index 0000000..bf5bd6d
--- /dev/null
+++ b/src/ft_check_missing_defines.c
@@ -0,0 +1,93 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_check_missing_defines.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+
+static int
+ ft_check_missing_other_number_defines(t_cub *clist)
+{
+ if (ft_check_not_found(FT_INF_PATH) < 0 ||
+ ft_check_ext(FT_INF_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_NUMBER, clist));
+ return (ft_check_missing_sfx(clist));
+}
+static int
+ ft_check_missing_number_defines(t_cub *clist)
+{
+ if (ft_check_not_found(FT_ZER_PATH) < 0 ||
+ ft_check_ext(FT_ZER_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_ONE_PATH) < 0 ||
+ ft_check_ext(FT_ONE_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_TWO_PATH) < 0 ||
+ ft_check_ext(FT_TWO_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_THR_PATH) < 0 ||
+ ft_check_ext(FT_THR_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_FOU_PATH) < 0 ||
+ ft_check_ext(FT_FOU_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_FIV_PATH) < 0 ||
+ ft_check_ext(FT_FIV_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_SIX_PATH) < 0 ||
+ ft_check_ext(FT_SIX_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_SEV_PATH) < 0 ||
+ ft_check_ext(FT_SEV_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_EIG_PATH) < 0 ||
+ ft_check_ext(FT_EIG_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_NIN_PATH) < 0 ||
+ ft_check_ext(FT_NIN_PATH, ".xpm") < 0 ||
+ ft_check_not_found(FT_PER_PATH) < 0 ||
+ ft_check_ext(FT_PER_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_NUMBER, clist));
+ return (ft_check_missing_other_number_defines(clist));
+}
+
+static int
+ ft_check_missing_more_tex_defines(t_cub *clist)
+{
+ if (ft_check_not_found(FT_CAP_HEALTH_PATH) < 0 ||
+ ft_check_ext(FT_CAP_HEALTH_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_H_CAPTION, clist));
+ if (ft_check_not_found(FT_CAP_AMMO_PATH) < 0 ||
+ ft_check_ext(FT_CAP_AMMO_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_A_CAPTION, clist));
+ return (ft_check_missing_number_defines(clist));
+}
+
+int
+ ft_check_missing_tex_defines(t_cub *clist)
+{
+ if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 ||
+ ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist));
+ if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 ||
+ ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist));
+ if (ft_check_not_found(FT_WEAPON_ONE_PATH) < 0 ||
+ ft_check_ext(FT_WEAPON_ONE_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_W_ONE, clist));
+ 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_more_tex_defines(clist));
+}
diff --git a/src/ft_check_missing_sfx.c b/src/ft_check_missing_sfx.c
new file mode 100644
index 0000000..34d08e2
--- /dev/null
+++ b/src/ft_check_missing_sfx.c
@@ -0,0 +1,65 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_check_missing_sfx.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:42 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+
+static int
+ ft_check_missing_weapon_sfx(t_cub *clist)
+{
+ if (ft_check_not_found(FT_SFX_W_ONE_LOAD_PATH) < 0 ||
+ ft_check_ext(FT_SFX_W_ONE_LOAD_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_LOAD, clist));
+ if (ft_check_not_found(FT_SFX_W_ONE_FIRE_PATH) < 0 ||
+ ft_check_ext(FT_SFX_W_ONE_FIRE_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_W_ONE_FIRE, clist));
+ if (ft_check_not_found(FT_SFX_W_TWO_LOAD_PATH) < 0 ||
+ ft_check_ext(FT_SFX_W_TWO_LOAD_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_W_TWO_LOAD, clist));
+ 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));
+ if (ft_check_not_found(FT_SFX_OOA_PATH) < 0 ||
+ ft_check_ext(FT_SFX_OOA_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_OOA, clist));
+ return (0);
+}
+
+int
+ ft_check_missing_sfx(t_cub *clist)
+{
+ if (ft_check_not_found(FT_SFX_DEATH_PATH) < 0 ||
+ ft_check_ext(FT_SFX_DEATH_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_DEATH, clist));
+ if (ft_check_not_found(FT_SFX_N_LVL_PATH) < 0 ||
+ ft_check_ext(FT_SFX_N_LVL_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_N_LVL, clist));
+ if (ft_check_not_found(FT_SFX_SCR_ONE_PATH) < 0 ||
+ ft_check_ext(FT_SFX_SCR_ONE_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_SCR_ONE, clist));
+ if (ft_check_not_found(FT_SFX_SCR_TWO_PATH) < 0 ||
+ ft_check_ext(FT_SFX_SCR_TWO_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_SCR_TWO, clist));
+ if (ft_check_not_found(FT_SFX_TRAP_PATH) < 0 ||
+ ft_check_ext(FT_SFX_TRAP_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_TRAP, clist));
+ if (ft_check_not_found(FT_SFX_HEAL_PATH) < 0 ||
+ ft_check_ext(FT_SFX_HEAL_PATH, ".wav") < 0)
+ return (ft_missing_error(FT_ERR_MISS_SFX_HEAL, clist));
+ return (ft_check_missing_weapon_sfx(clist));
+}
diff --git a/src/ft_convert_keycode.c b/src/ft_convert_keycode.c
index 22e6169..01d315c 100644
--- a/src/ft_convert_keycode.c
+++ b/src/ft_convert_keycode.c
@@ -35,5 +35,6 @@ int32_t
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);
+ keycode = (tmp_code == FT_THREE_KEY) ? (FT_THREE_KEY) : (keycode);
return (keycode);
}
diff --git a/src/ft_del_map.c b/src/ft_del_map.c
new file mode 100644
index 0000000..0c03007
--- /dev/null
+++ b/src/ft_del_map.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_del_map.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+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_words(ml->map);
+ ft_free_sprites_path(ml->sprite_path);
+}
diff --git a/src/ft_del_extra_sprites.c b/src/ft_del_sfx_cmd.c
index 21df608..4fd38ee 100644
--- a/src/ft_del_extra_sprites.c
+++ b/src/ft_del_sfx_cmd.c
@@ -1,31 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_key_loop.c :+: :+: :+: */
+/* ft_del_sfx_cmd.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 */
+/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
-#include <mlx.h>
#include <stdint.h>
-#include <stddef.h>
void
- ft_del_extra_sprites(t_cub *cl)
+ ft_del_sfx_cmd(t_cub *clist)
{
uint8_t i;
- i = 1;
- while ((i + 2) <= cl->mlist.topsp)
+ i = 0;
+ while (i < 13)
{
- if (cl->tlist[i + 7].img)
- mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img);
+ ft_memdel((void*)&clist->sfx[i].cmd);
i++;
}
+ ft_memdel((void*)&clist->sfx[1].cmd_alt);
+ ft_memdel((void*)&clist->sfx[3].cmd_alt);
}
diff --git a/src/ft_darken_rgb.c b/src/ft_del_sprites_lists.c
index 223a540..bb382e6 100644
--- a/src/ft_darken_rgb.c
+++ b/src/ft_del_sprites_lists.c
@@ -1,33 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_darken_rgb.c :+: :+: :+: */
+/* ft_del_sprites_lists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/03/05 16:04:28 by rbousset #+# #+# */
-/* Updated: 2020/03/05 16:04:29 by rbousset ### ########lyon.fr */
+/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
+#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-uint32_t
- ft_darken(t_rgb rgb, t_cub *cl)
+void
+ ft_del_sprites_lists(t_cub *clist)
{
- t_rgb darker;
- float calc;
- float dist;
+ uint8_t i;
- if ((dist = cl->rlist.row_dist) <= 0)
- dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- darker = rgb;
- darker.r /= calc;
- darker.g /= calc;
- darker.b /= calc;
- return (ft_rgb_to_hex(darker));
+ i = 0;
+ while (i < 8)
+ {
+ ft_memdel((void*)&clist->sprites[i]);
+ i++;
+ }
+ ft_memdel((void*)&clist->sprites);
+ i = 0;
+ while (i < 3)
+ {
+ ft_memdel((void*)&clist->weaps[i]);
+ i++;
+ }
+ ft_memdel((void*)&clist->weaps);
}
diff --git a/src/ft_del_tex.c b/src/ft_del_tex.c
new file mode 100644
index 0000000..70f23fa
--- /dev/null
+++ b/src/ft_del_tex.c
@@ -0,0 +1,107 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_del_tex.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <mlx.h>
+#include <stdint.h>
+
+static void
+ ft_del_extra_sprites(t_cub *cl)
+{
+ uint8_t i;
+
+ i = 1;
+ while ((i + 2) <= cl->mlist.topsp)
+ {
+ if (cl->tlist[i + 7].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img);
+ i++;
+ }
+}
+
+static void
+ ft_del_tnum(t_cub *cl)
+{
+ int8_t i;
+
+ i = 0;
+ while (i < 12)
+ {
+ if (cl->tnum[i].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tnum[i].img);
+ i++;
+ }
+}
+
+static void
+ ft_del_tweap(t_cub *cl)
+{
+ int8_t i;
+
+ i = 0;
+ while (i < 6)
+ {
+ if (cl->tweap[i].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tweap[i].img);
+ i++;
+ }
+}
+
+static void
+ ft_del_bonus_tex(t_cub *cl)
+{
+ 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->tlist[18].img)
+ 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);
+ if (cl->tlist[21].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[21].img);
+ if (cl->tlist[22].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[22].img);
+}
+
+void
+ ft_del_tex(t_cub *cl)
+{
+ if (cl->wlist.inited)
+ {
+ if (cl->tlist[0].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[0].img);
+ if (cl->tlist[1].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[1].img);
+ if (cl->tlist[2].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[2].img);
+ if (cl->tlist[3].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[3].img);
+ if (cl->tlist[4].img)
+ mlx_destroy_image(cl->wlist.wlx, cl->tlist[4].img);
+ ft_del_bonus_tex(cl);
+ ft_del_tweap(cl);
+ ft_del_tnum(cl);
+ ft_del_extra_sprites(cl);
+ }
+}
+
diff --git a/src/ft_draw_ammo_back.c b/src/ft_draw_ammo_back.c
new file mode 100644
index 0000000..b9bb408
--- /dev/null
+++ b/src/ft_draw_ammo_back.c
@@ -0,0 +1,90 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_ammo_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
+/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_draw_back(uint16_t y, uint16_t x, t_cub *cl)
+{
+ const uint16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20)))] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y];
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20))) + 1] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 1];
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20))) + 2] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 2];
+}
+
+static void
+ ft_put_ammo_back(t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
+
+ x_ratio = (int)(((cl->tlist[16].img_w) << 16) / cl->amm_back_w) + 1;
+ y_ratio = (int)(((cl->tlist[16].img_h) << 16) / cl->amm_back_h) + 1;
+ y = 0;
+ while (y < cl->amm_back_h)
+ {
+ cl->tlist[16].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->amm_back_w)
+ {
+ cl->tlist[16].tex_x = ((x * x_ratio) >> 16);
+ ft_draw_back(y, x, cl);
+ x++;
+ }
+ y++;
+ }
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ uint16_t x;
+ uint16_t y;
+ const uint16_t scl = cl->mlist.scale;
+
+ x = 0;
+ y = cl->wlist.y_size - (2 * ((cl->mlist.map_h * scl)) + 20);
+ while (x < (cl->mlist.map_w * scl) + 20)
+ {
+ while (y < cl->wlist.y_size - (cl->mlist.map_h * scl) - 20)
+ y++;
+ x++;
+ }
+ y -= cl->wlist.y_size - (2 * ((cl->mlist.map_h * scl)) + 20);
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->amm_back_h = y;
+ cl->amm_back_w = x;
+}
+
+void
+ ft_draw_ammo_back(t_cub *cl)
+{
+ ft_get_hw(cl);
+ ft_put_ammo_back(cl);
+}
diff --git a/src/ft_draw_ammo_bar.c b/src/ft_draw_ammo_bar.c
new file mode 100644
index 0000000..bf8dbda
--- /dev/null
+++ b/src/ft_draw_ammo_bar.c
@@ -0,0 +1,138 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_ammo_bar.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
+/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl)
+{
+ const int16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[(x + 10) * 4 +
+ (cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
+ (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40)))] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y];
+ cl->img.ptr[(x + 10) * 4 +
+ (cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
+ (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40))) + 1] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 1];
+ cl->img.ptr[(x + 10) * 4 +
+ (cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
+ (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40))) + 2] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 2];
+}
+
+static void
+ ft_put_next_number(char n, uint16_t x_offset, t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
+
+ x_ratio = (int)(((cl->tnum[n - 48].img_w) << 16) / cl->ammo_num_w) + 1;
+ y_ratio = (int)(((cl->tnum[n - 48].img_h) << 16) / cl->ammo_num_h) + 1;
+ y = 0;
+ while (y < cl->ammo_num_h)
+ {
+ cl->tnum[n - 48].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->ammo_num_w)
+ {
+ cl->tnum[n - 48].tex_x = ((x * x_ratio) >> 16);
+ if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x * 4 + 4 *
+ cl->tnum[n - 48].img_h * cl->tnum[n - 48].tex_y])
+ ft_draw_tnum(n - 48, y, x + x_offset, cl);
+ x++;
+ }
+ y++;
+ }
+}
+
+static void
+ ft_put_image_from_number(char *num, t_cub *cl)
+{
+ const size_t len = ft_strlen(num);
+ const int16_t scl = cl->mlist.scale;
+
+ if (len == 4)
+ {
+ ft_put_next_number(num[0], 0, cl);
+ ft_put_next_number(num[1], (1 * (cl->mlist.map_w * scl) / 4), cl);
+ ft_put_next_number(num[2], (2 * (cl->mlist.map_w * scl) / 4), cl);
+ ft_put_next_number(num[3], (3 * (cl->mlist.map_w * scl) / 4), cl);
+ }
+ else if (len == 3)
+ {
+ ft_put_next_number(num[0], (1 * (cl->mlist.map_w * scl) / 4), cl);
+ ft_put_next_number(num[1], (2 * (cl->mlist.map_w * scl) / 4), cl);
+ ft_put_next_number(num[2], (3 * (cl->mlist.map_w * scl) / 4), cl);
+ }
+ else if (len == 2)
+ {
+ ft_put_next_number(num[0], (1 * (cl->mlist.map_w * scl) / 4), cl);
+ ft_put_next_number(num[1], (2 * (cl->mlist.map_w * scl) / 4), cl);
+ }
+ else
+ ft_put_next_number(num[0], (2 * (cl->mlist.map_w * scl) / 4), cl);
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ int16_t x;
+ int16_t y;
+ const int16_t scl = cl->mlist.scale;
+
+ x = 10;
+ y = (cl->wlist.y_size - 10) - (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40;
+ while (y < (int16_t)(cl->wlist.y_size - (cl->mlist.map_h * scl)) - 30)
+ {
+ while (x < (int16_t)((cl->mlist.map_w * scl) / 4) + 20)
+ x++;
+ y++;
+ }
+ y -= (cl->wlist.y_size - 10) - (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40;
+ x -= 10;
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->ammo_num_h = y;
+ cl->ammo_num_w = x;
+}
+
+void
+ ft_draw_ammo_bar(t_cub *cl)
+{
+ char num[5];
+ uint8_t w_id;
+
+ w_id = cl->plist.handles_weapon;
+ w_id = (w_id == 2) ? (1) : (w_id);
+ w_id = (w_id == 4) ? (2) : (w_id);
+ ft_get_hw(cl);
+ if (cl->plist.ammo[w_id] >= 0)
+ {
+ ft_sprintf(num, "%hd", cl->plist.ammo[w_id]);
+ ft_put_image_from_number(num, cl);
+ }
+ else if (cl->plist.ammo[w_id] == -4)
+ {
+ ft_put_next_number(59,
+ (2 * (cl->mlist.map_w * cl->mlist.scale) / 4), cl);
+ }
+}
+
diff --git a/src/ft_draw_ammo_caption.c b/src/ft_draw_ammo_caption.c
new file mode 100644
index 0000000..96e37a2
--- /dev/null
+++ b/src/ft_draw_ammo_caption.c
@@ -0,0 +1,94 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_ammo_caption.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
+/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_draw_caption(uint16_t y, uint16_t x, t_cub *cl)
+{
+ const int16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[(x + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20 - 10)))] =
+ (uint8_t)cl->tlist[22].ptr[cl->tlist[22].tex_x * 4 + 4 *
+ cl->tlist[22].img_w * cl->tlist[22].tex_y];
+ cl->img.ptr[(x + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20 - 10))) + 1] =
+ (uint8_t)cl->tlist[22].ptr[cl->tlist[22].tex_x * 4 + 4 *
+ cl->tlist[22].img_w * cl->tlist[22].tex_y + 1];
+ cl->img.ptr[(x + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size -
+ (2 * ((cl->mlist.map_h * scl)) + 20 - 10))) + 2] =
+ (uint8_t)cl->tlist[22].ptr[cl->tlist[22].tex_x * 4 + 4 *
+ cl->tlist[22].img_w * cl->tlist[22].tex_y + 2];
+}
+
+static void
+ ft_put_ammo_caption(t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
+
+ x_ratio = (int)(((cl->tlist[22].img_w) << 16) / cl->ammo_cap_w) + 1;
+ y_ratio = (int)(((cl->tlist[22].img_h) << 16) / cl->ammo_cap_h) + 1;
+ y = 0;
+ while (y < cl->ammo_cap_h)
+ {
+ cl->tlist[22].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->ammo_cap_w)
+ {
+ cl->tlist[22].tex_x = ((x * x_ratio) >> 16);
+ if (cl->tlist[22].ptr[cl->tlist[22].tex_x * 4 + 4 *
+ cl->tlist[22].img_h * cl->tlist[22].tex_y])
+ ft_draw_caption(y, x, cl);
+ x++;
+ }
+ y++;
+ }
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ int16_t x;
+ int16_t y;
+ const int16_t scl = cl->mlist.scale;
+
+ x = 20;
+ y = cl->wlist.y_size - (2 * ((cl->mlist.map_h * scl)) + 20 - 10);
+ while (y < (int16_t)((cl->wlist.y_size - 10)
+ - (2 * ((cl->mlist.map_h * scl) / 1.3)) - 40))
+ {
+ while (x < (int16_t)((cl->mlist.map_w * scl) + 5))
+ x++;
+ y++;
+ }
+ y -= cl->wlist.y_size - (2 * ((cl->mlist.map_h * scl)) + 20 - 10);
+ x -= 20;
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->ammo_cap_h = y;
+ cl->ammo_cap_w = x;
+}
+
+void
+ ft_draw_ammo_caption(t_cub *cl)
+{
+ ft_get_hw(cl);
+ ft_put_ammo_caption(cl);
+}
diff --git a/src/ft_draw_circle.c b/src/ft_draw_circle.c
index 249b2e9..4456aca 100644
--- a/src/ft_draw_circle.c
+++ b/src/ft_draw_circle.c
@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <cub3d.h>
-#include <mlx.h>
#include <stdint.h>
#include <math.h>
diff --git a/src/ft_draw_handweap.c b/src/ft_draw_handweap.c
index f171c42..42e7bfd 100644
--- a/src/ft_draw_handweap.c
+++ b/src/ft_draw_handweap.c
@@ -55,24 +55,15 @@ static int16_t
}
}
-#include <libft.h>
-void
- ft_draw_handweap(t_cub *cl)
+static void
+ ft_put_handweap(int8_t w_id, int32_t y_ratio, int32_t x_ratio, t_cub *cl)
{
- int32_t x_ratio;
- int32_t y_ratio;
int16_t x;
int16_t y;
int16_t move;
- int8_t w_id;
- w_id = cl->plist.handles_weapon;
- w_id += (cl->plist.fire == 1) ? (1) : 0;
- x_ratio = (int32_t)(((cl->tweap[w_id].img_w - 50) << 16) / cl->wlist.x_size) + 1;
- y_ratio = (int32_t)(((cl->tweap[w_id].img_h - 50) << 16) / cl->wlist.y_size) + 1;
y = 0;
- move = ft_set_move(cl);
- move = (cl->plist.fire == 1) ? (0) : (move);
+ move = (cl->plist.fire == 1) ? (0) : (ft_set_move(cl));
while (y < (int16_t)cl->wlist.y_size)
{
cl->tweap[w_id].tex_y = ((y * y_ratio) >> 16);
@@ -90,3 +81,19 @@ void
y++;
}
}
+
+void
+ ft_draw_handweap(t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int8_t w_id;
+
+ w_id = cl->plist.handles_weapon;
+ w_id += (cl->plist.fire == 1) ? (1) : (0);
+ x_ratio = (int32_t)(((cl->tweap[w_id].img_w - 50) << 16)
+ / cl->wlist.x_size) + 1;
+ y_ratio = (int32_t)(((cl->tweap[w_id].img_h - 50) << 16)
+ / cl->wlist.y_size) + 1;
+ ft_put_handweap(w_id, y_ratio, x_ratio, cl);
+}
diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c
index bc1e1b2..0ef9590 100644
--- a/src/ft_draw_heals.c
+++ b/src/ft_draw_heals.c
@@ -61,22 +61,19 @@ static void
ft_put_heal(t_sprite *sprite, t_cub *cl)
{
float dist;
- float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0)
+ if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2)
+ + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0)
dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] =
- (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[17].img_h * sprite->tex_y] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
- (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[17].img_h * sprite->tex_y + 1] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
- (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[17].img_h * sprite->tex_y + 2] / calc;
+ rgb.r = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[17].img_h * sprite->tex_y + 2];
+ rgb.g = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[17].img_h * sprite->tex_y + 1];
+ rgb.b = (uint8_t)cl->tlist[17].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[17].img_h * sprite->tex_y];
+ *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 +
+ (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
void
diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c
index 62c64b0..1e5a775 100644
--- a/src/ft_draw_heals_extra.c
+++ b/src/ft_draw_heals_extra.c
@@ -10,11 +10,8 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdlib.h>
-#include <math.h>
void
ft_calc_heal(t_cub *cl)
diff --git a/src/ft_draw_health_caption.c b/src/ft_draw_health_caption.c
new file mode 100644
index 0000000..b2cb675
--- /dev/null
+++ b/src/ft_draw_health_caption.c
@@ -0,0 +1,95 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_health_caption.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
+/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_draw_caption(uint16_t y, uint16_t x, t_cub *cl)
+{
+ const int16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 5))] =
+ (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 *
+ cl->tlist[21].img_w * cl->tlist[21].tex_y];
+ cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 5)) + 1] =
+ (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 *
+ cl->tlist[21].img_w * cl->tlist[21].tex_y + 1];
+ cl->img.ptr[(x + (cl->mlist.map_w * scl) + 20) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 5)) + 2] =
+ (uint8_t)cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 *
+ cl->tlist[21].img_w * cl->tlist[21].tex_y + 2];
+}
+
+static void
+ ft_put_health_caption(t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
+
+ x_ratio = (int)(((cl->tlist[21].img_w) << 16) / cl->life_cap_w) + 1;
+ y_ratio = (int)(((cl->tlist[21].img_h) << 16) / cl->life_cap_h) + 1;
+ y = 0;
+ while (y < cl->life_cap_h)
+ {
+ cl->tlist[21].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->life_cap_w)
+ {
+ cl->tlist[21].tex_x = ((x * x_ratio) >> 16);
+ if (cl->tlist[21].ptr[cl->tlist[21].tex_x * 4 + 4 *
+ cl->tlist[21].img_h * cl->tlist[21].tex_y])
+ ft_draw_caption(y, x, cl);
+ x++;
+ }
+ y++;
+ }
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ int16_t x;
+ int16_t y;
+ const int16_t scl = cl->mlist.scale;
+
+ x = (cl->mlist.map_w * scl) + 20;
+ y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10;
+ while (y < (int16_t)((cl->wlist.y_size - 10)
+ - ((cl->mlist.map_h * scl) / 1.3)))
+ {
+ x = (cl->mlist.map_w * scl) + 20;
+ while (x < (int16_t)((cl->mlist.map_w * scl) + 10 + ((24 * scl))))
+ x++;
+ y++;
+ }
+ y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10;
+ x -= (cl->mlist.map_w * scl) + 20;
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->life_cap_h = y;
+ cl->life_cap_w = x;
+}
+
+void
+ ft_draw_health_caption(t_cub *cl)
+{
+ ft_get_hw(cl);
+ ft_put_health_caption(cl);
+}
diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c
index 5feab32..a10b2f3 100644
--- a/src/ft_draw_hud.c
+++ b/src/ft_draw_hud.c
@@ -14,66 +14,6 @@
#include <stdint.h>
static void
- ft_put_image_back_to_ptr(uint16_t y, uint16_t x, t_cub *cl)
-{
- const uint32_t col = 0x00d2d4d6;
-
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) =
- (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y) & col;
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) =
- (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y + 1) & col;
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) =
- (uint8_t)*(cl->tlist[16].ptr + cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y + 2) & col;
-}
-
-static void
- ft_draw_minimap_back_image(uint16_t h, uint16_t w, t_cub *cl)
-{
- int32_t x_ratio;
- int32_t y_ratio;
- int16_t x;
- int16_t y;
-
- x_ratio = (int)((cl->tlist[16].img_w << 16) / w) + 1;
- y_ratio = (int)((cl->tlist[16].img_h << 16) / h) + 1;
- y = cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) - 20;
- while (y < (int32_t)cl->wlist.y_size)
- {
- x = 0;
- cl->tlist[16].tex_y = (y * y_ratio) >> 16;
- while (x < (uint16_t)((cl->mlist.map_w
- * cl->mlist.scale) + 20 + (32 * cl->mlist.scale)))
- {
- cl->tlist[16].tex_x = (x * x_ratio) >> 16;
- ft_put_image_back_to_ptr(y, x, cl);
- x++;
- }
- y++;
- }
-}
-
-static void
- ft_draw_minimap_back(size_t map_h, size_t map_w, t_win *wl, t_cub *cl)
-{
- const uint16_t scl = cl->mlist.scale;
- uint16_t x;
- uint16_t y;
-
- x = 0;
- y = wl->y_size - (map_h * scl) - 20;
- while (x < (map_w * scl) + 20 + (32 * scl))
- {
- while (y < wl->y_size)
- y++;
- x++;
- }
- ft_draw_minimap_back_image(y, x, cl);
-}
-
-static void
ft_draw_stage_back(t_cub *clist)
{
float x;
@@ -104,10 +44,13 @@ static void
int8_t
ft_draw_hud(t_cub *clist)
{
- ft_draw_minimap_back(clist->mlist.map_h,
- clist->mlist.map_w, &clist->wlist, clist);
+ ft_draw_ammo_back(clist);
+ ft_draw_minimap_back(clist);
ft_draw_map(clist->mlist.map, clist);
ft_draw_life_bar(clist);
+ ft_draw_ammo_bar(clist);
+ ft_draw_health_caption(clist);
+ ft_draw_ammo_caption(clist);
if (clist->mlist.isnlvl)
{
ft_draw_stage_back(clist);
diff --git a/src/ft_draw_life_bar.c b/src/ft_draw_life_bar.c
index 80ec63e..b7dc161 100644
--- a/src/ft_draw_life_bar.c
+++ b/src/ft_draw_life_bar.c
@@ -17,60 +17,106 @@
static void
ft_draw_tnum(int8_t id, int16_t y, int16_t x, t_cub *cl)
{
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) =
- (uint8_t)*(cl->tnum[id].ptr + cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y);
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) =
- (uint8_t)*(cl->tnum[id].ptr + cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y + 1);
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) =
- (uint8_t)*(cl->tnum[id].ptr + cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y + 2);
-}
+ const int16_t scl = cl->mlist.scale;
-/* static void */
-/* ft_put_image_from_number(char *num, t_cub *cl) */
-/* { */
-/* } */
+ cl->img.ptr[(x + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ + 40))] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y];
+ cl->img.ptr[(x + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ + 40)) + 1] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 1];
+ cl->img.ptr[(x + (int16_t)((cl->mlist.map_w * scl) + 10)) * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ + 40)) + 2] =
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y + 2];
+}
static void
- ft_put_percent_image(t_cub *cl)
+ ft_put_next_number(char n, uint16_t x_offset, t_cub *cl)
{
int32_t x_ratio;
int32_t y_ratio;
- int32_t x;
- int32_t y;
+ int16_t x;
+ int16_t y;
- x_ratio = (int)((cl->tnum[10].img_w << 16) / (cl->mlist.map_w * cl->mlist.scale) - 10) + 1;
- y_ratio = (int)((cl->tnum[10].img_h << 16) / (cl->mlist.map_h * cl->mlist.scale) - 10) + 1;
- y = cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) - 10;
- while (y < (int32_t)(cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) - 10 + (8 * cl->mlist.scale)))
+ x_ratio = (int)(((cl->tnum[n - 48].img_w) << 16) / cl->life_num_w) + 1;
+ y_ratio = (int)(((cl->tnum[n - 48].img_h) << 16) / cl->life_num_h) + 1;
+ y = 0;
+ while (y < cl->life_num_h)
{
- cl->tnum[10].tex_y = (y * y_ratio) >> 16;
- x = ((cl->mlist.map_w * cl->mlist.scale) + 20);
- while (x < (int32_t)((cl->mlist.map_w * cl->mlist.scale)
- + 10 + ((32 * cl->mlist.scale))))
+ cl->tnum[n - 48].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->life_num_w)
{
- cl->tnum[10].tex_x = (x * x_ratio) >> 16;
- if (cl->tnum[10].ptr[cl->tnum[10].tex_x * 4 + 4 *
- cl->tnum[10].img_h * cl->tnum[10].tex_y])
- ft_draw_tnum(10, y, x, cl);
+ cl->tnum[n - 48].tex_x = ((x * x_ratio) >> 16);
+ if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x * 4 + 4 *
+ cl->tnum[n - 48].img_h * cl->tnum[n - 48].tex_y])
+ ft_draw_tnum(n - 48, y, x + x_offset, cl);
x++;
}
y++;
}
}
+static void
+ ft_put_image_from_number(char *num, t_cub *cl)
+{
+ const size_t len = ft_strlen(num);
+ const int16_t scl = cl->mlist.scale;
+
+ if (len == 3)
+ {
+ ft_put_next_number(num[0], 0, cl);
+ ft_put_next_number(num[1], (1 * (24 * scl) / 4), cl);
+ ft_put_next_number(num[2], (2 * (24 * scl) / 4), cl);
+ }
+ else if (len == 2)
+ {
+ ft_put_next_number(num[0], (1 * (24 * scl) / 4), cl);
+ ft_put_next_number(num[1], (2 * (24 * scl) / 4), cl);
+ }
+ else
+ ft_put_next_number(num[0], (2 * (24 * scl) / 4), cl);
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ int16_t x;
+ int16_t y;
+ const int16_t scl = cl->mlist.scale;
+
+ x = ((cl->mlist.map_w * scl) + 20) + (24 * scl) - ((24 * scl) / 4);
+ y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 10;
+ while (y < (int16_t)(cl->wlist.y_size - 50))
+ {
+ while (x < (int16_t)((cl->mlist.map_w * scl) + 10 + ((24 * scl))))
+ x++;
+ y++;
+ }
+ y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 10;
+ x -= ((cl->mlist.map_w * scl) + 20) + (24 * scl) - ((24 * scl) / 4);
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->life_num_h = y;
+ cl->life_num_w = x;
+}
+
void
ft_draw_life_bar(t_cub *cl)
{
- char *num;
- float calc;
+ char num[4];
+ float calc;
+ const int16_t scl = cl->mlist.scale;
- ft_put_percent_image(cl);
calc = ((float)cl->plist.life / (float)FT_STRT_LIFE) * 100.0;
- if (!(num = ft_itoa((int64_t)calc)))
- ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl);
- /* ft_put_image_from_number(num, cl); */
- ft_memdel((void*)&num);
+ ft_sprintf(num, "%hd", (int16_t)calc);
+ ft_get_hw(cl);
+ ft_put_next_number(58, (3 * (24 * scl) / 4), cl);
+ ft_put_image_from_number(num, cl);
}
diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c
index 286f69d..02bdfc3 100644
--- a/src/ft_draw_map.c
+++ b/src/ft_draw_map.c
@@ -39,9 +39,9 @@ static void
void
ft_draw_map(char **map, t_cub *clist)
{
- const uint8_t scale = clist->mlist.scale;
size_t x;
size_t y;
+ const uint8_t scale = clist->mlist.scale;
x = 0;
y = 0;
diff --git a/src/ft_draw_map_back.c b/src/ft_draw_map_back.c
new file mode 100644
index 0000000..4945b3d
--- /dev/null
+++ b/src/ft_draw_map_back.c
@@ -0,0 +1,90 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_draw_map_back.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/22 20:02:47 by rbousset #+# #+# */
+/* Updated: 2020/02/22 20:02:48 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_draw_back(uint16_t y, uint16_t x, t_cub *cl)
+{
+ const uint16_t scl = cl->mlist.scale;
+
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 20))] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y];
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 20)) + 1] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 1];
+ cl->img.ptr[x * 4 +
+ (cl->img.sizeline * (y + cl->wlist.y_size - (cl->mlist.map_h * scl)
+ - 20)) + 2] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 2];
+}
+
+static void
+ ft_put_minimap_back(t_cub *cl)
+{
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
+
+ x_ratio = (int)(((cl->tlist[16].img_w) << 16) / cl->map_back_w) + 1;
+ y_ratio = (int)(((cl->tlist[16].img_h) << 16) / cl->map_back_h) + 1;
+ y = 0;
+ while (y < cl->map_back_h)
+ {
+ cl->tlist[16].tex_y = ((y * y_ratio) >> 16);
+ x = 0;
+ while (x < cl->map_back_w)
+ {
+ cl->tlist[16].tex_x = ((x * x_ratio) >> 16);
+ ft_draw_back(y, x, cl);
+ x++;
+ }
+ y++;
+ }
+}
+
+static void
+ ft_get_hw(t_cub *cl)
+{
+ uint16_t x;
+ uint16_t y;
+ const uint16_t scl = cl->mlist.scale;
+
+ x = 0;
+ y = cl->wlist.y_size - (cl->mlist.map_h * scl) - 20;
+ while (x < (cl->mlist.map_w * scl) + 20 + (24 * scl))
+ {
+ while (y < cl->wlist.y_size)
+ y++;
+ x++;
+ }
+ y -= cl->wlist.y_size - (cl->mlist.map_h * scl) - 20;
+ y = (y <= 0) ? (1) : (y);
+ x = (x <= 0) ? (1) : (x);
+ cl->map_back_h = y;
+ cl->map_back_w = x;
+}
+
+void
+ ft_draw_minimap_back(t_cub *cl)
+{
+ ft_get_hw(cl);
+ ft_put_minimap_back(cl);
+}
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index 5fc28d3..b381957 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -13,7 +13,6 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@@ -69,22 +68,19 @@ static void
ft_put_sprite(t_sprite *sprite, t_cub *cl)
{
float dist;
- float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0)
+ if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2)
+ + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0)
dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc;
+ rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2];
+ rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1];
+ rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y];
+ *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 +
+ (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
void
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c
index f4ac6ee..323906a 100644
--- a/src/ft_draw_sprite_extra.c
+++ b/src/ft_draw_sprite_extra.c
@@ -10,11 +10,9 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
#include <stdlib.h>
-#include <math.h>
void
ft_sprite_h_w(t_cub *cl, t_sprite *sprite)
diff --git a/src/ft_draw_square.c b/src/ft_draw_square.c
index 4223f26..a535be4 100644
--- a/src/ft_draw_square.c
+++ b/src/ft_draw_square.c
@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <cub3d.h>
-#include <mlx.h>
#include <stdint.h>
void
diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c
index dcd36e7..0724a6d 100644
--- a/src/ft_draw_textures.c
+++ b/src/ft_draw_textures.c
@@ -22,28 +22,26 @@
** 4 : sprite
*/
-void ft_draw_texture(t_cub *cl, int x, int y, int tex_y)
+void
+ ft_draw_texture(t_cub *cl, int x, int y, int tex_y)
{
- float dist;
- float calc;
+ float dist;
+ t_rgb rgb;
if ((dist = cl->rlist.wall_dist) <= 0)
dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
- (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 *
- cl->tlist[cl->w_side].img_h * tex_y] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
- (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 *
- cl->tlist[cl->w_side].img_h * tex_y + 1] / calc;
- cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
- (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 *
- cl->tlist[cl->w_side].img_h * tex_y + 2] / calc;
+ rgb.b = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
+ * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y];
+ rgb.g = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
+ * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y + 1];
+ rgb.r = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
+ * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y + 2];
+ *(int*)(cl->img.ptr + ((uint16_t)x * 4 +
+ (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
-void ft_choose_tex(t_cub *clist)
+void
+ ft_choose_tex(t_cub *clist)
{
if (clist->rlist.sqy == clist->mlist.nlx
&& clist->rlist.sqx == clist->mlist.nly)
diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c
index 71e8fe8..ed53dc0 100644
--- a/src/ft_draw_traps.c
+++ b/src/ft_draw_traps.c
@@ -10,10 +10,8 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdlib.h>
#include <math.h>
static void
@@ -61,22 +59,19 @@ static void
ft_put_trap(t_sprite *sprite, t_cub *cl)
{
float dist;
- float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0)
+ if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2)
+ + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0)
dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] =
- (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[15].img_h * sprite->tex_y] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
- (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[15].img_h * sprite->tex_y + 1] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
- (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[15].img_h * sprite->tex_y + 2] / calc;
+ rgb.r = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y + 2];
+ rgb.g = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y + 1];
+ rgb.b = (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 *
+ cl->tlist[15].img_h * sprite->tex_y];
+ *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 +
+ (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
void
diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c
index c524190..cbeffe1 100644
--- a/src/ft_draw_traps_extra.c
+++ b/src/ft_draw_traps_extra.c
@@ -10,11 +10,8 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdlib.h>
-#include <math.h>
void
ft_calc_trap(t_cub *cl)
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index 16dc63c..7bfba8d 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -10,7 +10,6 @@
/* */
/* ************************************************************************** */
-#include <stdio.h>
#include <cub3d.h>
#include <stdint.h>
diff --git a/src/ft_draw_weapons.c b/src/ft_draw_weapons.c
index 4a75c9f..c527987 100644
--- a/src/ft_draw_weapons.c
+++ b/src/ft_draw_weapons.c
@@ -10,10 +10,8 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdlib.h>
#include <math.h>
static void
@@ -68,22 +66,19 @@ static void
ft_put_weapon(t_sprite *sprite, t_cub *cl)
{
float dist;
- float calc;
+ t_rgb rgb;
- if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0)
+ if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2)
+ + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0)
dist = 0.0001;
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1] / calc;
- cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] =
- (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 *
- cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2] / calc;
+ rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2];
+ rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1];
+ rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x
+ * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y];
+ *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 +
+ (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
void
diff --git a/src/ft_draw_weapons_extra.c b/src/ft_draw_weapons_extra.c
index 04b61ea..ed3ed53 100644
--- a/src/ft_draw_weapons_extra.c
+++ b/src/ft_draw_weapons_extra.c
@@ -10,10 +10,8 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdlib.h>
static void
ft_calc_weapon(uint8_t id, t_cub *cl)
@@ -40,4 +38,5 @@ void
{
ft_calc_weapon(0, cl);
ft_calc_weapon(1, cl);
+ ft_calc_weapon(2, cl);
}
diff --git a/src/ft_exit.c b/src/ft_exit.c
index b9e68d0..ed1191c 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -19,99 +19,17 @@
#include <pthread.h>
static void
- ft_free_some_extras(t_cub *clist)
+ ft_del_last_remains(t_cub *clist)
{
- uint8_t i;
-
- i = 0;
- while (i < 8)
- {
- ft_memdel((void*)&clist->sprites[i]);
- i++;
- }
- i = 0;
- while (i < 4)
- {
- if (clist->tweap[i].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tweap[i].img);
- i++;
- }
- i = 0;
- while (i < 2)
+ if (!clist->wlist.inited)
{
- if (clist->mlist.isweapon[i] && clist->tlist[i + 18].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[i + 18].img);
- i++;
+ ft_memdel((void*)&clist->wlist.winptr);
+ ft_memdel((void*)&clist->wlist.wlx);
}
- ft_memdel((void*)&clist->sprites);
ft_memdel((void*)&clist);
}
static void
- ft_free_lists(t_cub *clist)
-{
- uint8_t i;
-
- ft_memdel((void*)&clist->mlist.filename);
- ft_memdel((void*)&clist->mlist.no_tex_path);
- ft_memdel((void*)&clist->mlist.so_tex_path);
- ft_memdel((void*)&clist->mlist.ea_tex_path);
- ft_memdel((void*)&clist->mlist.we_tex_path);
- ft_memdel((void*)&clist->mlist.nl_tex_path);
- ft_memdel((void*)&clist->mlist.fl_tex_path);
- ft_memdel((void*)&clist->mlist.ce_tex_path);
- ft_memdel((void*)&clist->mlist.nlevel_path);
- ft_memdel((void*)&clist->mlist.skybox_path);
- ft_memdel((void*)&clist->mlist.traps_path);
- ft_memdel((void*)&clist->mlist.music_path);
- ft_memdel((void*)&clist->mlist.music_cmd);
- ft_memdel((void*)&clist->mlist.mapl);
- ft_free_words(clist->mlist.map);
- i = -1;
- while (++i < 10)
- ft_memdel((void*)&clist->sfx[i].cmd);
- ft_memdel((void*)&clist->sfx[1].cmd_alt);
- ft_memdel((void*)&clist->sfx[3].cmd_alt);
- ft_free_sprites(clist->mlist.sprite_path);
- if (!clist->wlist.inited)
- ft_memdel((void*)&clist->wlist.winptr);
-}
-
-static void
- ft_del_tex(t_cub *clist)
-{
- int8_t i;
-
- if (clist->tlist[0].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[0].img);
- if (clist->tlist[1].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[1].img);
- if (clist->tlist[2].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[2].img);
- if (clist->tlist[3].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[3].img);
- if (clist->tlist[4].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img);
- if (clist->mlist.isnlvl && clist->tlist[5].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img);
- if (clist->mlist.isftex && clist->tlist[6].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img);
- if (clist->mlist.isctex && clist->tlist[7].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img);
- if (clist->mlist.istraps && clist->tlist[15].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
- if (clist->tlist[16].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img);
- if (clist->mlist.isheals && clist->tlist[17].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img);
- i = -1;
- while (++i < 11)
- if (clist->tnum[i].img)
- mlx_destroy_image(clist->wlist.wlx, clist->tnum[i].img);
- ft_del_extra_sprites(clist);
-}
-
-static void
ft_cancel_threads(t_cub *clist)
{
uint8_t i;
@@ -122,7 +40,7 @@ static void
pthread_join(clist->mtid, NULL);
}
i = -1;
- while (++i < 10)
+ while (++i < 13)
{
pthread_mutex_unlock(&clist->sfx[i].mutex);
pthread_cancel(clist->sfx[i].tid);
@@ -142,8 +60,10 @@ int
mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr);
}
ft_cancel_threads(clist);
- ft_free_lists(clist);
- ft_free_some_extras(clist);
+ ft_del_map(&clist->mlist);
+ ft_del_sprites_lists(clist);
+ ft_del_sfx_cmd(clist);
+ ft_del_last_remains(clist);
ft_printf("Exiting program\n");
exit(exit_code);
return (0);
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index f5a501a..f8a6db8 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -73,11 +73,21 @@ int
int
ft_space_key(t_cub *clist)
{
- if (clist->plist.fire == 0)
+ uint8_t w_id;
+
+ w_id = clist->plist.handles_weapon;
+ w_id = (w_id == 2) ? (1) : (w_id);
+ w_id = (w_id == 4) ? (2) : (w_id);
+ if (clist->plist.fire == 0 &&
+ (clist->plist.ammo[w_id] > 0 || clist->plist.ammo[w_id] == -4))
{
+ clist->plist.ammo[w_id] -= w_id;
clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
clist->plist.fire = 1;
ft_shoot(clist, clist->wlist.x_size / 2);
+ return (0);
}
+ else if (clist->plist.fire == 0 && clist->plist.ammo[w_id] <= 0)
+ clist->sfx[12].sfx_play(clist->sfx);
return (0);
}
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index 56e1351..59b4a4f 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -30,19 +30,44 @@ static uint16_t
}
static void
+ ft_set_ammo(uint8_t weap_id, t_player *pl)
+{
+ if (weap_id == 0)
+ pl->ammo[0] = FT_WEAP_ONE_STRT_AMMO;
+ else if (weap_id == 1)
+ pl->ammo[1] += FT_WEAP_TWO_STRT_AMMO;
+ else if (weap_id == 2)
+ pl->ammo[2] += FT_WEAP_THREE_STRT_AMMO;
+ if (pl->ammo[weap_id] > FT_WEAP_MAX_AMMO)
+ pl->ammo[weap_id] = FT_WEAP_MAX_AMMO;
+}
+
+static void
ft_weapon_check(const char map_char, t_player *pl, t_cub *cl)
{
uint8_t weap_id;
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 == 0) ? (0) : (pl->handles_weapon);
+ pl->handles_weapon = (weap_id == 1) ? (2) : (pl->handles_weapon);
+ pl->handles_weapon = (weap_id == 2) ? (4) : (pl->handles_weapon);
+ ft_set_ammo(weap_id, pl);
+ 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_floor_cast.c b/src/ft_floor_cast.c
index 160a2c1..e9315ed 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -16,30 +16,28 @@
static void
ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x)
{
+ float dist;
+
+ dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001);
*(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
+ (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
static void
ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl)
{
float dist;
- float calc;
+ t_rgb rgb;
dist = (cl->rlist.row_dist > 0) ? (cl->rlist.row_dist) : (0.0001);
- calc = (dist * 0.1 * cl->mlist.darklvl);
- calc = (calc >= 255) ? (255) : (calc);
- calc = (calc < 1) ? (1) : (calc);
- calc = (cl->mlist.darklvl > 0) ? (calc) : (1);
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y)) =
- (uint8_t)*(cl->tlist[tid].ptr + cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_w * cl->tlist[tid].tex_y) / calc;
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 1) =
- (uint8_t)*(cl->tlist[tid].ptr + cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_w * cl->tlist[tid].tex_y + 1) / calc;
- *(cl->img.ptr + x * 4 + (cl->img.sizeline * y) + 2) =
- (uint8_t)*(cl->tlist[tid].ptr + cl->tlist[tid].tex_x * 4 + 4 *
- cl->tlist[tid].img_w * cl->tlist[tid].tex_y + 2) / calc;
+ rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
+ * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y];
+ rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
+ * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1];
+ rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
+ * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2];
+ *(int*)(cl->img.ptr + ((uint16_t)x * 4 +
+ (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
static void
diff --git a/src/ft_free_words.c b/src/ft_free_words.c
index 3ca01c8..50795c2 100644
--- a/src/ft_free_words.c
+++ b/src/ft_free_words.c
@@ -13,7 +13,7 @@
#include <libft.h>
uint8_t
- ft_free_sprites(char **sprites)
+ ft_free_sprites_path(char **sprites)
{
uint8_t i;
diff --git a/src/ft_get_map.c b/src/ft_get_map.c
index bbe9a7f..4cb4941 100644
--- a/src/ft_get_map.c
+++ b/src/ft_get_map.c
@@ -17,7 +17,7 @@
#include <stdint.h>
static void
- ft_linecpy(char *line, char *mapl, size_t start, t_cub *clist)
+ ft_linecpy(char *line, char *mapl, size_t start)
{
size_t i;
size_t j;
@@ -28,12 +28,7 @@ static void
slen = ft_strlen(line);
while (i < slen && line[i])
{
- if (line[i] == '!' && clist->plist.has_weapon[0])
- mapl[j] = '0';
- else if (line[i] == '@' && clist->plist.has_weapon[1])
- mapl[j] = '0';
- else
- mapl[j] = line[i];
+ mapl[j] = line[i];
i++;
j++;
}
@@ -52,7 +47,7 @@ static int8_t
return (-1);
}
ft_linecpy(line, clist->mlist.mapl,
- clist->mlist.mapl_len, clist);
+ clist->mlist.mapl_len);
clist->mlist.mapl_len += ft_strlen(line) + 1;
return (0);
}
diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c
index 0d9018a..c506775 100644
--- a/src/ft_get_player_spawn.c
+++ b/src/ft_get_player_spawn.c
@@ -82,11 +82,6 @@ void
plist->start_x = plist->pos_x;
plist->start_y = plist->pos_y;
ft_get_start_side(clist->mlist.map[y][x], plist);
- ft_get_sprite_spawn(clist);
- ft_get_trap_spawn(clist);
- ft_get_heal_spawn(clist);
- if (clist->isdead == 0)
- ft_get_weapon_spawn(clist);
return ;
}
x++;
diff --git a/src/ft_get_topsp.c b/src/ft_get_spawns.c
index ee16714..6422785 100644
--- a/src/ft_get_topsp.c
+++ b/src/ft_get_spawns.c
@@ -1,30 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_check_map_line.c :+: :+: :+: */
+/* ft_get_sprite_spawns.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/14 17:28:34 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:28:37 by rbousset ### ########lyon.fr */
+/* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <cub3d.h>
-#include <stddef.h>
#include <stdint.h>
void
- ft_get_topsp(char c, t_cub *clist)
+ ft_get_spawns(t_cub *cl)
{
- int8_t x;
-
- if ((x = ft_strlchr(FT_CHRST_SPRITES, c)) > 0)
- {
- if ((x + 2) > clist->mlist.topsp)
- {
- clist->mlist.topsp = x + 2;
- }
- }
+ ft_get_player_spawn(&cl->plist, cl);
+ ft_get_sprite_spawn(cl);
+ ft_get_trap_spawn(cl);
+ ft_get_heal_spawn(cl);
+ if (cl->isdead == 0)
+ ft_get_weapon_spawn(cl);
}
diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c
index 5a5ecd0..05b13b2 100644
--- a/src/ft_get_sprite.c
+++ b/src/ft_get_sprite.c
@@ -13,7 +13,6 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
static int8_t
ft_get_sprite_id(char *word)
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c
index c2db153..f4d7e1e 100644
--- a/src/ft_get_sprite_spawns.c
+++ b/src/ft_get_sprite_spawns.c
@@ -13,7 +13,6 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
void
ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x)
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_hooks_and_loops.c b/src/ft_hooks_and_loops.c
index 9293496..b8bdd36 100644
--- a/src/ft_hooks_and_loops.c
+++ b/src/ft_hooks_and_loops.c
@@ -15,7 +15,7 @@
#include <mlx.h>
void
-ft_hooks_and_loops(t_win *wl, t_cub *cl)
+ ft_hooks_and_loops(t_win *wl, t_cub *cl)
{
mlx_hook(wl->winptr, 2, (1L << 0), ft_key_event, cl);
mlx_hook(wl->winptr, 3, (1L << 1), ft_key_release, cl);
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index d1b589e..942b9a4 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 three
*/
t_player
@@ -52,7 +53,11 @@ 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.ammo[0] = 0;
+ plist.ammo[1] = 0;
+ plist.ammo[2] = 0;
plist.life = FT_STRT_LIFE;
plist.fire = 0;
return (plist);
@@ -61,6 +66,8 @@ t_player
static int8_t
ft_init_win(t_win *wl)
{
+ if (!(wl->wlx = malloc(1)))
+ return (-1);
if (!(wl->winptr = malloc(1)))
return (-1);
wl->inited = 0;
@@ -96,8 +103,6 @@ static int8_t
cl->walltexgood = 0;
ft_init_funptr(cl);
ft_init_ref(cl);
- if (ft_init_sprites(&cl->sprites) < 0)
- return (-1);
return (0);
}
@@ -108,8 +113,22 @@ int8_t
return (-1);
if (ft_init_win(&clist->wlist) < 0)
return (-1);
+ if (ft_init_sprites(&clist->sprites) < 0)
+ return (-1);
+ if (ft_init_weaps(&clist->weaps) < 0)
+ return (-1);
ft_sprintf(clist->fps_count, "fps: 60");
clist->isdead = 0;
clist->moves = 0;
+ clist->life_num_h = 0;
+ clist->life_num_w = 0;
+ clist->life_cap_h = 0;
+ clist->life_cap_w = 0;
+ clist->map_back_h = 0;
+ clist->map_back_w = 0;
+ clist->amm_back_h = 0;
+ clist->amm_back_w = 0;
+ clist->ammo_cap_h = 0;
+ clist->ammo_cap_w = 0;
return (0);
}
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index 717506c..9ddbb47 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -68,8 +68,10 @@ int8_t
ft_bzero(mlist->sprite_order, 4096);
ft_bzero(mlist->traps_order, 512);
ft_bzero(mlist->heals_order, 64);
- ft_bzero(mlist->weaps_nbr, 2);
- ft_bzero(mlist->weaps_order, 2);
+ mlist->weaps_nbr[0] = 0;
+ mlist->weaps_nbr[1] = 0;
+ mlist->weaps_nbr[2] = 0;
+ ft_bzero(mlist->weaps_order, 1);
return (0);
}
@@ -96,8 +98,6 @@ int8_t
mlist->isskybox = 0;
mlist->istraps = 0;
mlist->isheals = 0;
- mlist->isweapon[0] = 0;
- mlist->isweapon[1] = 0;
mlist->traps_nbr = 0;
mlist->heals_nbr = 0;
return (ft_init_map_norme(mlist));
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 6fc8504..9b58656 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -22,16 +22,19 @@
/*
** sfx[] index summary
** -------------------
-** 0: death
-** 1: footstep | double
-** 2: new level
-** 3: pain | double
-** 4: trap
-** 5: heal
-** 6: weapon one load
-** 7: weapon one fire
-** 8: weapon two load
-** 9: weapon two fire
+** 0: death
+** 1: footstep | double
+** 2: new level
+** 3: pain | double
+** 4: trap
+** 5: heal
+** 6: weapon one load
+** 7: weapon one fire
+** 8: weapon two load
+** 9: weapon two fire
+** 10: weapon three load
+** 11: weapon three fire
+** 12: out of ammunitions
*/
static int8_t
@@ -56,10 +59,20 @@ 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);
+ pthread_create(&cl->sfx[12].tid, NULL,
+ ft_sfx_ooa_thread, &cl->sfx);
}
static void
@@ -75,6 +88,9 @@ 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;
+ cl->sfx[12].sfx_play = ft_sfx_ooa;
}
int8_t
@@ -92,10 +108,13 @@ 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 ||
+ ft_init_sfx_cmd(&cl->sfx[12].cmd, FT_SFX_OOA_PATH) < 0)
return (-1);
i = -1;
- while (++i < 10)
+ while (++i < 13)
pthread_mutex_init(&cl->sfx[i].mutex, NULL);
ft_init_sfx_pthreads(cl);
ft_init_sfx_funptr(cl);
diff --git a/src/ft_init_sprites.c b/src/ft_init_sprites.c
index 4fc9aed..2099089 100644
--- a/src/ft_init_sprites.c
+++ b/src/ft_init_sprites.c
@@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_init_lists.c :+: :+: :+: */
+/* ft_init_sprites.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
diff --git a/src/ft_init_weaps.c b/src/ft_init_weaps.c
new file mode 100644
index 0000000..f3f7452
--- /dev/null
+++ b/src/ft_init_weaps.c
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_init_weaps.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+int8_t
+ ft_init_weaps(t_sprite ***weaps)
+{
+ uint8_t i;
+
+ if (!(*weaps = (t_sprite**)ft_calloc(3, sizeof(t_sprite*))))
+ return (-1);
+ i = 0;
+ while (i < 3)
+ {
+ if (!(*((*weaps) + i) = (t_sprite*)ft_calloc(1, sizeof(t_sprite))))
+ return (-1);
+ i++;
+ }
+ return (0);
+}
diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c
index 59d0b58..40c57df 100644
--- a/src/ft_init_winlx.c
+++ b/src/ft_init_winlx.c
@@ -18,6 +18,7 @@
int
ft_init_winlx(t_cub *clist)
{
+ ft_memdel((void*)&clist->wlist.wlx);
if (!(clist->wlist.wlx = mlx_init()))
return (-1);
return (0);
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 52ef477..8ea5b90 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -43,6 +43,9 @@ int
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));
+ else if (keycode == FT_THREE_KEY && clist->plist.fire == 0
+ && clist->plist.has_weapon[2] == 1 && clist->plist.handles_weapon != 4)
+ return (ft_switch_weap_three(clist));
ft_insert_key(keycode, clist);
return (0);
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 77f2d7d..22975f8 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -72,6 +72,29 @@ static void
cl->plist.pos_y = old_y;
}
+static int
+ ft_handle_keys(uint8_t i, float old_y, float old_x, t_cub *cl)
+{
+ cl->key_ptr[cl->key_input[i]](cl);
+ if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3)
+ {
+ cl->sfx[1].sfx_play(cl->sfx);
+ 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 &&
+ (uint32_t)cl->plist.pos_y == cl->mlist.nly)
+ {
+ cl->sfx[2].sfx_play(cl->sfx);
+ return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ?
+ (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
+ }
+ }
+ }
+ return (0);
+}
+
int
ft_key_loop(t_cub *cl)
{
@@ -83,23 +106,7 @@ int
i = 0;
while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5)
{
- cl->key_ptr[cl->key_input[i]](cl);
- if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3)
- {
- cl->sfx[1].sfx_play(cl->sfx);
- 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 &&
- (uint32_t)cl->plist.pos_y == cl->mlist.nly)
- {
- cl->sfx[2].sfx_play(cl->sfx);
- return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ?
- (ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
- }
- }
- }
+ ft_handle_keys(i, old_y, old_x, cl);
i++;
}
cl->moves = (cl->key_input[0] == -1) ? (0) : (cl->moves);
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 057b053..46fe022 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -74,7 +74,7 @@ static int8_t
return (ret);
}
-void
+static void
ft_save_name(const char *map_path, t_cub *clist)
{
ft_memdel((void*)&clist->mlist.filename);
@@ -105,7 +105,7 @@ void
ft_map_error(clist->errmsg, clist);
ft_check_map_last_line(clist);
ft_check_map_surrounds(&clist->mlist, clist);
- ft_get_player_spawn(&clist->plist, clist);
+ ft_get_spawns(clist);
ft_get_nlvl_pos(&clist->mlist);
ft_check_missing(clist);
ft_set_minimap_scale(clist);
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index cbcda24..1a12c46 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -13,28 +13,27 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void
- ft_calc_tex(t_cub *clist)
+ ft_calc_tex(t_cub *cl)
{
- if (clist->rlist.side == 0)
- clist->rlist.wall_hit_x = (clist->plist.pos_x) +
- clist->rlist.wall_dist * clist->rlist.y_ray_dir;
+ if (cl->rlist.side == 0)
+ cl->rlist.wall_hit_x = (cl->plist.pos_x) +
+ cl->rlist.wall_dist * cl->rlist.y_ray_dir;
else
- clist->rlist.wall_hit_x = (clist->plist.pos_y) +
- clist->rlist.wall_dist * clist->rlist.x_ray_dir;
- clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x);
- clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x *
- (double)clist->tlist[clist->w_side].img_w);
- if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0)
- clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w
- - clist->tlist[clist->w_side].tex_x - 1;
- else if (clist->rlist.side == 1 && clist->rlist.y_ray_dir < 0)
- clist->tlist[clist->w_side].tex_x = clist->tlist[clist->w_side].img_w
- - clist->tlist[clist->w_side].tex_x - 1;
+ cl->rlist.wall_hit_x = (cl->plist.pos_y) +
+ cl->rlist.wall_dist * cl->rlist.x_ray_dir;
+ cl->rlist.wall_hit_x -= floor(cl->rlist.wall_hit_x);
+ cl->tlist[cl->w_side].tex_x = (int)(cl->rlist.wall_hit_x *
+ (double)cl->tlist[cl->w_side].img_w);
+ if (cl->rlist.side == 0 && cl->rlist.x_ray_dir > 0)
+ cl->tlist[cl->w_side].tex_x = cl->tlist[cl->w_side].img_w
+ - cl->tlist[cl->w_side].tex_x - 1;
+ else if (cl->rlist.side == 1 && cl->rlist.y_ray_dir < 0)
+ cl->tlist[cl->w_side].tex_x = cl->tlist[cl->w_side].img_w
+ - cl->tlist[cl->w_side].tex_x - 1;
}
static void
@@ -68,7 +67,7 @@ static void
}
static void
- ft_castray_norme(uint16_t i, t_win *wl, t_cub *cl)
+ ft_castray_loop(uint16_t i, t_win *wl, t_cub *cl)
{
ft_initray(i, cl);
cl->rlist.line_h = (int16_t)(wl->y_size / cl->rlist.wall_dist);
@@ -78,15 +77,17 @@ static void
cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2;
if (cl->rlist.wall_b >= (int16_t)wl->y_size)
cl->rlist.wall_b = wl->y_size - 1;
+ ft_choose_tex(cl);
+ ft_calc_tex(cl);
+ cl->rlist.wall_bz[i] = cl->rlist.wall_b;
+ cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
}
void
ft_castray(t_cub *cl)
{
uint16_t i;
- t_win *wl;
- wl = &cl->wlist;
if (!(cl->rlist.wall_dist_tab =
(float*)malloc(sizeof(float) * cl->wlist.x_size)))
return ;
@@ -94,14 +95,10 @@ void
(int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t))))
return ;
i = 0;
- while (i < wl->x_size)
+ while (i < cl->wlist.x_size)
{
- ft_castray_norme(i, wl, cl);
- ft_choose_tex(cl);
- ft_calc_tex(cl);
+ ft_castray_loop(i, &cl->wlist, cl);
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
- cl->rlist.wall_bz[i] = cl->rlist.wall_b;
- cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
i++;
}
ft_floor_cast(cl);
diff --git a/src/ft_rgb_to_hex.c b/src/ft_rgb_to_hex.c
index e101dcf..2b72287 100644
--- a/src/ft_rgb_to_hex.c
+++ b/src/ft_rgb_to_hex.c
@@ -14,10 +14,14 @@
#include <stdint.h>
uint32_t
- ft_rgb_to_hex(t_rgb rgb)
+ ft_rgb_to_hex(float dist, t_rgb rgb, t_cub *cl)
{
uint32_t res;
+ float calc;
+ calc = (dist * 0.1 * cl->mlist.darklvl);
+ calc = (calc >= 255) ? (255) : (calc);
+ calc = (calc < 1) ? (1) : (calc);
rgb.r = (rgb.r > 255) ? (255) : (rgb.r);
rgb.g = (rgb.g > 255) ? (255) : (rgb.g);
rgb.b = (rgb.b > 255) ? (255) : (rgb.b);
@@ -25,6 +29,7 @@ uint32_t
rgb.g = (rgb.g < 0) ? (0) : (rgb.g);
rgb.b = (rgb.b < 0) ? (0) : (rgb.b);
res = 0;
- res += ((rgb.r << 16) + (rgb.g << 8) + rgb.b);
+ res += (((uint8_t)(rgb.r / calc) << 16) + ((uint8_t)(rgb.g / calc) << 8)
+ + (uint8_t)(rgb.b / calc));
return (res);
}
diff --git a/src/ft_save_to_bmp.c b/src/ft_save_to_bmp.c
index 1737226..24d28d8 100644
--- a/src/ft_save_to_bmp.c
+++ b/src/ft_save_to_bmp.c
@@ -53,8 +53,8 @@ static uint8_t
uint32_t i;
(void)img;
- if (!(bmp = (uint8_t*)malloc((3 * cl->wlist.x_size
- * cl->wlist.y_size) * sizeof(uint8_t))))
+ if (!(bmp = (uint8_t*)ft_calloc(3 * cl->wlist.x_size
+ * cl->wlist.y_size, sizeof(uint8_t))))
return (NULL);
y = cl->wlist.y_size;
i = 0;
diff --git a/src/ft_set_minimap_scale.c b/src/ft_set_minimap_scale.c
index 14a6f56..fcda6f6 100644
--- a/src/ft_set_minimap_scale.c
+++ b/src/ft_set_minimap_scale.c
@@ -12,6 +12,7 @@
#include <cub3d.h>
+#include <libft.h>
void
ft_set_minimap_scale(t_cub *clist)
{
@@ -21,16 +22,15 @@ void
if (ml->map_w > ml->map_h)
{
ml->scale = (clist->wlist.x_size / (uint16_t)ml->map_w);
- ml->scale = ((ml->scale - 1) < 1) ? (1) : (ml->scale);
- ml->scale = (clist->wlist.y_size < (ml->map_h * ml->scale))
- ? ((clist->wlist.y_size / (uint16_t)ml->map_h) - 1) : (ml->scale);
+ ml->scale = (clist->wlist.x_size < (ml->map_w * ml->scale))
+ ? ((clist->wlist.x_size / (uint16_t)ml->map_w) - 1) : (ml->scale);
}
else
{
ml->scale = (clist->wlist.y_size / (uint16_t)ml->map_h);
- ml->scale = ((ml->scale - 1) < 1) ? (1) : (ml->scale);
ml->scale = (clist->wlist.y_size < (ml->map_h * ml->scale))
? ((clist->wlist.y_size / (uint16_t)ml->map_h) - 1) : (ml->scale);
}
+ ml->scale = ((ml->scale - 1) < 1) ? (1) : (ml->scale);
ml->scale = (ml->scale >= 10) ? (ml->scale / 4) : (ml->scale);
}
diff --git a/src/ft_sfx_ooa.c b/src/ft_sfx_ooa.c
new file mode 100644
index 0000000..880aea5
--- /dev/null
+++ b/src/ft_sfx_ooa.c
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_ooa.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_ooa_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[12].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[12].mutex);
+ if (system(sfx[12].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_ooa(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[12].mutex);
+}
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_suffer_animation.c b/src/ft_suffer_animation.c
index 6a325bc..1b48e47 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -15,6 +15,23 @@
#include <mlx.h>
#include <stdint.h>
+static void
+ ft_get_damaged(t_cub *cl)
+{
+ cl->plist.life -= FT_TRAP_DAMAGE_AMOUNT;
+ if (cl->plist.life <= 0)
+ {
+ cl->isdead = 1;
+ cl->sfx[0].sfx_play(cl->sfx);
+ ft_death_screen(cl);
+ }
+ else
+ {
+ cl->sfx[4].sfx_play(cl->sfx);
+ cl->sfx[3].sfx_play(cl->sfx);
+ }
+}
+
void
ft_linux_suffer_animation(t_cub *cl)
{
@@ -36,18 +53,7 @@ void
mlx_put_image_to_window(cl->wlist.wlx,
cl->wlist.winptr, cl->img.img, 0, 0);
mlx_destroy_image(cl->wlist.wlx, cl->img.img);
- cl->plist.life -= FT_TRAP_DAMAGE_AMOUNT;
- if (cl->plist.life <= 0)
- {
- cl->isdead = 1;
- cl->sfx[0].sfx_play(cl->sfx);
- ft_death_screen(cl);
- }
- else
- {
- cl->sfx[4].sfx_play(cl->sfx);
- cl->sfx[3].sfx_play(cl->sfx);
- }
+ ft_get_damaged(cl);
}
void
@@ -69,20 +75,9 @@ void
rgb.g += 20;
rgb.b += 20;
*(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb);
+ (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(0, rgb, cl);
}
}
- cl->plist.life -= FT_TRAP_DAMAGE_AMOUNT;
- if (cl->plist.life <= 0)
- {
- cl->isdead = 1;
- cl->sfx[0].sfx_play(cl->sfx);
- ft_death_screen(cl);
- }
- else
- {
- cl->sfx[4].sfx_play(cl->sfx);
- cl->sfx[3].sfx_play(cl->sfx);
- }
+ ft_get_damaged(cl);
cl->doicast = 0;
}
diff --git a/src/ft_switch_weapons.c b/src/ft_switch_weapons.c
index 186f7be..c936ed6 100644
--- a/src/ft_switch_weapons.c
+++ b/src/ft_switch_weapons.c
@@ -28,3 +28,11 @@ int8_t
cl->plist.handles_weapon = 2;
return (0);
}
+
+int8_t
+ ft_switch_weap_three(t_cub *cl)
+{
+ cl->sfx[10].sfx_play(cl->sfx);
+ cl->plist.handles_weapon = 4;
+ return (0);
+}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index ecbb568..a6eec43 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -38,78 +38,59 @@
** 17: heal pack
** 18: weapon one sprite
** 19: weapon two sprite
+** 20: weapon three sprite
+** 21: health caption
+** 22: ammo caption
*/
static void
- ft_init_numbers(t_cub *cl)
+ ft_wall_tex_init_even_more_bonus(t_cub *cl)
{
- /* cl->tnum[0].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_ZER_PATH, &cl->tnum[0].img_w, &cl->tnum[0].img_h); */
- /* cl->tnum[0].ptr = mlx_get_data_addr(cl->tnum[0].img, */
- /* &cl->tnum[0].bpp, &cl->tnum[0].sizeline, &cl->tnum[0].endian); */
- /* cl->tnum[1].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_ONE_PATH, &cl->tnum[1].img_w, &cl->tnum[1].img_h); */
- /* cl->tnum[1].ptr = mlx_get_data_addr(cl->tnum[1].img, */
- /* &cl->tnum[1].bpp, &cl->tnum[1].sizeline, &cl->tnum[1].endian); */
- /* cl->tnum[2].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_TWO_PATH, &cl->tnum[2].img_w, &cl->tnum[2].img_h); */
- /* cl->tnum[2].ptr = mlx_get_data_addr(cl->tnum[2].img, */
- /* &cl->tnum[2].bpp, &cl->tnum[2].sizeline, &cl->tnum[2].endian); */
- /* cl->tnum[3].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_THR_PATH, &cl->tnum[3].img_w, &cl->tnum[3].img_h); */
- /* cl->tnum[3].ptr = mlx_get_data_addr(cl->tnum[3].img, */
- /* &cl->tnum[3].bpp, &cl->tnum[3].sizeline, &cl->tnum[3].endian); */
- /* cl->tnum[4].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_FOU_PATH, &cl->tnum[4].img_w, &cl->tnum[4].img_h); */
- /* cl->tnum[4].ptr = mlx_get_data_addr(cl->tnum[4].img, */
- /* &cl->tnum[4].bpp, &cl->tnum[4].sizeline, &cl->tnum[4].endian); */
- /* cl->tnum[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_FIV_PATH, &cl->tnum[5].img_w, &cl->tnum[5].img_h); */
- /* cl->tnum[5].ptr = mlx_get_data_addr(cl->tnum[5].img, */
- /* &cl->tnum[5].bpp, &cl->tnum[5].sizeline, &cl->tnum[5].endian); */
- /* cl->tnum[6].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_SIX_PATH, &cl->tnum[6].img_w, &cl->tnum[6].img_h); */
- /* cl->tnum[6].ptr = mlx_get_data_addr(cl->tnum[6].img, */
- /* &cl->tnum[6].bpp, &cl->tnum[6].sizeline, &cl->tnum[6].endian); */
- /* cl->tnum[7].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_SEV_PATH, &cl->tnum[7].img_w, &cl->tnum[7].img_h); */
- /* cl->tnum[7].ptr = mlx_get_data_addr(cl->tnum[7].img, */
- /* &cl->tnum[7].bpp, &cl->tnum[7].sizeline, &cl->tnum[7].endian); */
- /* cl->tnum[8].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_EIG_PATH, &cl->tnum[8].img_w, &cl->tnum[8].img_h); */
- /* cl->tnum[8].ptr = mlx_get_data_addr(cl->tnum[8].img, */
- /* &cl->tnum[8].bpp, &cl->tnum[8].sizeline, &cl->tnum[8].endian); */
- /* cl->tnum[9].img = mlx_xpm_file_to_image(cl->wlist.wlx, */
- /* FT_NIN_PATH, &cl->tnum[9].img_w, &cl->tnum[9].img_h); */
- /* cl->tnum[9].ptr = mlx_get_data_addr(cl->tnum[9].img, */
- /* &cl->tnum[9].bpp, &cl->tnum[9].sizeline, &cl->tnum[9].endian); */
- cl->tnum[10].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- FT_PER_PATH, &cl->tnum[10].img_w, &cl->tnum[10].img_h);
- cl->tnum[10].ptr = mlx_get_data_addr(cl->tnum[10].img,
- &cl->tnum[10].bpp, &cl->tnum[10].sizeline, &cl->tnum[10].endian);
+ cl->tlist[21].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_CAP_HEALTH_PATH, &cl->tlist[21].img_w, &cl->tlist[21].img_h);
+ cl->tlist[21].ptr = mlx_get_data_addr(cl->tlist[21].img,
+ &cl->tlist[21].bpp, &cl->tlist[21].sizeline, &cl->tlist[21].endian);
+ cl->tlist[22].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_CAP_AMMO_PATH, &cl->tlist[22].img_w, &cl->tlist[22].img_h);
+ cl->tlist[22].ptr = mlx_get_data_addr(cl->tlist[22].img,
+ &cl->tlist[22].bpp, &cl->tlist[22].sizeline, &cl->tlist[22].endian);
}
static void
- ft_next_sprite_init(t_cub *cl)
+ ft_wall_tex_init_more_bonus(t_cub *cl)
{
- uint8_t i;
-
- i = 1;
- while (cl->mlist.sprite_path[i][0])
- {
- cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w,
- &cl->tlist[i + 7].img_h);
- cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img,
- &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline,
- &cl->tlist[i + 7].endian);
- i++;
- }
+ cl->tlist[16].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_HUD_BACK_PATH, &cl->tlist[16].img_w, &cl->tlist[16].img_h);
+ cl->tlist[16].ptr = mlx_get_data_addr(cl->tlist[16].img,
+ &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian);
+ cl->tlist[18].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_WEAPON_ONE_SPR_PATH, &cl->tlist[18].img_w, &cl->tlist[18].img_h);
+ cl->tlist[18].ptr = mlx_get_data_addr(cl->tlist[18].img,
+ &cl->tlist[18].bpp, &cl->tlist[18].sizeline, &cl->tlist[18].endian);
+ cl->tlist[19].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ 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);
+ ft_wall_tex_init_even_more_bonus(cl);
+ cl->walltexgood = 1;
+ if (cl->mlist.sprite_var > 1)
+ ft_next_sprite_init(cl);
}
static void
- ft_wall_tex_init_norme_bis(t_cub *cl)
+ ft_wall_tex_init_next_bonus(t_cub *cl)
{
+ if (cl->mlist.isheals)
+ {
+ cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h);
+ cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img,
+ &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian);
+ }
if (cl->mlist.isskybox)
{
cl->tlist[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
@@ -124,26 +105,11 @@ static void
cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img,
&cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
}
- cl->tlist[16].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- FT_HUD_BACK_PATH, &cl->tlist[16].img_w, &cl->tlist[16].img_h);
- cl->tlist[16].ptr = mlx_get_data_addr(cl->tlist[16].img,
- &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian);
- cl->tlist[18].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- FT_WEAPON_ONE_SPR_PATH, &cl->tlist[18].img_w, &cl->tlist[18].img_h);
- cl->tlist[18].ptr = mlx_get_data_addr(cl->tlist[18].img,
- &cl->tlist[18].bpp, &cl->tlist[18].sizeline, &cl->tlist[18].endian);
- cl->tlist[19].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- 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);
- ft_init_numbers(cl);
- cl->walltexgood = 1;
- if (cl->mlist.sprite_var > 1)
- ft_next_sprite_init(cl);
+ ft_wall_tex_init_more_bonus(cl);
}
-
+
static void
- ft_wall_tex_init_norme(t_cub *cl)
+ ft_wall_tex_init_bonus(t_cub *cl)
{
if (cl->mlist.isnlvl)
{
@@ -166,14 +132,7 @@ static void
cl->tlist[15].ptr = mlx_get_data_addr(cl->tlist[15].img,
&cl->tlist[15].bpp, &cl->tlist[15].sizeline, &cl->tlist[15].endian);
}
- if (cl->mlist.isheals)
- {
- cl->tlist[17].img = mlx_xpm_file_to_image(cl->wlist.wlx,
- FT_HEAL_PACK_PATH, &cl->tlist[17].img_w, &cl->tlist[17].img_h);
- cl->tlist[17].ptr = mlx_get_data_addr(cl->tlist[17].img,
- &cl->tlist[17].bpp, &cl->tlist[17].sizeline, &cl->tlist[17].endian);
- }
- ft_wall_tex_init_norme_bis(cl);
+ ft_wall_tex_init_next_bonus(cl);
}
void
@@ -199,5 +158,5 @@ void
cl->mlist.sprite_path[0], &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
- ft_wall_tex_init_norme(cl);
+ ft_wall_tex_init_bonus(cl);
}
diff --git a/src/ft_tex_num_init.c b/src/ft_tex_num_init.c
new file mode 100644
index 0000000..34b5c11
--- /dev/null
+++ b/src/ft_tex_num_init.c
@@ -0,0 +1,90 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_tex_num_init.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: fmoenne- <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:43:55 by fmoenne- #+# #+# */
+/* Updated: 2020/02/14 17:43:56 by fmoenne- ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <mlx.h>
+
+/*
+** tnum[] index summary
+** ---------------------
+** 0: zero
+** 1: one
+** 2: two
+** 3: three
+** 4: four
+** 5: five
+** 6: six
+** 7: seven
+** 8: eight
+** 9: nine
+** 10: percent
+** 11: infinite
+*/
+
+static void
+ ft_next_num_init(t_cub *cl)
+{
+ cl->tnum[6].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_SIX_PATH, &cl->tnum[6].img_w, &cl->tnum[6].img_h);
+ cl->tnum[6].ptr = mlx_get_data_addr(cl->tnum[6].img,
+ &cl->tnum[6].bpp, &cl->tnum[6].sizeline, &cl->tnum[6].endian);
+ cl->tnum[7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_SEV_PATH, &cl->tnum[7].img_w, &cl->tnum[7].img_h);
+ cl->tnum[7].ptr = mlx_get_data_addr(cl->tnum[7].img,
+ &cl->tnum[7].bpp, &cl->tnum[7].sizeline, &cl->tnum[7].endian);
+ cl->tnum[8].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_EIG_PATH, &cl->tnum[8].img_w, &cl->tnum[8].img_h);
+ cl->tnum[8].ptr = mlx_get_data_addr(cl->tnum[8].img,
+ &cl->tnum[8].bpp, &cl->tnum[8].sizeline, &cl->tnum[8].endian);
+ cl->tnum[9].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_NIN_PATH, &cl->tnum[9].img_w, &cl->tnum[9].img_h);
+ cl->tnum[9].ptr = mlx_get_data_addr(cl->tnum[9].img,
+ &cl->tnum[9].bpp, &cl->tnum[9].sizeline, &cl->tnum[9].endian);
+ cl->tnum[10].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_PER_PATH, &cl->tnum[10].img_w, &cl->tnum[10].img_h);
+ cl->tnum[10].ptr = mlx_get_data_addr(cl->tnum[10].img,
+ &cl->tnum[10].bpp, &cl->tnum[10].sizeline, &cl->tnum[10].endian);
+ cl->tnum[11].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_INF_PATH, &cl->tnum[11].img_w, &cl->tnum[11].img_h);
+ cl->tnum[11].ptr = mlx_get_data_addr(cl->tnum[11].img,
+ &cl->tnum[11].bpp, &cl->tnum[11].sizeline, &cl->tnum[11].endian);
+}
+
+void
+ ft_num_tex_init(t_cub *cl)
+{
+ cl->tnum[0].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_ZER_PATH, &cl->tnum[0].img_w, &cl->tnum[0].img_h);
+ cl->tnum[0].ptr = mlx_get_data_addr(cl->tnum[0].img,
+ &cl->tnum[0].bpp, &cl->tnum[0].sizeline, &cl->tnum[0].endian);
+ cl->tnum[1].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_ONE_PATH, &cl->tnum[1].img_w, &cl->tnum[1].img_h);
+ cl->tnum[1].ptr = mlx_get_data_addr(cl->tnum[1].img,
+ &cl->tnum[1].bpp, &cl->tnum[1].sizeline, &cl->tnum[1].endian);
+ cl->tnum[2].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_TWO_PATH, &cl->tnum[2].img_w, &cl->tnum[2].img_h);
+ cl->tnum[2].ptr = mlx_get_data_addr(cl->tnum[2].img,
+ &cl->tnum[2].bpp, &cl->tnum[2].sizeline, &cl->tnum[2].endian);
+ cl->tnum[3].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_THR_PATH, &cl->tnum[3].img_w, &cl->tnum[3].img_h);
+ cl->tnum[3].ptr = mlx_get_data_addr(cl->tnum[3].img,
+ &cl->tnum[3].bpp, &cl->tnum[3].sizeline, &cl->tnum[3].endian);
+ cl->tnum[4].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_FOU_PATH, &cl->tnum[4].img_w, &cl->tnum[4].img_h);
+ cl->tnum[4].ptr = mlx_get_data_addr(cl->tnum[4].img,
+ &cl->tnum[4].bpp, &cl->tnum[4].sizeline, &cl->tnum[4].endian);
+ cl->tnum[5].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_FIV_PATH, &cl->tnum[5].img_w, &cl->tnum[5].img_h);
+ cl->tnum[5].ptr = mlx_get_data_addr(cl->tnum[5].img,
+ &cl->tnum[5].bpp, &cl->tnum[5].sizeline, &cl->tnum[5].endian);
+ ft_next_num_init(cl);
+}
diff --git a/src/ft_tex_sprites_extra_init.c b/src/ft_tex_sprites_extra_init.c
new file mode 100644
index 0000000..9ff7612
--- /dev/null
+++ b/src/ft_tex_sprites_extra_init.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_tex_sprites_extra_init.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: fmoenne- <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:43:55 by fmoenne- #+# #+# */
+/* Updated: 2020/02/14 17:43:56 by fmoenne- ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+#include <mlx.h>
+
+void
+ ft_next_sprite_init(t_cub *cl)
+{
+ uint8_t i;
+
+ i = 1;
+ while (cl->mlist.sprite_path[i][0])
+ {
+ cl->tlist[i + 7].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ cl->mlist.sprite_path[i], &cl->tlist[i + 7].img_w,
+ &cl->tlist[i + 7].img_h);
+ cl->tlist[i + 7].ptr = mlx_get_data_addr(cl->tlist[i + 7].img,
+ &cl->tlist[i + 7].bpp, &cl->tlist[i + 7].sizeline,
+ &cl->tlist[i + 7].endian);
+ i++;
+ }
+ cl->mlist.topsp = i + 1;
+}
diff --git a/src/ft_tex_weap_init.c b/src/ft_tex_weap_init.c
index 983da0b..3425fb4 100644
--- a/src/ft_tex_weap_init.c
+++ b/src/ft_tex_weap_init.c
@@ -10,10 +10,7 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
-#include <stdint.h>
-#include <stdio.h>
#include <mlx.h>
/*
@@ -23,6 +20,8 @@
** 1: weapon one fire
** 2: weapon two
** 3: weapon two fire
+** 4: weapon three
+** 5: weapon three fire
*/
void
@@ -44,4 +43,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);
}
diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c
index 4cc759e..19da836 100644
--- a/src/ft_treat_args.c
+++ b/src/ft_treat_args.c
@@ -29,21 +29,29 @@ uint8_t
return (0);
}
+static void
+ ft_init_macos_img(t_cub *clist)
+{
+ if (FT_OS == 1)
+ {
+ clist->img.img = mlx_new_image(clist->wlist.wlx,
+ clist->wlist.x_size, clist->wlist.y_size);
+ clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
+ &clist->img.sizeline, &clist->img.endian);
+ }
+}
+
uint8_t
- ft_use_args(int argc, const char *argv[], char *const envp[], t_cub *clist)
+ ft_use_args(int argc, const char *argv[], t_cub *clist)
{
- clist->envp = envp;
if (argc < 3)
{
if (ft_init_winptr(clist) < 0)
return (ft_exit(FT_RET_FAILED_MLX, clist));
- if (FT_OS == 1)
- {
- clist->img.img = mlx_new_image(clist->wlist.wlx,
- clist->wlist.x_size, clist->wlist.y_size);
- clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
- &clist->img.sizeline, &clist->img.endian);
- }
+ ft_wall_tex_init(clist);
+ ft_weap_tex_init(clist);
+ ft_num_tex_init(clist);
+ ft_init_macos_img(clist);
ft_draw_scene(clist);
if (clist->mlist.ismusic)
ft_enable_music(clist);
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);
}
diff --git a/src/main.c b/src/main.c
index 623787b..4cbd7a2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -16,7 +16,7 @@
#include <stdlib.h>
int
- main(int argc, const char *argv[], char *const envp[])
+ main(int argc, const char *argv[])
{
t_cub *clist;
@@ -29,8 +29,6 @@ int
ft_parse_map(argv[1], clist);
if (ft_init_winlx(clist) < 0)
return (ft_exit(FT_RET_FAILED_MLX, clist));
- ft_wall_tex_init(clist);
- ft_weap_tex_init(clist);
- ft_use_args(argc, argv, envp, clist);
+ ft_use_args(argc, argv, clist);
return (FT_RET_FINE);
}