The Daily Click ::. Forums ::. Klik Coding Help ::. Randomly Generating Tiles
 

Post Reply  Post Oekaki 
 

Posted By Message

Scott Handelman



Registered
  19/05/2004
Points
  117
14th August, 2004 at 20:29:23 -

I looked through the articles, and I'm sure my question has been answered there, but I couldn't find it.

I'm trying to make a game similar to Pipe Dream, the classic game where you have to build a pipeline before the liquid reaches the end.

I've created the tiles I need and have set it so that with each left mouse click they rotate 90 degrees (using separate direction frames). The next obstacle I'm trying to tackle is randomly generating a 20x15 board of these tiles. I tried using nested loops, one for the rows and one for the columns, but maybe I don't fully comprehend how loops work in MMF because this method didn't work for me.

What I WANT to happen is in every loop iteration, a random tile should be created at (Global Value A, Global Value B) and in one loop, 32 should be added to A and in the other 32 should be added to B. Also, the direction of the tile should be random each time. I also tried it so that instead of wasting global values, I created a small object that holds the position of the next tile to be placed.

Anyone have any pointers?

 
n/a

_rydin



Registered
  06/06/2004
Points
  317
15th August, 2004 at 03:11:50 -

Pipe Dream!!! Cool!

Here's how I'd make the random tiles. Have an active object the same size of the tiles go through the entire level one row at a time. You should make it move in the tile size incriments too. And then, have counter constantly choosing random numbers going. And each time the tile maker moves to the next square, have it generate a random number, and when they are the same, make an event that makes a tile where the tile maker is. Then simply set direction to all, so then it can choose one at random, unless you arn't using all the directions.

I guess that's basicly what you were trying to acomplish with the loops and all. Tell me if this helps.

Good luck by the way. I love pipe dream.

 
"Computers in the future may perhaps only weigh 1.5 tons."
-Popular Mechanics, forecasting the development of computer technology, 1949

Scott Handelman



Registered
  19/05/2004
Points
  117
15th August, 2004 at 13:16:25 -

Okay, I've figured out how to generate the board. I decided to put loops aside for the moment and just use a timed event (Every .02 seconds...). I know fast loops will generate the board much more quickly for me, but this will suffice for now. I can always go back and fix it later.

 
n/a

vortex2



Registered
  27/05/2002
Points
  1406
15th August, 2004 at 13:43:45 -

Ok look it's really actually simple. have your active with it's directions right? then go :

Start of frame: Start loop "X" Frame Width / 32 times.

On loop "X": Start loop "Y" Frame Height / 32 times.

On loop "Y": Set active x position to: LoopIndex("X")*32,Set active y position to: LoopIndex("Y")*32 , Set direction to (select all the directions), Add tile to backdrop (or paste into backdrop, add backdrop stays if you scroll though).


And that's it..... it's really simple to do, and it's much better then using timed events.

EDIT: for a 20X15 board, just change the number of x loops to 20 and the number of y loops to 15 .

Image Edited by the Author.

Image Edited by the Author.

 
A bit of insanity with every bite!
   

Post Reply



 



Advertisement

Worth A Click