From: Christian Heller Date: Sat, 20 Jul 2013 03:20:57 +0000 (+0200) Subject: Use enum instead of define for directions in yx_uint16 library. X-Git-Tag: tce~1145 X-Git-Url: https://plomlompom.com/repos/te"st.html?a=commitdiff_plain;h=a037841b38d73f59839731eb3ffaf4edc43d9cf0;p=plomrogue Use enum instead of define for directions in yx_uint16 library. --- diff --git a/src/map_object_actions.c b/src/map_object_actions.c index b016c0c..c9bdea3 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -43,7 +43,7 @@ extern void move_monster (struct World * world, struct Monster * monster) { if (is_passable(world->map, t)) monster->map_obj.pos = t; } -extern void move_player (struct World * world, char d) { +extern void move_player (struct World * world, enum dir d) { // Move player in direction d, update log and turn over to the enemy. struct yx_uint16 t = mv_yx_in_dir (d, world->player->pos); struct Monster * monster; diff --git a/src/map_object_actions.h b/src/map_object_actions.h index d67e8bb..2202b27 100644 --- a/src/map_object_actions.h +++ b/src/map_object_actions.h @@ -9,7 +9,7 @@ struct Monster; extern char is_passable (struct Map *, struct yx_uint16); extern void move_monster (struct World *, struct Monster *); -extern void move_player (struct World *, char); +extern void move_player (struct World *, enum dir); extern void player_wait(struct World *); #endif diff --git a/src/yx_uint16.c b/src/yx_uint16.c index 55c832b..a0b8940 100644 --- a/src/yx_uint16.c +++ b/src/yx_uint16.c @@ -5,7 +5,7 @@ extern char yx_uint16_cmp (struct yx_uint16 a, struct yx_uint16 b) { if (a.y == b.y && a.x == b.x) return 1; else return 0; } -extern struct yx_uint16 mv_yx_in_dir (char d, struct yx_uint16 yx) { +extern struct yx_uint16 mv_yx_in_dir (enum dir d, struct yx_uint16 yx) { // Return yx coordinates one step to the direction d of yx. if (d == NORTH) yx.y--; else if (d == EAST) yx.x++; diff --git a/src/yx_uint16.h b/src/yx_uint16.h index 4751b68..3a13f01 100644 --- a/src/yx_uint16.h +++ b/src/yx_uint16.h @@ -3,16 +3,17 @@ #include -#define NORTH 1 -#define EAST 2 -#define SOUTH 3 -#define WEST 4 +enum dir { + NORTH = 1, + EAST = 2, + SOUTH = 3, + WEST = 4 }; struct yx_uint16 { uint16_t y; uint16_t x; }; extern char yx_uint16_cmp (struct yx_uint16, struct yx_uint16); -extern struct yx_uint16 mv_yx_in_dir (char, struct yx_uint16); +extern struct yx_uint16 mv_yx_in_dir (enum dir, struct yx_uint16); #endif