From b34c99f3322baff9eefdc567691101c9fd39dc45 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 16 May 2013 02:49:18 +0200 Subject: [PATCH] Added monster. Doesn't do much; only blocks the way so far. --- roguelike.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/roguelike.c b/roguelike.c index 396f1f6..4e369bc 100644 --- a/roguelike.c +++ b/roguelike.c @@ -10,6 +10,7 @@ struct World { int turn; char * log; struct Map * map; + struct Monster * monster; struct Player * player; }; struct KeyBinding { @@ -32,6 +33,10 @@ struct Player { int y; int x; }; +struct Monster { + int y; + int x; }; + void draw_with_linebreaks (struct Win *, char *, int); void draw_text_from_bottom (struct Win *, char *); void draw_log (struct Win *); @@ -116,6 +121,7 @@ void draw_map (struct Win * win) { struct World * world = (struct World *) win->data; struct Map * map = world->map; struct Player * player = world->player; + struct Monster * monster = world->monster; char * cells = map->cells; int width_map_av = map->width - map->offset_x; int height_map_av = map->height - map->offset_y; @@ -126,6 +132,8 @@ void draw_map (struct Win * win) { if (y < height_map_av && x < width_map_av) { if (z == (map->width * player->y) + player->x) mvwaddch(win->curses, y, x, '@'); + else if (z == (map->width * monster->y) + monster->x) + mvwaddch(win->curses, y, x, 'M'); else mvwaddch(win->curses, y, x, cells[z]); z++; } } } } @@ -326,7 +334,8 @@ char is_passable (struct World * world, int x, int y) { // Check if coordinate on (or beyond) map is accessible to movement. char passable = 0; if (0 <= x && x < world->map->width && 0 <= y && y < world->map->height) - if ('.' == world->map->cells[y * world->map->width + x]) + if ( '.' == world->map->cells[y * world->map->width + x] + && (y != world->monster->y || x != world->monster->x)) passable = 1; return passable; } @@ -377,9 +386,13 @@ int main () { struct Map map = init_map(); world.map = ↦ struct Player player; - player.y = 10; - player.x = 10; + player.y = 16; + player.x = 16; world.player = &player; + struct Monster monster; + monster.y = 16; + monster.x = 80; + world.monster = &monster; WINDOW * screen = initscr(); noecho(); -- 2.30.2