-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_movement.c
93 lines (88 loc) · 3.1 KB
/
player_movement.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* player_movement.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/03 12:12:34 by lstorey #+# #+# */
/* Updated: 2024/05/08 14:51:13 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void move_up(t_game_list *game)
{
if (game->map_array[game->y_ppos - 1][game->x_ppos] != '1')
{
game->steps++;
ft_printf("steps taken: %i\n", game->steps);
game->y_ppos -= 1;
game->img->img_p->instances->y -= game->tile_size;
if (game->map_array[game->y_ppos][game->x_ppos] == 'C')
{
ft_printf("You found an egg!\n");
remove_collectable(game, game->x_ppos, game->y_ppos);
ft_printf("collectables left:%i\n", game->c_count);
}
if (game->c_count == 0 && game->map_array
[game->y_ppos][game->x_ppos] == 'E')
end_game(game, 0);
}
}
void move_down(t_game_list *game)
{
if (game->map_array[game->y_ppos + 1][game->x_ppos] != '1')
{
game->steps++;
ft_printf("steps taken: %i\n", game->steps);
game->y_ppos += 1;
game->img->img_p->instances->y += game->tile_size;
if (game->map_array[game->y_ppos][game->x_ppos] == 'C')
{
ft_printf("You found an egg!\n");
remove_collectable(game, game->x_ppos, game->y_ppos);
ft_printf("collectables left:%i\n", game->c_count);
}
if (game->c_count == 0 && game->map_array
[game->y_ppos][game->x_ppos] == 'E')
end_game(game, 0);
}
}
void move_left(t_game_list *game)
{
if (game->map_array[game->y_ppos][game->x_ppos - 1] != '1')
{
game->steps++;
ft_printf("steps taken: %i\n", game->steps);
game->x_ppos -= 1;
game->img->img_p->instances->x -= game->tile_size;
if (game->map_array[game->y_ppos][game->x_ppos] == 'C')
{
ft_printf("You found an egg!\n");
remove_collectable(game, game->x_ppos, game->y_ppos);
ft_printf("collectables left:%i\n", game->c_count);
}
if (game->c_count == 0 && game->map_array
[game->y_ppos][game->x_ppos] == 'E')
end_game(game, 0);
}
}
void move_right(t_game_list *game)
{
if (game->map_array[game->y_ppos][game->x_ppos + 1] != '1')
{
game->steps++;
ft_printf("steps taken: %i\n", game->steps);
game->x_ppos += 1;
game->img->img_p->instances->x += game->tile_size;
if (game->map_array[game->y_ppos][game->x_ppos] == 'C')
{
ft_printf("You found an egg!\n");
remove_collectable(game, game->x_ppos, game->y_ppos);
ft_printf("collectables left:%i\n", game->c_count);
}
if (game->c_count == 0 && game->map_array
[game->y_ppos][game->x_ppos] == 'E')
end_game(game, 0);
}
}