-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
128 lines (120 loc) · 2.77 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmadau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/17 14:00:37 by tmadau #+# #+# */
/* Updated: 2018/09/18 17:36:18 by tmadau ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int check_map(t_map *in, t_raycast *op)
{
int ret;
int x;
int y;
x = 0;
y = 0;
if ((ret = place_player(in, op)) != 1)
return (ret);
x = -1;
y = -1;
while (++x < in->get_x)
{
if (in->map[0][x] == 0)
return (0);
if (in->map[in->get_y - 1][x] == 0)
return (0);
}
while (++y < in->get_y)
{
if (in->map[y][0] == 0)
return (0);
if (in->map[y][in->get_x - 1] == 0)
return (0);
}
return (1);
}
void ft_init_stuff(t_raycast *op, t_sdl *var)
{
op->dir_x = -1;
op->dir_y = 0;
op->plane_x = 0;
op->plane_y = 0.66;
var->time = 0.005;
var->old_time = 0.005;
op->height = 600;
op->width = 1000;
}
int ft_sdl_init(t_sdl *var)
{
var->running = 0;
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return (1);
var->window = SDL_CreateWindow("Wolf 3D",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1000, 600, 0);
var->renderer = SDL_CreateRenderer(var->window,
-1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(var->renderer, 0, 0, 0, 255);
SDL_RenderClear(var->renderer);
return (0);
}
void game_run(char **av, t_raycast *op, t_map *in, t_sdl *var)
{
get_matrix(av[1], in);
if (in->tk == 0)
{
var->running = 1;
ft_putstr(LINE_ERR);
}
else if (in->y != 0)
{
alloc_matrix(av[1], in);
if (!check_map(in, op))
{
var->running = 1;
ft_putstr(MAP_ER);
}
else if (place_player(in, op))
{
ft_sdl_init(var);
ft_init_stuff(op, var);
}
}
else
{
var->running = 1;
ft_putstr(DATA_ERR);
}
}
int main(int ac, char **av)
{
t_raycast op;
t_map in;
t_sdl var;
t_buttons ev;
if (ac == 2)
{
if (open(av[1], O_RDONLY) == -1)
ft_putstr(MAP_ERR);
else
{
game_run(av, &op, &in, &var);
while (var.running == 0)
{
while (op.count_x++ < op.width)
ft_do_stuff(&op, &var, &in);
events(&op, &ev, &var, &in);
}
SDL_DestroyWindow(var.window);
SDL_Quit();
}
}
else
ft_putstr(ARG_ERR);
return (0);
}