Modifying our platform game
We now have all the knowledge we need for creating a multi-level game. First, we will create a list of levels and a function to load them:
var levels = [ {tiles: "level1.json", enemies: "level1.js"}, {tiles: "level2.json", enemies: "level2.js"} ]; var currentLevel = 0; var loadNextLevel = function(group){ var level = levels[currentLevel++]; // clear old level $("#level0").remove(); $("#level1").remove(); for(var i = 0; i < enemies.length; i++){ enemies[i].div.remove(); } enemies = []; // create the new level // first the tiles gf.importTiled(level.tiles, group, "level"); // then the enemies $.getScript(level.enemies); // finaly return the div holdoing the tilemap return $("#level1"); }
The highlighted lines are the ones that do the remote loading of files. This...