would this reset?

okay i have a sprite that moves on my some dimensions that i set with a random function to make it stop in random places...now it sometimes goes off the screen would this code make it reset then redo its random function again?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
m_iRandomNumberY = rand() % ((545/6)*5) + 545/8;


if(m_iRandomNumberY <= 55 || m_iRandomNumberY >= 900)
{
 m_iRandomNumberY = rand() % ((545/6)*5) + 545/8;
}







I don't know what it is you want to reset. If m_iRandomNumberY is not in the range 55-900 it will get a new value if that's what you mean.

We can actually simplify this line
m_iRandomNumberY = rand() % ((545/6)*5) + 545/8;
to this
m_iRandomNumberY = rand() % 450 + 68;
This means that m_iRandomNumberY can only be in the range 68-517 and the if statement is unnecessary.
Last edited on

it will get a new value if that's what you mean.



yea thats what i wanted it to do...for the game i am making i want the sprite to choose a rand position on the screen..but if there is a certain amount already on the screen i want it to be able to move off and re random if that makes sense...
Topic archived. No new replies allowed.