Produce Random grid of blocks

Get help using Construct 2

Post » Thu Mar 07, 2013 10:50 am

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: https://docs.google.com/file/d/0Bzt0PtP2tXTYNVNGZXU4S3R5YkE/edit?usp=sharing

Many thanks

Adam

B
7
S
1
G
2
Posts: 12
Reputation: 1,232

Post » Thu Mar 07, 2013 11:01 am

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
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Thu Mar 07, 2013 11:29 am

Thanks for the information, unfortunatley I have the free version not the full one.
B
7
S
1
G
2
Posts: 12
Reputation: 1,232

Post » Thu Mar 07, 2013 11:52 am

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
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Thu Mar 07, 2013 12:03 pm

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.
B
200
S
51
G
30
Posts: 896
Reputation: 36,494

Post » Fri Mar 08, 2013 1:01 pm

All sorted with a combination of the above thanks alot.
B
7
S
1
G
2
Posts: 12
Reputation: 1,232


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 3 guests