# Problemas at spawinig objects from a IA [Boss battle]

Get help using Construct 2

### » Mon Oct 26, 2015 1:56 am

Hi guys!

It's my second time asking your help (I have to warn you, my english is Tarzan-like)

Well, my problem is in a boss battle that I'm doing. In some parte of the battle, I need that the boss spawns a determined number of shots (BossFinalWeapon in the capx - image), for example, when boss is in state 3 (Estado 3 in the images), it should spawn ONLY 3 shots, then wait 1 sec and then spawn another 2 shots (and so on, in total are 15 shots, as you can see in the image). The problem is. sometimes the instructions works just fine, but in others, the boss spawns like 6 or more shots at same time, making a mess. I tried everything, using variables controlling the number of shots, using cooldown, etc... As this is a random issue (the possibilities this happening are like 60/40) I don't find the proper way to solve it, beacuse it's completely random. I don't know how to control it and neither know what is causing it. I attach the image with the events in construct 2.

The image

B
7
S
1
Posts: 5
Reputation: 584

### » Tue Oct 27, 2015 5:27 pm

I would think about re-organizing your code according to Object Oriented principles... chiefly modularity.

i.e.

Make a function that spawns a boss bullet a specific number of times. You can randomly generate the angle and image spawn point within certain bounds (it looks like your angle in bounded 230-310 deg). Then you can simply call that function and input a specific number of times that you want the boss to fire.

In this function, use trigger once and a for loop with an input parameter for the loop number, something like:
Code: Select all
`local variable randomImagePoint = -1;local variable randomAngle = -1;Function bossSuperAttack (Number_Of_Shots)  trigger once  for loopindex: 0 :: Number_Of_Shots     randomImagePoint = round(random(6));     randomAngle = round(random(81)) + 230;     Spawn BossFinalWeapon on Layer 4 (image point randomImagePoint);     Set angle to randomAngle;     Wait 1 sec;`

Then when you want the boss to fire four shots (on a certain condition) you simply call bossSuperAttack(4).

If you don't want the attack to come from different points each firing, simply move the random assignment up one level to the function, rather than inside the loop (like the above shows).
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,867

### Who is online

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