in coinrun/coinrun.cpp [623:673]
void remove_traces_add_monsters()
{
maze->monsters.clear();
for (int y=1; y<maze->h; ++y) {
for (int x=1; x<maze->w-1; x++) {
int& c = maze->get_elem(x, y);
int& b = maze->get_elem(x, y-1);
int cl = maze->get_elem(x-1, y);
int cr = maze->get_elem(x+1, y);
if (c==' ' && randn(20)==0 && !is_wall(b) && y>2) {
maze->set_elem(x, y, FLYING_MONSTER);
} else if (c==' ') {
maze->set_elem(x, y, SPACE);
}
if ((c=='a' || c=='b') && is_wall(b))
c = 'S';
if (is_wall(c) && is_wall(b))
b = 'A';
if (c==FLYING_MONSTER || c==WALKING_MONSTER || c==SAW_MONSTER) {
std::shared_ptr<Monster> m(new Monster);
m->x = x;
m->y = y;
for (int t=0; t<MONSTER_TRAIL; t++) {
m->prev_x[t] = x;
m->prev_y[t] = y;
}
m->is_flying = c==FLYING_MONSTER;
m->is_walking = c==WALKING_MONSTER;
std::vector<int> *type_theme_idxs;
if (m->is_flying) {
type_theme_idxs = &flying_theme_idxs;
} else if (m->is_walking) {
type_theme_idxs = &walking_theme_idxs;
} else {
type_theme_idxs = &ground_theme_idxs;
}
int chosen_idx = randn(type_theme_idxs->size());
m->theme_n = (*type_theme_idxs)[chosen_idx];
c = SPACE;
if (!m->is_walking || (!is_wall(cl) && !is_wall(cr))) // walking monster should have some free space to move
maze->monsters.push_back(m);
}
}
}
}