mirror of
https://github.com/ysoftdevs/pf2016.git
synced 2026-01-18 01:27:47 +01:00
add level 6 and 7 with bouncing box
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"height":6,
|
||||
"name":"sky",
|
||||
"opacity":1,
|
||||
|
||||
64
data/levels/level-07.json
Normal file
64
data/levels/level-07.json
Normal file
@@ -0,0 +1,64 @@
|
||||
{ "height":6,
|
||||
"layers":[
|
||||
{
|
||||
"data":[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, 0, 14, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 14, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 14, 13, 14, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"height":6,
|
||||
"name":"ground",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":18,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"data":[0, 41, 41, 41, 41, 41, 41, 0, 41, 41, 41, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 41, 41, 41, 41, 0, 31, 31, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 31, 31, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 41, 41, 0, 31, 0, 31, 0, 31, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"height":6,
|
||||
"name":"walls",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":18,
|
||||
"x":0,
|
||||
"y":0
|
||||
},
|
||||
{
|
||||
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
"height":6,
|
||||
"name":"sky",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":18,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextobjectid":4,
|
||||
"orientation":"orthogonal",
|
||||
"properties":
|
||||
{
|
||||
|
||||
},
|
||||
"renderorder":"right-down",
|
||||
"tileheight":64,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"image":"..\/images\/gfx64\/tiles.png",
|
||||
"imageheight":448,
|
||||
"imagewidth":640,
|
||||
"margin":0,
|
||||
"name":"base",
|
||||
"properties":
|
||||
{
|
||||
|
||||
},
|
||||
"spacing":0,
|
||||
"tilecount":70,
|
||||
"tileheight":64,
|
||||
"tilewidth":64
|
||||
}],
|
||||
"tilewidth":64,
|
||||
"version":1,
|
||||
"width":18
|
||||
}
|
||||
116
index.html
116
index.html
@@ -15,12 +15,13 @@
|
||||
<script src="js/app/level-04.js"></script>
|
||||
<script src="js/app/level-05.js"></script>
|
||||
<script src="js/app/level-06.js"></script>
|
||||
<script src="js/app/level-07.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script>
|
||||
var state = new Kiwi.State('state');
|
||||
var levels = [level1, level2, level3, level4, level5, level6];
|
||||
var levels = [level1, level2, level3, level4, level5, level6, level7];
|
||||
|
||||
state.preload = function() {
|
||||
this.addJSON('level1', 'data/levels/level-01.json');
|
||||
@@ -29,6 +30,7 @@ state.preload = function() {
|
||||
this.addJSON('level4', 'data/levels/level-04.json');
|
||||
this.addJSON('level5', 'data/levels/level-05.json');
|
||||
this.addJSON('level6', 'data/levels/level-06.json');
|
||||
this.addJSON('level7', 'data/levels/level-07.json');
|
||||
this.addSpriteSheet('base', './data/images/gfx64/tiles.png', 64, 64);
|
||||
this.addSpriteSheet('character', './data/images/gfx64/marble_black.png', 80, 80 );
|
||||
this.addSpriteSheet('oneWay', './data/images/gfx64/st_oneway.png', 64, 64 );
|
||||
@@ -114,7 +116,7 @@ state.buttonReleased = function(sprite) {
|
||||
this.myButton.text = '...';
|
||||
this.activateScene();
|
||||
} else if (this.stageState == 'stop') {
|
||||
this.resetCharacter();
|
||||
this.resetStage();
|
||||
this.myButton.text = 'Start'
|
||||
this.stageState = 'init';
|
||||
} else if (this.stageState == 'complete') {
|
||||
@@ -129,6 +131,22 @@ state.resetCharacter = function () {
|
||||
this.character.y = this.character.initialY - 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all objects that should be back in the original position.
|
||||
* Dragable redirectors are left on original place.
|
||||
*/
|
||||
state.resetStage = function() {
|
||||
this.resetCharacter();
|
||||
var redirectors = this.redirectorGroup.members;
|
||||
for ( var i = 0; i < redirectors.length; i++ ) {
|
||||
var redirector = redirectors[i];
|
||||
if (redirector.type == 'box') {
|
||||
redirector.x = redirector.initialX;
|
||||
redirector.y = redirector.initialY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.startedDrag = function(sprite) {
|
||||
sprite.formerX = sprite.x;
|
||||
sprite.formerY = sprite.y;
|
||||
@@ -142,6 +160,17 @@ state.resetDrag = function(sprite) {
|
||||
sprite.y = sprite.formerY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tile index from specified coordinates.
|
||||
*/
|
||||
state.getTileIndex = function(x, y) {
|
||||
var tile = this.tilemap.layers[0].getTileFromXY(x / 64 , y / 64);
|
||||
if (tile == null) {
|
||||
return 0;
|
||||
}
|
||||
return tile.index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform adjustments of coordinates for drop operation.
|
||||
* Make sure that object is dropped on valid place and check
|
||||
@@ -159,8 +188,7 @@ state.stoppedDrag = function(sprite) {
|
||||
sprite.y = sprite.y - sprite.y % 64;
|
||||
|
||||
// Make sure that we drop tile only on valid ground
|
||||
var tile = this.tilemap.layers[0].getTileFromXY(sprite.x / 64 , sprite.y /64);
|
||||
if ((tile.index == 0) || (tile == null)) {
|
||||
if (this.getTileIndex(sprite.x, sprite.y) == 0) {
|
||||
this.resetDrag(sprite);
|
||||
} else {
|
||||
// Make sure that we are not dropping on another redirector object
|
||||
@@ -195,8 +223,6 @@ state.update = function () {
|
||||
this.checkCollision();
|
||||
|
||||
this.updateCharacterAnimation();
|
||||
|
||||
// this.resetCharacter();
|
||||
}
|
||||
|
||||
state.updateCharacterAnimation = function () {
|
||||
@@ -212,10 +238,57 @@ state.updateCharacterAnimation = function () {
|
||||
}
|
||||
}
|
||||
|
||||
//Resolve collisions between the character and the first layer.
|
||||
/**
|
||||
* Create effect based on type of redirector.
|
||||
*/
|
||||
state.applyRedirectorMechanics = function(tileX, tileY, redirector) {
|
||||
var isRecalculationRequired = false;
|
||||
var redirectorTileX = Math.round(redirector.x/64);
|
||||
var redirectorTileY = Math.round(redirector.y/64);
|
||||
|
||||
// Box has hit regions around. Compute based on vector of player
|
||||
if (redirector.type == 'box') {
|
||||
tileX+=this.character.physics.velocity.x/64;
|
||||
tileY+=this.character.physics.velocity.y/64;
|
||||
}
|
||||
|
||||
// Check for hit
|
||||
if ((tileX != redirectorTileX ) || (tileY != redirectorTileY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirector.type == 'vector') {
|
||||
this.character.physics.velocity.x = redirector.affectVelocityX;
|
||||
this.character.physics.velocity.y = redirector.affectVelocityY;
|
||||
} else if (redirector.type == 'teleport') {
|
||||
this.character.x = redirector.affectedX - 8;
|
||||
this.character.y = redirector.affectedY - 8;
|
||||
} else if (redirector.type == 'box') {
|
||||
// Move tile when it is possible
|
||||
if (this.getTileIndex(redirector.x + this.character.physics.velocity.x, redirector.y + this.character.physics.velocity.y) != 0) {
|
||||
redirector.x += this.character.physics.velocity.x;
|
||||
redirector.y += this.character.physics.velocity.y;
|
||||
}
|
||||
// Bounce
|
||||
this.character.physics.velocity.x = -this.character.physics.velocity.x;
|
||||
this.character.physics.velocity.y = -this.character.physics.velocity.y;
|
||||
|
||||
// Bounce from box should relaunch direction calculation
|
||||
// This is for the case when box lies close to redirector
|
||||
isRecalculationRequired = true;
|
||||
}
|
||||
|
||||
// Correction of coordinates
|
||||
this.character.y = Math.round(this.character.y);
|
||||
this.character.x = Math.round(this.character.x);
|
||||
return isRecalculationRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve collisions between the character and the first layer.
|
||||
*/
|
||||
state.checkCollision = function () {
|
||||
this.tilemap.layers[1].physics.overlapsTiles( this.character, true );
|
||||
|
||||
|
||||
if ((this.character.physics.velocity.x == 0) && (this.character.physics.velocity.y == 0)) {
|
||||
if (this.stageState == 'running') {
|
||||
@@ -232,21 +305,20 @@ state.checkCollision = function () {
|
||||
return;
|
||||
}
|
||||
|
||||
var isRecalculationRequired = false;
|
||||
var redirectors = this.redirectorGroup.members;
|
||||
for ( var i = 0; i < redirectors.length; i++ ) {
|
||||
var redirector = redirectors[i];
|
||||
if (((Math.round(positionX/64) == Math.round(redirector.x/64) )) && (Math.round(positionY/64) == Math.round(redirector.y/64))) {
|
||||
if (redirector.type == 'vector') {
|
||||
this.character.physics.velocity.x = redirector.affectVelocityX;
|
||||
this.character.physics.velocity.y = redirector.affectVelocityY;
|
||||
} else if (redirector.type == 'teleport') {
|
||||
this.character.x = redirector.affectedX - 8;
|
||||
this.character.y = redirector.affectedY - 8;
|
||||
}
|
||||
this.character.y = Math.round(this.character.y);
|
||||
this.character.x = Math.round(this.character.x);
|
||||
if (this.applyRedirectorMechanics(Math.round(positionX/64), Math.round(positionY/64), redirectors[i])) {
|
||||
isRecalculationRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the second round of calculation in case of hit of box
|
||||
if (isRecalculationRequired) {
|
||||
for ( var i = 0; i < redirectors.length; i++ ) {
|
||||
this.applyRedirectorMechanics(Math.round(positionX/64), Math.round(positionY/64), redirectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (((Math.round(positionX/64) == Math.round(this.finishMarker.x/64) )) && (Math.round(positionY/64) == Math.round(this.finishMarker.y/64))) {
|
||||
this.stageState = 'complete';
|
||||
@@ -260,7 +332,11 @@ state.checkCollision = function () {
|
||||
|
||||
}
|
||||
|
||||
var game = new Kiwi.Game(null, 'PF 2016', levelSelectorState);
|
||||
var gameOptions = {
|
||||
width: 840,
|
||||
height: 600
|
||||
};
|
||||
var game = new Kiwi.Game(null, 'PF 2016', levelSelectorState, gameOptions);
|
||||
game.levelIndex = 0;
|
||||
game.states.addState(state);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var level6 = {};
|
||||
level6.create = function(context) {
|
||||
// Define start coordinates
|
||||
context.character.initialX = 1*64;
|
||||
context.character.initialX = 2*64;
|
||||
context.character.initialY = 1*64;
|
||||
context.character.initialVelocityX = 64;
|
||||
context.character.initialVelocityY = 0;
|
||||
@@ -27,16 +27,18 @@ level6.create = function(context) {
|
||||
teleportTarget.affectedX = 3*64;
|
||||
teleportTarget.affectedY = 3*64;
|
||||
context.redirectorGroup.addChild(teleportTarget);
|
||||
|
||||
// Create redirector objects
|
||||
addRedirector(context, 3, 1, -1, 0, 9);
|
||||
addRedirector(context, 4, 3, 1, 0, 0);
|
||||
addRedirector(context, 5, 4, 0, 1, 6);
|
||||
addRedirector(context, 10, 3, 0, 1, 6);
|
||||
|
||||
// Add block
|
||||
// Add moving box
|
||||
var box = new Kiwi.GameObjects.Sprite(context, context.textures.box, 4*64, 1*64);
|
||||
box.type = 'box';
|
||||
box.initialX = 4*64;
|
||||
box.initialY = 64;
|
||||
context.redirectorGroup.addChild(box);
|
||||
|
||||
|
||||
// Create redirector objects
|
||||
addRedirector(context, 9, 1, -1, 0, 9);
|
||||
addRedirector(context, 9, 3, 1, 0, 0);
|
||||
addRedirector(context, 10, 2, 0, -1, 3);
|
||||
|
||||
}
|
||||
55
js/app/level-07.js
Normal file
55
js/app/level-07.js
Normal file
@@ -0,0 +1,55 @@
|
||||
var level7 = {};
|
||||
level7.create = function(context) {
|
||||
// Define start coordinates
|
||||
context.character.initialX = 2*64;
|
||||
context.character.initialY = 1*64;
|
||||
context.character.initialVelocityX = 64;
|
||||
context.character.initialVelocityY = 0;
|
||||
|
||||
// Define finish coordinates
|
||||
context.finishMarker.x = 9*64;
|
||||
context.finishMarker.y = 4*64;
|
||||
|
||||
// Add teleport
|
||||
var teleport = new Kiwi.GameObjects.Sprite(context, context.textures.teleport, 3*64, 3*64);
|
||||
teleport.animation.add('idle', [ 0, 1, 2, 3 ], 0.3, true);
|
||||
teleport.animation.play('idle', true);
|
||||
teleport.type = 'teleport';
|
||||
teleport.affectedX = 10*64;
|
||||
teleport.affectedY = 1*64;
|
||||
context.redirectorGroup.addChild(teleport);
|
||||
|
||||
// Add target teleport marker
|
||||
var teleportTarget = new Kiwi.GameObjects.Sprite(context, context.textures.teleport, 10*64, 1*64);
|
||||
teleportTarget.animation.add('idle', [ 3, 2, 1, 0 ], 0.3, true);
|
||||
teleportTarget.animation.play('idle', true);
|
||||
teleportTarget.type = 'teleport';
|
||||
teleportTarget.affectedX = 3*64;
|
||||
teleportTarget.affectedY = 3*64;
|
||||
context.redirectorGroup.addChild(teleportTarget);
|
||||
|
||||
// Create redirector objects
|
||||
addRedirector(context, 3, 1, -1, 0, 9);
|
||||
addRedirector(context, 4, 3, 1, 0, 0);
|
||||
addRedirector(context, 5, 4, 0, 1, 6);
|
||||
addRedirector(context, 9, 1, 0, 1, 6);
|
||||
addRedirector(context, 8, 1, 0, 1, 6);
|
||||
addRedirector(context, 10, 3, 1, 0, 0);
|
||||
addRedirector(context, 10, 2, 0, -1, 3);
|
||||
addRedirector(context, 11, 3, -1, 0, 9);
|
||||
|
||||
// Add moving box
|
||||
var box = new Kiwi.GameObjects.Sprite(context, context.textures.box, 4*64, 1*64);
|
||||
box.type = 'box';
|
||||
box.initialX = 4*64;
|
||||
box.initialY = 64;
|
||||
context.redirectorGroup.addChild(box);
|
||||
|
||||
// Add moving box
|
||||
var box2 = new Kiwi.GameObjects.Sprite(context, context.textures.box, 9*64, 3*64);
|
||||
box2.type = 'box';
|
||||
box2.initialX = 9*64;
|
||||
box2.initialY = 3*64;
|
||||
context.redirectorGroup.addChild(box2);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user