Recently we were focused on improving our last game New Tap Order 2 and Unity tutorial series has been neglected. Now it’s a perfect time to resume this part on our devBlog. Today we prepared for you complete, simple mini game which refers to New Tap Order 2.
New Tap Order 2 mini game – Introduction
Long time ago we published post about abstract classes and virtual methods: C# Abstract class, C# virtual methods and functions. We decided to create more complex and practical example where they can be used.
Results are shown below:
This simple game based on well-known idea of top down shooters where space ship goes to top, avoid incoming dangers, collect useful items and destroy what can be destroyed. In our New Tap Order 2 Mini Game you can control triangle and move it from left to right. You can collect coins to gain points and crystal to temporarily destroy incoming spikes. Of course spikes can destroy the triangle so the longer you can avoid them the more chances to collect coins (points) you will have.
Whole game are divided into a dozen or so scripts. They are quite simple so we will just briefly describe the most important game’s parts:
- Main – controls main game’s logic like starting, finishing and handling scores,
- Player – as the name says, it implements player’s behaviors like moving and dying. It also contains PlayerClock and PlayerGodMode components.
- Spawnable, Coin, Crystal, Spike – they describe all spawnable objects’ behaviors,
- GUI – it’s responsible for changing and updating screens,
- InputController – it’s get user input from TouchPanels or from keyboard
- Spawner, Destroyer – Spawner creates all spawnables in the scene and Destroyer makes sure that they are destroyed when they are no longer needed
There are also another scripts in our project like Timer, Background or RendererSortingLayer (read more here: Sorting layer and order for quads). There are also extension methods mentioned before (Extension methods in C# and Unity).
This mini game is pretty simple. Main scene is constructed as you can see in the picture below:
Triangle can be moved only in one axis. Flight to top is imitated by changing background’s texture offset (read more here: Unity Parallax: The Secret).
Where are abstracts and virtuals?
There are two places where we used abstract classes and virtual methods in our mini game. First, we created AbstractResizer which contains one method and one field. It’s used by CameraFitter to change object’s scale. If you change screen’s aspect ratio, CameraFitter stretches Spawner and Destroyer to screen size.
Virtual methods can be found in Spawnable script which defines default coin, spike and crystal behaviours. All spawnables are moving down and has default destroy method. With this approach we can just get Spawnable component and execute generic methods in Player’s collisions.
As always you can download whole solution here: Download
If you have any question feel free to ask in comments below 🙂
Until next time,
Aliasing Games Team