diff options
Diffstat (limited to 'src/ft_get_sprite_spawns.c')
-rw-r--r-- | src/ft_get_sprite_spawns.c | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c index f4d7e1e..9329c51 100644 --- a/src/ft_get_sprite_spawns.c +++ b/src/ft_get_sprite_spawns.c @@ -14,7 +14,58 @@ #include <cub3d.h> #include <stdint.h> -void +/* +** cl->sprite[] index summary +** -------------------------- +** 0: sprite 2 - tlist[4] - 4096 +** 1: sprite 3 - tlist[8] - 4096 +** 2: sprite 4 - tlist[9] - 4096 +** 3: sprite 5 - tlist[10] - 4096 +** 4: sprite 6 - tlist[11] - 4096 +** 5: sprite 7 - tlist[12] - 4096 +** 6: sprite 8 - tlist[13] - 4096 +** 7: sprite 9 - tlist[14] - 4096 +** 8: trap - tlist[15] - 512 +** 9: heal - tlist[17] - 64 +** 10: weapon one - tlist[18] - 4 +** 11: weapon two - tlist[19] - 4 +** 12: weapon three - tlist[20] - 4 +*/ + +static void + ft_check_amount(t_cub *cl, int s_n) +{ + if (s_n < 8 && cl->mlist.sprite_nbr[s_n] > 4096) + ft_map_error(FT_ERR_TOO_MUCH_SPRT, cl); + else if (s_n == 8 && cl->mlist.sprite_nbr[s_n] > 512) + ft_map_error(FT_ERR_TOO_MUCH_TRAPS, cl); + else if (s_n == 9 && cl->mlist.sprite_nbr[s_n] > 64) + ft_map_error(FT_ERR_TOO_MUCH_HEALS, cl); + else if (s_n == 10 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_ONE, cl); + else if (s_n == 11 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_TWO, cl); + else if (s_n == 12 && cl->mlist.sprite_nbr[s_n] > 4) + ft_map_error(FT_ERR_TOO_MUCH_W_THREE, cl); +} + +static int8_t + ft_other_next_sprite(t_cub *cl, int s_n) +{ + if (s_n + 1 == 8) + return (ft_get_next_sprite(cl, 8, 'T', 0)); + if (s_n + 1 == 9) + return (ft_get_next_sprite(cl, 9, '+', 0)); + if (s_n + 1 == 10) + return (ft_get_next_sprite(cl, 10, '!', 0)); + if (s_n + 1 == 11) + return (ft_get_next_sprite(cl, 11, '@', 0)); + if (s_n + 1 == 12) + return (ft_get_next_sprite(cl, 12, '#', 0)); + return (0); +} + +int8_t ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x) { size_t y; @@ -30,6 +81,7 @@ void if (clist->mlist.map[y][x] == c) { clist->mlist.sprite_nbr[s_n]++; + clist->sprites[s_n][i].exists = 1; clist->sprites[s_n][i].s_pos_x = x; clist->sprites[s_n][i].s_pos_y = y; i++; @@ -37,11 +89,11 @@ void } x = 0; } - if (clist->sprites[s_n][(i - 1 < 0) ? (0) : (i - 1)].s_pos_x != 0 - && s_n + 1 < 7) - { - ft_get_next_sprite(clist, s_n + 1, c + 1, 0); - } + ft_check_amount(clist, s_n); + if (/* clist->sprites[s_n][(i - 1 < 0) ? (0) : (i - 1)].s_pos_x != 0 + && */ s_n + 1 <= 7) + return (ft_get_next_sprite(clist, s_n + 1, c + 1, 0)); + return (ft_other_next_sprite(clist, s_n)); } void @@ -62,6 +114,7 @@ void if (ft_ischarset("2", clist->mlist.map[y][x])) { clist->mlist.sprite_nbr[0]++; + clist->sprites[0][i].exists = 1; clist->sprites[0][i].s_pos_x = x; clist->sprites[0][i].s_pos_y = y; i++; |