Hey
I have a fight with sprite-pointers.
I want to display multiple Sprites using pointers depending on score-condition.
Something like that:
If your score points are above 100 create one "box".
If your score points are above 200 create two "box" and so on.
My solution so far :
/// Game - Class ///////////////////////////
//... Here somewhere I define the pointer
sf::Sprite *ptrSprite;
// end Game - Class
int Game_run()
{
//...
if (Score >= 100 )
{
if (ptrSprite == 0)
{
// Create the new sprite
ptrSprite = new sf::Sprite(IMG_Plop);
// Set the position in y-axis and it's velocity to random.
// I don't know if it's alright, but I have more than one rand because it
// appears to me that the y is always quite the same or it is close by the last number.
short int randY=rand() % 480 + 1;
randY=rand() % 480 + 1;
randY=rand() % 480 + 1;
randY=rand() % 480 + 1;
randY=rand() % 480 + 1;
ptrSprite->SetPosition(810, randY);
// Set a random velocity between -50 and -200.
ptrSpriteVelocity = rand() % 200;
ptrSpriteVelocity -= 200;
}
}
// Below is the delete command
if (Score > 100 && ptrSprite != 0)
{
ptrSprite->Move(ptrSpriteVelocity * ElapsedTime,0);
// If the Sprite reaches the end delete it.
if (ptrSprite->GetPosition().x < -10)
{
delete ptrSprite;
ptrSprite = 0;
}
}
return 0 ;
}
I don't know how to do this.
My only idea is to make this for each pointer I define, so that this code appears as often as the number of pointers plus the condition of points.
But this wouldn't be a clear and well code.
Thanks : D