-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.c
151 lines (142 loc) · 4.02 KB
/
cub3d.c
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
147
148
149
150
151
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmerchin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/10 10:56:04 by bmerchin #+# #+# */
/* Updated: 2021/01/12 16:17:14 by bmerchin ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
/*
** List data->security possible errors
** security 0 : Resolution
** security 1 : Floor
** security 2 : Ceiling
** security 3 : Sprite
** security 4 : NO
** security 5 : SO
** security 6 : WE
** security 7 : EA
** security 8 : Starting Direction in the map
** security 9 : If there is a missing wall
** security 10 : Wrong character
** security 11 : Texture opening check
*/
void raycasting_calculation(t_data *data)
{
int i;
i = 0;
while (i < data->x_screen_size)
{
raycasting_initialize(data, &i);
raycasting_move_until_wall(data);
raycasting_line_position(data);
put_column_image(data, i);
data->buff[i] = data->dist_wall;
data->hit = 0;
i++;
}
sprite_dist_calc(data);
sort_sprite(data);
sprite(data);
save_image(data);
}
int render_next_frame(t_data *data)
{
if (data->save == 0)
mlx_put_image_to_window(data->mlx, data->win, data->img, 0, 0);
victory_exit_check(data);
if (data->life == 0)
{
echo_the_end(data);
return (0);
}
move_according_to_key_press(data);
heal_at_spawn(data);
attack_if_possible(data);
raycasting_calculation(data);
if (MINIMAP_SIZE * data->x_map <= data->x_screen_size
&& MINIMAP_SIZE * data->y_map <= data->y_screen_size && BONUS)
add_minimap_and_company(data);
data->frame++;
open_door(data);
if (data->frame % 40 > 19)
data->time = 1;
else
data->time = 0;
return (0);
}
void run_mlx(t_data *data)
{
data->mlx = mlx_init();
if (data->save == 0)
{
screen_resize(data);
data->win = mlx_new_window(data->mlx, data->x_screen_size,
data->y_screen_size, "Among Us in cub3D - A 42 Paris Project");
mlx_loop_hook(data->mlx, render_next_frame, data);
mlx_hook(data->win, 2, 1L << 0, ft_key_hook, data);
mlx_hook(data->win, 3, 1L << 1, ft_key_unhook, data);
if (LINUX)
mlx_hook(data->win, 33, 1L << 5, exit_free, data);
}
data->img = mlx_new_image(data->mlx, data->x_screen_size,
data->y_screen_size);
data->addr = mlx_get_data_addr(data->img,
&data->bits_per_pixel, &data->line_length, &data->endian);
init_images_mlx(data);
if (data->save == 1)
render_next_frame(data);
mlx_loop(data->mlx);
}
int main(int ac, char **av)
{
int fd;
char *line;
t_data data;
line = NULL;
fd = open(av[1], O_RDONLY);
data.av = av[1];
if (security_cub(ac, av, &data, fd) == 1)
return (0);
store_info(fd, &data, line);
if (security_data(&data) == 1)
return (free_struct(&data, 0));
store_map(fd, &data);
check_map(&data);
if (security_check(&data) == 1)
return (free_struct(&data, 1));
fill_map_one(&data);
texture_check(&data);
if (data.security[11] == 1)
return (free_struct(&data, 1));
print_info(&data);
set_vector_dir(&data);
print_map(&data);
run_mlx(&data);
return (free_struct(&data, 1));
}
/*
** List of Bonus
** 1 : Minimap
** 2 : Sprint
** 3 : Different Sprites (15+)
** 4 : Animated Sprites
** 5 : Crouch
** 6 : Colision with walls
** 7 : Colision with sprites
** 8 : Life Bar
** 9 : HUD
** 10 : Enemy can damage your life
** 11 : Exit message on the screen
** 12 : Multiple level in the game
** 13 : Hiden doors
** 14 : Doors
** 15 : Gameplay
** 16 : Possibility to heal at spawn
** 17 : Different textures for one side
** 18 : Handmade pixel art for this game
*/