Behind the scenes: Random, but not quite!

facebooktwittergoogle_plusredditmail

Ever wondered how do they spawn enemies in games, in such a way that the spawn positions make sense and are somehow unpredictable?

“Simple”, you might say, “just use random numbers”. Well, this kinda works, at least most of the times. The problem lies within that 1% of times when you happen to spawn a monster on top of another or at a position that doesn’t make any sense. Depending on the game specifics there might also be other problems, like spawning large groups too close together, leaving most of the screen empty, spawning off-screen et cetera.

A snapshot of the Awareness Sensor in action.

A snapshot of the Awareness Sensor in action.

Here is our solution to the problem. We call it the “Awareness Sensor”. It is a module that examines the play-field and regularly fills a queue with spawn point suggestions. In the picture to the right you can see:

  1. on-screen spawn positions (blue)
  2. off-screen (white)
  3. off-playfield (black)
  4. possible horizontal and vertical line spawn positions (purple)
  5. already occupied positions (red) and
  6. neighbouring to occupied (green) positions

 

 

A cell spawning a Reactor

A cell spawning a Reactor

To ameliorate the fact that this is a regular grid, we add a random displacement within the boundaries of the cell.

Even though this grid approach is trivial in theory, making it run fast was rather complicated. We’re not going to bore you with the details. Just note that not all possible positions are displayed. The sensor is only working when more spawn positions are required, being gentle to your mobile’s battery so you can play more!

Stay tuned for more news and behind the scenes stuff!

spacer

Leave a Reply

Your email address will not be published. Required fields are marked *