Development secrets in Alchemist Dungeon. Building walls

In this post I'll explain how the walls made in this game

The problem that I encountered is drawing the correct wall sprite depending on the neighboring walls cause of many variations of it. So how to avoid lots of these checks in code? Bits. Let's explain this one

Random Bits.png

Let's suppose we have to choose correct sprite in red-squared tile. At the beginning, we look at the state of neighbors (wall or not) and mark it as 1 or 0 as a bit. After that, we combine all bits to one number from top neighbor in clockwise direction. In this example it will be 01000000b = 64. The found number is a ID for sprite that we need to draw

Pluses

  • constant time to find the correct sprite
  • easy to debug
  • easy to implement

Minuses

  • need a 256 sprite sheet
  • sprite repeating

Test this algorithm here: https://ldjam.com/events/ludum-dare/42/alchemist-dungeon