mercredi 9 février 2022

how can i keep the value generated by rand()

i'm trying to generate a random float value to use as a position for my sprite. my problem is that once i generated said value, i can't find a way to store it without it changing.

Once rand() generated the float value, how can i keep it as lv->boo->pos->x ? I only want rand() to generate 1 value for the x position by sprite, but still keep on changing the y position.

level_t *move(level_t *lv)
{
    sfTime time = sfClock_getElapsedTime(lv->boo->move_clock);

    if (time.microseconds / 1000000.0 > 0.5)
    {
        float origin = random_origin();
        lv->boo->pos.x = origin;
        lv->boo->pos.y += 1.25;
        sfSprite_setPosition(lv->boo->boosprite, lv->boo->pos);
        if (lv->boo->pos.y > 1400) {
            lv->boo->pos.y = 0;
            return 0;
        }
    }
    return lv;
}

float random_origin()
{
    float origin = (float)rand()/(float)(RAND_MAX/2000.0);
    return origin;
}



Aucun commentaire:

Enregistrer un commentaire