aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_bad_boy_actions.c
blob: 775e9176859f2beac97f1f84b996676f93846ce5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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>
#include <math.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;

	if (FT_OS == 2)
	{
		r_x = (random() % 2 == 1) ? (1) : (-1);
		r_y = (random() % 2 == 1) ? (1) : (-1);
	}
	else
	{
		r_x = (rand() % 2 == 1) ? (1) : (-1);
		r_y = (rand() % 2 == 1) ? (1) : (-1);
	}
	sl->s_pos_x += (0.1 * r_x);
	sl->s_pos_y += (0.1 * r_y);
	ft_bb_collision(old_y, old_x, sl, ml);
	ml->map[lround(old_y)][lround(old_x)] = '0';
	ml->map[lround(sl->s_pos_y)][lround(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;
}