-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoves.c
65 lines (60 loc) · 2.21 KB
/
moves.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmeier <mmeier@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 16:29:48 by mmeier #+# #+# */
/* Updated: 2024/04/04 18:03:58 by mmeier ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
/*Moving functions adjust location of player instance incase no "1" is present
by using addition or substraction with pixel size (PX) (defined in header
file).y_pos & x_pos parallely tracked for easier reading purpose for later
use in function void collect_all (size_pos_collect.c)*/
void move_up(t_game *game)
{
if (game->map[game->img->player->instances->y / PX - 1]
[game->img->player->instances->x / PX] != '1')
{
game->img->player->instances->y -= PX;
game->count++;
game->y_pos -= 1;
ft_printf("moves: %d\n", game->count);
}
}
void move_left(t_game *game)
{
if (game->map[game->img->player->instances->y / PX]
[game->img->player->instances->x / PX - 1] != '1')
{
game->img->player->instances->x -= PX;
game->count++;
game->x_pos -= 1;
ft_printf("moves: %d\n", game->count);
}
}
void move_down(t_game *game)
{
if (game->map[game->img->player->instances->y / PX + 1]
[game->img->player->instances->x / PX] != '1')
{
game->img->player->instances->y += PX;
game->count++;
game->y_pos += 1;
ft_printf("moves: %d\n", game->count);
}
}
void move_right(t_game *game)
{
if (game->map[game->img->player->instances->y / PX]
[game->img->player->instances->x / PX + 1] != '1')
{
game->img->player->instances->x += PX;
game->count++;
game->x_pos += 1;
ft_printf("moves: %d\n", game->count);
}
}