-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathso_long.h
190 lines (164 loc) · 3.06 KB
/
so_long.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef SO_LONG_H
# define SO_LONG_H
# include "basics.h"
# include <mlx.h>
/* Size of every sprite */
# define IMG_SIZE 64
// ---------- TILES
typedef enum e_tiletype
{
EMPTY = '0',
WALL = '1',
COLLECTABLE = 'C',
PLAYER = 'P',
EXIT = 'E',
ENEMY = 'M',
FOLLOWER = 'F'
} t_tiletype;
/* Struct for each tile */
typedef struct s_tile
{
t_tiletype type;
t_tiletype og_type;
t_vector position;
struct s_tile *up;
struct s_tile *down;
struct s_tile *left;
struct s_tile *right;
} t_tile;
// ---------- IMAGES
/* All posible wall images */
typedef struct s_wall_img
{
void *block;
void *up_left;
void *up;
void *up_right;
void *right;
void *down_right;
void *down;
void *down_left;
void *left;
} t_wall_img;
/* Collectables animation info */
typedef struct s_coll_img
{
void *current_img;
int anim_frames;
void *img_0;
void *img_1;
} t_collect_img;
/* Info for the particle-like effect */
typedef struct s_effect
{
void *img;
t_vector pos;
int frames;
int counter;
} t_effect;
/* An image that covers the whole window */
typedef struct s_panel
{
void *pointer;
char *pixels;
t_vector size;
int bpp;
int line_size;
int endian;
} t_panel;
/* Color */
typedef struct s_color
{
int r;
int g;
int b;
int a;
} t_color;
// ---------- ENEMIES
typedef enum e_enemytype
{
HORIZONTAL_ENEM = 'H',
VERTICAL_ENEM = 'V',
FOLLOW_ENEM = 'F'
} t_enemyytpe;
/* Enemies animation info */
typedef struct s_enemy_imgs
{
int basic_anim;
void *basic_current;
void *basic_01;
void *basic_02;
int follow_anim;
void *follow_current;
void *follow_01;
void *follow_02;
} t_enemy_img;
/* Struct to make a list of enemies */
typedef struct s_enemy
{
t_enemyytpe type;
int dir;
t_tile *og_tile;
t_tile *tile;
struct s_enemy *next;
} t_enemy;
// ---------- GAME
/* All valid input keys */
enum e_keycode
{
KEY_UP = 13,
KEY_DOWN = 1,
KEY_LEFT = 0,
KEY_RIGHT = 2,
RESET = 15,
ESC = 53
};
/* Info about the player */
typedef struct s_player
{
t_tile *tile;
void *current_img;
int framecount;
int idle_frames;
void *idle_img_0;
void *idle_img_1;
int action_frames;
void *action_img;
} t_player;
/* All info for the game run */
typedef struct s_game
{
void *mlx;
void *window;
t_vector wndw_size;
t_tile **tilemap;
t_player player;
int og_collects;
int collects;
int moves;
t_enemy *enemy_list;
t_vector img_size;
t_wall_img wall_imgs;
t_collect_img collects_imgs;
t_enemy_img enemy_imgs;
void *door_open_img;
void *door_close_img;
t_effect effect;
void *red_panel;
void *white_panel;
} t_game;
// ---------------------------
// FUNCTIONS
t_bool start(t_game *game, int argc, char **argv);
t_color new_color(int r, int g, int b, int a);
void *new_panel(t_game *game, t_color color);
int input(int key, t_game *game);
int update(t_game *game);
void render(t_game game);
void effect_anim(t_effect *effect, t_vector pos);
void action_anim(t_player *player);
void remove_player(t_game *game);
void kill_player(t_game *game, t_vector pos);
int reset(t_game *game);
int end_program(t_game *game);
#endif