How to set up a Destroyer + it's turrets?

For questions about using Classic.

Post » Thu Sep 08, 2011 10:12 pm

I have destroyer ships shooting at each other.

The enemy destroyers have one AI and behavior script.

These enemy destroyers have multiple turrets on them.

Each turret has it's own set of sprites, events, AI, targeting, etc..
(The turrets are set up without turret behavior so they are using some custom sprites for collision detection, etc..)

How to best set up one destroyer ship 'template' (1 AI for destroyer + 1 turret w. behavior then multiply that turret on the ship) so that I can multiply these destroyers, spawning a second destroyer, which has all turrets set up like the first one and both are attacking the player ship?

Should I create the two destroyers by hand, positioning all sprites on them for the turret-parts and so make them hard-coded? Like one bunch of commands would be Enemy_Destroyer_1,(on it the turrets with their own behavior) all hard-coded/hand-positioned and it moves, for ex. via global variables and create all Enemy_Destroyer_1..2..X by hand?

Or is there a way in Construct v1.2 to set up one destroyer template, then just spawn two of this template at different battlefield coordinates, both ship's behaviors fully working, they can attack, maneuver, etc.. as was coded in the template?mercy2011-09-08 22:25:20
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Sat Sep 10, 2011 2:50 pm

I'm confused. Can't seem to set up the turrets properly.
Each turret has 4 sprite parts. If I want to have 5 turrets, must I create 5x4 sprites for all turrets at the beginning of the layout? pfff..

I want to position all 4 turrets (sprite sets) at different places. mercy2011-09-10 14:52:32
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Sat Sep 10, 2011 3:40 pm

you can use containers if each turret is unique, but if you have lets say 4 turrets that are all the "same" sprite, as in a single object type containers may not be the best way. you'll have to give each ship an id, and then give the turrets two variables, one for their ID, and one for their ship ID. using events youll have to make a
>for each ship
>turrets variable 'ship id'=ships('ID')
-ACTION: TURRET SET POSITION TO SHIP, IMAGE POINT = ('TURRET POS ID')

you could try it with or without the for each, not sure if it'll make a difference, but sometimes it does depending on what your doing.

so for each ship, lets say if they had 4 turrets, you'd have 4 turret objects that youd need to create, and give them each the same 'SHIP ID' when you spawn them (you would do this at the start of the layout, or when you spawn a ship by creating 4 instances and giving them their given ships id as 'SHIP ID'), and then numbering them 1 2 3 4 for their TURRET POS ID. that variable would tell each turret what exactly they are on their given ship. of course if you were to follow everything i said youd need to give the ship 4 image points. i realize this is a little confusing to describe in words, so if you have any trouble just reply :DQuaziGNRLnose2011-09-10 15:41:49
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Tue Sep 13, 2011 7:48 pm



The turrets are created and placed okay. How to move them together with the starship now?

Every tick do what? Couldn't find a command like:

For i=1 to 4 Move_object(Turret.i, MyDestroyer.ImagePoint.i)

?mercy2011-09-13 19:49:39
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Tue Sep 13, 2011 8:59 pm

OK, I finally managed it. Gaaarrhhh.. Construct has a very original way of using private variables to move/handle objects created on the fly..mercy2011-09-13 21:01:00
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Tue Sep 13, 2011 9:55 pm

I'm glad you handled well. I just learnt something :D
B
3
G
1
Posts: 44
Reputation: 563

Post » Tue Sep 13, 2011 11:21 pm

Are you using loops to position your turrets on the destroyer?
If you are, you could just use an 'always' event and sub events, like this;

Always
(Sub Event) TurretID = 1   Set turret pos to ship1 imagepoint 1
(Sub Event) TurretID = 2   Set turret pos to ship1 imagepoint 2

And so on. You don't have to do it this way, you got it working.

It just seemed as though you were going to use loops to
position your turrets, when you could easily do that with an
'always' event. That's how I would have done it, but you got it
working, so good for you :)Intrepid2011-09-13 23:22:16
B
12
S
2
G
4
Posts: 44
Reputation: 2,389

Post » Thu Sep 15, 2011 8:38 am

Thanks for the idea, but I couldn't find the "Always" event in Construct v1.2. It would really be nicer with "Always"

Edit: Found always among events. Thank You!

mercy2011-09-15 08:58:06
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Thu Sep 15, 2011 8:48 am

I have a turret sprite, which I destroy at the beginning of the layout.
At runtime 4 copies of this is created as can be seen above. I gave them private variables.

Here is the problem:

It seems, the created turret sprites' .Angle properties cannot be accessed via their private variables ?

I want to narrow down the angle range of the turrets so they can only rotate away from the ship in a ~110 wide angle. The turrets must not turn toward the other turrets beside them, plus they must of course not turn inside, the deck the ship, so they cannot shoot their own destroyer's control towers into pieces.

I want to get each turrets current Angle, compare and don't allow it to increase or decrease too much.

Turret.Angle('ID')

Turret('ID').Angle

Turret.Value('ID') & Turret.Angle

give errors.

Here an "if" would be helpful, like:

If (turret('ID').Angle > 320)
   Turret('ID').Angle--;

Is there any way to access & compare private variables of created objects? I want a lot of turrets created at begin of layout so making and adding 50 unique turrets sprites by hand is not very flexible.

I thought of maybe making a global variable, create a loop but i can't access the created objects properties AND private variable at the same time.

I can only set its position by directly accessing the private variable:

Turret: Set position to object MyDestroyer image point 'ID'

"Compare angle" does not give access to the created turrets private variable so I could identify, which turrets angle should be compared.

Compare private variable gives errors, when I try to give it
Turret.Angle('ID')
Turret('ID').Angle

mercy2011-09-15 09:32:43
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Post » Thu Sep 15, 2011 2:51 pm

Okay, I got it working. Created a loop, which picked only turrets with certain private variables, guess it can be done with arrays too in case of unique ship structures. Then simply with a sub-event I compared Turret.Angle and with "set angle" set the turret angle. It turns out this way "set angle" affects only the turret on which the loop count is at the moment. Good!

Managed to create an angle range with too loops, so the turrets don't turn inward, over ports of the ship. From this point on it should be an INI file, or:

1. one row of turrets at left port
2. other row for right port.
3. few turrets on the bow
4. few turrets on the stern

And the angle-ranges can now be set for each row/group. Hmm..

This means that I have to begin creating eye-catching graphics design - which has to get attention even in thumbnail size so people click on the screenshots and get hooked - with only 1-2 years of experience, which is not enough.

Still, failure is not an option, onward is the only way! Albeit very rocky. The greatest task, making eyecandy, cannot be regulated with easy-made Construct commands. Steep slope. So many newbies are falling into the depths below, like me. Game industry nowadays seems like the Wild-Wild West.. :(( mercy2011-09-15 15:44:27
B
25
S
5
G
5
Posts: 138
Reputation: 5,638

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests