This section will cover how I implemented the functionalities and made sure the problems I faced
This section will cover how I implemented the functionalities and made sure the problems I faced
This part is one of the trickiest to figure out. Though I wrote some ideas to implement it, things dont always go to plan.
This was suppose to be original way to rotate the gears in the game.
In Unity, there will be a Gear manager that will find the starting gears and rotate it. After which, the gear will find its neighboring gears and give the speed and direction the respective gear through Recursion.
This would have work fine if I only had one layer (basically a section of which the gear can be place). However, with the addition of Joint, this is not a good idea as it will reach Stack Overflow.
Making each gear independent from one another
This time around, I made the gear independent to one another. It will rotate if another gear tells it to rotate. This was better and does not cause stack overflow.
Joint are also similar in a sense. It will only rotate if either the top or bottom part of the gear rotates.
Using Z-index
To make the game seem like that there are multiple layers in the game, I place different layers at different Z-index. So when the camera see the first layer, the background will block the sight of both the second and third layer.
If the camera wants to see the second layer, both the camera and the background move such that the camera cant see layer 1. That way, there is no overlap in the gears.
Using finite state machine pattern
As the mouse have different states (such as the moving state, deleting state), I thought it would be best represented as a finite-state machine. This work well as it helps with both readability and debugging.
Using Inheritance and composition
To make gear various gear, I use inheritance to make sure that each gear class has a specific set of function in order to rotate.
I would use composition to assign the roles. (like starting gear would have a starting gear script). This make creating different gear quite easy and making different layers much easier too.
Using Interfaces
To have the object move, I used an interface as it gives the different script that implements the interface to be able to move.
In the mouse behaviour, the moving state would be able move the object using function from the Imoveable interface.
Telling different gear script to Jam
To jam the different gears, the jamming gear will tell other gears to stop moving. That gear will pass the message to tell the other gears to stop rotating as well. As a result, all the other gears would stop.
To release the gear from their stop state, they have to remove the gear that is sending the message to resume the rotation of gear.