Page 1 of 1

view.x,y& rand-->still problems with screen range

PostPosted: Thu Apr 22, 2004 2:10 pm
by Just4Fun
Quote:
Makslane wrote: Try this:

x = (rand(40) - 20) + your_x_center;
This will make the actor around your x center with the range:
your_x_center - 20 to your_x_center + 20


I'm still having trouble with this. Please,anyone,help.

My screen coordinates for view.x are:

-360 (left upper corner)
-160 (right upper corner)
-260 (x center) ??

My screen coordinates for view.y are:

-130 (left upper corner)
130 (Lower left corner)
0 (y center) ??


Please show me the code for this. I have tried your example over and over. I have tried many senarios but I think I'm missing something.


Here is how I think it should work, but it doesn't:

x or y= rand (a random number from 0 to some number) - ( distance from actor's x or y center) + (view.x center or view.y center)

The actor should move between the view.x (-360) and view.x (-160) coordinates and view.y (-130) to (130) at rand locations.

I'm sorry to be so slow about this. If I can ever get the proper code through my head, my next very simple activation region demo will be pretty much done. TIA

PostPosted: Thu Apr 22, 2004 8:14 pm
by jazz_e_bob
Good morning.

I empathize with your frustration.

I must go to work this morning but I will look at your problem later today.

jazz

PostPosted: Thu Apr 22, 2004 11:12 pm
by makslane
x = (rand(200) - 100) + (-260);
y = (rand(260) - 130) + 0;

I think this works

PostPosted: Fri Apr 23, 2004 3:45 am
by jazz_e_bob
I'll see how you go with the previous post... :wink:

PostPosted: Fri Apr 23, 2004 3:23 pm
by Just4Fun
jazz-e-bob,
Would you try to explain to me what is happening with this code. I need to understand it before I can apply it to my situation. The math doesn't seem to give me the boundries that I am after. I think I understand, but the logic isn't working... :?: Thank you...

PostPosted: Fri Apr 23, 2004 8:19 pm
by jazz_e_bob
makslane wrote:x = (rand(200) - 100) + (-260);
y = (rand(260) - 130) + 0;


Yep

x is a random number between -360 and -160
y is a random number between -130 and 130

Don't forget:
The view is positioned from its upper left corner.
Actors are positioned from their centre.

Hope this helps. :)

PostPosted: Fri Apr 23, 2004 9:09 pm
by Just4Fun
*Maybe* I just got it!

Does this mean that the -360 to -160 would always be at least the rand distance generated in x,y away from the actor? So, when I figured my coordinates based on the view, they would not work because my rand actor moves to different parts of the screen so sometimes the number generated would push the actor off a part of the screen? In this case, the logic I tried to use would not work for the application needed (restriction of random object movement to the screen boundries)?
-----------------------------
-360 to -160
**********************
**********************
**********************
**********************
******************* Actor
**********************
------------------------------