Blog02-Twin-Stick Shooter: Level Functionality
This second blog on the twin-stick shooter prototype game will be a summary of how the project was finished off.
My first task since the previous blog was to create a health system for my character. I was following along with Code Monkey’s (2018b) tutorial on how to make one, however, this way of creating a health system was more complicated than it needed to be for my project, so I decided to create a simpler health system based off of a mixture between that, another of Code Monkey’s tutorials and Alexander Zotov’s (2017) tutorial instead.
Here is one of those tutorials: How to create a basic health bar:
After the basic health system was finished, I needed to set up how the health points would be taken from the player’s character or enemies. So, naturally, I made it so the character and enemies take damage when they come into contact with bullets. (Enemies can accidentally shoot each other in this). In order to do this, I had decided that I needed to use ‘OnCollisionEnter2D’, however I ended up using ‘OnTriggerEnter2D’ instead as my first idea on how to go about it wasn’t working (with how I had things set up for my game specifically) for some reason and I needed to move onto the other requirements quickly.
This is the tutorial I looked at on how to use ‘OnCollisionEnter2D’:
While I was working on the health system, I was also writing up a script for the enemy’s artificial intelligence. The main tutorial that I followed in order to do this was another tutorial from Blackthornprod:
This tutorial doesn’t have the enemy move with physics, isn’t as simple and clear as it could be and doesn’t have everything that I felt was needed for the enemy AI script, so - naturally - I made alterations to what was shown in the tutorial.
I changed the script so that the enemy uses ‘Rigidbody.Velocity’ to move (like the player’s character).
I had the distance between the enemy and the character calculated first and held in a variable called: ‘distanceBetween’. This was so that I could simply use the variable name whenever the results of this calculation were needed rather that repeating the same calculation over and over again throughout the function (This means there’s less code & it’s clearer).
I made it so the enemy could only see the player if the player was within the enemy’s sight distance and gave the enemy a different objective for if they can’t see the player (Can see = kill player, can’t see = continue heading to duck pond to hunt).
I then added a ‘Death’ function within the Health script that checks for which game object the script is attached to (player or enemy) and whether the character’s current health has reached zero (or below - just in case). It then either loads a basic main menu I created and saves the current score as the highscore (player) or adds to the current score and destroys the game object (enemy).
Here are a couple of the tutorials I looked at in order to make a scoring system for my prototype game:
Using Static Variables:
Using ‘PlayerPrefs’:
The scoring system was the last thing I worked on before it needed to be submitted, so I didn’t have much time left and had to rush through it. This meant I had left smaller details out and hadn’t had time to work out last minute problems. In future I will try to allow for some extra buffer time before the due date - especially seeing as programming required a calm, rational mind to do the work properly. I was advised to try to keep all the contents of a particular script together in future, rather than allowing them to cross over with other scripts - if possible. (General rule: ‘One script, one purpose’).
<--BACK

















