aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/cub3d.h16
-rw-r--r--inc/cub3d_defines.h125
-rw-r--r--inc/cub3d_structs.h44
3 files changed, 111 insertions, 74 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index a7f6b7d..fa42b4f 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -17,6 +17,7 @@
#include <cub3d_structs.h>
#include <stddef.h>
#include <stdint.h>
+#include <time.h>
/*
** ====== STRUCTS ======
@@ -35,6 +36,7 @@ t_bmp_file ft_init_bmp(void);
t_bmp_info ft_init_bmp_info(void);
t_rgb ft_hex_to_og_rgb(uint32_t color);
int8_t ft_init_sfx(t_sfx *sfx);
+int8_t ft_init_sprites(t_sprite ***sprites);
/*
** ====== HOOKS ======
@@ -82,6 +84,8 @@ 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_draw_skybox(t_cub *cl);
void ft_macos_suffer_animation(t_cub *cl);
void ft_linux_suffer_animation(t_cub *cl);
@@ -116,6 +120,7 @@ size_t ft_get_map_h(char **map);
size_t ft_get_map_w(char **map);
void ft_get_sprite_spawn(t_cub *clist);
void ft_get_trap_spawn(t_cub *clist);
+void ft_get_heal_spawn(t_cub *clist);
int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist);
int8_t ft_check_ext(const char *filep, const char *ext);
int8_t ft_check_not_found(const char *path);
@@ -150,8 +155,15 @@ void ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl);
*/
void ft_sfx_death(t_cub *cl);
-void ft_sfx_trap(t_cub *cl);
+void ft_sfx_footstep(t_cub *cl);
void ft_sfx_new_level(t_cub *cl);
+void ft_sfx_pain(t_cub *cl);
+void ft_sfx_trap(t_cub *cl);
+void *ft_sfx_death_thread(void *vargp);
+void *ft_sfx_footstep_thread(void *vargp);
+void *ft_sfx_new_lvl_thread(void *vargp);
+void *ft_sfx_pain_thread(void *vargp);
+void *ft_sfx_trap_thread(void *vargp);
/*
** ====== OTHER ======
@@ -171,5 +183,7 @@ uint32_t ft_rgb_to_hex(t_rgb rgb);
t_bmp_rgb ft_hex_to_rgb(uint32_t color);
uint32_t ft_darken(t_rgb rgb, t_cub *cl);
void ft_death_screen(t_cub *cl);
+void ft_get_fps_count(clock_t delta_time, t_cub *cl);
+void ft_find_item(t_player *pl, t_map *ml, t_cub *cl);
# endif
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index 0cd15fa..e82fef5 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -16,6 +16,17 @@
/*
** ====== RETURN VALUES ======
*/
+
+/*
+** ret vals:
+** 1: no argv[1]
+** 2: failed structs init
+** 3: failed mlx init
+** 4: map error
+** 5: no map
+** 6: read error
+*/
+
enum
{
FT_RET_FINE,
@@ -31,16 +42,6 @@ enum
} retvals;
/*
-** ret vals:
-** 1: no argv[1]
-** 2: failed structs init
-** 3: failed mlx init
-** 4: map error
-** 5: no map
-** 6: read error
-*/
-
-/*
** ====== OS ======
*/
@@ -67,7 +68,7 @@ enum
# define FT_F1_KEY 122
# define FT_TAB_KEY 48
# define FT_ESC_KEY 53
-/* TODO macOS return key */
+/* TODO: macOS return key */
# else
# define FT_W_KEY 119
# define FT_A_KEY 97
@@ -86,11 +87,15 @@ enum
*/
# define FT_SFX_DEATH_PATH "./media/sound/sfx/death_screen.wav"
+# define FT_SFX_FS_ONE_PATH "./media/sound/sfx/footstep_one.wav"
+# define FT_SFX_FS_TWO_PATH "./media/sound/sfx/footstep_two.wav"
# define FT_SFX_N_LVL_PATH "./media/sound/sfx/next_lvl.wav"
# define FT_SFX_SCR_ONE_PATH "./media/sound/sfx/scream_one.wav"
# define FT_SFX_SCR_TWO_PATH "./media/sound/sfx/scream_two.wav"
# define FT_SFX_TRAP_PATH "./media/sound/sfx/trap.wav"
# define FT_DEATH_SCREEN_PATH "./media/img/death_screen.xpm"
+# define FT_HUD_BACK_PATH "./media/img/plate_small.xpm"
+# define FT_HEAL_PACK_PATH "./media/img/first_aid.xpm"
/*
** ====== SOUNDS ======
@@ -114,7 +119,7 @@ enum
** ====== COLLISION ======
*/
-# define FT_COLL_MULT 0.225
+# define FT_COLL_MULT 0.3
/*
** ====== SCREEN ======
@@ -129,12 +134,13 @@ enum
*/
# define FT_CHRST_VALID_PARSE "RNSEWFCLMT"
-# define FT_CHRST_MAP_ENTRY "0123456789NSEWLT "
+# define FT_CHRST_MAP_ENTRY "0123456789NSEWLT+ "
# define FT_CHRST_SPRITES "23456789"
# define FT_CHRST_SPAWN "NSEW"
-# define FT_CHRST_MAP_NON_WALL "023456789NESWLT"
+# define FT_CHRST_MAP_NON_WALL "023456789NESWLT+"
# define FT_CHRST_COLLISION "123456789 "
# define FT_CHRST_DETECT "1L"
+# define FT_CHRST_ITEM "+!@"
/*
** ====== BMP ======
@@ -148,43 +154,45 @@ enum
** ====== MAP ERROR MSG ======
*/
-# define FT_ERR_ALLOCATE "Allocation error"
-# define FT_ERR_READ "read error"
-# define FT_ERR_ARGS "too many or to few arguments"
-# define FT_ERR_ARGV "Bad arguments"
-# define FT_ERR_RES_SMALL "resolution is too small, 50x50 minimum pls"
-# define FT_ERR_RES_ALPHA "resolution should be digits only"
-# define FT_ERR_SH_ALPHA "shadow amount should be digits only"
-# define FT_ERR_SH_RANGE "shadow should be set between 0 - 20"
-# define FT_ERR_NOT_A_CUB "given map is not a .cub"
-# define FT_ERR_NOT_A_XPM "given texture is not a .xpm"
-# define FT_ERR_NOT_A_WAV "given sound file is not a .wav"
-# define FT_ERR_COLOR_ALPHA "colors should be digits only"
-# define FT_ERR_COLOR_MAX "colors should be maximum 255"
-# define FT_ERR_COLOR_ARGS "colors should be three numbers with commas"
-# define FT_ERR_SPRITE_DUMB "bad sprite order"
-# define FT_ERR_UNFINISHED "no map"
-# define FT_ERR_MAP_LEN "map length inconsistency"
-# define FT_ERR_ILL_ENTRY "illegal map entry"
-# define FT_ERR_ALR_SET "duplicate entry"
-# define FT_ERR_ILL_MAP "map contains illegal char"
-# define FT_ERR_MULT_SPAWN "multiple spawn points"
-# define FT_ERR_MULT_NLVL "multiple spawn new level access points"
-# define FT_ERR_NO_MAP "No map"
-# define FT_ERR_MAP_WALLS "bad space or map is not surrounded by walls"
-# define FT_ERR_MAP_EMPL "empty line in map"
-# define FT_ERR_MAP_L_L "last line is invalid"
-# define FT_ERR_RD_NO "could not find north side texture file"
-# define FT_ERR_RD_SO "could not find south side texture file"
-# define FT_ERR_RD_EA "could not find east side texture file"
-# define FT_ERR_RD_WE "could not find west side texture file"
-# define FT_ERR_RD_SP "could not find sprite texture file"
-# define FT_ERR_RD_SB "could not find skybox file"
-# define FT_ERR_RD_NL_TEX "could not find next level texture file"
-# define FT_ERR_RD_NL_MAP "could not find next level map file"
-# define FT_ERR_RD_MUSIC "could not find music file"
-# define FT_ERR_RD_TRAP "could not find trap texture file"
-# define FT_ERR_WR_BMP "could not export to bmp"
+# define FT_ERR_ALLOCATE "Allocation error"
+# define FT_ERR_READ "read error"
+# define FT_ERR_ARGS "too many or to few arguments"
+# define FT_ERR_ARGV "Bad arguments"
+# define FT_ERR_RES_SMALL "resolution is too small, 50x50 minimum pls"
+# define FT_ERR_RES_ALPHA "resolution should be digits only"
+# define FT_ERR_SH_ALPHA "shadow amount should be digits only"
+# define FT_ERR_SH_RANGE "shadow should be set between 0 - 20"
+# define FT_ERR_NOT_A_CUB "given map is not a .cub"
+# define FT_ERR_NOT_A_XPM "given texture is not a .xpm"
+# define FT_ERR_NOT_A_WAV "given sound file is not a .wav"
+# define FT_ERR_COLOR_ALPHA "colors should be digits only"
+# define FT_ERR_COLOR_MAX "colors should be maximum 255"
+# define FT_ERR_COLOR_ARGS "colors should be three numbers with commas"
+# define FT_ERR_SPRITE_DUMB "bad sprite order"
+# define FT_ERR_UNFINISHED "no map"
+# define FT_ERR_MAP_LEN "map length inconsistency"
+# define FT_ERR_ILL_ENTRY "illegal map entry"
+# define FT_ERR_ALR_SET "duplicate entry"
+# define FT_ERR_ILL_MAP "map contains illegal char"
+# define FT_ERR_MULT_SPAWN "multiple spawn points"
+# define FT_ERR_MULT_NLVL "multiple spawn new level access points"
+# define FT_ERR_NO_MAP "No map"
+# define FT_ERR_MAP_WALLS "bad space or map is not surrounded by walls"
+# define FT_ERR_MAP_EMPL "empty line in map"
+# define FT_ERR_MAP_L_L "last line is invalid"
+# define FT_ERR_RD_NO "could not find north side texture file"
+# define FT_ERR_RD_SO "could not find south side texture file"
+# define FT_ERR_RD_EA "could not find east side texture file"
+# define FT_ERR_RD_WE "could not find west side texture file"
+# define FT_ERR_RD_SP "could not find sprite texture file"
+# define FT_ERR_RD_SB "could not find skybox file"
+# define FT_ERR_RD_NL_TEX "could not find next level texture file"
+# define FT_ERR_RD_NL_MAP "could not find next level map file"
+# define FT_ERR_RD_MUSIC "could not find music file"
+# define FT_ERR_RD_TRAP "could not find trap texture file"
+# define FT_ERR_WR_BMP "could not export to bmp"
+# 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"
/*
** ====== MISSING ERROR MSG ======
@@ -203,17 +211,20 @@ enum
# define FT_ERR_MISS_CEIL_C "ceiling color"
# define FT_ERR_MISS_PLAYER_SPAWN "player spawn"
# define FT_ERR_MISS_TRAP "traps"
-# define FT_ERR_MISS_SFX_DEATH "missing sound effect death"
-# define FT_ERR_MISS_SFX_N_LVL "missing sound effect new level"
-# define FT_ERR_MISS_SFX_SCR_ONE "missing sound effect scream one"
-# define FT_ERR_MISS_SFX_SCR_TWO "missing sound effect scream two"
-# define FT_ERR_MISS_SFX_TRAP "missing sound effect trap"
-# define FT_ERR_MISS_DEATH_SCREEN "missing death screen image"
+# define FT_ERR_MISS_SFX_DEATH "sound effect death"
+# define FT_ERR_MISS_SFX_N_LVL "sound effect new level"
+# define FT_ERR_MISS_SFX_SCR_ONE "sound effect scream one"
+# define FT_ERR_MISS_SFX_SCR_TWO "sound effect scream two"
+# define FT_ERR_MISS_SFX_TRAP "sound effect trap"
+# define FT_ERR_MISS_DEATH_SCREEN "death screen image"
+# define FT_ERR_MISS_HUD_BACK "HUD background image"
+# define FT_ERR_MISS_HEAL_PACK "heal pack image"
/*
** ====== OTHER ======
*/
# define FT_PARSE_END_RET 25
+# define FT_HEAL_PACK_AMOUNT 10
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 29c6ac7..fc3eead 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -14,9 +14,9 @@
# define CUB3D_STRUCTS_H
#include <stddef.h>
-#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
+#include <pthread.h>
typedef struct s_win
{
@@ -57,15 +57,23 @@ typedef struct s_bmp_info
typedef struct s_sfx
{
- char **death;
- char **new_lvl;
- char **pain_one;
- char **pain_two;
- char **trap;
- pid_t death_pid;
- pid_t new_lvl_pid;
- pid_t pain_pid;
- pid_t trap_pid;
+ char *death;
+ char *footstep_one;
+ char *footstep_two;
+ char *new_lvl;
+ char *pain_one;
+ char *pain_two;
+ char *trap;
+ pthread_t death_tid;
+ pthread_t footstep_tid;
+ pthread_t new_lvl_tid;
+ pthread_t pain_tid;
+ pthread_t trap_tid;
+ pthread_mutex_t death_mutex;
+ pthread_mutex_t footstep_mutex;
+ pthread_mutex_t new_lvl_mutex;
+ pthread_mutex_t pain_mutex;
+ pthread_mutex_t trap_mutex;
} t_sfx;
typedef struct s_bmp_rgb
@@ -105,8 +113,8 @@ typedef struct s_sprite
int32_t y;
int32_t tex_x;
int32_t tex_y;
- int32_t s_pos_x;
- int32_t s_pos_y;
+ uint64_t s_pos_x;
+ uint64_t s_pos_y;
double spritex;
double spritey;
int32_t spriteheight;
@@ -189,7 +197,6 @@ typedef struct s_map
char *mapl;
char **sprite_path;
char **map;
- char **mcmd_words;
int8_t x_step;
int8_t y_step;
size_t map_w;
@@ -199,7 +206,9 @@ typedef struct s_map
uint8_t sprite_var;
int32_t sprite_order[8][4096];
int32_t traps_nbr;
+ int32_t heals_nbr;
int32_t traps_order[512];
+ int32_t heals_order[64];
size_t line_chk;
size_t map_start;
uint8_t isspawn;
@@ -209,6 +218,7 @@ typedef struct s_map
uint8_t isctex;
uint8_t isskybox;
uint8_t istraps;
+ uint8_t isheals;
uint8_t darklvl;
uint8_t scale;
int8_t topsp;
@@ -230,7 +240,8 @@ typedef struct s_cub
char *const *envp;
char errmsg[64];
int32_t key_input[5];
- pid_t mpid;
+ char fps_count[9];
+ pthread_t mtid;
int (*key_ptr[6])(struct s_cub*);
int8_t (*get_ptr[14])(char**, struct s_cub*);
char ref[22][3];
@@ -242,9 +253,10 @@ typedef struct s_cub
struct s_img death_screen;
struct s_rgb f_rgb;
struct s_rgb c_rgb;
- struct s_img tlist[16];
- struct s_sprite sprites[8][4096];
+ struct s_img tlist[18];
+ struct s_sprite **sprites;
struct s_sprite traps[512];
+ struct s_sprite heals[64];
struct s_sfx sfx;
} t_cub;