Exemple #1
0
/**
 * @brief Spawn a monster, and (try to) place it at x,y (or y,x..)
 *
 * @param y Y coordinate
 * @param x X coordinate
 * @param n Number of the monsterdef to tuse
 * @param head Head of list to attach this monster to (usually level->monsters)
 * @param level Pointer to the level where monster will be spawned
 * @param maxlevel Maximum level of monster.
 *
 * @return True if successfull, false if it failed.
 */
bool spawn_monster_at(int y, int x, int n, monster_t *head, void *level, int maxlevel)
{
        spawn_monster(n, head, maxlevel);
        if(head->next->level > maxlevel) {
                unspawn_monster(head->next);
                return false;
        }

        if(!place_monster_at(y, x, head->next, (level_t *) level)) {
                unspawn_monster(head->next);
                return false;
        }

        return true;
}
Exemple #2
0
int main(int argc, char * argv []) {
    NCurses ncurses;
    Map map(ncurses.width() / 2, ncurses.height() - 10);

    map.iterate([](const AxialPosition & p, char & c) {
        c = tiles[rnd(0, (int)strlen(tiles) - 1)];
    });

    game.active = true;
    game.ncurses = &ncurses;
    game.map = ↦
    game.player = spawn();

    auto player = game.player.lock();
    player->act = player_act;
    player->icon = '@';

    for(int i = 0; i < 20; i++) {
        spawn_monster();
    }

    do {
        std::sort(entities.begin(), entities.end(), [](const std::shared_ptr<Entity> a, const std::shared_ptr<Entity> b) -> bool {
            return a->energy < b->energy;
        });

        for(auto && entity : entities) {
            draw();

            while(entity->energy > 0 && entity->act != nullptr) {
                int cost = entity->act(entity);

                if(cost < 0) {
                    goto next_entity;
                }

                entity->energy -= cost;
            }

            entity->energy += entity->energy_gain;
next_entity:
            ;
        }
    } while(game.active);
}