(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
06-29-24 05:07 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - single random numbers with int output? New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
spiroth10

Paratroopa


 





Since: 01-28-06
From: USA

Last post: 6340 days
Last view: 6340 days
Posted on 08-19-06 11:27 AM Link | Quote
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).
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6341 days
Last view: 6340 days
Posted on 08-19-06 03:33 PM Link | Quote
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?
Guy Perfect









Since: 11-18-05

Last post: 6342 days
Last view: 6341 days
Posted on 08-20-06 08:28 PM Link | Quote
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.


(edited by Guy Perfect on 08-20-06 07:30 PM)
Add to favorites | Next newer thread | Next older thread
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 358.16 kB (max 423.63 kB)