aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_get_player_spawn.c
blob: 86420967f9883015d67050d1cd1cb1ced68f05c2 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_get_player_spawn.c                              :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:28:47 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:28:47 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

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

static void
	ft_get_s_dir(t_player *pl)
{
	pl->dir_y = -pl->dir_y;
	pl->dir_x = -pl->dir_x;
	pl->plane_x = -pl->plane_x;
	pl->plane_y = -pl->plane_y;
}

static void
	ft_get_e_dir(t_player *pl)
{
	float	sav_dir_y;
	float	sav_plane_x;

	sav_dir_y = pl->dir_y;
	pl->dir_y = -pl->dir_x;
	pl->dir_x = -sav_dir_y;
	sav_plane_x = pl->plane_x;
	pl->plane_x = -pl->plane_y;
	pl->plane_y = sav_plane_x;
}

static void
	ft_get_w_dir(t_player *pl)
{
	float	sav_dir_y;
	float	sav_plane_x;

	sav_dir_y = pl->dir_y;
	pl->dir_y = pl->dir_x;
	pl->dir_x = sav_dir_y;
	sav_plane_x = pl->plane_x;
	pl->plane_x = pl->plane_y;
	pl->plane_y = -sav_plane_x;
}

static void
	ft_get_start_side(char c, t_player *pl)
{
	if (c == 'E')
		ft_get_w_dir(pl);
	else if (c == 'S')
		ft_get_s_dir(pl);
	else if (c == 'W')
		ft_get_e_dir(pl);
}

void
	ft_get_player_spawn(t_player *plist, 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 (ft_ischarset(FT_CHRST_SPAWN, clist->mlist.map[y][x]))
			{
				plist->pos_x = x + 0.5;
				plist->pos_y = y + 0.5;
				plist->start_x = plist->pos_x;
				plist->start_y = plist->pos_y;
				ft_get_start_side(clist->mlist.map[y][x], plist);
				return ;
			}
			x++;
		}
		x = 1;
		y++;
	}
}