Need a quick tip on how to handle simple random spawning

Get help using Construct 2

Post » Tue Apr 22, 2014 12:41 am

Picture Below.
Orange square is the player. Gray is a building and all 20 buildings are 1 sprite copied over and over. When the pink AI collides with the player, there are 2 different choices. One choice is supposed to turn a single random building green, the other turns a single random building red.

Do I have to create 20 different sprites for the buildings, 20 for green, and 20 for red? Or is there a simpler way to do it? The game ends when there are no longer any gray buildings left, and ending message depends on the number of red and green buildings on the board, different message for different amounts. Do I create 60 seperate sprites or is there an easier way? Any tips are Much Appreciated!

Image
B
33
S
16
G
6
Posts: 54
Reputation: 5,366

Post » Tue Apr 22, 2014 1:25 am

You could use animation frames to easily switch from gray to green or red.

on.collision pick nth.grays instance int(random(0,grays.count-1)) // When player collides with enemy, pick a random instance of the gray buildings
grays.changeframe to choose(1,2) // assuming frames 1 and 2 are green and red.

// Now we need to check if any gray buildings are left, this could be every tick, or when one the buildings have changed

pick by comparison grays.animationframe = 0 // picks all the gray buildings
sub event > system.comparetwovalues grays.pickedcount =< 0 // the subevent inherits the picked buildings so now we see if any gray buildings are left, if not end the game
B
10
S
2
G
1
Posts: 92
Reputation: 926

Post » Tue Apr 22, 2014 1:41 am

Image
You do not have the required permissions to view the files attached to this post.
B
10
S
2
G
1
Posts: 92
Reputation: 926

Post » Tue Apr 22, 2014 3:17 am

Wow, that's fantastic! I REALLY appreciate the time you took to explain it!
Your effort won't go to waste, I will carry this information on all my projects
B
33
S
16
G
6
Posts: 54
Reputation: 5,366


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests