void game_step()

in procgen/src/games/starpilot.cpp [368:430]


    void game_step() override {
        BasicAbstractGame::game_step();

        bool is_firing = special_action != 0;

        for (int i = (int)(entities.size()) - 1; i >= 0; i--) {
            auto m = entities[i];

            if (m->type == PLAYER)
                continue;

            if (should_fire(m, cur_time)) {
                int bullet_type = m->type == TURRET ? BULLET3 : BULLET2;
                float bullet_r = hp_bullet_r[m->type];
                float b_vx = agent->x - m->x;
                float b_vy = agent->y - m->y;
                float bv_scale = hp_vs[bullet_type] * V_SCALE / sqrt(b_vx * b_vx + b_vy * b_vy);
                b_vx = b_vx * bv_scale;
                b_vy = b_vy * bv_scale;

                std::shared_ptr<Entity> new_bullet(new Entity(m->x, m->y, b_vx, b_vy, bullet_r, bullet_type));
                new_bullet->face_direction(b_vx, b_vy, -1 * PI / 2);
                entities.push_back(new_bullet);
            }

            if (m->health <= 0 && is_destructible(m->type) && !m->will_erase) {
                spawn_child(m, EXPLOSION, .5 * m->rx, true);

                step_data.reward += ENEMY_REWARD;
                m->will_erase = true;
            }
        }

        while (spawners.size() > 0 && cur_time == spawners[int(spawners.size()) - 1]->spawn_time) {
            entities.push_back(spawners[int(spawners.size()) - 1]);
            spawners.pop_back();
        }

        float bullet_r = hp_bullet_r[PLAYER];

        if (is_firing) {
            float theta = special_action == 2 ? PI : 0;
            float v_scale = hp_vs[BULLET_PLAYER] * V_SCALE;

            float vx = cos(theta) * v_scale;
            float vy = sin(theta) * v_scale;
            float x_off = agent->rx * cos(theta);

            auto bullet = std::make_shared<Entity>(agent->x + x_off, agent->y, vx, vy, bullet_r, BULLET_PLAYER);
            bullet->collides_with_entities = true;
            bullet->face_direction(vx, vy);
            bullet->rotation -= PI / 2;
            entities.push_back(bullet);
        }

        if (cur_time == SHOOTER_WIN_TIME) {
            auto finish = std::make_shared<Entity>(main_width, main_height / 2, -1 * hp_slow_v * V_SCALE, 0, 2, main_height / 2, FINISH_LINE);
            choose_random_theme(finish);
            match_aspect_ratio(finish, false);
            finish->x = main_width + finish->rx;
            entities.push_back(finish);
        }
    }