-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwolf.h
More file actions
156 lines (123 loc) · 3.45 KB
/
wolf.h
File metadata and controls
156 lines (123 loc) · 3.45 KB
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
152
153
154
155
156
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* wolf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bturcott <bturcott@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/20 22:02:59 by mbartole #+# #+# */
/* Updated: 2019/04/25 15:13:27 by mbartole ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WOLF_H
# define WOLF_H
# include <fcntl.h>
# include <math.h>
# include "libft/libft.h"
# include "SDL/includes/SDL.h"
# include "SDL/includes/SDL_mixer.h"
typedef struct s_point
{
int x;
int y;
int h;
} t_point;
typedef struct s_view
{
int x;
int y;
int horiz;
float angle;
} t_view;
/*
** flags: 0 - show mini-map; /m/
** 1 - swith on texture on walls /t/
** 2 - on/off movement on mouse /space/
*/
typedef struct s_sdl
{
SDL_Window *window;
SDL_Renderer *render;
SDL_Texture *text;
SDL_Texture *mapa;
unsigned char flags[3];
int mouse_pos[2];
t_vector *map;
t_view cam;
SDL_Surface *floor;
SDL_Texture **texture_pack;
Mix_Chunk **samples;
Mix_Music *music;
} t_sdl;
# define UP 26
# define RIGHT 7
# define DOWN 22
# define LEFT 4
# define SWITCH_MAP 16
# define SWITCH_TEXT 23
# define SWITCH_MOUSE 44
# define USAGE "./wolf [path_to_file_with_map]\n"
# define MAP_DEFAULT "default.map"
# define MAP(x) ((t_point *)((x)->cont))
# define MAP_W(x) ((int)x->offset)
# define MAP_H(x) ((int)(x->len / x->offset / sizeof(t_point)))
# define NAME "Wolf3D"
# define WIN_POS_X 500
# define WIN_POS_Y 500
# define WIN_W 1500
# define WIN_H 1000
# define WIN_FLAGS 0
# define REN_FLAGS 0
# define TXT_FORMAT SDL_PIXELFORMAT_ARGB8888
# define TXT_ACCESS SDL_TEXTUREACCESS_STREAMING
# define FOV M_PI / 3
# define CAM_H 32
# define WALL_H 64
# define STEP (float)FOV / WIN_W
# define DIST (int)(WIN_W / 2 / tan(FOV / 2))
# define BLOCK 64
# define ABS(x) ((x) > 0 ? (x) : -(x))
# define QT_12(x) ((x) >= 0)
# define QT_34(x) ((x) <= 0)
# define QT_14(x) ((x) <= M_PI / 2 && (x) >= -M_PI / 2)
# define QT_23(x) ((x) >= M_PI / 2 || (x) <= -M_PI / 2)
# define ROT_STEP M_PI / 128
# define MOV_STEP (float)BLOCK / 16
/*
** utils
*/
int clean_all(t_sdl *sdl, char *msg);
void reprint_all(t_sdl *sdl);
void fit_angle(float *angle);
/*
** read map from file
*/
void read_map(t_sdl *sbox, int fd);
/*
** handle movements and collisions
*/
void movements(t_sdl *sdl, int key, float ang);
/*
** create mini-map
*/
void draw_map(t_sdl *sdl, unsigned int *map);
/*
** get height of wall (ray-casting, in fact)
*/
float get_height(t_sdl *sbox, float ang, int *offset, char *fl);
/*
** casting of walls
*/
void pixels_to_render(t_sdl *sbox, unsigned int *map, float ang);
void texts_to_render(t_sdl *sbox, float ang);
/*
** painting of walls
*/
void paint_walls(t_sdl *sdl, int *params);
/*
** playing music
*/
int init_music(t_sdl *sdl);
int sounds_control_panel(Mix_Chunk **samples, int command);
void sounds(t_sdl *sdl, SDL_Event e);
#endif