Create a line of monsters

Get help using Construct 2

Post » Thu Aug 23, 2012 11:01 am

Hi all,

I am trying to create a tower defense type game but I am having problems making a list of enemies appear, I'll try to explain...

What I want is there to be a line of, lets say: enemy1, enemy2, enemy1, enemy3. with a 2 second gap between them and I would like to create them from a sprite "Start".

I am able to do this with all the same enemies but I can't seem to work out how to get it to work for different ones??
B
25
S
8
G
6
Posts: 35
Reputation: 4,905

Post » Thu Aug 23, 2012 1:13 pm

Use a one-dimensional array containing a number or string for every enemy type.

If you don't understand arrays, it won't make much sense, but if you do, you will see what I mean.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Aug 23, 2012 2:59 pm

I did try that but I couldn't seem to work out how to run through the list to create a different creature each time with a gap of 2sec.


B
25
S
8
G
6
Posts: 35
Reputation: 4,905

Post » Thu Aug 23, 2012 3:21 pm

You can use a single object with multiple instances.
You just define the differences between the enemies using instance variables, and animations.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Thu Aug 23, 2012 3:33 pm

I'd do something like this.

Make an array, each entry corresponding to a monster type.

Then try something like:

global variable monsterIndex = 0

every 2 seconds:

if array.at(monsterIndex) = "zombie"
--> create zombie
if array.at(monsterIndex) = "ghost"
--> create ghost
if array.at(monsterIndex) = "squid"
--> create squid

(etc, for all the monsters)

Add 1 to monsterIndex


Do you see what I'm getting at?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Aug 23, 2012 3:47 pm

Excellent, I hadn't thought about using the variable as the array ref.
B
25
S
8
G
6
Posts: 35
Reputation: 4,905


Return to How do I....?

Who is online

Users browsing this forum: makkancs and 23 guests