Jump to content

Auto generating levels with Tiled


Sawyer
 Share

Recommended Posts

I'm creating a game using tilemaps. 

Every level is designed similarly which contains chests and levers to open gates.

I thought it would be a good idea to set up some global objects, such as levelSetup, which passes in the tilemap for that level to reduce the code for each state.

levelSetup( ) adds the player, levers and chests, while I also have a globalObjects function which handles collisions and everything else for the player.

I've only just realised that I now have some problems with this way about things. The main one being;

  • How could I tell the current level (state) when a specific lever is pulled from the global function so I can open the corresponding gate?
Link to comment
Share on other sites

In my game, I create switches in their own object layer in Tiled. Then, in the code that loads and processes the tilemaps (and makes all the layers and stuff) that code iterates through each object creating Switch instances. Each Switch instance "knows" what it controls by looking for named objects. Essentially, any object that has a "name" property can be referenced by a Switch. When the Switch gets invoked, it calls "state.namedEntities[nameFromSwitch].invoke();" to toggle the thing, whatever it is.

Portals works the same way: an object layer in Tiled named portals, special code that makes all the Portals, referring to "levelName" and "portalName" (for where the player appears in the next level).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...