Spaceships Radar
This is not a game!
Source project download link here and at end! - Github
This is the result of a thecnical challenge.
The challenge was:
- Create a pool of game objects.
- Active game objects from pool WITHOUT ANY CONVENTIONAL LOOP in Fibonacci sequence.
- For, while, Foreach.
- Destroy the game objects after 1 sec.
- Count and show the current active game objects in the scene.
- Add the info in UI.
- Optionally add any other pertinent info.
How I solved:
"The loop"
I just done the activation loop recursivelly.
Also add a single while loop, only to create the repetition of the "game loop" and prevent the end of the "game".
The Fibonacci
I reviewd the concepts of fibonacci on the web and created two algorithms:
- The first algorithm I setted in a class "Fibonacci.cs" that returns to me the fibonacci result of a given number;
- The second one is in the class "SpaceShipSpawner.cs" and uses the "Fibonacci" class to create an preseted pool size and the activate the game objects following the sequence.
So there's two fibonacci algorithms:
- One to get the result of a number;
- One adapted to activate the game objects accordingly the number result;
What is "The pool"?
Object Pooling is just a solution or a "Design Pattern" to prevent the process of "create, destroy then re-create the same object" since this can cost a lot of computational resources depending of the project. (e.g: A lot of guns in a game shooting a several bullets at same time)
So the process of pooling consists in:
- Create a pool of a type of gameobject (eg: bullets, enemy bullets, balls, cars)
- Create or Instatiate the game object;
- Active it when its needed.
- Deactive when fullfil its purpose.
- Reset its position or whatever status that it's possess, clear its mesh or sprite, etc. Just reset all of it behaviour and components likewise it was new and ready to use.
- Return it to its pool (eg: a pool of bullets, a pool of cars).
- If it's needed again, just activate the existing gameobject already created
The behaviour of pooling can vary because can be adaptable.
You can create a static pool that have a size and when all of game objects are active you need to deactive one game object then return it to the pool before reuse it or you can create a dynamic pool that increases its size when need a game object but all of it are in use or active.
Both have pros and cons. Just depends on your scenario.
You can download the source project and check it :)
Leave a comment
Log in with itch.io to leave a comment.