An example of the levelComplete method that is available as part of a GameSkeleton setup.
Use wasd or arrows to move. Complete each level by going over the red spot.
(function() {
var scene1 = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1],
[1,2,2,2,0,0,0,0,0,1,0,0,1,0,0,0,0,2,2,2,1],
[1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1,0,3,1,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
var scene2 = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1],
[1,2,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
var scene3 = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
function LevelComplete() {
var specs = {gWidth:672, gHeight:288, controllerDivId:"controller", gameScale:0, gameLoop:this.loop, initializationSpecifics:this.setup, tileW:32, tileH:32}
tabageos.EventDispatcher.call(this);
tabageos.GameSkeleton.call(this, specs);
this.establishKeyEventsForReset();
}
LevelComplete.constructor = LevelComplete;
LevelComplete.prototype = Object.create(tabageos.GameSkeleton.prototype);
Object.assign(LevelComplete.prototype,tabageos.EventDispatcher.prototype);
LevelComplete.prototype.setup = function() {
this.player = new tabageos.MapTraveler(32,48,32,32, scene1,null,1,0,32,32,scene1.length,scene1[0].length,0);
this.player._directCanvasObject = this.charLayer;
this.player._autoAnimate = 1;
this.player.setupForTileMove();
this._cameraType = 1;
var cValues = {1:"#6495ed",0:"#FFFFFF", 2:"#212121", 3:"#ff0000"};
this.player._veloc.x = 0;
this.player._veloc.y = 0;
this.camera.colorValues = cValues;
this.removeHUD();
this.sceneChanger.addScene(scene1);
this.sceneChanger.addScene(scene2);
this.sceneChanger.addScene(scene3);
this.sceneChanger.changeCurrentMap(1);
tabageos.BlitMath.drawSquaresFromPattern(this.display, this.sceneChanger.currentMap, 32,32, cValues);
this.player._map = tabageos.BlitMath.replaceAllOfValueFromMultiArray(this.player._map,3,0);
this.afterSceneChange = function(e) {//not an event handler a direct method call.
//because of how everything is set up, we still have 'this' in here.
this.player._map = tabageos.BlitMath.replaceAllOfValueFromMultiArray(this.player._map,3,0);
this.camera.reset();
this.callCamera(0);
};
this.controller.basicArrows.a = 49;//1
this.controller.basicWasd.a = 49;
this.controller.basicArrows.b = 50;//2
this.controller.basicWasd.b = 50;
this.controller.basicArrows.c = 51;//3
this.controller.basicWasd.c = 51;
if(this.controller._style != 3) {
this.controller._basicControllerButtonTakedown();
this.controller.standardControllerButtonSetup();
}
};
LevelComplete.prototype.showLevelSelectOptions = function(ts) {
this.charLayer.context.clearRect(0,0,3336,320);
this.animatePixelType(this.camera.v.x + 24,24,"Level Complete!",.5);
this.pixelType(this.camera.v.x + 24, 48, (!this.device ? "Press 1, 2, or 3 to continue" : "Press a, b or c to continue") );
this.callCamera(ts);
if(this.controller.buttons.a) {
this.hideText();
this.player.setX(120); this.player.setY(32);
this.transitionToSceneByDoor(1);//this method is actively ending this alternate loop and giving it back to the loop method, there is also endLevelComplete.
return;
}
if(this.controller.buttons.b) {
this.hideText();
this.player.setX(120); this.player.setY(32);
this.transitionToSceneByDoor(2);
return;
}
if(this.controller.buttons.c) {
this.hideText();
this.player.setX(120); this.player.setY(32);
this.transitionToSceneByDoor(3);
return;
}
};
LevelComplete.prototype.loop = function(ts) {
var cb = this.controller.buttons;
if(cb.left||cb.right|cb.up||cb.down) {
this.player.tileMove(cb.left,cb.right,cb.up,cb.down);
cb.left = 0; cb.right = 0; cb.up = 0; cb.down = 0;
}
this.player.autoAnimation();
var tile = tabageos.BlitMath.checkTileValueAt(this.player.x,this.player.y,this.sceneChanger.currentMap,32,32);
if(tile && tile === 3) {
//the levelComplete method will cause the method passed to it to take over the loop.
this.levelComplete(this.showLevelSelectOptions);
}
};
new LevelComplete();
})();
back to top