-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
125 lines (118 loc) · 3.58 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlegendr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/06/02 15:41:22 by mlegendr #+# #+# */
/* Updated: 2016/06/02 15:41:24 by mlegendr ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "wolf3d.h"
#include <string.h>
static int key_press(int keycode, t_env *env)
{
if (keycode == 27)
tag(env);
if (keycode == 257)
env->player.move.walk = 1;
if (keycode == 28 && env->aa)
env->aa = 0;
else if (keycode == 28)
env->aa = 1;
if (keycode == 123 || keycode == 0)
env->player.move.left = 1;
if (keycode == 124 || keycode == 2)
env->player.move.right = 1;
if (keycode == 126 || keycode == 13)
env->player.move.forward = 1;
if (keycode == 125 || keycode == 1)
env->player.move.backward = 1;
if (keycode == 49)
env->player.move.jump = 1;
if (keycode == 53)
exit(0);
return (0);
}
static int key_release(int keycode, t_env *env)
{
if (keycode == 49)
env->player.move.jump = 0;
if (keycode == 257)
env->player.move.walk = 0;
if (keycode == 123 || keycode == 0)
env->player.move.left = 0;
if (keycode == 124 || keycode == 2)
env->player.move.right = 0;
if (keycode == 126 || keycode == 13)
env->player.move.forward = 0;
if (keycode == 125 || keycode == 1)
env->player.move.backward = 0;
return (0);
}
static void init(t_env *env)
{
env->tag_color = new_pixel_8u(230, 30, 80, 0);
env->prev_time = clock();
env->player.move.backward = 0;
env->player.move.forward = 0;
env->player.move.left = 0;
env->player.move.right = 0;
env->player.move.jump = 0;
env->win_width = 1024;
env->win_height = 1024;
env->player.angle = M_PI;
env->player.x = 6.5;
env->player.y = 6.5;
env->player.jump_speed = 0;
env->player.jump_alt = 0;
env->player.fov = M_PI / 4;
env->aa = 1;
}
static void init2(t_env *env)
{
if (!(env->img = new_mlx_image_8u(env->mlx_ptr,
env->win_width, env->win_height)))
return ;
if (!(env->aliased_img = new_mlx_image_8u(env->mlx_ptr,
env->win_width, env->win_height)))
return ;
if (!(env->minimap = new_mlx_image_8u(env->mlx_ptr,
200, 200)))
return ;
if (!(env->texture = new_mlx_xpm_image_8u(env->mlx_ptr,
"texture/bot.xpm")))
return ;
if (!(env->skybox = new_mlx_xpm_image_8u(env->mlx_ptr,
"texture/skybox.xpm")))
return ;
if (!(env->tag = new_mlx_xpm_image_8u(env->mlx_ptr,
"texture/tag.xpm")))
return ;
}
int main(void)
{
t_env env;
init(&env);
if (!(env.mlx_ptr = mlx_init()))
return (1);
env.info = parse("first_map_wolf3d", env.mlx_ptr);
if (!(env.win = mlx_new_window(env.mlx_ptr, env.win_width,
env.win_height, "Wolf3d")))
{
return (1);
}
init2(&env);
raycast(env);
mlx_expose_hook(env.win, expose, &env);
mlx_hook(env.win, KEYPRESS, KEYPRESSMASK, key_press, &env);
mlx_hook(env.win, KEYRELEASE, KEYRELEASEMASK, key_release, &env);
mlx_hook(env.win, 17, (1L << 17), red_cross, 0);
mlx_loop_hook(env.mlx_ptr, loop_hook, &env);
mlx_loop(env.mlx_ptr);
return (0);
}