refactor generic code in levels

This commit is contained in:
Juraj Michalek
2015-12-27 20:06:38 +01:00
parent aa9fbd8f58
commit 7ca021b51b
4 changed files with 76 additions and 38 deletions

24
js/app/level-01.js Normal file
View File

@@ -0,0 +1,24 @@
var level1 = {};
level1.create = function(context) {
// Create redirector objects
addRedirector(context, 10, 2, 1, 0, 0);
addRedirector(context, 10, 3, 0, 1, 6);
// Define player coordinates
context.character.x = 2*64 - 8;
context.character.y = 64 - 8;
context.character.physics.acceleration.x = 0;
context.character.physics.maxVelocity.y = 140;
// Define finish coordinates
context.finishMarker.x = 6*64;
context.finishMarker.y = 4*64;
// Create collision layer
for(var i = 21; i < context.tilemap.tileTypes.length; i++) {
context.tilemap.tileTypes[i].allowCollisions = Kiwi.Components.ArcadePhysics.ANY;
}
}

8
js/app/level-02.js Normal file
View File

@@ -0,0 +1,8 @@
var level2 = {};
level2.create = function(context) {
// Define finish coordinates
context.finishMarker.x = 8*64;
context.finishMarker.y = 2*64;
}

14
js/app/level-tools.js Normal file
View File

@@ -0,0 +1,14 @@
/**
* Register new redirector
*/
function addRedirector(context, x, y, vectorX, vectorY, imageIndex) {
var redirector = new Kiwi.GameObjects.Sprite(context, context.textures.oneWay, x*64, y*64);
redirector.affectVelocityX = context.velocityX * vectorX;
redirector.affectVelocityY = context.velocityY * vectorY;
redirector.cellIndex = imageIndex;
redirector.input.enableDrag(true);
redirector.input.onDragStarted.add(context.startedDrag, context);
redirector.input.onDragStopped.add(context.stoppedDrag, context );
context.redirectorGroup.addChild(redirector);
}