Galaxy Shooter: Space Invasion

Overview

About the project

Galaxy Shooter Space Invasion was one of my first projects in game development. It was developed for a final project in University. In this game, The Earth is under attack from an invading unidentified alien fleet! The alien's surprise attack has destroyed most of Earth's defenses. It is up to you to protect the planet with everything you've got!

Date
April 15, 2021
My Role
Programmer
See this Project & More!
The Game

My First Adventure

Galaxy Shooter: Space Invasion was one of my first game development projects. It was made during my time at Southern New Hampshire University for a class's final project. This game was inspired from classic arcade games such as Galaga and your goal is to protect Earth by defending against the waves of aliens coming down at you. You must shoot and destroy any incoming alien ship. You can also use power-ups to help you in your defense.

The art and sound assets were provided to us. However, in this project I acted as the lead programmer. The development time of this game took around 2 months. The entire project was done and completed alone. I used an agile methodology when developing the game. However, as this was my first game project, there were many difficulties and challenges I faced.

The Journey

Challenges I Overcame

The development of this game came with a number of challenges. Firstly, I was a university student learning how to program in C#, learning how to develop in Unity and learning how to make a game. Each of these skills are difficult to learn and my challenge here was to learn them simultaneously. Here are some of the challenges I overcame and what I learned.

  • Learned how to program in C# in order to be able to program the game in Unity.
  • Learned how to use and develop in Unity by reading textbooks and following tutorials and eventually experimenting with the software.
  • Learned how to develop a game using an agile development methodology by staying after classes at university and have additional discussions with professors and other professionals.
  • Creating a unique experience for players by creating a loop cycle for enemies to spawn in random areas in order to surprise the player.

My Impact

This was a completely solo project done in a university class. Art assets & music were provided, however I did program in the mechanics of the game. My impact on this game are as follows:

  • Gameplay, UI & Audio:
    -
    Player controller.
    - Enemy controller.
    - Powerup mechanics.
    - Collision Handler
    - Animations.
    - Spawn Managers.
    - Score Manager.
    - Main Menu UI
    - Main game audio
Gameplay Mechanic Descriptions & Video Examples

Galaxy Shooter: Space Invasion - Breakdown

Galaxy Shooter: Space Invasion was a university project that took around a month to complete. The class focused on C# programming and later focused on Unity. However, I took the initiative and learned Unity so I could create games. This game was developed using C# in Unity. This section is to showcase videos & code snippets of the created mechanics.

Here are some examples of gameplay mechanics & features that I worked on! Each description of the mechanic will have a video. If you'd like to see the code as well, it will be posted at the bottom of the page!

** Note: some of these videos will have background music is disabled to avoid loud music in your headphones. See the music section to view audio implementation **

Player Controller & Starting the Game

The first video here showcases the player controller as well as how to start the game.

To start the game the player can either attack the Asteroid with their laser or run into it with their ship. The asteroid script is fairly simple. When the game starts, the asteroid's script first tells it to rotate using a vector3 forward multiplied by a speed value and Time.deltaTime. Then an OnTriggerEnter2D is used to check whether the player's laser hit the asteroid or if the player's ship hit it. In the case of the laser, an explosion animation is played, the object is destroyed and the Spawn Manager script is instantiated for enemies. The same functionality is used for when the player collides with the asteroid. However, the player will also take damage. This damage method comes from the Player Controller Script.

The Player Controller is made up of various methods. The first method, "Calculate Movement", is to control the player. I used Unity's input system to allow for player movement. To do this I added the "horizontal" and "vertical" inputs to variables and then added them to another variable that also takes in a new Vector3. Player boundaries are also applied in the Calculate Movement method. A series of IF statements are used to determine how far a player can move on the Y axis before they are stopped. On the X axis, the player is allowed to move as far as they want. However, once they are off of the screen, they are teleported to the other side.

Player's attacking mechanic is also run via the Player Controller. The method "Fire Laser" instantiates a laser prefab and uses a Vector3 to launch it straight up from a predetermined position. This method also checks to see if the player has a powerup called "Triple Shot" and if so, instantiates a different type of laser. After each use of the laser, a cooldown timer determines when the player can shoot next. Finally, the audio for laser is played.

  • The laser itself contains its own script. This script is what makes the laser move upward. Once the laser prefab moves offscreen, it is then destroyed to keep the game clean of unused objects.

The next important method in the Player Controller is the "Damage" method. As the name suggests, this handles the player's health points. First, the method checks to see if the player has a shield activated. If not, the player will take damage (loses a life). An extra set of checks determine if the player is at a certain amount of health. If so, the script calls either the "RightEngineDamage" or "LeftEngineDamage" methods to visually show the damage on the ship. Finally, if the player loses all of their lives, the death logic will run. This method destroys the player's model, instantiates the death animation and plays the death audio.

Finally, the Player Controller also handles logic for power ups. The powerups themselves are not instantiated here. However what the powerups do are stored in this script. The powerups include a triple laser shot, speed boost and shield. Triple shot activates a new prefab for triple lasers, speed boost multiplies the current speed by the boost and the shield activates a visual effect with a collider.

Enemy Controller & Spawn Manager

This next video shows how the enemy controller works. This was not my first AI I've created, but it was my first game AI I created. The implementation was simple, but worked well for this game.

First, in the Update method, I implemented a simple movement logic for the enemy AI. I used transform.Translate() with a Vector3.down multiplied by the enemy speed & Time. This allowed for the enemies to move at about 4 meters per second down the screen. However, I didn't want the enemies to just move down the screen in one place. Therefore I also implemented the logic to randomize their respawn locations if they managed to move down the screen without being destroyed. Once they are off the screen, they are randomly teleported to another location above the player (off-screen).

Next, I implemented logic very similar to the asteroid's script. An OnTriggerEnter2D was used to check whether the player or the player's laser collided with the enemy. If either one of these objects collides with the enemy, a death animation is played, the object is destroyed along with it's collider and an audio file will play for the explosion. If the player was the one to collide with the enemy script, the player will also take damage.

The next script, the Spawn Manager was created so that the enemies didn't always spawn in the exact same location. To do this I created an IEnumerator which has a loop to check if the player has died or not. If the player is dead, spawning stops. Otherwise, a variable containing a Vector3 with a random range (contained in the game area) was created. This variable is then used to instantiate enemy prefabs in a random position.

  • The same logic is used to spawn in powerups.

Powerup Scripts

This next video showcases the powerups available in this game. Each powerup has their own ability. The powerup ability's logic is located in the Player Controller. However, this next script controls how the powerups move down the screen & which one should be activated on pickup.

Once the powerups are instantiated on the screen via the Spawn Manager, the Powerup script is then active. First, the powerups are translated down the screen using a Vector3.down multiplied by speed & time in the Update method. An IF statement also checks to see if they've gone off screen. If so, they are destroyed from the game.

Finally, an OnTriggerEnter2D is used to check if the player collided with the powerup. Once the collision occurs, audio plays and the trigger method checks to see what the Powerup ID is (defined in the inspector). After the Powerup ID is checked, the appropriate powerup is then activated from the Player Controller script.

Note: The Triple Laser powerup has an additional script that handles the logic just like the normal laser script.

UI Manager

Next we are showcasing the UI manager. The main role for this script is to manage the player score, player lives and display the game over screen when the player dies.

This script starts its activation by setting the player's score to zero and caching the game manager in the Start method. Next, two methods called "UpdateScore" & "UpdateLives" are used to update the player's score when destroying enemies and to update the player's life UI every time they take damage. The Update Score method takes in a integer parameter which is updated via the Enemy Controller script. The Update Lives method takes in a parameter that is equal to the number of HP points the player has and updates the UI accordingly.

Finally, the last method "GameOverSequence" displays the UI when the player dies. The Game Manager's boolean value is set to true in this method and two UI texts are set to active on the screen. Then a coroutine is started which animates the text "You are Dead" on the screen.

Game Manager

The game manager is a script that handles the reloading of the level and quitting the level.

Once the UI Manager script sets the Game Manager Boolean "_isGameOver" to true, this script will allow the player to press "R" to reload the level or "Q" to quit. The player is informed of these options when they die and the UI text is shown.

Gameplay Mechanic Code Examples

Player Controller & Starting Game Scripts

Here is the script of the player controller code and the asteroid used to start the game.

Player Controller Code
Asteroid (Start Game) Code

Laser Script

Here is the script in charge of the laser's logic.

Laser Logic

Enemy Controller Script

Here is the script for the Enemy Controller.

Enemy Controller Code

Spawn Manager Script

Here is the script for the Spawn Manager.

Spawn Manager Code

Powerup Scripts

Here is the script for the Powerup logic.

Powerup Script
Triple Laser Powerup Prefab Code

UI & Game Manager Scripts

These scripts handle the Game Manager & UI Managers

UI Manager Code
Game Manager Code
Main Menu Code
Quit Game Code