예제 #1
0
파일: npc.c 프로젝트: RylandAlmanza/mygame
int npc_act(int npc_id) {
    struct npc *npc = npcs + npc_id;
    enum direction direction;
    switch (npc->type_name) {
        case WOODSMAN:
            direction = (random() % 7) - 1;
            if (direction == -1) {
                break;
            }
            struct coord destination = adjacent_coord(npc->x, npc->y, direction);
            if (npc_can_pass(destination.x, destination.y)) {
                move_npc(npc_id, destination.x, destination.y);
            }
            break;
    }
}
예제 #2
0
void Dungeon::game_turn()
{

	Character *c;
	if (PC::instance()->is_alive()) {
		queue_pc_turn();
	}

	while (PC::instance()->is_alive() &&
		(c = event_queue.remove_shift()) &&
		(c != PC::instance())) {
		int next = ((NPC*)c)->get_next_location(floors.at(active_floor));
		move_npc((NPC *)c, next);

		add_event((1000 / c->get_speed()), c);
	}
	IO_handler::instance()->display_dungeon();
	if (PC::instance()->is_alive() && c == PC::instance()) {
		IO_handler::instance()->handle_input();
	}
}