(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
07-01-24 08:55 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - single random numbers with int output?
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
Guy Perfect
Posts: 340/451
Yeah, you should declare variables for the sprites' positions. X and Y. You'll have a behavior program set up to manipulate these AFTER they have been initialized. Something like "If not on the ground, then Y = Y - GravitationalForce" or whatever.

To position them randomly at the start, just use rand() once on X and Y each in order to set up an initial value.



EDIT:
After some further consideration, I also see that what you might want to do is to draw a number of sprites to the screen in random locations when you call your function, in which case they would be repositioned each time the function is called. The best way to handle this is to declare your X and Y variables globally and in an array such that all of the sprites can have variables of their own. Initialize these variables with rand(), but only once. In the function, only put in the code to draw the sprites to the screen.
Sukasa
Posts: 1509/2068
Well, make a set of two variables that are not going to be overwritten for the sprite, and then set each of them to a random number ONCE. After that, set the sprite to those two variable, and the sprite will be set to a random place on the screen and not move.

That's what you wanted, right?
spiroth10
Posts: 58/145
is this possible?
I know you can do something like:
[code]
int rande;
rande = rand()%100;
[/code]

but then your integer is ALWAYS changing.

lets say Im working with SDL/Allegro/DirectX. I want to draw an enemy sprite to the screen at a random y or x value. If I use an int with rand or srand, I'll have an enemy randomly redraw itself forever should I use that int as my x/y value.

is there any way around this conondrum?

sure, I could just draw all the enemies outside the screen and have them move in like most games do, but thats not what Im looking for.

I just cannot think of a solution. No matter what I come up with, there just doesn't seem to be a way to have sprites drawn at random coordinates (that I can figure out at least).
Acmlm's Board - I3 Archive - Programming - single random numbers with int output?


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.010 seconds; used 349.55 kB (max 381.13 kB)