I called my Space Invaders Project called Moonflower Axis, I wanted to create a Space Invaders that didn’t rely on the standard Sci-Fi conventions. So instead of space ships and aliens as the main visual assets, I decided to use a Magic Girl and corrupted enemies, inspired by anime.
This project is where I started focusing a lot on the visual aspects of the game as well as the basic fundamentals on the games mechanics. The assets such as the sprites and the background were created through Paint tool SAI, however these sprites were not created through pixel art which could’ve been a better choice when designing a game with little focus on the character (since the size of the sprites are so small).
This project was the starting point on how I managed to add backgrounds, utilising sorting layers.
The mechanics of the game focus on player movement, bullets, and the enemy respawn.
Scripting: Player Movement
The script for the player movement works injunction to the bullet. The Input.GetAxis command outputs a value between 1 and -1 within the horizontal axis. So by putting this command (along with Vector3.right) in the update function, the value will be determined through the arrow key input. By multiplying the speed with the values from the Vector, it will allows us to adjust the movement speed variable.
The GetComponent script allows Unity to call back to a specific sprite thats linked to that specific code.
Unity recognizes these commands with the corresponding inputs so essentially it allows the player to move left and right.
the “If” statement focuses on the input for the bullet. In summary, everytime the player input the space command, bullets will be fired from the player’s position. The Time.time + fireRate command makes sure that the bullets only fire every fame rather than in large stacks.
Scripting: Bullet Behaviour
The Bullet Behaviour script controls the bullet’s speed as well as it’s despawn mechanics. I used a bullet prefab to allow it to be reused multiple times and can be transferred to different scenes.
Similarly to how I input the player’s movement, I wanted the projectiles to move upwards when fired, so I added Vector3.up multiplying it with the speed so later on, the speed can be adjusted injunction to the bullets movement.
To have the bullets despawn however, I added an if statement so when the projectiles position was greater than 7 on the Y axis, they would despawn, this is so the game doesn’t have to render large amounts of bullets after they leave the camera view.
Now the main focus is for the bullets to collide with enemies and destroy them when they’re hit. The bullets should also despawn when this happens. So I started by adding colliders to the enemy sprites and the bullet prefab.
Then I focused on scripting the collision event, I added an if statement so when the bullet does collide with the enemy it destroys the two objects.
However, I also added a respawn function for the enemies, allowing a range between (-7, 7) on the axis so there’s an element of replayability to the game. Giving a large range for the enemies respawn locations also allows a level of difficulty to the game as it adds a level of unpredictability to the gameplay.
Scripting: Enemy Behaviour
For enemy behaviour, I used similar code from the player movement script. Since their only function is to move down, I just needed to add the enemyTransform.position function so the I could add a vector and a speed variable.
As it currently stands, I’ve managed to add in an enemy respawn, basic player controls and attack mechanics. This project allowed me to develop an understanding on how vectors work and how to code collision functions. It also allowed me to gain a better understanding on how the Unity interface works in terms of the importance of positioning sprites within the game as I was experimenting where I would want enemies to spawn.
As mentioned previously, I haven’t had much experience in coding with C# especially in Unity, so the main challenge for me was picking up new commands and features especially in regards to vectors and the instantiate command. However the project taught me code that I could use as mechanics for other future, developed projects.
Software Used: Paint Tool SAI, Unity 2D and Visual Studio