Legend of Zelda: A Link to the Past had some pretty nice cliffs. I'd like to create something similar, but am having trouble figuring out how to place them.

LOZ grid

Image is from: How did LoZ: A Link to the Past handle sub-tile collisions?

Anyways, I have a bunch of tiles like in the above image. How can I simplify how they are placed in the game world? I currently have a 50x50 grid and a painter class in Java that tells the system where to place the tile: Painter.fill(this, 15, 30, 13, 50, Terrain.EMPTY) would fill X-15 and Y-30 with a set of EMPTY tiles (basic ground tiles) 13x50 tiles wide. I can also apply 'for' loops to paint the entire map with a type of tile, or tell it to only make a row X-tiles long, like this:

for (int i=0; i < LENGTH; i++) {
        if (map[i] == Terrain.EMPTY && map[i+50] == Terrain.WATER){
            map[i] = Terrain.CLIFF_S_BOTTOM;
            map[i-50] = Terrain.CLIFF_S_MID;
            map[i-100] = Terrain.CLIFF_S_TOP;

Is there a simpler way I could be telling my code to place lots tiles in a particular formation quickly?

EDIT: I just learned about the concept of bitmasking. I think this will solve most of my problems, but I'm still open to other ways of solving the problem.

Enums keep appearing as a possible alternative to the bitmask solution. Are they viable for this application?

  • 1
    \$\begingroup\$ Are you looking for something like gamedevelopment.tutsplus.com/tutorials/… ? \$\endgroup\$ – Josh Oct 26 '16 at 20:31
  • \$\begingroup\$ Hah...little sheepish here. I had never heard of bitmasking before you mentioned it. \$\endgroup\$ – user5352515 Oct 26 '16 at 20:35
  • \$\begingroup\$ I skimmed the article. It looks like I can use bitmasking to solve a lot of the problems I've been running into. \$\endgroup\$ – user5352515 Oct 26 '16 at 20:38
  • \$\begingroup\$ It should be noted that if you go with bitmasking, you're limited to 64 permutations. \$\endgroup\$ – Krythic Oct 26 '16 at 23:37
  • \$\begingroup\$ The power of bitmasking comes into play when you need a tile that's passible, swimmable, and a cliff. \$\endgroup\$ – Krythic Oct 26 '16 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.