How do I set random objects to be visible each play?

Get help using Construct 2

Post » Sun May 01, 2016 11:40 pm

The title is not completely clear due charactere limitation, but what I want to do is:

I will add lets say, 5 solid sprites, that are like walls, to my top down shooter, they will create some kind of barriers as game progresses making the player's dodging and movement limited.

They will begin invisible and will become visible as the score increases. That I know how to do.

But I want that, at each play, as the game has only one level, the order is randomized.

So I was thinking about this:

If score > X, set choose(wall1,wall2,wall3,wall4,wall5) visible

This first part I get. But when it comes to setting the rest visible, when the first was random, is the problem. Should I create all possibilities independently? Like:

If score > X² and wall1 is visible, set choose(wall2,wall3,wall4,wall5) visible
If score > X² and wall2 is visible, set choose(wall1,wall3,wall4,wall5) visible

And so on. And what is worse, is that I should all variables for each instance depending how many walls are up. For example:

If score > X³ and wall1 and wall2 are visible, set choose(wall3,wall4,wall5) visible
If score > X³ and wall1and wall3 are visible, set choose(wall2,wall4,wall5) visible

So you can see how a pain that would be.

What I wonder is if there is some easier way to do that.
B
9
S
3
G
1
Posts: 20
Reputation: 1,169

Post » Mon May 02, 2016 5:56 am

How about using an array and on the start of the layout, you put all of your wall's UID into the array? (use "For each" loop)

See https://www.scirra.com/manual/108/array . If know the size of the array, you can pick a random index from the array with respect to its size and remove one randomized UID from the array. Then, pick a wall by its UID using UID number you acquired from the array. Now, set this picked wall to be visible and solid.

Note: Also when you removed an element from the array, please check whether all the elements succeeding it are shifted up in index like in Linked List or not. I forgot whether this is the case or not. This is so that you can see whether you have to sort the array after removing an element or not.

Do you follow or do you need further assistance?
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Mon May 02, 2016 6:07 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: yolkgames and 31 guests