diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 22:40:47 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-18 22:40:47 +0100 |
commit | 3520f4bf3d435991f402e46731c15838baae0894 (patch) | |
tree | c8cbf06ebd69a422cbcf2cb8381916af172da726 /src | |
parent | Still sfx to do (diff) | |
parent | Bug fix (diff) | |
download | 42-cub3d-3520f4bf3d435991f402e46731c15838baae0894.tar.gz 42-cub3d-3520f4bf3d435991f402e46731c15838baae0894.tar.bz2 42-cub3d-3520f4bf3d435991f402e46731c15838baae0894.tar.xz 42-cub3d-3520f4bf3d435991f402e46731c15838baae0894.tar.zst 42-cub3d-3520f4bf3d435991f402e46731c15838baae0894.zip |
Merge branch 'master' into weaps
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_check_map_line.c | 4 | ||||
-rw-r--r-- | src/ft_check_missing.c | 3 | ||||
-rw-r--r-- | src/ft_draw_heals.c | 109 | ||||
-rw-r--r-- | src/ft_draw_heals_extra.c | 43 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 46 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 15 | ||||
-rw-r--r-- | src/ft_draw_traps_extra.c | 3 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_find_item.c | 53 | ||||
-rw-r--r-- | src/ft_get_heal_spawn.c | 45 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 1 | ||||
-rw-r--r-- | src/ft_get_traps.c | 6 | ||||
-rw-r--r-- | src/ft_init_map.c | 2 | ||||
-rw-r--r-- | src/ft_key_loop.c | 1 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 | ||||
-rw-r--r-- | src/ft_tex_init.c | 10 | ||||
-rw-r--r-- | src/ft_warp_level.c | 4 |
17 files changed, 308 insertions, 40 deletions
diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index b9fd636..50464a9 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -37,8 +37,8 @@ static int8_t ft_sprintf(clist->errmsg, FT_ERR_MULT_NLVL); return (-1); } - if (line[i] == 'T') - clist->mlist.istraps = 1; + clist->mlist.istraps = (line[i] == 'T') ? (1) : (clist->mlist.istraps); + clist->mlist.isheals = (line[i] == '+') ? (1) : (clist->mlist.isheals); ft_get_topsp(line[i], clist); return (0); } diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 5498058..fcebf3f 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -71,6 +71,9 @@ static int 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_HEAL_PACK_PATH) < 0 || + ft_check_ext(FT_HEAL_PACK_PATH, ".xpm") < 0) + return (ft_missing_error(FT_ERR_MISS_HEAL_PACK, clist)); return (ft_check_missing_sprites(clist)); } diff --git a/src/ft_draw_heals.c b/src/ft_draw_heals.c new file mode 100644 index 0000000..d51ae97 --- /dev/null +++ b/src/ft_draw_heals.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +static void + ft_sort_heals_norme(float *dist_tab, int32_t it, t_cub *cl) +{ + uint32_t tmp; + + tmp = 0; + if (dist_tab[it] > dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.heals_order[it]; + cl->mlist.heals_order[it] = cl->mlist.heals_order[it + 1]; + cl->mlist.heals_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_heals(t_cub *cl) +{ + float dist_tab[4096]; + int32_t it; + + it = 0; + while (it < cl->mlist.sprite_nbr) + { + dist_tab[it] = ((cl->plist.pos_x - cl->heals[it].s_pos_x) * + (cl->plist.pos_x - cl->heals[it].s_pos_x) + + (cl->plist.pos_y - cl->heals[it].s_pos_y) * + (cl->plist.pos_y - cl->heals[it].s_pos_y)); + cl->mlist.heals_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.heals_nbr) + { + ft_sort_heals_norme(dist_tab, it, cl); + } +} + +static void + ft_put_heal(t_sprite *sprite, t_cub *cl) +{ + float dist; + float calc; + + if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 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; +} + +void + ft_draw_heals(t_cub *cl, t_sprite *sprite) +{ + int32_t d; + + sprite->x = sprite->drawstartx; + while (sprite->x < sprite->drawendx) + { + sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + + sprite->spritescreenx)) + * cl->tlist[17].img_w / sprite->spritewidth); + sprite->y = sprite->drawstarty; + while (sprite->y < sprite->drawendy) + { + d = sprite->y * 256 - cl->wlist.y_size * 128 + + sprite->spriteheight * 128; + sprite->tex_y = ((d * cl->tlist[17].img_h / 2) / + sprite->spriteheight) / 128; + if (sprite->transformy > 0 + && cl->tlist[17].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[17].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + ft_put_heal(sprite, cl); + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_heals_extra.c b/src/ft_draw_heals_extra.c new file mode 100644 index 0000000..62c64b0 --- /dev/null +++ b/src/ft_draw_heals_extra.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_heals_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +void + ft_calc_heal(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.heals_nbr) + { + sprite = cl->heals[i]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y + - cl->plist.dir_x * cl->plist.plane_y); + sprite.transformx = sprite.invdet * (cl->plist.dir_y * sprite.spritex + - cl->plist.dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * (-cl->plist.plane_y * sprite.spritex + + cl->plist.plane_x * sprite.spritey); + sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite.transformx / sprite.transformy); + ft_sprite_h_w(cl, &sprite); + ft_draw_heals(cl, &sprite); + i++; + } +} diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index b304102..ceea280 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -13,23 +13,26 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <math.h> static void - ft_sort_sprites_norme(float *dist_tab, int32_t it, t_cub *cl) + ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) { uint32_t tmp; + uint32_t it; + it = *i; tmp = 0; - if (dist_tab[it] > dist_tab[it + 1]) + if (dist_tab[it] < dist_tab[it + 1]) { tmp = dist_tab[it]; dist_tab[it] = dist_tab[it + 1]; dist_tab[it + 1] = tmp; - tmp = cl->mlist.sprite_order[it]; - cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; - cl->mlist.sprite_order[it + 1] = tmp; + tmp = cl->mlist.sprite_order[j][it]; + cl->mlist.sprite_order[j][it] = cl->mlist.sprite_order[j][it + 1]; + cl->mlist.sprite_order[j][it + 1] = tmp; it = 0; } } @@ -37,31 +40,30 @@ static void void ft_sort_sprites(t_cub *cl) { - float dist_tab[4096]; - int32_t it; - int32_t jt; + float dist_tab[8][4096]; + uint16_t it; + uint16_t jt; - it = 0; - jt = 0; - while (jt < cl->mlist.sprite_var) + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) { - while (it < cl->mlist.sprite_nbr) + while (++it < cl->mlist.sprite_nbr) { - dist_tab[it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * + dist_tab[jt][it] = + ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); - cl->mlist.sprite_order[it] = it; - it++; + cl->mlist.sprite_order[jt][it] = it; } - it = 0; - jt++; - } - it = 0; - while (it < cl->mlist.sprite_nbr) - { - ft_sort_sprites_norme(dist_tab, it, cl); + it = -1; } + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) + while (++it < cl->mlist.sprite_nbr) + ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 2545ec0..9198e8d 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -13,12 +13,11 @@ #include <libft.h> #include <cub3d.h> #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include <math.h> void - ft_sprite_height(t_cub *cl, t_sprite *sprite) + ft_sprite_h_w(t_cub *cl, t_sprite *sprite) { sprite->spriteheight = abs((int)(cl->wlist.y_size / (sprite->transformy))); sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist.y_size / 2; @@ -27,11 +26,6 @@ void sprite->drawendy = sprite->spriteheight / 2 + cl->wlist.y_size / 2; if (sprite->drawendy >= (int)cl->wlist.y_size) sprite->drawendy = cl->wlist.y_size - 1; -} - -void - ft_sprite_width(t_cub *cl, t_sprite *sprite) -{ sprite->spritewidth = abs((int)(cl->wlist.x_size / (sprite->transformy))); sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawstartx < 0) @@ -41,6 +35,7 @@ void sprite->drawendx = cl->wlist.x_size - 1; } + static void ft_init_sprite(t_cub *cl, t_sprite *sprite) { @@ -63,17 +58,17 @@ void i = 0; j = 0; + ft_sort_sprites(cl); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][i]; + sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; sprite.current_sprite = (j == 0) ? 4 : j + 7; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); ft_init_sprite(cl, &sprite); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); + ft_sprite_h_w(cl, &sprite); ft_draw_sprite(cl, &sprite); i++; } diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c index a2fd0ab..c524190 100644 --- a/src/ft_draw_traps_extra.c +++ b/src/ft_draw_traps_extra.c @@ -36,8 +36,7 @@ void + cl->plist.plane_x * sprite.spritey); sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * (1 + sprite.transformx / sprite.transformy); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); + ft_sprite_h_w(cl, &sprite); ft_draw_traps(cl, &sprite); i++; } diff --git a/src/ft_exit.c b/src/ft_exit.c index 78b6d0a..390f234 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -86,6 +86,8 @@ static void 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); ft_del_extra_sprites(clist); } diff --git a/src/ft_find_item.c b/src/ft_find_item.c new file mode 100644 index 0000000..d00b62d --- /dev/null +++ b/src/ft_find_item.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_find_item.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 */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +static uint16_t + ft_fetch_heals_id(uint64_t pos_y, uint64_t pos_x, t_cub *cl) +{ + uint16_t id; + + id = 0; + while (id <= 64) + { + if (cl->heals[id].s_pos_y == pos_y && cl->heals[id].s_pos_x == pos_x) + return (id); + id++; + } + return (0); +} + +void + ft_find_item(t_player *pl, t_map *ml, t_cub *cl) +{ + uint16_t id; + + if (ft_ischarset(FT_CHRST_ITEM, + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x])) + { + if (ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] == '+' + && pl->life < 100) + { + pl->life += FT_HEAL_PACK_AMOUNT; + pl->life = (pl->life > 100) ? (100) : (pl->life); + ml->map[(uint64_t)pl->pos_y][(uint64_t)pl->pos_x] = '0'; + id = ft_fetch_heals_id((uint64_t)pl->pos_y, + (uint64_t)pl->pos_x, cl); + cl->heals[id].s_pos_x = 0; + cl->heals[id].s_pos_y = 0; + /* TODO: ft_sfx_heal(3) */ + } + } +} diff --git a/src/ft_get_heal_spawn.c b/src/ft_get_heal_spawn.c new file mode 100644 index 0000000..142709b --- /dev/null +++ b/src/ft_get_heal_spawn.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 18:24:52 by rbousset #+# #+# */ +/* Updated: 2020/02/28 18:24:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +void + ft_get_heal_spawn(t_cub *clist) +{ + size_t x; + size_t y; + uint8_t i; + + x = 1; + y = 1; + i = 0; + while (clist->mlist.map[y]) + { + while (clist->mlist.map[y][x]) + { + if (clist->mlist.map[y][x] == '+') + { + clist->mlist.heals_nbr++; + if (clist->mlist.heals_nbr > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, clist); + clist->heals[i].s_pos_x = x; + clist->heals[i].s_pos_y = y; + i++; + } + x++; + } + x = 1; + y++; + } +} diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index ef2edd9..1ba6437 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -84,6 +84,7 @@ void 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); return ; } x++; diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c index b7d12e1..fef3179 100644 --- a/src/ft_get_traps.c +++ b/src/ft_get_traps.c @@ -1,7 +1,7 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_get_tex_nl.c :+: :+: :+: */ +/* ft_get_traps.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ @@ -19,7 +19,7 @@ void { size_t x; size_t y; - uint8_t i; + uint16_t i; x = 1; y = 1; @@ -31,6 +31,8 @@ void if (clist->mlist.map[y][x] == 'T') { clist->mlist.traps_nbr++; + if (clist->mlist.traps_nbr > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, clist); clist->traps[i].s_pos_x = x; clist->traps[i].s_pos_y = y; i++; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 8b97906..d610fac 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -89,8 +89,10 @@ int8_t mlist->ismusic = 0; mlist->isskybox = 0; mlist->istraps = 0; + mlist->isheals = 0; mlist->sprite_nbr = 0; mlist->traps_nbr = 0; + mlist->heals_nbr = 0; mlist->darklvl = 0; return (ft_init_map_norme(mlist)); } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index 0108202..e0177e2 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -89,6 +89,7 @@ int { ft_sfx_footstep(cl); 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 && diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index aa050c5..2d7df79 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -106,6 +106,7 @@ void } ft_floor_cast(cl); ft_calc_sprite(cl); + ft_calc_heal(cl); ft_calc_trap(cl); ft_memdel((void*)&cl->rlist.wall_dist_tab); ft_memdel((void*)&cl->rlist.wall_bz); diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index fe8aadd..6486e87 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -36,6 +36,7 @@ ** 14 : sprite 9 ** 15 : trap ** 16 : HUD back +** 17 : heal pack */ static void @@ -79,9 +80,7 @@ static void &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian); cl->walltexgood = 1; if (cl->mlist.sprite_var > 1) - { ft_next_sprite_init(cl); - } } static void @@ -108,6 +107,13 @@ 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); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index fadbb2a..a2b6006 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -61,6 +61,10 @@ static void 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); ft_del_extra_sprites(cl); i = -1; while (++i < 8) |