From: Christian Heller Date: Tue, 2 Jul 2013 00:32:33 +0000 (+0200) Subject: Started implementing items. They don't do much but lie around on the map. X-Git-Tag: tce~1180 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/template?a=commitdiff_plain;h=bbea8aaa3fa48f00ea46a7d8d79138e02929881e;p=plomrogue Started implementing items. They don't do much but lie around on the map. --- diff --git a/src/draw_wins.c b/src/draw_wins.c index 0ec8d7a..5b60d81 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -76,6 +76,7 @@ void draw_map_win (struct Win * win) { struct Map * map = world->map; struct Player * player = world->player; struct Monster * monster; + struct Item * item; char * cells = map->cells; uint16_t width_map_av = map->size.x - map->offset.x; uint16_t height_map_av = map->size.y - map->offset.y; @@ -86,13 +87,17 @@ void draw_map_win (struct Win * win) { if (y < height_map_av && x < width_map_av) { mvwaddch(win->frame.curses_win, y, x, cells[z]); z++; } } } - if ( player->pos.y >= map->offset.y && player->pos.y < map->offset.y + win->frame.size.y - && player->pos.x >= map->offset.x && player->pos.x < map->offset.x + win->frame.size.x) - mvwaddch(win->frame.curses_win, player->pos.y - map->offset.y, player->pos.x - map->offset.x, '@'); + for (item = world->item; item != 0; item = item->next) + if ( item->pos.y >= map->offset.y && item->pos.y < map->offset.y + win->frame.size.y + && item->pos.x >= map->offset.x && item->pos.x < map->offset.x + win->frame.size.x) + mvwaddch(win->frame.curses_win, item->pos.y - map->offset.y, item->pos.x - map->offset.x, item->name); for (monster = world->monster; monster != 0; monster = monster->next) if ( monster->pos.y >= map->offset.y && monster->pos.y < map->offset.y + win->frame.size.y && monster->pos.x >= map->offset.x && monster->pos.x < map->offset.x + win->frame.size.x) - mvwaddch(win->frame.curses_win, monster->pos.y - map->offset.y, monster->pos.x - map->offset.x, monster->name); } + mvwaddch(win->frame.curses_win, monster->pos.y - map->offset.y, monster->pos.x - map->offset.x, monster->name); + if ( player->pos.y >= map->offset.y && player->pos.y < map->offset.y + win->frame.size.y + && player->pos.x >= map->offset.x && player->pos.x < map->offset.x + win->frame.size.x) + mvwaddch(win->frame.curses_win, player->pos.y - map->offset.y, player->pos.x - map->offset.x, '@'); } 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 ce3f5a4..37e90c9 100644 --- a/src/roguelike.c +++ b/src/roguelike.c @@ -102,6 +102,12 @@ void save_game(struct World * world) { write_uint16_bigendian(world->monster->next->pos.x, file); write_uint16_bigendian(world->monster->next->next->pos.y, file); write_uint16_bigendian(world->monster->next->next->pos.x, file); + write_uint16_bigendian(world->item->pos.y, file); + write_uint16_bigendian(world->item->pos.x, file); + write_uint16_bigendian(world->item->next->pos.y, file); + write_uint16_bigendian(world->item->next->pos.x, file); + write_uint16_bigendian(world->item->next->next->pos.y, file); + write_uint16_bigendian(world->item->next->next->pos.x, file); fclose(file); } void toggle_window (struct WinMeta * win_meta, struct Win * win) { @@ -197,7 +203,7 @@ int main (int argc, char *argv[]) { default: exit(EXIT_FAILURE); } } - // Initialize log, player and monsters. + // Initialize log, player, monsters and items. world.log = calloc(1, sizeof(char)); update_log (&world, " "); struct Player player; @@ -212,6 +218,16 @@ int main (int argc, char *argv[]) { monster1.name = 'A'; monster2.name = 'B'; monster3.name = 'C'; + struct Item item1; + struct Item item2; + struct Item item3; + world.item = &item1; + item1.next = &item2; + item2.next = &item3; + item3.next = 0; + item1.name = '&'; + item2.name = '%'; + item3.name = '#'; // For interactive mode, try to load world state from savefile. FILE * file; @@ -227,6 +243,12 @@ int main (int argc, char *argv[]) { monster2.pos.x = read_uint16_bigendian(file); monster3.pos.y = read_uint16_bigendian(file); monster3.pos.x = read_uint16_bigendian(file); + item1.pos.y = read_uint16_bigendian(file); + item1.pos.x = read_uint16_bigendian(file); + item2.pos.y = read_uint16_bigendian(file); + item2.pos.x = read_uint16_bigendian(file); + item3.pos.y = read_uint16_bigendian(file); + item3.pos.x = read_uint16_bigendian(file); fclose(file); } // For non-interactive mode, try to load world state from frecord file. @@ -251,6 +273,11 @@ int main (int argc, char *argv[]) { for (player.pos.y = player.pos.x = 0; 0 == is_passable(&map, player.pos);) { player.pos.y = rrand(0, 0) % map.size.y; player.pos.x = rrand(0, 0) % map.size.x; } + struct Item * item; + for (item = world.item; item != 0; item = item->next) + for (item->pos.y = item->pos.x = 0; 0 == is_passable(&map, item->pos);) { + item->pos.y = rrand(0, 0) % map.size.y; + item->pos.x = rrand(0, 0) % map.size.x; } struct Monster * monster; for (monster = world.monster; monster != 0; monster = monster->next) for (monster->pos.y = monster->pos.x = 0; 0 == is_passable(&map, monster->pos);) { diff --git a/src/roguelike.h b/src/roguelike.h index 963031f..a72b7ca 100644 --- a/src/roguelike.h +++ b/src/roguelike.h @@ -17,6 +17,7 @@ struct World { uint32_t turn; char * log; struct Map * map; + struct Item * item; struct Monster * monster; struct Player * player; }; @@ -25,6 +26,11 @@ struct Map { struct yx_uint16 offset; char * cells; }; +struct Item { + struct Item * next; + char name; + struct yx_uint16 pos; }; + extern uint16_t rrand(char, uint32_t); extern void update_log (struct World *, char *);