aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_weapon_spawn.c
blob: a54d2b6057bb2ad677b9844294b5c5299e419154 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_get_weapon_spawn.c                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/28 20:54:28 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/28 20:54:29 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <stdint.h>

static void
	ft_get_weapon_id_spawn(uint8_t id, size_t y, size_t x, t_cub *clist)
{
	clist->mlist.weaps_nbr[id]++;
	if (clist->mlist.weaps_nbr[id] > 1)
	{
		if (id == 0)
			ft_map_error(FT_ERR_TOO_MUCH_W_ONE, clist);
		else
			ft_map_error(FT_ERR_TOO_MUCH_W_TWO, clist);
	}
	clist->weaps[id][0].s_pos_x = x;
	clist->weaps[id][0].s_pos_y = y;
	clist->weaps[id][0].current_sprite = 18 + id;
	clist->mlist.weapon_var++;
}

void
	ft_get_weapon_spawn(t_cub *clist)
{
	size_t	x;
	size_t	y;

	x = 1;
	y = 1;
	while (clist->mlist.map[y])
	{
		while (clist->mlist.map[y][x])
		{
			if (clist->mlist.map[y][x] == '!')
				ft_get_weapon_id_spawn(0, y, x, clist);
			else if (clist->mlist.map[y][x] == '@')
				ft_get_weapon_id_spawn(1, y, x, clist);
			x++;
		}
		x = 1;
		y++;
	}
}