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;
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.
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) {
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;
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;
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.
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);) {