aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d_defines.h2
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--src/ft_check_missing.c26
-rw-r--r--src/ft_death_screen.c2
-rw-r--r--src/ft_draw_hud.c95
-rw-r--r--src/ft_error.c9
-rw-r--r--src/ft_tex_init.c5
7 files changed, 90 insertions, 51 deletions
diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h
index e52eb7a..1aa380f 100644
--- a/inc/cub3d_defines.h
+++ b/inc/cub3d_defines.h
@@ -93,6 +93,7 @@ enum
# 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"
/*
** ====== SOUNDS ======
@@ -211,6 +212,7 @@ enum
# 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_HUD_BACK "missing HUD background image"
/*
** ====== OTHER ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 9c61907..a08d7b2 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -250,7 +250,7 @@ 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_img tlist[17];
struct s_sprite **sprites;
struct s_sprite traps[512];
struct s_sfx sfx;
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
index a17bdea..4d06276 100644
--- a/src/ft_check_missing.c
+++ b/src/ft_check_missing.c
@@ -14,15 +14,6 @@
#include <cub3d.h>
#include <unistd.h>
-int
- ft_missing_error(const char *err, t_cub *clist)
-{
- ft_dprintf(STDERR_FILENO, "Error\n");
- ft_dprintf(STDERR_FILENO,
- "\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err);
- return (ft_exit(FT_ERR_MISSING, clist));
-}
-
static int
ft_check_missing_sfx(t_cub *clist)
{
@@ -60,6 +51,18 @@ static int
}
static int
+ ft_check_missing_tex_defines(t_cub *clist)
+{
+ if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 ||
+ ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist));
+ if (ft_check_not_found(FT_HUD_BACK_PATH) < 0 ||
+ ft_check_ext(FT_HUD_BACK_PATH, ".xpm") < 0)
+ return (ft_missing_error(FT_ERR_MISS_HUD_BACK, clist));
+ return (ft_check_missing_sprites(clist));
+}
+
+static int
ft_check_missing_norme(t_cub *clist)
{
if (!clist->mlist.isftex)
@@ -82,10 +85,7 @@ static int
return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));
if (clist->mlist.istraps && !clist->mlist.traps_path[0])
return (ft_missing_error(FT_ERR_MISS_TRAP, clist));
- if (ft_check_not_found(FT_DEATH_SCREEN_PATH) < 0 ||
- ft_check_ext(FT_DEATH_SCREEN_PATH, ".xpm") < 0)
- return (ft_missing_error(FT_ERR_MISS_DEATH_SCREEN, clist));
- return (ft_check_missing_sprites(clist));
+ return (ft_check_missing_tex_defines(clist));
}
int
diff --git a/src/ft_death_screen.c b/src/ft_death_screen.c
index cc299d1..e8ddc3a 100644
--- a/src/ft_death_screen.c
+++ b/src/ft_death_screen.c
@@ -25,10 +25,10 @@ static void
while (y < (int32_t)cl->wlist.y_size)
{
x = 0;
+ cl->death_screen.tex_y = ((y * y_ratio) >> 16);
while (x < (int32_t)cl->wlist.x_size)
{
cl->death_screen.tex_x = ((x * x_ratio) >> 16);
- cl->death_screen.tex_y = ((y * y_ratio) >> 16);
cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
(uint8_t)cl->death_screen.ptr[cl->death_screen.tex_x * 4 + 4 *
cl->death_screen.img_w * cl->death_screen.tex_y];
diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c
index eb329c6..3db6b60 100644
--- a/src/ft_draw_hud.c
+++ b/src/ft_draw_hud.c
@@ -13,32 +13,67 @@
#include <cub3d.h>
#include <stdint.h>
+/* static void */
+/* ft_draw_minimap_back(size_t map_h, size_t map_w, t_win *wl, t_cub *cl) */
+/* { */
+/* const uint16_t scl = cl->mlist.scale; */
+/* uint32_t x; */
+/* uint32_t y; */
+/* int32_t col; */
+
+/* col = 0x00353535; */
+/* x = 0; */
+/* y = wl->y_size - (map_h * scl) - 20; */
+/* while (x < (map_w * scl) + 20 + (3 * scl)) */
+/* { */
+/* while (y < wl->y_size) */
+/* { */
+/* *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col; */
+/* if (!(y % 3)) */
+/* { */
+/* if (col < 0x00aaaaaa) */
+/* col += 0x00010101; */
+/* } */
+/* y++; */
+/* } */
+/* col = 0x00353535; */
+/* y = wl->y_size - (map_h * scl) - 20; */
+/* x++; */
+/* } */
+/* } */
+
static void
- ft_draw_life_back(t_win *wl, t_cub *cl)
+ ft_draw_minimap_back_image(uint16_t h, uint16_t w, t_cub *cl)
{
- const uint16_t scl = cl->mlist.scale;
- uint32_t x;
- uint32_t y;
- int32_t col;
+ int32_t x_ratio;
+ int32_t y_ratio;
+ int16_t x;
+ int16_t y;
- col = 0x00353535;
- x = (cl->mlist.map_w * scl) + 20;
- y = wl->y_size - (cl->mlist.map_h * scl) - 20;
- while (x < ((cl->mlist.map_w * scl) + 20) + (3 * scl))
+ x_ratio = (int)((cl->tlist[16].img_w << 16) / w) + 1;
+ y_ratio = (int)((cl->tlist[16].img_h << 16) / h) + 1;
+ y = cl->wlist.y_size - (cl->mlist.map_h * cl->mlist.scale) - 20;
+ while (y < (int32_t)cl->wlist.y_size)
{
- while (y < wl->y_size)
+ x = 0;
+ cl->tlist[16].tex_y = (y * y_ratio) >> 16;
+ while (x < (uint16_t)((cl->mlist.map_w
+ * cl->mlist.scale) + 20 + (3 * cl->mlist.scale)))
{
- *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col;
- if (!(y % 3))
- {
- if (col < 0x00aaaaaa)
- col += 0x00010101;
- }
- y++;
+ cl->tlist[16].tex_x = (x * x_ratio) >> 16;
+ cl->img.ptr[x * 4 + (cl->img.sizeline * y)] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y];
+ cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 1];
+ cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y + 2];
+ cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;
+ x++;
}
- col = 0x00353535;
- y = wl->y_size - (cl->mlist.map_h * scl) - 20;
- x++;
+ y++;
}
}
@@ -46,29 +81,18 @@ static void
ft_draw_minimap_back(size_t map_h, size_t map_w, t_win *wl, t_cub *cl)
{
const uint16_t scl = cl->mlist.scale;
- uint32_t x;
- uint32_t y;
- int32_t col;
+ uint16_t x;
+ uint16_t y;
- col = 0x00353535;
x = 0;
y = wl->y_size - (map_h * scl) - 20;
- while (x < (map_w * scl) + 20)
+ while (x < (map_w * scl) + 20 + (3 * scl))
{
while (y < wl->y_size)
- {
- *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = col;
- if (!(y % 3))
- {
- if (col < 0x00aaaaaa)
- col += 0x00010101;
- }
y++;
- }
- col = 0x00353535;
- y = wl->y_size - (map_h * scl) - 20;
x++;
}
+ ft_draw_minimap_back_image(y, x, cl);
}
static void
@@ -107,7 +131,6 @@ int8_t
ft_draw_minimap_back(clist->mlist.map_h,
clist->mlist.map_w, &clist->wlist, clist);
ft_draw_map(clist->mlist.map, clist);
- ft_draw_life_back(&clist->wlist, clist);
ft_draw_life_bar(&clist->wlist, clist);
if (clist->mlist.isnlvl)
{
diff --git a/src/ft_error.c b/src/ft_error.c
index 87be01e..0f2bc97 100644
--- a/src/ft_error.c
+++ b/src/ft_error.c
@@ -34,3 +34,12 @@ int
errmsg);
return (ft_exit(FT_RET_MAP_ERR, clist));
}
+
+int
+ ft_missing_error(const char *err, t_cub *clist)
+{
+ ft_dprintf(STDERR_FILENO, "Error\n");
+ ft_dprintf(STDERR_FILENO,
+ "\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err);
+ return (ft_exit(FT_ERR_MISSING, clist));
+}
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 298fbfc..fe8aadd 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -35,6 +35,7 @@
** 13 : sprite 8
** 14 : sprite 9
** 15 : trap
+** 16 : HUD back
*/
static void
@@ -72,6 +73,10 @@ static void
cl->tlist[7].ptr = mlx_get_data_addr(cl->tlist[7].img,
&cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
}
+ cl->tlist[16].img = mlx_xpm_file_to_image(cl->wlist.wlx,
+ FT_HUD_BACK_PATH, &cl->tlist[16].img_w, &cl->tlist[16].img_h);
+ cl->tlist[16].ptr = mlx_get_data_addr(cl->tlist[16].img,
+ &cl->tlist[16].bpp, &cl->tlist[16].sizeline, &cl->tlist[16].endian);
cl->walltexgood = 1;
if (cl->mlist.sprite_var > 1)
{