Space Shooter Challenge: Boss Part 2 — Weapons

Space Shooter Challenge: Boss Part 2 — WeaponsI now have a boss that moves in multiple different ways, but what value is it without the ability to hurt the Player.Let’s start with the Mines that launch out the sides. I want them to disperse in somewhat…


This content originally appeared on Level Up Coding - Medium and was authored by Calum Slee

Space Shooter Challenge: Boss Part 2 — Weapons

I now have a boss that moves in multiple different ways, but what value is it without the ability to hurt the Player.

Let’s start with the Mines that launch out the sides. I want them to disperse in somewhat of a circular motion then continue down the screen, creating obstacles for the Player.

In the different Movement Coroutines, I called a FireMines method, passing through a string for the side. This allowed me to use a switch statement and set the Parent GameObject to be the correct empty object for the side that I set up in yesterday’s article.

Then, I used GetComponentsInChildren to create an Array, before cycling through this with a foreach loop. GetComponentsInChildren also adds the Parent Object to the Array. The parent object is situated at 0,0,0, and I don’t exactly want a Mine to be Instantiated there. Therefore I need to check the Tag to eliminate the object I don’t want. From there, I Instantiate my Mine Prefab and add it to the Laser Container for a tidy Hierarchy.

Once the boss is complete, I intend to tidy up the switch statement with ints as opposed to strings.

Next, I needed to create functionality for the Mines. To do so, I wanted to store the Boss as a variable, then run a Coroutine, that moves the Mine in the opposite direction from the Boss. I also created a random time, for this to run, before allowing each Mine to just travel downwards.

Additionally, I created a Destroy method that checks for the screen bounds so as not to have Mines floating in the game world forever!

For the Turrets, I started with the Turret script itself. First, creating a public method to kick things off. This requires a bool to be passed from the Boss script, as well as an int for the side to fire.

If the Boss is allowing the Turrets to fire, I start two Coroutines, one for rotating — which will be looked at in tomorrow’s article, and one for firing the large turrets.

For the smaller turrets, I need to run a SideSelection method similar to the Mine method.

If the Boss stops the Turrets from firing, I simply use StopAllCoroutines.

I used an int here as opposed to strings! This boss is an ongoing build!

Additionally, once the boss is complete, I intend on making an Array of GameObjects to store the different empty holders.

For the Firing Coroutines. I check the tag to differentiate between the two sizes, then in a while loop I Instantiate the appropriate Laser Prefab, and add the Laser to the Container.

The only extra aspect in the un shown FireLargeTurrets Coroutine, is that I had to create a Vector3 offset for the laser. The reason I didn’t do so for the Standard Turret, is that it fires two smaller lasers in very close proximity. I didn’t want this to do two doses of damage to the player, so I created an Empty Object that contained the behavior of the Laser, with two objects nested in it containing laser sprites.

To call the TurretControl method from the Boss Script, I created a method to store each Turret’s script as I would be accessing them multiple times for various uses.

Once accessing the scripts, I added them to a List.

From here, I could simply access each turret script in my allTurrets List, and access whichever public method I liked. I created a StartTurrets and StopTurrets method that called my TurretControl method passing through the appropriate calls.

Then I called these two methods at the beginning and end of my StateSelector method respectively.

Tomorrow, let’s look at implementing the Health system, and having the turrets track the player.


Space Shooter Challenge: Boss Part 2 — Weapons was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Calum Slee


Print Share Comment Cite Upload Translate Updates
APA

Calum Slee | Sciencx (2021-07-08T03:10:12+00:00) Space Shooter Challenge: Boss Part 2 — Weapons. Retrieved from https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/

MLA
" » Space Shooter Challenge: Boss Part 2 — Weapons." Calum Slee | Sciencx - Thursday July 8, 2021, https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/
HARVARD
Calum Slee | Sciencx Thursday July 8, 2021 » Space Shooter Challenge: Boss Part 2 — Weapons., viewed ,<https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/>
VANCOUVER
Calum Slee | Sciencx - » Space Shooter Challenge: Boss Part 2 — Weapons. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/
CHICAGO
" » Space Shooter Challenge: Boss Part 2 — Weapons." Calum Slee | Sciencx - Accessed . https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/
IEEE
" » Space Shooter Challenge: Boss Part 2 — Weapons." Calum Slee | Sciencx [Online]. Available: https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/. [Accessed: ]
rf:citation
» Space Shooter Challenge: Boss Part 2 — Weapons | Calum Slee | Sciencx | https://www.scien.cx/2021/07/08/space-shooter-challenge-boss-part-2%e2%80%8a-%e2%80%8aweapons/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.