VICTOR MATHEUS

Spaceships Radar

This was a GREAT challenge for the fact that I was not allowed to use any conventional loops. Take a look in the process of the development below!

The Challenge

  1. Create a pool of game objects.
  2. Active game objects from pool WITHOUT ANY CONVENTIONAL LOOP in Fibonacci sequence.
    1. For, while, Foreach.
  3. Destroy the game objects after 1 sec.
  4. Count and show the current active game objects in the scene.
  5. Add the info in UI.
  6. 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:

  1. The first algorithm I setted in a class “Fibonacci.cs” that returns to me the fibonacci result of a given number;
  2. 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:

  1. One to get the result of a number;
  2. 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:

  1. Create a pool of a type of gameobject (eg: bullets, enemy bullets, balls, cars)
  2. Create or Instatiate the game object;
  3. Active it when its needed.
  4. Deactive when fullfil its purpose.
    1. 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.
    2. Return it to its pool (eg: a pool of bullets, a pool of cars).
  5. 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.

Gallery