From: Christian Heller Date: Thu, 16 May 2013 00:49:18 +0000 (+0200) Subject: Added monster. Doesn't do much; only blocks the way so far. X-Git-Tag: tce~1299 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/blog?a=commitdiff_plain;h=b34c99f3322baff9eefdc567691101c9fd39dc45;p=plomrogue Added monster. Doesn't do much; only blocks the way so far. --- 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();