How to set vertical velocity in OpenGL 2D?

  2d-games, c++

I’m working on a school project for which I have to upgrade existing code for a platformer game to have more functionality. I’m turning it into one of those games where things fall from top of the screen and a player needs to catch it. This is my code for making a new object:

pickup = new Sprite(1);
pickup->SetFrameSize(32.0f, 32.0f);
pickup->SetNumberOfFrames(1);
pickup->AddTexture("resources/point.png");
pickup->IsVisible(false);
pickup->IsActive(false);
pickup->SetValue(50);

And this is a method that spawns that object:

void SpawnPickup(float p_DeltaTime)
{
    if (pickup->IsVisible() == false)
    {
        pickupSpawnTimer += p_DeltaTime;
        if (pickupSpawnTimer > pickupSpawnThreshold)
        {
            float marginX = pickup->GetSize().width;
            float spawnX = (rand() % (int)(screen_width - (marginX * 2))) + marginX;
            float spawnY = 25.0f;
            pickup->SetPosition(spawnX, spawnY);
            pickup->IsVisible(true);
            pickup->IsActive(true);
            pickupSpawnTimer = 0.0f;
        }
    }
}

I’ve looked online but couldn’t find an appropriate solution. Someone suggested using SetVelocity() but that is as far as my knowledge goes only horizontal. What is the best way to make objects move from top to bottom as soon as they spawn?

Source: Windows Questions C++

LEAVE A COMMENT