diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-30 17:46:28 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-30 17:46:28 +0200 |
commit | df8d32e84a60558c38a0d75496c82de657103648 (patch) | |
tree | 964706cdd49ea979e42eef21dfa6f5af4299a7ce /src/ft_bad_boy_actions.c | |
parent | Commit (diff) | |
download | 42-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/ft_bad_boy_actions.c')
-rw-r--r-- | src/ft_bad_boy_actions.c | 59 |
1 files changed, 59 insertions, 0 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; +} |