The Daily Click ::. Forums ::. Klik Coding Help ::. Random Object Placement
 

Post Reply  Post Oekaki 
 

Posted By Message

Brian Haase (FSP)



Registered
  22/01/2005
Points
  691
30th January, 2005 at 15:02:54 -

I'm building sort of an 'air strike' routine, and I need to create objects at random places within a certain region of the window. Right now, the air strike routine is in it's own event group, activated only when the strike is required to start. How can I place the burst rounds at random though?

 
Current Projects:
Bomb Squad (Total Progress - 3%)
:: Current Task Progress: 40%
:: Current Task - Level Editor Shell

Dave Matthew (Jester Gaming)



Registered
  09/07/2004
Points
  148
30th January, 2005 at 15:13:39 -

maybe you can do like this:
if "Object"'s internal flag 0 is off then
+set X("Object") to random(frame width)
+set Y("Object") to random(frame height)
+set internal flag 0 on
where "Object" is an explosion or whatever.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
30th January, 2005 at 15:13:42 -

You could try creating the object, then if you want it to randomly appear around an object, set it to the X & Y position of object + Random( ## ) - [half of that number]

Example:
Create Object1 at: 0,0
Positon Object 1 XPositon of Object2 + Random ( 10 ) - 5
Positon Object 1 YPositon of Object2 + Random ( 10 ) - 5

Not sure if this is what you were talking about, but from what I'm seeing, that might be it.

 
http://www.facebook.com/truediamondgame

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
30th January, 2005 at 16:16:51 -

Bearing in mind im too lazy to actually test these first...
Also dont blame me if half of it turns into smileys and stuff.

For a point within a rectangular area bounded by minimum and maximum X and Y positions;

* every 01"-00
create "burst" at 0,0

* "burst" internal flag 1 is off
set "burst" X position to Random( value( "Max X" ) - value( "Min X" ) ) + value( "Min X" )
set "burst" Y position to Random( value( "Max Y" ) - value( "Min Y" ) ) + value( "Min Y" )
set "burst" flag 1 to on


For a point within a square area of given dimensions, centered around a given point.

* every 01"-00
create "burst" at 0,0

* "burst" internal flag 1 is off
set "burst" X position to value("Target X") - value("Area") + Random(value("Area") * 2)
set "burst" Y position to value("Target Y") - value("Area") + Random(value("Area") * 2)
set "burst" flag 1 to on


For a point within a circular area of given radius, centered around a given point.

* every 01"-00
create "burst" at 0,0

* "burst" internal flag 1 is off
set "burst" X position to value("Target X") + (Cos(Random(360)) * Random( value("Radius")))
set "burst" Y position to value("Target Y") - (Sin(Random(360)) * Random( value("Radius")))
set "burst" flag 1 to on

there are probably lots of other ways but i cant be bothered to think of them
i've a feeling that might already be more than you wanted to know anyhow.

Incase youre wondering (sorry if you already know and im being patronising), the bit about flags is because you cant create objects at a runtime-generated position - you have to create them somewhere (preferably offscreen) and then move them where you want. The problem is, if you keep creating objects, they all move to the same spot. Flags are useful for this, as they are set to off by default when the object is created(you could use alterable values but it would be a waste). however, i wouldn't be surprised if what i just said turns out to be complete crap and theres a really simple way i dont know.

i should have posted than in the articles section


 
n/a

Brian Haase (FSP)



Registered
  22/01/2005
Points
  691
30th January, 2005 at 16:29:41 -

Thanks everyone! I forgot the flags would cause the objects to distinguish differently, I was afraid they would all move to one spot like you were saying - Check it out:

http://www.bottledkarma.com/gfactory/nr2art_2.jpg
http://www.bottledkarma.com/gfactory/nr2art_3.jpg

Most of 'em already scattered in those shots, but you can still see a few of the burst rings.

 
Current Projects:
Bomb Squad (Total Progress - 3%)
:: Current Task Progress: 40%
:: Current Task - Level Editor Shell
   

Post Reply



 



Advertisement

Worth A Click