Produce Random grid of blocks

0 favourites
  • 6 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hi all

    I am experimenting with Construct to teach some kids in my school about game making.I have followed a few of the threads on here to get to where I am now.

    I want the game to generate a 10 by 10 grid of 60px square boxes. The boxes are randomly picked from a choice of 3.

    I have coded this using nested loops. The top loop however doesnt stop at 10 rows like it is set, it just keeps going. If someone could tell me what I have done wrong I would appreciate it.

    Project link: docs.google.com/file/d/0Bzt0PtP2tXTYNVNGZXU4S3R5YkE/edit

    Many thanks

    Adam

  • I havent looked at your file, but you can just put the different blocks into a family to pick randomly.

    Then the event (fake code)

    conditions

    start of layout -

    + for loop "y" 1 to 10

    + for loop "x" 1 to 10

    actions

    create family sprite

    +set position x to 60*loopcountx

    +set position y to 60*loopcounty

  • Thanks for the information, unfortunatley I have the free version not the full one.

  • Well you could either use the same block but set it's animation frame at random, or keep the same conditions and create a series of sub events like

    conditions

    start of layout -

    + for loop "y" 1 to 10

    + for loop "x" 1 to 10

    action

    set local variable to random(3)

    sub event condition

    +local variable = 0

    create sprite type 1

    +set position x to 60*loopcountx

    +set position y to 60*loopcounty

    sub event condition

    +local variable = 1

    create sprite type 2

    +set position x to 60*loopcountx

    +set position y to 60*loopcounty

    etc

  • It would seem your loop is re-running every tick.

    Select all of event two, and drag it into "On start of Layout" and you see it works.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • All sorted with a combination of the above thanks alot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)