-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|236|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Maps and Levels


 
Pakz
Created : 23 January 2019
Edited : 23 January 2019
Language : Monkey2

Bitwise technique

Id System for neighbouring tiles

Latest Update

When you have a tile map you might have tiles that fit next to each other.

For instance a single wall block would have edges on all sides while if there is another wall next to it then the side where it connects would look different.

When you go through every possible connection that a tile can make above/left/right there is 16 different tiles. The Bitwise technique lets you automatically find that tile.

The example code show how to do this :

( I learned this from a book called "Procedural Content Generation for C++ Game Development" which was given away for free at packt a while ago.)

 

Comments


Wednesday, 23 January 2019, 09:03
Jayenkai
I typically use a function labelled Mat(x,y) which fills a matrix array of 9 values.
Each game tends to have a specifically coded mat function, but in general they end up specifying where walls or floors or other objects are, in relation to the given x,y.
The numbers 1-9 are layed out the same as the numbers on the Numpad, for ease of "glance at the keyboard to remember which is which", with 1 being bottom left, 9 top right, 5 middle, etc..

But, yeah, the same idea. Fill the matrix for the player, or enemies, or falling objects, etc.
Even though the code inside the function can be drastically different between games, the way they're used is usually the same, and it's good to use common techniques between games.

.. in many ways, I'm the reverse of "reusable code" in that my game code stays the same, and all the function code is different!!!
Wednesday, 23 January 2019, 09:51
spinal
I did a similar thing in a version of sensitive to calculate the tile used for the shadows. Don't know if it was any faster, but it sure felt more 'proper'.
Wednesday, 23 January 2019, 11:32
rockford
I've done something similar for a number of my older games, including B'lox!, Drench and a Puyo Puyo clone (to name just three).