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.
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) {
// 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.
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; }
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");
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;
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();