Boss Battle — Day 4: A boss is like an onion. Figuring out a better destruction system.

Esteban Ibarra
7 min readMay 13, 2021

--

If you'd like to attempt this behemoth of a project with the same sprites, here is a link to the boss ship sprites in their current state. Or you can just download them from here at the end of the article.

Occams razor wins again!

One of the issues I had for a long time with this was how to shoot the boss elements without them being shot too early. Also, how to display the ship damage after the ships been hit a certain amount of times. At first, I put some if/thens to display the damage after a certain amount of time, and I tried many unsuccessful attempts at coming up with a communication system that would say when it’s ok to get shot. After a few days of constant problem solving and thinking about it, It turns out I was overcomplicating things and the easiest solution was to just destroy the ship in layers. When one layer is destroyed, it would remove itself and activate the next one. It actually killed two birds with one stone because I could hold the boss turrets and weapons on one layer, then the boss piece on the next layer, and when that layer got destroyed, show the damaged boss piece below, and then that could get destroyed to show the piece below that!

For illustrative purposes, each layer is moved up on the z-axis. In reality, they’re on top of each other using sprite sorting.

This required an insane amount of organizing and sorting but by the end, we got a very clean and working destructible boss!

Each Section is an empty that holds the rest of the boss pieces/layers.

After importing all the boss pieces, be sure to change them all to 2D sprite type. For the base and 3side panel pieces, be sure to change them to multi-sprites and cut them up into 3 and 2 rows.

I’ll give you the file names for each section, here’s a reference where each section goes:

Before we continue, let’s get the code you attach to the destructable pieces out of the way. It’s the target code but whittled down to its necessities:

We have an hitpoint variable we can assign in the inspector, but we’ll give it 2 by default. 1 hp is a little too quick, at least with 2hp, things will stay on screen a little longer which helps for testing. Be sure to attach this script onto anything inside of a layer. Once everything destroys itself, the layer script will know and will do its work to activate the next layer.

Speaking of which, The layer code you’ll attach to each layer is just as simple:

Layer.cs — place this on every layer.

The layer inherits from the section code, and once there are no more children objects inside of it, it will let the Section code know to remove one from the current layer and then destroy itself.

Section 0: 1 layer with 4 turrets/tanktops.

Here’s mine:

Section 1: lower right:

basedestruct_2, not in a layer.

0:base_2

1: any amount of turrets/tanktops

2: 2_arm_Sleeve_destroy

3: 2_arm_sleeve

4: more turrets.

What each layer looks like:

Don’t forget to place collider2d boxes and target.cs on each destructable object.

Section 2:

basedestruct_1

0: base_1

1: 2_side_destroyed_1

2:2side1

3: couple of turrets to taste.

Here’s how it looks like:

Section 3:

basedestruct_0

0:base_0

1:3side_destroyed_0

2:3side_0

3:turrets

and how it looks:

Section 4:

1:Turrets

2:4Top

How it should look: Not much to it!

Section 5:

1:5heart

2:5heart cover_d

3:5heart cover

4:turret

and how it looks:

Section 6! We’re almost done!

1:1frontcover
2:FrontGuns — these are the small circular turrets.

3:1tanktop

4:more turrets

and how it looks:

Section 7:

basedestruct2
0:base_2
1:turrets
2: 2arm sleeve_destroy
3: 2armsleeve
4:turrets

Here’s each layer in context:

Section 8:

basedestruct_1
0:base_1
1:8side_destroyed_1
2:8side_1
3:turrets

note: I renamed 3side to 8side, important thing to remember is the placement of the side pieces in proper order. The left side is really just a mirror of the right so you’ll already know how to place them.

and for reference:

And finally, section 9:

basedestruct_0
0:base_01
1:9side_destroyed_0
2:9side_0
3:turrets

again, I renamed the side from 3 to 9 to keep with each section. You know what to do. :)

Each section has a BossSection.cs script attached to it which contains a few things:

A section id in case we need to keep track of certain instances.

ChildrenCount was a special variable because normally, we check for 0 children to know the section is finished, but some sections have the destroyed base image inside of it and that piece is never destroyed so instead we change the children count to 1 to let the other scripts know that section is done. We’ll talk about the elements of the layers later, but in a nutshell, the only thing those items need to care about is destroy themselves when hit enough times. Our layer and section scripts do the rest. This is great because the scripts allow us to add and remove elements on the fly without needing to modify any of them! Everything is self contained and modular.

Here’s the entire code, I think we’ve had enough work putting things together today so we’ll go over the code tomorrow! See you then!

Boss Sprites:

base
basedestruct
3side
3sideDestroyed
2armsleeve
2armSleeveDestroyed
1TankTop
6Top
5Heart
5HeartCover
5HeartCover_d
1FrontCover
Boss_FrontGun_frame1
Boss_Front_Gun2_frame2

--

--

Esteban Ibarra
Esteban Ibarra

Written by Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.

No responses yet