Checking available space

seveksevek Member, PRO Posts: 30

Hi guys.

So, I need a suggestion from you guys.

Imagine, a rectangular block(Master block) that stretches from top to bottom.
A smaller block is spawned at a random height inside of the master block.

Then I would like to spawn another smaller block if there is an avaiable space in the master block.
(For example, if the first block is spawned too close to the top, then there is no space avaialble, thus the second block is only spawned below the first one).

How could I check if there is an available space ?

Thank bunch!

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    Hi @sevek

    With a table. Basically, say you can fit 10 spawn blocks into your master block, make a table with 10 rows. Make the column integer, fill up the column cell values with all 10 possible y coordinates of your little blocks.

    Then make an game integer attribute, call it Count, set it to the same number as the rows, in this case, 10. Another game integer attribute, called Rand.

    In the button that initiates a new spawn, put:

    Rule: When touch is pressed and When Count > 0
    Change Attribute Rand to random(1,Count)
    Spawn LittleBlock
    x pos: whatever that is; y pos: tableCellValue(Rand,1)
    Add/Remove Row YourTable
    Action: Remove Row At Index Rand
    Change Attribute Count to Count-1
    

    Remember that if you want to keep on repeating the whole thing, you need to make a 2nd table, and before you start each time, use the Copy Table behaviour to copy into the second table, then reference this second table in the above rules.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • seveksevek Member, PRO Posts: 30

    Thanks gyroscope!

    I will implement this! =) You are awesome!!

    Cheers!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    You're very welcome. :smile:

    I've made a small adjustment ('cos I made a small oversight... :wink: ) Thought it best to point it out in case you miss it - with the Change Attribute Rand, you'll see it's now:

    Change Attribute Rand to random(1,Count)

    :)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • seveksevek Member, PRO Posts: 30

    =) Thanks!

    I am working on it now and will let you know how I did it!

    Thanks! =)

  • seveksevek Member, PRO Posts: 30

    Just quick questions.

    what would be the purpose of the following rules?

    Add/Remove Row YourTable
    Action: Remove Row At Index Rand
    Change Attribute Count to Count-1

  • seveksevek Member, PRO Posts: 30

    Just quick questions.

    what would be the purpose of the following rules?

    Add/Remove Row YourTable
    Action: Remove Row At Index Rand
    Change Attribute Count to Count-1

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    Hi, first to say, for your info, I've now added When touch is pressed to the rules for the button.

    @sevek said:
    Just quick questions.

    what would be the purpose of the following rules?

    Add/Remove Row YourTable
    Action: Remove Row At Index Rand
    Change Attribute Count to Count-1

    The system is as follows:

    First time, a random number between 1 and Count(10) is chosen, let's say it's 6.
    Now the y coordinate in row 6 of the table for the spawned actor is used.
    Next, that row 6 is removed (using the Add/Remove Row behaviour), and the rows below it all move up one.
    Count is made to be Count - 1, so Count is now 9

    2nd time, a a random number between 1 and Count(9) is chosen, let's say it's 3.
    Now the y coordinate in row 3 of the table for the spawned actor is used.
    Next, that row 3 is removed (using the Add/Remove Row behaviour), and the rows below it all move up one.
    Count is made to be Count - 1, so Count is now 8

    etc.... until Count is zero.

    Because the rows are deleted one by one, that's why I suggest deleting these rows in a copy of the "master" table; that way, when you reset all the attributes to their start values, you copy the table again and use that copy, leaving the master table intact for the next time.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • seveksevek Member, PRO Posts: 30

    Oh I see.

    It is to avoid overlapping.
    For the game that I am designing, a new master block is spawned every 0.8 second and the old one is destroyed, which I have the codes.

    Thank you so much for spending time to explain it thoroughly.
    Really appreciate it! =D
    Hope you are enjoying the weather!

    Cheers!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2014

    @sevek said:
    Oh I see.
    It is to avoid overlapping.

    That's right!

    Glad it helped; and yes, it's been lovely here today though I must mention I'm not a great "sun worshipper"! Cheers. :smile:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.