From: Christian Heller Date: Thu, 20 Jun 2013 01:26:23 +0000 (+0200) Subject: Have a number (currently: 3) of monsters, instead of only one. Lots of stuff hard... X-Git-Tag: tce~1209 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/conditions?a=commitdiff_plain;h=6d5705b43adbc2a4b522f971206007c9073c7144;p=plomrogue Have a number (currently: 3) of monsters, instead of only one. Lots of stuff hard-coded that should be more flexible, but it's a start. --- diff --git a/src/draw_wins.c b/src/draw_wins.c index 818037a..3741e49 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -74,22 +74,24 @@ void draw_map_win (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; + struct Monster * monster; char * cells = map->cells; - uint16_t width_map_av = map->width - map->offset_x; + uint16_t width_map_av = map->width - map->offset_x; uint16_t height_map_av = map->height - map->offset_y; uint16_t x, y, z; for (y = 0; y < win->frame.size.y; y++) { z = map->offset_x + (map->offset_y + y) * (map->width); for (x = 0; x < win->frame.size.x; x++) { if (y < height_map_av && x < width_map_av) { - if (z == (map->width * player->y) + player->x) - mvwaddch(win->frame.curses_win, y, x, '@'); - else if (z == (map->width * monster->y) + monster->x) - mvwaddch(win->frame.curses_win, y, x, 'M'); - else mvwaddch(win->frame.curses_win, y, x, cells[z]); - z++; } } } } + z++; } } } + if ( player->y >= map->offset_y && player->y < map->offset_y + win->frame.size.y + && player->x >= map->offset_x && player->x < map->offset_x + win->frame.size.x) + mvwaddch(win->frame.curses_win, player->y - map->offset_y, player->x - map->offset_x, '@'); + for (monster = world->monster; monster != 0; monster = monster->next) + if ( monster->y >= map->offset_y && monster->y < map->offset_y + win->frame.size.y + && monster->x >= map->offset_x && monster->x < map->offset_x + win->frame.size.x) + mvwaddch(win->frame.curses_win, monster->y - map->offset_y, monster->x - map->offset_x, monster->name); } void draw_info_win (struct Win * win) { // Draw info window by appending win->data integer value to "Turn: " display. diff --git a/src/roguelike.c b/src/roguelike.c index 54c62c2..f3da256 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -55,6 +55,10 @@ void save_game(struct World * world) { write_uint16_bigendian(world->player->x, file); write_uint16_bigendian(world->monster->y, file); write_uint16_bigendian(world->monster->x, file); + write_uint16_bigendian(world->monster->next->y, file); + write_uint16_bigendian(world->monster->next->x, file); + write_uint16_bigendian(world->monster->next->next->y, file); + write_uint16_bigendian(world->monster->next->next->x, file); fclose(file); } void record_action (char action) { @@ -67,22 +71,26 @@ void next_turn (struct World * world) { // Increment turn and move enemy. world->turn++; rrand(1, world->seed * world->turn); - char d = rrand(0, 0) % 5; - uint16_t ty = world->monster->y; - uint16_t tx = world->monster->x; - if (1 == d) - ty++; - else if (2 == d) - ty--; - else if (3 == d) - tx++; - else if (4 == d) - tx--; - if (tx == world->player->x && ty == world->player->y) - update_log(world, "\nThe monster hits you."); - else if (is_passable(world->map, ty, tx)) { - world->monster->y = ty; - world->monster->x = tx; } } + char d; + struct Monster * monster; + uint16_t ty, tx; + for (monster = world->monster; monster != 0; monster = monster->next) { + d = rrand(0, 0) % 5; + ty = monster->y; + tx = monster->x; + if (1 == d) + ty++; + else if (2 == d) + ty--; + else if (3 == d) + tx++; + else if (4 == d) + tx--; + if (tx == world->player->x && ty == world->player->y) + update_log(world, "\nThe monster hits you."); + else if (is_passable(world->map, ty, tx)) { + monster->y = ty; + monster->x = tx; } } } void update_log (struct World * world, char * text) { // Update log with new text to be appended. @@ -115,9 +123,12 @@ void move_player (struct World * world, char d) { if ('e' == d) { dir = "east"; tx++; } - if (ty == world->monster->y && tx == world->monster->x) - success = 2; - else if (is_passable(world->map, ty, tx)) { + struct Monster * monster; + for (monster = world->monster; monster != 0; monster = monster->next) + if (ty == monster->y && tx == monster->x) { + success = 2; + break; } + if (2 != success && is_passable(world->map, ty, tx)) { success = 1; world->player->y = ty; world->player->x = tx; } @@ -265,8 +276,16 @@ int main (int argc, char *argv[]) { update_log (&world, " "); struct Player player; world.player = &player; - struct Monster monster; - world.monster = &monster; + struct Monster monster1; + struct Monster monster2; + struct Monster monster3; + world.monster = &monster1; + monster1.next = &monster2; + monster2.next = &monster3; + monster3.next = 0; + monster1.name = 'A'; + monster2.name = 'B'; + monster3.name = 'C'; FILE * file; if (1 == world.interactive && 0 == access("savefile", F_OK)) { file = fopen("savefile", "r"); @@ -274,8 +293,12 @@ int main (int argc, char *argv[]) { world.turn = read_uint32_bigendian(file); player.y = read_uint16_bigendian(file); player.x = read_uint16_bigendian(file); - monster.y = read_uint16_bigendian(file); - monster.x = read_uint16_bigendian(file); + monster1.y = read_uint16_bigendian(file); + monster1.x = read_uint16_bigendian(file); + monster2.y = read_uint16_bigendian(file); + monster2.x = read_uint16_bigendian(file); + monster3.y = read_uint16_bigendian(file); + monster3.x = read_uint16_bigendian(file); fclose(file); } else { world.turn = 1; @@ -294,9 +317,11 @@ int main (int argc, char *argv[]) { for (player.y = player.x = 0; 0 == is_passable(&map, player.y, player.x);) { player.y = rrand(0, 0) % map.height; player.x = rrand(0, 0) % map.width; } - for (monster.y = monster.x = 0; 0 == is_passable(&map, monster.y, monster.x);) { - monster.y = rrand(0, 0) % map.height; - monster.x = rrand(0, 0) % map.width; } } + struct Monster * monster; + for (monster = world.monster; monster != 0; monster = monster->next) + for (monster->y = monster->x = 0; 0 == is_passable(&map, monster->y, monster->x);) { + monster->y = rrand(0, 0) % map.height; + monster->x = rrand(0, 0) % map.width; } } WINDOW * screen = initscr(); noecho(); diff --git a/src/roguelike.h b/src/roguelike.h index 99e115d..2ae0c88 100644 --- a/src/roguelike.h +++ b/src/roguelike.h @@ -21,6 +21,8 @@ struct Player { uint16_t x; }; struct Monster { + struct Monster * next; + char name; uint16_t y; uint16_t x; };