aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_bad_boy_actions.c
blob: 4e332cc31bcbf06f25c5e11a3222ae4f3c8ee751 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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 <mlx.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;
}

/*
** rand(3) index list
** ------------------
** rand() 0 - 3
** 0: goes south
** 1: goes north
** 2: goes west
** 3: goes east
*/

void
	ft_bb_walk(t_bad_boy *bl, t_sprite *sl, t_map *ml)
{
	int8_t			r;
	const double	old_x = sl->s_pos_x;
	const double	old_y = sl->s_pos_y;

	if (FT_OS == 2)
		r = random() % 4;
	else
		r = rand() % 4;
	sl->r = r;
	if (r == 0)
		sl->s_pos_y += FT_ENMY_MOVE_SPEED;
	else if (r == 1)
		sl->s_pos_y -= FT_ENMY_MOVE_SPEED;
	else if (r == 2)
		sl->s_pos_x -= FT_ENMY_MOVE_SPEED;
	else if (r == 3)
		sl->s_pos_x += FT_ENMY_MOVE_SPEED;
	ft_bb_collision(old_y, old_x, sl, ml);
	ml->map[llround(old_y)][llround(old_x)] = '0';
	ml->map[llround(sl->s_pos_y)][llround(sl->s_pos_x)] = 'e';
	bl->does = 1;
}

/*
** skelton misses one random
** shot out of four
*/

void
	ft_check_bad_boy_shoot(t_cub *cl)
{
	int8_t	i;
	int8_t	r;

	i = 0;
	while (i < cl->mlist.sprite_nbr[13])
	{
		if (FT_OS == 2)
			r = random() % 4;
		else
			r = rand() % 4;
		if (cl->bad_boy[i].does == 2 && cl->bad_boy[i].sleep == 0)
		{
			cl->sfx[15].sfx_play(cl->sfx);
			if (r != 3)
			{
				if (FT_OS == 1)
					ft_macos_suffer_animation(FT_ENMY_DAMAGE_AMOUNT, cl);
				else
					ft_linux_suffer_animation(FT_ENMY_DAMAGE_AMOUNT, cl);
			}
		}
		i++;
	}
}

void
	ft_bb_fire(t_bad_boy *bl, t_sprite *sl, t_map *ml)
{
	(void)sl;
	(void)ml;
	bl->does = 2;
}