aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-27 13:55:24 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-27 13:55:24 +0100
commitb626f171f26f709b27e790911b48f7a4272dc707 (patch)
treede04209c5ffecc5f26baac853951bc1748c925d4 /src
parentReady to try traps (diff)
download42-cub3d-b626f171f26f709b27e790911b48f7a4272dc707.tar.gz
42-cub3d-b626f171f26f709b27e790911b48f7a4272dc707.tar.bz2
42-cub3d-b626f171f26f709b27e790911b48f7a4272dc707.tar.xz
42-cub3d-b626f171f26f709b27e790911b48f7a4272dc707.tar.zst
42-cub3d-b626f171f26f709b27e790911b48f7a4272dc707.zip
In progress
Diffstat (limited to 'src')
-rw-r--r--src/ft_del_sprites_lists.c4
-rw-r--r--src/ft_get_spawns.c2
-rw-r--r--src/ft_get_sprite_spawns.c59
-rw-r--r--src/ft_get_traps.c56
-rw-r--r--src/ft_init_map.c13
-rw-r--r--src/ft_init_sprites.c29
-rw-r--r--src/ft_raycasting.c2
7 files changed, 106 insertions, 59 deletions
diff --git a/src/ft_del_sprites_lists.c b/src/ft_del_sprites_lists.c
index bb382e6..613ac82 100644
--- a/src/ft_del_sprites_lists.c
+++ b/src/ft_del_sprites_lists.c
@@ -17,10 +17,10 @@
void
ft_del_sprites_lists(t_cub *clist)
{
- uint8_t i;
+ int8_t i;
i = 0;
- while (i < 8)
+ while (i < FT_TOTAL_SPRT)
{
ft_memdel((void*)&clist->sprites[i]);
i++;
diff --git a/src/ft_get_spawns.c b/src/ft_get_spawns.c
index 6422785..9bd7040 100644
--- a/src/ft_get_spawns.c
+++ b/src/ft_get_spawns.c
@@ -19,7 +19,7 @@ void
{
ft_get_player_spawn(&cl->plist, cl);
ft_get_sprite_spawn(cl);
- ft_get_trap_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_spawns.c b/src/ft_get_sprite_spawns.c
index 8a92a3c..047523a 100644
--- a/src/ft_get_sprite_spawns.c
+++ b/src/ft_get_sprite_spawns.c
@@ -17,22 +17,47 @@
/*
** cl->sprite[] index summary
** --------------------------
-** 0: sprite 2 - tlist[4]
-** 1: sprite 3 - tlist[8]
-** 2: sprite 4 - tlist[9]
-** 3: sprite 5 - tlist[10]
-** 4: sprite 6 - tlist[11]
-** 5: sprite 7 - tlist[12]
-** 6: sprite 8 - tlist[13]
-** 7: sprite 9 - tlist[14]
-** 8: trap - tlist[15]
-** 9: heal - tlist[17]
-** 10: weapon one - tlist[18]
-** 11: weapon two - tlist[19]
-** 12: weapon three - tlist[20]
+** 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
*/
-void
+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 == 7)
+ return (ft_get_next_sprite(cl, 8, 'T', 0));
+ return (0);
+}
+
+int8_t
ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x)
{
size_t y;
@@ -55,11 +80,11 @@ void
}
x = 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)
- {
- ft_get_next_sprite(clist, s_n + 1, c + 1, 0);
- }
+ return (ft_get_next_sprite(clist, s_n + 1, c + 1, 0));
+ return (ft_other_next_sprite(clist, s_n));
}
void
diff --git a/src/ft_get_traps.c b/src/ft_get_traps.c
index fef3179..db0699c 100644
--- a/src/ft_get_traps.c
+++ b/src/ft_get_traps.c
@@ -14,35 +14,35 @@
#include <cub3d.h>
#include <stdint.h>
-void
- ft_get_trap_spawn(t_cub *clist)
-{
- size_t x;
- size_t y;
- uint16_t i;
+/* void */
+/* ft_get_trap_spawn(t_cub *clist) */
+/* { */
+/* size_t x; */
+/* size_t y; */
+/* uint16_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] == '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++;
- }
- x++;
- }
- x = 1;
- y++;
- }
-}
+/* x = 1; */
+/* y = 1; */
+/* i = 0; */
+/* while (clist->mlist.map[y]) */
+/* { */
+/* while (clist->mlist.map[y][x]) */
+/* { */
+/* 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++; */
+/* } */
+/* x++; */
+/* } */
+/* x = 1; */
+/* y++; */
+/* } */
+/* } */
int8_t
ft_get_traps(char **words, t_cub *clist)
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index f2f2d94..e85c6a6 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -57,6 +57,8 @@ static int8_t
int8_t
ft_init_map_norme(t_map *mlist)
{
+ int8_t i;
+
mlist->darklvl = 0;
mlist->scale = 0;
mlist->nlx = 0;
@@ -64,10 +66,12 @@ int8_t
mlist->sprite_var = 0;
mlist->weapon_var = 0;
mlist->topsp = 0;
- ft_bzero(mlist->sprite_nbr, 8);
- ft_bzero(mlist->sprite_order, 8);
- ft_bzero(mlist->st_o, 8);
- ft_bzero(mlist->traps_order, 512);
+ ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT);
+ ft_bzero(mlist->sprite_order, FT_TOTAL_SPRT);
+ i = -1;
+ while (++i < FT_TOTAL_SPRT)
+ ft_bzero(mlist->sprite_order[i], 4096);
+ ft_bzero(mlist->st_o, FT_TOTAL_SPRT);
ft_bzero(mlist->heals_order, 64);
mlist->weaps_nbr[0] = 0;
mlist->weaps_nbr[1] = 0;
@@ -99,7 +103,6 @@ int8_t
mlist->isskybox = 0;
mlist->istraps = 0;
mlist->isheals = 0;
- mlist->traps_nbr = 0;
mlist->heals_nbr = 0;
return (ft_init_map_norme(mlist));
}
diff --git a/src/ft_init_sprites.c b/src/ft_init_sprites.c
index 2099089..1a23c26 100644
--- a/src/ft_init_sprites.c
+++ b/src/ft_init_sprites.c
@@ -16,19 +16,38 @@
#include <stdlib.h>
#include <stdint.h>
+/*
+** 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
+*/
+
int8_t
ft_init_sprites(t_sprite ***sprites)
{
- uint8_t i;
+ int8_t i;
- if (!(*sprites = (t_sprite**)ft_calloc(8, sizeof(t_sprite*))))
+ if (!(*sprites = (t_sprite**)ft_calloc(FT_TOTAL_SPRT, sizeof(t_sprite*))))
return (-1);
- i = 0;
- while (i < 8)
+ i = -1;
+ while (++i < 8)
{
if (!(*((*sprites) + i) = (t_sprite*)ft_calloc(4096, sizeof(t_sprite))))
return (-1);
- i++;
}
+ if (!(*((*sprites) + 8) = (t_sprite*)ft_calloc(512, sizeof(t_sprite))))
+ return (-1);
return (0);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 8a79154..0a1acac 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -108,7 +108,7 @@ void
pthread_join(tid[1], 0x0);
ft_calc_sprite(cl);
ft_calc_heal(cl);
- ft_calc_trap(cl);
+ /* ft_calc_trap(cl); */
ft_calc_weaps(cl);
if (cl->plist.handles_weapon > -1)
ft_draw_handweap(cl);