-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.c
52 lines (46 loc) · 1.19 KB
/
play.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
#include "so_long.h"
void move_player(t_st_list *list, int y, int x, int key_code)
{
int prev_y;
int prev_x;
prev_y = list->or_map->y;
prev_x = list->or_map->x;
if (check_move(list, list->or_map, y, x) != 1)
return ;
list->or_map->y = y;
list->or_map->x = x;
list->or_map->map[y][x] = 'P';
list->or_map->map[prev_y][prev_x] = '0';
print_moves(key_code);
}
int check_move(t_st_list *list, t_map *or_map, int y, int x)
{
if (or_map->map[y][x] == 'E')
{
if (or_map->num_c != or_map->check_c)
return (0);
else
{
my_printf("You reached your destination! Congratulations!\n");
clear_all(list);
}
}
if (or_map->map[y][x] == 'C')
or_map->check_c++;
if (or_map->map[y][x] == '1')
return (0);
return (1);
}
void print_moves(int key_code)
{
static int count = 0;
count++;
if (key_code == ARROW_UP || key_code == W)
my_printf("Move %i, with a movement up\n", count);
if (key_code == ARROW_DOWN || key_code == S)
my_printf("Move %i, with a movement down\n", count);
if (key_code == ARROW_RIGHT || key_code == D)
my_printf("Move %i, with a movement right\n", count);
if (key_code == ARROW_LEFT || key_code == A)
my_printf("Move %i, with a movement left\n", count);
}