aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 12:38:21 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-11 12:38:21 +0100
commitb236416db21d03f7749e1c80d5b7abee70ea07d5 (patch)
tree69d7ddceef69415ec70bf383f1365552b8b8c7e1
parentPerfect collision on them traps (diff)
download42-cub3d-b236416db21d03f7749e1c80d5b7abee70ea07d5.tar.gz
42-cub3d-b236416db21d03f7749e1c80d5b7abee70ea07d5.tar.bz2
42-cub3d-b236416db21d03f7749e1c80d5b7abee70ea07d5.tar.xz
42-cub3d-b236416db21d03f7749e1c80d5b7abee70ea07d5.tar.zst
42-cub3d-b236416db21d03f7749e1c80d5b7abee70ea07d5.zip
Pretty cool animation
-rw-r--r--Makefile1
-rw-r--r--inc/cub3d.h1
-rw-r--r--inc/cub3d_structs.h1
-rw-r--r--src/ft_draw_hud.c2
-rw-r--r--src/ft_floor_cast.c2
-rw-r--r--src/ft_init_lists.c1
-rw-r--r--src/ft_key_loop.c1
-rw-r--r--src/ft_suffer_animation.c44
8 files changed, 51 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6c0dfb2..7b374c8 100644
--- a/Makefile
+++ b/Makefile
@@ -83,6 +83,7 @@ SRCS_NAME += ft_init_funptr.c
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 = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 9487883..4172c9d 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -78,6 +78,7 @@ void ft_sprite_height(t_cub *cl, t_sprite *sprite);
void ft_calc_sprite(t_cub *cl);
void ft_draw_sprite(t_cub *cl, t_sprite *sprite);
void ft_draw_skybox(t_cub *cl);
+void ft_suffer_animation(t_cub *cl);
/*
** ====== PARSING ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 5ba3b38..7665e96 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -120,6 +120,7 @@ typedef struct s_player
float cam_x;
float plane_x;
float plane_y;
+ int8_t life;
} t_player;
typedef struct s_ray
diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c
index 4ae497a..486112d 100644
--- a/src/ft_draw_hud.c
+++ b/src/ft_draw_hud.c
@@ -65,7 +65,7 @@ static void
while (y < clist->wlist.y_size - (clist->mlist.map_h * scl) - 20)
{
*(int*)(clist->img.ptr +
- ((uint8_t)x * 4 + (y * clist->img.sizeline))) = col;
+ ((uint16_t)x * 4 + (y * clist->img.sizeline))) = col;
y++;
}
y = clist->wlist.y_size - (clist->mlist.map_h * scl) - 45;
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index b6c7e72..2eda9d8 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -17,7 +17,7 @@ static void
ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x)
{
*(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
+ (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
}
static void
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 8ba9a13..79b0d14 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -43,6 +43,7 @@ t_player
plist.dir_y = 0;
plist.plane_x = 0;
plist.plane_y = 0.66;
+ plist.life = 100;
return (plist);
}
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index d19daaa..29718df 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -58,6 +58,7 @@ static void
{
pl->pos_x = old_x + ((old_x - x) / 4);
pl->pos_y = old_y + ((old_y - y) / 4);
+ ft_suffer_animation(cl);
x = ft_find_x(key, pl);
y = ft_find_y(key, pl);
}
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
new file mode 100644
index 0000000..bb69b4b
--- /dev/null
+++ b/src/ft_suffer_animation.c
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_key_loop.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */
+/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <mlx.h>
+#include <stdint.h>
+
+void
+ ft_suffer_animation(t_cub *cl)
+{
+ uint16_t x;
+ uint16_t y;
+
+ cl->img.img = mlx_new_image(cl->wlist.wlx,
+ cl->wlist.x_size, cl->wlist.y_size);
+ cl->img.ptr = mlx_get_data_addr(cl->img.img, &cl->img.bpp,
+ &cl->img.sizeline, &cl->img.endian);
+ x = 0;
+ y = 0;
+ while (y < cl->wlist.y_size)
+ {
+ while (x < cl->wlist.x_size)
+ {
+ *(int*)(cl->img.ptr +
+ (x * 4 + (y * cl->img.sizeline))) = 0x00ce1212;
+ x++;
+ }
+ x = 0;
+ y++;
+ }
+ mlx_put_image_to_window(cl->wlist.wlx,
+ cl->wlist.winptr, cl->img.img, 0, 0);
+ mlx_destroy_image(cl->wlist.wlx, cl->img.img);
+}