aboutsummaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--Makefile4
-rw-r--r--inc/cub3d.h4
-rw-r--r--inc/cub3d_defines.h17
-rw-r--r--inc/cub3d_structs.h9
-rw-r--r--map/map_one.cub15
-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
12 files changed, 129 insertions, 85 deletions
diff --git a/Makefile b/Makefile
index 2692ab5..e408802 100644
--- a/Makefile
+++ b/Makefile
@@ -85,8 +85,8 @@ SRCS_NAME += ft_init_bmp.c
SRCS_NAME += ft_floor_cast.c
SRCS_NAME += ft_floor_cast_inits.c
SRCS_NAME += ft_suffer_animation.c
-SRCS_NAME += ft_draw_traps.c
-SRCS_NAME += ft_draw_traps_extra.c
+# SRCS_NAME += ft_draw_traps.c
+# SRCS_NAME += ft_draw_traps_extra.c
SRCS_NAME += ft_draw_life_bar.c
SRCS_NAME += ft_init_sfx.c
SRCS_NAME += ft_sfx_death.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index b7f8a36..a6a0db7 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -92,8 +92,6 @@ void ft_sort_sprites(t_cub *cl, int16_t i, int16_t j);
void ft_sort_s_t(t_cub *cl, float **dist_tab);
void ft_calc_sprite(t_cub *cl);
void ft_draw_sprite(t_cub *cl, t_sprite *sprite);
-void ft_calc_trap(t_cub *cl);
-void ft_draw_traps(t_cub *cl, t_sprite *sprite);
void ft_calc_heal(t_cub *cl);
void ft_draw_heals(t_cub *cl, t_sprite *sprite);
void ft_calc_weaps(t_cub *cl);
@@ -145,8 +143,8 @@ int8_t ft_get_tex_nl(char **words, t_cub *clist);
int8_t ft_get_music(char **words, t_cub *clist);
size_t ft_get_map_h(char **map);
size_t ft_get_map_w(char **map);
+int8_t ft_get_next_sprite(t_cub *clist, int s_n, char c, size_t x);
void ft_get_sprite_spawn(t_cub *clist);
-void ft_get_trap_spawn(t_cub *clist);
void ft_get_heal_spawn(t_cub *clist);
void ft_get_weapon_spawn(t_cub *clist);
int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 76c0fc5..7b4d1b8 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -232,11 +232,12 @@ enum
# define FT_ERR_RD_TRAP "could not find trap texture file"
# define FT_ERR_WR_BMP "could not export to bmp"
# define FT_ERR_UNDEF_SPRITE "undefined sprite"
+# define FT_ERR_TOO_MUCH_SPRT "too much sprites, limit is 4096"
# define FT_ERR_TOO_MUCH_HEALS "too much heal packs, limit is 64"
# define FT_ERR_TOO_MUCH_TRAPS "too much traps, limit is 512"
-# define FT_ERR_TOO_MUCH_W_ONE "too much weapon one, limit is 1"
-# define FT_ERR_TOO_MUCH_W_TWO "too much weapon two, limit is 1"
-# define FT_ERR_TOO_MUCH_W_THREE "too much weapon three, limit is 1"
+# define FT_ERR_TOO_MUCH_W_ONE "too much weapon one, limit is 4"
+# define FT_ERR_TOO_MUCH_W_TWO "too much weapon two, limit is 4"
+# define FT_ERR_TOO_MUCH_W_THREE "too much weapon three, limit is 4"
/*
** ====== MISSING ERROR MSG ======
@@ -285,10 +286,9 @@ enum
# define FT_ERR_MISS_A_CAPTION "ammo caption"
/*
-** ====== OTHER ======
+** ====== GAMEPLAY ======
*/
-# define FT_PARSE_END_RET 25
# define FT_STRT_LIFE 250
# define FT_TRAP_DAMAGE_AMOUNT 45
# define FT_HEAL_PACK_AMOUNT 20
@@ -298,4 +298,11 @@ enum
# define FT_WEAP_THREE_STRT_AMMO 24
# define FT_WEAP_MAX_AMMO 1000
+/*
+** ====== OTHER ======
+*/
+
+# define FT_PARSE_END_RET 25
+# define FT_TOTAL_SPRT 9
+
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index caf4964..836d168 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -202,15 +202,13 @@ typedef struct s_map
size_t map_w;
size_t map_h;
size_t mapl_len;
- int32_t sprite_nbr[8];
+ int32_t sprite_nbr[FT_TOTAL_SPRT];
uint8_t sprite_var;
uint8_t weapon_var;
- int32_t sprite_order[8][4096];
- int32_t st_o[8];
- int32_t traps_nbr;
+ int32_t sprite_order[FT_TOTAL_SPRT][4096];
+ int32_t st_o[FT_TOTAL_SPRT];
int32_t heals_nbr;
int32_t weaps_nbr[3];
- int32_t traps_order[512];
int32_t heals_order[64];
int32_t weaps_order[3][1];
size_t line_chk;
@@ -275,7 +273,6 @@ typedef struct s_cub
struct s_img tweap[6];
struct s_img tnum[12];
struct s_sprite **sprites;
- struct s_sprite traps[512];
struct s_sprite heals[64];
struct s_sprite **weaps;
struct s_sfx sfx[13];
diff --git a/map/map_one.cub b/map/map_one.cub
index 631a8af..dbe6894 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1024 768
+R 1331 998
NO ./media/img/tex/wood_wall_1_small.xpm
SO ./media/img/tex/wood_wall_1_small.xpm
@@ -10,12 +10,7 @@ F ./media/img/tex/parquet_small.xpm
S ./media/img/sprites/pillar.xpm
S3 ./media/img/sprites/pylon.xpm
-S4 ./media/img/sprites/hey.xpm
-S5 ./media/img/sprites/larry.xpm
-S6 ./media/img/sprites/linus.xpm
-S7 ./media/img/sprites/spikes.xpm
-S8 ./media/img/sprites/wood_chest.xpm
-S9 ./media/img/sprites/first_aid.xpm
+S4 ./media/img/sprites/larry.xpm
T ./media/img/sprites/spikes.xpm
@@ -23,11 +18,11 @@ SH 2
1111111111111111111
1000000000000000001
- 1020304050607080901
1000000000000000001
-111111111111020304050607080901
+ 1000000000000000001
+111111111111000000000000000001
100000000000000000000000000001
-100000000000020304050607080901
+100000000000020304000000T0T001
100000000000000000000000000001
1001000000T0000000000000000001
10110+0+0111000001110000000111
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);