aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-30 17:46:28 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-30 17:46:28 +0200
commitdf8d32e84a60558c38a0d75496c82de657103648 (patch)
tree964706cdd49ea979e42eef21dfa6f5af4299a7ce /src
parentCommit (diff)
download42-cub3d-df8d32e84a60558c38a0d75496c82de657103648.tar.gz
42-cub3d-df8d32e84a60558c38a0d75496c82de657103648.tar.bz2
42-cub3d-df8d32e84a60558c38a0d75496c82de657103648.tar.xz
42-cub3d-df8d32e84a60558c38a0d75496c82de657103648.tar.zst
42-cub3d-df8d32e84a60558c38a0d75496c82de657103648.zip
It's moving!
Diffstat (limited to 'src')
-rw-r--r--src/ft_bad_boy_actions.c59
-rw-r--r--src/ft_big_t.c1
-rw-r--r--src/ft_init_bad_boys.c10
-rw-r--r--src/ft_key_loop.c2
-rw-r--r--src/ft_raycasting.c1
-rw-r--r--src/ft_select_bad_boy_action.c35
-rw-r--r--src/ft_time.c23
7 files changed, 130 insertions, 1 deletions
diff --git a/src/ft_bad_boy_actions.c b/src/ft_bad_boy_actions.c
new file mode 100644
index 0000000..6b7b3bf
--- /dev/null
+++ b/src/ft_bad_boy_actions.c
@@ -0,0 +1,59 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_bad_boy_actions.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdlib.h>
+
+void
+ ft_bb_wait(t_bad_boy *bl, t_sprite *sl, t_map *ml)
+{
+ (void)sl;
+ (void)ml;
+ bl->does = 0;
+}
+
+static void
+ ft_bb_collision(double old_y, double old_x, t_sprite *sl, t_map *ml)
+{
+ if (!ft_ischarset("0e", ml->map[(uint64_t)old_y][(uint64_t)old_x]))
+ {
+ sl->s_pos_x = old_x;
+ sl->s_pos_y = old_y;
+ }
+}
+
+void
+ ft_bb_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml)
+{
+ int8_t r_x;
+ int8_t r_y;
+ const double old_x = sl->s_pos_x;
+ const double old_y = sl->s_pos_y;
+
+ r_x = (rand() % 2 == 1) ? (1) : (-1);
+ r_y = (rand() % 2 == 1) ? (1) : (-1);
+ sl->s_pos_x += 0.3 * (r_x);
+ sl->s_pos_y += 0.3 * (r_y);
+ ft_bb_collision(old_y, old_x, sl, ml);
+ ml->map[(uint64_t)old_y][(uint64_t)old_x] = '0';
+ ml->map[(uint64_t)sl->s_pos_y][(uint64_t)sl->s_pos_x] = 'e';
+ bl->does = 1;
+}
+
+void
+ ft_bb_fire(t_bad_boy *bl, t_sprite *sl, t_map *ml)
+{
+ (void)sl;
+ (void)ml;
+ bl->does = 2;
+}
diff --git a/src/ft_big_t.c b/src/ft_big_t.c
index b4d7e52..5fe65c6 100644
--- a/src/ft_big_t.c
+++ b/src/ft_big_t.c
@@ -70,6 +70,7 @@ void
{
cl->big_t[i][0] = dist_tab[j][k];
cl->big_t[i][1] = (float)ft_set_current_sprite(cl, j);
+ cl->big_t[i][1] += (j == 13) ? (cl->bad_boy[k].does) : (0);
cl->big_t[i][2] = (float)j;
cl->big_t[i][3] = (float)k;
k++;
diff --git a/src/ft_init_bad_boys.c b/src/ft_init_bad_boys.c
index 8ddc9a5..ef67498 100644
--- a/src/ft_init_bad_boys.c
+++ b/src/ft_init_bad_boys.c
@@ -15,6 +15,15 @@
#include <stdint.h>
#include <stdlib.h>
+/*
+** bad_boy[].does list
+** -------------------
+** 0: waiting
+** 1: walking
+** 2: firing
+** 3: be dead
+*/
+
int8_t
ft_init_bad_boys(t_cub *cl)
{
@@ -28,6 +37,7 @@ int8_t
{
cl->bad_boy[i].life = 5;
cl->bad_boy[i].does = 0;
+ cl->bad_boy[i].sleep = 0;
cl->bad_boy[i].act[0] = ft_bb_wait;
cl->bad_boy[i].act[1] = ft_bb_walk;
cl->bad_boy[i].act[2] = ft_bb_fire;
diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c
index 9ca9185..eb020da 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -46,7 +46,7 @@ static uint64_t
}
static void
- ft_collision(float old_y, float old_x, int32_t key, t_cub *cl)
+ ft_collision(double old_y, double old_x, int32_t key, t_cub *cl)
{
uint64_t x;
uint64_t y;
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index cc00963..e01e4ff 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -106,6 +106,7 @@ void
pthread_create(&tid[1], 0x0, ft_floor_cast, (void*)cl);
pthread_join(tid[0], 0x0);
pthread_join(tid[1], 0x0);
+ ft_select_bad_boy_action(cl);
ft_calc_sprite(cl);
if (cl->plist.handles_weapon > -1)
ft_draw_handweap(cl);
diff --git a/src/ft_select_bad_boy_action.c b/src/ft_select_bad_boy_action.c
new file mode 100644
index 0000000..6b3d2ef
--- /dev/null
+++ b/src/ft_select_bad_boy_action.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_select_bad_boy_actions.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:28:51 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:28:51 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdlib.h>
+
+void
+ ft_select_bad_boy_action(t_cub *cl)
+{
+ int8_t i;
+ int8_t r;
+
+ i = 0;
+ while (i < cl->mlist.sprite_nbr[13])
+ {
+ if (cl->bad_boy[i].sleep == 0 && cl->bad_boy[i].life > 0)
+ {
+ r = rand() % 2;
+ cl->bad_boy[i].act[r](&cl->bad_boy[i],
+ &cl->sprites[13][i], &cl->mlist);
+ cl->bad_boy[i].sleep = 1;
+ }
+ i++;
+ }
+}
diff --git a/src/ft_time.c b/src/ft_time.c
index fb0b0d2..d175bbf 100644
--- a/src/ft_time.c
+++ b/src/ft_time.c
@@ -38,9 +38,32 @@ void
}
void
+ ft_bad_boys_time(clock_t before, t_cub *cl)
+{
+ int8_t i;
+ static clock_t dt = 0;
+ clock_t curr;
+
+ curr = clock();
+ dt += curr - before;
+ i = 0;
+ while (i < cl->mlist.sprite_nbr[13])
+ {
+ if (cl->bad_boy[i].sleep == 1 && dt > 0 && ft_clock_to_ms(dt) > 600.0)
+ {
+ cl->bad_boy[i].sleep = 0;
+ dt = 0;
+ }
+ i++;
+ }
+}
+
+void
ft_timings(clock_t before, t_cub *cl)
{
if (cl->plist.fire == 1)
ft_handle_firing(before, cl);
+ if (cl->mlist.sprite_nbr[13] > 0)
+ ft_bad_boys_time(before, cl);
ft_get_fps_count(before, cl);
}