Link to my game Galaxy Infiltrators: here
The second prototype I had to make for this assignment was a game based on Space Invaders. This means my game needed to consist of a turret sprite moving on the x-axis with the ability to fire projectiles at oncoming enemies.
Deciding a Theme
For this game, I chose to stick with the space theme, as it gave me a good opportunity to create some interesting pixel art sprites as well as a background image of space to complete the theme.
Sprites



For my main player sprite, I created a pixel art spaceship in Photoshop in 32×32. I also used these same dimensions for my enemy and health sprites after this as it allowed me to create sprites quickly but with a defined art style.
Scripting

I started the scripting by creating a Player Behaviour script, which gives the player basic movement with the use of Input.GetAxis(“Horizontal”). This allows the player to move along the x-axis, which is exactly what I was wanting. This Script also includes references to the bullet which spawns when the sprite is fired, but I added this code later once I had a script set up for bullets specifically. For the laser sound effects I added for the bullet firing, all I needed to add was ‘PlayOneShot’, as well as the file route to the FMOD event which was quite simple to code.

The next script that I coded was for Bullet Behaviour. This uses the FixedUpdate function, which means everything inside will update at a set speed, instead of per frame like FixedUpdate would. Within this function is ‘bulletTransform.position’, which makes the bullet move once it has spawned and then allowed me to edit the velocity in the enemy’s inspector tab. I also made it so that once any fired bullet passed y = 6, it would despawn to help save PC memory and reduce lag. Towards the end of the script, there is another void function which I made ‘void OnTriggerEnter2D’ instead. This section of code makes it so both the enemy and the bullet get destroyed on collision but allows the enemy to respawn at a randomly set position just above the screen so they reappear seamlessly.

Following on from the end of my previous script, I created my enemy behaviour next. In a similar way to bullet behaviour, I used ‘Vector3.down’ instead of up. This means once the object has started moving in the direction specified, it will continue until destroyed.

While making my scripts, I added a small quality-of-life improvement for when the game will be viewed in the browser. The void update in the restart script above allows the player to hit escape during the game and it will pause and end the current game, making it easy to leave without going to another page.

As well as adding the laser sound effects, I decided to create a script to add some background music as well. All that I needed to do for this was use ‘void start’ so the audio plays as soon as the game begins.


I wanted to add a health system to my game, so by following this tutorial, I was able to create both a health manager and player collision scripts. These scripts work together and keep track of how much health the player has by keeping track of how many times it has collided with and showing that in the form of heart sprites on the screen. In the first image, I stated that ‘if (HealthManager.health<=0)’, then wrote with code below that if the health is less than or equal to 0, the game will end as the player dies
What I Have Learned/What I Would Change
Despite some challenges along the way, for example, when exporting my game to WebGL, all of my sprite speeds would slow dramatically. This in the end was an easy fix as all I needed to do was change ‘void update’ in my player and enemy scripts to ‘void FixedUpdate’. This made it so the game didn’t adapt and run differently depending on the PC’s framerate that it’s on, it instead locked it at a value no matter the platform. After introducing background music, I am much more familiarised with the FMOD process and will hopefully continue to understand it.
One change I would have made would have been to add in more enemies to make my game more challenging, as well as maybe a score too. Despite this, I do think this game was somewhat successful, despite the challenges posed along the way.
.