add make target that prints CC, CFLAGS, and LDFLAGS
[menche_rl.git] / game.c
blobef24356297bfe9fdb325d1de204a3b93aa36f5ad
1 #include "map.h"
2 #include "game.h"
4 enum dir {
5 LEFT,
6 DOWN,
7 UP,
8 RIGHT
9 };
11 int move_player(struct pos* playerpos, enum tile* map, enum dir direction)
13 switch(direction) {
14 case LEFT:
15 if(playerpos->x > 0 &&
16 get_tile(map, playerpos->y, playerpos->x - 1) == TILE_FLAT) {
17 playerpos->x -= 1;
18 return 1;
20 break;
21 case DOWN:
22 if((playerpos->y < 15) &&
23 get_tile(map, playerpos->y + 1, playerpos->x) == TILE_FLAT) {
24 playerpos->y += 1;
25 return 1;
27 break;
28 case UP:
29 if(playerpos->y > 0 &&
30 get_tile(map, playerpos->y - 1, playerpos->x) == TILE_FLAT) {
31 playerpos->y -= 1;
32 return 1;
34 break;
35 case RIGHT:
36 if(playerpos->x < 15 &&
37 get_tile(map, playerpos->y, playerpos->x + 1) == TILE_FLAT) {
38 playerpos->x += 1;
39 return 1;
41 break;
43 return 0;
46 int step(enum tile* map, struct pos* playerpos, int input)
48 switch(input) {
49 case 'h':
50 move_player(playerpos, map, LEFT);
51 break;
52 case 'j':
53 move_player(playerpos, map, DOWN);
54 break;
55 case 'k':
56 move_player(playerpos, map, UP);
57 break;
58 case 'l':
59 move_player(playerpos, map, RIGHT);
60 break;
61 case 'q':
62 return 0;
63 default:
64 return 1;
66 return 1;