-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_start.c
More file actions
74 lines (69 loc) · 2.21 KB
/
game_start.c
File metadata and controls
74 lines (69 loc) · 2.21 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
#include "so_long.h"
/* Render walls and empty spaces. */
void start_map(t_prog *sol)
{
int x;
int y;
y = -1;
while (++y < sol->size->y)
{
x = -1;
while (++x < sol->size->x)
{
if (sol->map[y][x] == 1)
put_image(sol, sol->wall, x, y);
else if (sol->map[y][x] == 0)
put_image(sol, sol->ground, x, y);
}
}
}
/* Attribute image files to it's pointers. */
static void get_images(t_prog *sol, int w, int h)
{
sol->plr_up = mlx_xpm_file_to_image(sol->mlx, "img/plr_b.xpm", &w, &h);
if (!sol->plr_up)
error_msg("Error\nCouldn't load image plr_b.xpm\n", sol);
sol->plr_down = mlx_xpm_file_to_image(sol->mlx, "img/plr_f.xpm", &w, &h);
if (!sol->plr_down)
error_msg("Error\nCouldn't load image plr_f.xpm\n", sol);
sol->plr_left = mlx_xpm_file_to_image(sol->mlx, "img/plr_l.xpm", &w, &h);
if (!sol->plr_left)
error_msg("Error\nCouldn't load image plr_l.xpm\n", sol);
sol->plr_right = mlx_xpm_file_to_image(sol->mlx, "img/plr_r.xpm", &w, &h);
if (!sol->plr_right)
error_msg("Error\nCouldn't load image plr_r.xpm\n", sol);
sol->wall = mlx_xpm_file_to_image(sol->mlx, "img/wall.xpm", &w, &h);
if (!sol->wall)
error_msg("Error\nCouldn't load image wall.xpm\n", sol);
sol->clt = mlx_xpm_file_to_image(sol->mlx, "img/collect.xpm", &w, &h);
if (!sol->clt)
error_msg("Error\nCouldn't load image collect.xpm\n", sol);
sol->ground = mlx_xpm_file_to_image(sol->mlx, "img/floor.xpm", &w, &h);
if (!sol->ground)
error_msg("Error\nCouldn't load image floor.xpm\n", sol);
sol->exit = mlx_xpm_file_to_image(sol->mlx, "img/exit.xpm", &w, &h);
if (!sol->exit)
error_msg("Error\nCouldn't load image exit.xpm\n", sol);
sol->player = sol->plr_down;
}
/* Start mlx processes, open window and call functions to put images on it. */
void game_start(t_prog *sol)
{
int w;
int h;
if (sol->mlx)
return ;
w = 0;
h = 0;
sol->mlx = mlx_init();
if (!sol->mlx)
error_msg("Error\nCouldn't initialize mlx.\n", sol);
sol->win = mlx_new_window(sol->mlx, sol->size->x * 32,
sol->size->y * 32, "So Long");
if (!sol->win)
error_msg("Error\nCouldn't initialize window.\n", sol);
sol->img = mlx_new_image(sol->mlx, 32, 32);
if (!sol->img)
error_msg("Error\nCouldn't initialize mlx image.\n", sol);
get_images(sol, w, h);
}