-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathso_long.c
69 lines (62 loc) · 1.97 KB
/
so_long.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeparra- <yeparra-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 13:44:28 by yeparra- #+# #+# */
/* Updated: 2024/11/14 19:00:02 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void update(t_game *game, int x, int y)
{
game->pos_x = x;
game->pos_y = y;
}
void render_map(t_game *game)
{
int x;
int y;
y = 0;
while (y < game->map_height)
{
x = 0;
while (x < game->map_width)
{
put_image(game, game->map[y][x], x, y);
x++;
}
y++;
}
}
void move_player(t_game *game, int x, int y)
{
char *move_str;
if (game->map[x][y] == '1')
return ;
handle_tile_interaction(game, x, y);
game->move_count++;
move_str = ft_itoa(game->move_count);
write(1, "Número de movimientos: ", 23);
write(1, move_str, ft_strlen(move_str));
write(1, "\n", 1);
free(move_str);
render_map(game);
}
int handle_key(int keycode, t_game *game)
{
find_player(game);
if (keycode == KEY_W)
move_player(game, game->pos_x - 1, game->pos_y);
else if (keycode == KEY_A)
move_player(game, game->pos_x, game->pos_y - 1);
else if (keycode == KEY_S)
move_player(game, game->pos_x + 1, game->pos_y);
else if (keycode == KEY_D)
move_player(game, game->pos_x, game->pos_y + 1);
else if (keycode == 65307)
mlx_destroy_window(game->win.mlx, game->win.win);
return (1);
}