aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_hud.c
blob: 6e4f86f83c77cc2770991c2747b6a966d1ffafe9 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_draw_hud.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/22 20:02:47 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/22 20:02:48 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

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

static void
	ft_draw_stage_back(t_cub *clist)
{
	float			x;
	uint32_t		y;
	int32_t			col;
	uint16_t		x_dest;
	const uint16_t	scl = clist->mlist.scale;

	col = 0x00353535;
	x = 0;
	y = clist->wlist.y_size - (clist->mlist.map_h * scl) - 45;
	x_dest = 1.5 * clist->mlist.scale + 70;
	while (x_dest > (clist->mlist.map_w * scl) + 20)
		x_dest--;
	while (x < x_dest)
	{
		while (y < clist->wlist.y_size - (clist->mlist.map_h * scl) - 20)
		{
			*(int*)(clist->img.ptr +
				((uint16_t)x * 4 + (y * clist->img.sizeline))) = col;
			y++;
		}
		y = clist->wlist.y_size - (clist->mlist.map_h * scl) - 45;
		x += 1.0;
	}
}

void
*ft_ammo_back_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_ammo_back(clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_minimap_back_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_minimap_back(clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_map_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_map(clist->mlist.map, clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_life_bar_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_life_bar(clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_ammo_bar_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_ammo_bar(clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_health_cap_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_health_caption(clist);
	pthread_exit(0x0);
	return (0x0);
}

void
*ft_ammo_cap_thread(void *vargp)
{
	t_cub	*clist;

	clist = (t_cub *)vargp;
	ft_draw_ammo_caption(clist);
	pthread_exit(0x0);
	return (0x0);
}

int8_t
	ft_draw_hud(t_cub *clist)
{
	pthread_t	tid[7];

	pthread_create(&tid[0], 0x0, ft_ammo_back_thread, (void*)clist);
	pthread_create(&tid[1], 0x0, ft_minimap_back_thread, (void*)clist);
	pthread_join(tid[0], 0x0);
	pthread_join(tid[1], 0x0);
	pthread_create(&tid[2], 0x0, ft_map_thread, (void*)clist);
	pthread_create(&tid[3], 0x0, ft_life_bar_thread, (void*)clist);
	pthread_create(&tid[4], 0x0, ft_ammo_bar_thread, (void*)clist);
	pthread_create(&tid[5], 0x0, ft_health_cap_thread, (void*)clist);
	pthread_create(&tid[6], 0x0, ft_ammo_cap_thread, (void*)clist);
	pthread_join(tid[2], 0x0);
	pthread_join(tid[3], 0x0);
	pthread_join(tid[4], 0x0);
	pthread_join(tid[5], 0x0);
	pthread_join(tid[6], 0x0);
	if (clist->mlist.isnlvl)
	{
		ft_draw_stage_back(clist);
	}
	return (0);
}