Code edit (4 edits merged)
Please save this source code
Code edit (17 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: path.setupPlayer is not a function' in or related to this line: 'path.setupPlayer(player);' Line Number: 393
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.playSound is not a function' in or related to this line: 'LK.playSound('step_disappear');' Line Number: 232
User prompt
when a path step disapear, a sound fx should be played.
/**** 
* Classes
****/
var Ball = Container.expand(function (assetName) {
	var self = Container.call(this);
	self.rotating = false;
	self.angle = 0;
	self.attachAsset(assetName, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.rotateAround = function (otherBall) {
		self.angle += 0.025 * (path.level * 0.5 + 1);
		self.rotation = self.angle + 1.57;
		otherBall.rotation = self.rotation + 3.14;
		self.x = otherBall.x + otherBall.width * 2 * Math.cos(self.angle);
		self.y = otherBall.y + otherBall.width * 2 * Math.sin(self.angle);
	};
});
var FirstPathStep = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('firstStep', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.disapear = function () {
		self.alpha = 1;
		self.timer = LK.setInterval(function () {
			self.alpha -= 0.01;
			if (self.alpha <= 0) {
				LK.clearInterval(self.timer);
				self.destroy();
			}
		}, 10);
	};
});
var LastPathStep = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('lastStep', {
		anchorX: 0.5,
		anchorY: 0.5
	});
});
var Path = Container.expand(function (level) {
	var self = Container.call(this);
	self.setupPlayer = function (player) {
		self.curStep = 0;
		for (var i = 0; i < 3; i++) {
			self.nextStep();
		}
		if (self.pathPositions && self.pathPositions[0]) {
			player.init(self.pathPositions[0].x, self.pathPositions[0].y);
		} else {
			console.error('Path positions not defined');
		}
	};
	LK.setScore(level);
	self.level = level;
	self.levels = [
	// level 0
	[{
		x: 1024,
		y: 2400
	}, {
		x: 1024,
		y: 2200
	}, {
		x: 1024,
		y: 2000
	}, {
		x: 1024,
		y: 1800
	}],
	// level 1
	[{
		x: 1024,
		y: 2400
	}, {
		x: 883,
		y: 2259
	}, {
		x: 742,
		y: 2118
	}, {
		x: 601,
		y: 1977
	}, {
		x: 601,
		y: 1777
	}, {
		x: 742,
		y: 1636
	}, {
		x: 942,
		y: 1636
	}, {
		x: 1024,
		y: 1818
	}, {
		x: 1106,
		y: 1636
	}, {
		x: 1306,
		y: 1636
	}, {
		x: 1447,
		y: 1777
	}, {
		x: 1447,
		y: 1977
	}, {
		x: 1306,
		y: 2118
	}, {
		x: 1165,
		y: 2259
	}, {
		x: 1024,
		y: 2400
	}],
	// level 2
	[{
		x: 1024,
		y: 2400
	}, {
		x: 1024,
		y: 2200
	}, {
		x: 824,
		y: 2200
	}, {
		x: 824,
		y: 2000
	}, {
		x: 824,
		y: 1800
	}, {
		x: 1024,
		y: 1800
	}, {
		x: 1224,
		y: 1800
	}, {
		x: 1424,
		y: 1800
	}, {
		x: 1424,
		y: 2000
	}, {
		x: 1424,
		y: 2200
	}, {
		x: 1624,
		y: 2200
	}, {
		x: 1824,
		y: 2200
	}, {
		x: 1824,
		y: 2000
	}, {
		x: 1824,
		y: 1800
	}, {
		x: 1824,
		y: 1600
	}, {
		x: 1824,
		y: 1400
	}, {
		x: 1824,
		y: 1200
	}, {
		x: 1624,
		y: 1200
	}, {
		x: 1424,
		y: 1200
	}, {
		x: 1224,
		y: 1200
	}, {
		x: 1024,
		y: 1200
	}, {
		x: 824,
		y: 1200
	}, {
		x: 624,
		y: 1200
	}, {
		x: 624,
		y: 1000
	}, {
		x: 624,
		y: 800
	}, {
		x: 624,
		y: 600
	}, {
		x: 624,
		y: 400
	}, {
		x: 624,
		y: 200
	}, {
		x: 824,
		y: 200
	}, {
		x: 1024,
		y: 200
	}, {
		x: 1224,
		y: 200
	}, {
		x: 1424,
		y: 200
	}]];
	if (self.level >= self.levels.length) {
		LK.showGameOver();
		return;
	}
	self.pathSteps = [];
	self.pathPositions = self.levels[self.level];
	self.addPathStep = function (position) {
		var step;
		if (self.curStep == 0) {
			step = self.addChild(new FirstPathStep());
		} else if (self.curStep == self.pathPositions.length - 1) {
			step = self.addChild(new LastPathStep());
		} else {
			step = self.addChild(new PathStep());
		}
		step.x = position.x;
		step.y = position.y;
		self.pathSteps.push(step);
	};
	self.curStep = 0;
	self.nextStep = function () {
		if (self.pathPositions && self.curStep < self.pathPositions.length) {
			self.addPathStep(self.pathPositions[self.curStep]);
			self.curStep++;
		}
	};
	self.setupPlayer = function (player) {
		self.curStep = 0;
		for (var i = 0; i < 3; i++) {
			self.nextStep();
		}
		if (self.pathPositions && self.pathPositions[0]) {
			player.init(self.pathPositions[0].x, self.pathPositions[0].y);
		} else {
			console.error('Path positions not defined');
		}
	};
});
var PathStep = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('step', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.disapear = function () {
		self.alpha = 1;
		self.timer = LK.setInterval(function () {
			self.alpha -= 0.01;
			if (self.alpha <= 0) {
				LK.clearInterval(self.timer);
				self.destroy();
			}
		}, 10);
		for (var i = 0; i < 5; i++) {
			var starFX = new StarFX(i * (2 * Math.PI / 5));
			starFX.x = self.x;
			starFX.y = self.y;
			starFX.playFX();
			game.addChild(starFX);
		}
	};
});
var Player = Container.expand(function () {
	var self = Container.call(this);
	var ball1 = self.addChild(new Ball('playerBall1'));
	var ball2 = self.addChild(new Ball('playerBall2'));
	ball2.rotating = true;
	self.init = function (x, y) {
		ball1.x = x;
		ball1.y = y;
		ball1.rotating = false;
		ball2.rotating = true;
	};
	self.IsMatching = function IsMatching(obj1, obj2) {
		var diffX = obj1.x - obj2.x;
		var diffY = obj1.y - obj2.y;
		return diffX * diffX + diffY * diffY <= 2000;
	};
	self.click = function () {
		var tempRotating = ball1.rotating;
		ball1.rotating = ball2.rotating;
		ball2.rotating = tempRotating;
		if (ball1.rotating) {
			ball1.rotation = ball1.angle = Math.atan2(ball1.y - ball2.y, ball1.x - ball2.x);
		} else if (ball2.rotating) {
			ball2.rotation = ball2.angle = Math.atan2(ball2.y - ball1.y, ball2.x - ball1.x);
		}
		var onStep1 = false;
		var onStep2 = false;
		var smallPathStep = 9999;
		for (var i = 0; i < path.pathSteps.length; i++) {
			if (path.pathSteps[i]) {
				if (self.IsMatching(path.pathSteps[i], ball1)) {
					onStep1 = true;
					smallPathStep = Math.min(smallPathStep, i);
				}
				if (self.IsMatching(path.pathSteps[i], ball2)) {
					onStep2 = true;
					smallPathStep = Math.min(smallPathStep, i);
				}
			}
		}
		if (!(onStep1 && onStep2)) {
			LK.showGameOver();
		} else {
			for (var i = 0; i < 6.28; i += 6.28 / 5) {
				var starFX = new StarFX();
				starFX.x = path.pathSteps[smallPathStep].x;
				starFX.y = path.pathSteps[smallPathStep].y;
				starFX.direction = i;
				game.addChild(starFX);
				starFX.playFX();
			}
			if (ball1.rotating) {
				ball2.x = path.pathSteps[smallPathStep + 1].x;
				ball2.y = path.pathSteps[smallPathStep + 1].y;
			} else {
				ball1.x = path.pathSteps[smallPathStep + 1].x;
				ball1.y = path.pathSteps[smallPathStep + 1].y;
			}
			//path.pathSteps[smallPathStep].disapear();
			path.pathSteps.splice(smallPathStep, 1);
			path.nextStep();
			if (path.pathSteps.length == 1) {
				showCongratsPopup();
			}
		}
	};
	self.rotate = function () {
		if (ball1.rotating) {
			ball1.rotateAround(ball2);
		} else if (ball2.rotating) {
			ball2.rotateAround(ball1);
		}
	};
});
var StarFX = Container.expand(function (direction) {
	var self = Container.call(this);
	self.attachAsset('starFX', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.direction = direction;
	self.playFX = function () {
		self.alpha = 1;
		self.timer = LK.setInterval(function () {
			self.alpha -= 0.03;
			self.x += Math.cos(self.direction) * 10;
			self.y += Math.sin(self.direction) * 10;
			if (self.alpha <= 0) {
				LK.clearInterval(self.timer);
				self.destroy();
			}
		}, 10);
	};
});
/**** 
* Initialize Game
****/
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/
// Initialize background stars
// Initialize obstacle asset
// Initialize player ship asset
function showCongratsPopup() {
	game.removeChild(path);
	game.removeChild(player);
	path = new Path(path.level + 1);
	path.setupPlayer(player);
	game.addChild(path);
	game.addChild(player);
}
var background = game.addChild(LK.getAsset('background', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1024,
	y: 1366
}));
var player = new Player();
var path = new Path(0);
game.addChild(path);
game.addChild(player);
path.setupPlayer(player);
game.on('down', function (obj) {
	player.click();
});
LK.on('tick', function () {
	// Move obstacles
	player.rotate();
}); ===================================================================
--- original.js
+++ change.js
@@ -70,9 +70,9 @@
 	}, {
 		x: 1024,
 		y: 1800
 	}],
-	// level 2
+	// level 1
 	[{
 		x: 1024,
 		y: 2400
 	}, {
@@ -117,9 +117,9 @@
 	}, {
 		x: 1024,
 		y: 2400
 	}],
-	// level 1
+	// level 2
 	[{
 		x: 1024,
 		y: 2400
 	}, {
@@ -335,9 +335,9 @@
 			} else {
 				ball1.x = path.pathSteps[smallPathStep + 1].x;
 				ball1.y = path.pathSteps[smallPathStep + 1].y;
 			}
-			path.pathSteps[smallPathStep].disapear();
+			//path.pathSteps[smallPathStep].disapear();
 			path.pathSteps.splice(smallPathStep, 1);
 			path.nextStep();
 			if (path.pathSteps.length == 1) {
 				showCongratsPopup();
:quality(85)/https://cdn.frvr.ai/65dcd075aa1982e6cdafc9ee.png%3F3) 
 tête de mort rouge. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65dcd498aa1982e6cdafca3f.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/65dcd629aa1982e6cdafca60.png%3F3) 
 tête de mort coter droit en bleu coter gauche en rouge. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65dcd709aa1982e6cdafca6e.png%3F3) 
 tourbillon bleu et rouge. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65de3ad9cfd2bc39a2010b3f.png%3F3) 
 bone. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65de3dcfcfd2bc39a2010b8d.png%3F3) 
 tourbillon rouge et bleu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65de4003cfd2bc39a2010bbf.png%3F3)