var ScoreIcon = Container.expand(function () {
	var self = Container.call(this);
	var iconGraphics = self.createAsset('scoreIcon', 'Score Icon Graphics', 0.5, 0.5);
});
var FinalScreen = Container.expand(function () {
	var self = Container.call(this);
	var finalScreenGraphics = self.createAsset('finalscreen', 'Final Screen Graphics', 0.5, 0.5);
	finalScreenGraphics.x = LK.stage.width / 2;
	finalScreenGraphics.y = LK.stage.height / 2;
	self.visible = false;
});
var BoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var pieceGraphics = self.createAsset('boxPiece', 'Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 20;
	self.velocityY = (Math.random() - 0.5) * 20;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var BottomBoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var bottomBoxPieceGraphics = self.createAsset('bottomBoxPiece', 'Bottom Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 60;
	self.velocityY = (Math.random() - 0.5) * 60;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var Shadow = Container.expand(function () {
	var self = Container.call(this);
	var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', 0.5, 0.5);
});
var TopBoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var topBoxPieceGraphics = self.createAsset('topBoxPiece', 'Top Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 60;
	self.velocityY = (Math.random() - 0.5) * 60;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var Cap = Container.expand(function () {
	var self = Container.call(this);
	var capGraphics = self.createAsset('cap', 'Cap Graphics', 0.5, 0.5);
	var startY;
	var isSwipingUp = false;
	self.on('down', function (obj) {
		startY = obj.event.getLocalPosition(self.parent).y;
	});
	self.on('move', function (obj) {
		var currentY = self.parent ? obj.event.getLocalPosition(self.parent).y : 0;
		if (startY - currentY > 50) {
			isSwipingUp = true;
		}
	});
	self.on('up', function (obj) {
		if (isSwipingUp && self.parent) {
			console.log('Cap swiped up');
			self.emit('swipeUp');
			self.moveUp = true;
			self.rotateAndMoveUp = true;
			isSwipingUp = false;
		}
	});
	LK.on('tick', function () {
		if (self.rotateAndMoveUp) {
			self.y -= 10;
			self.x -= 10;
			self.rotation -= 0.05;
			if (self.y <= self.startY - 400) {
				self.rotateAndMoveUp = false;
			}
		}
	});
});
var RedButton = Container.expand(function () {
	var self = Container.call(this);
	var buttonGraphics = self.createAsset('redbutton', 'Red Button Graphics', 0.5, 0.5);
});
var AxeLayers = Container.expand(function () {
	var self = Container.call(this);
	var lastTapTime = 0;
	self.on('down', function (obj) {
		var currentTime = Date.now();
		var tapLength = currentTime - lastTapTime;
		if (tapLength < 500 && tapLength > 0) {
			if (self.children.length > 0) {
				self.removeChildAt(self.children.length - 1);
			}
			if (self.children.length === 0) {
				self.destroy();
			}
		}
		lastTapTime = currentTime;
	});
	var layer0 = self.createAsset('layer0', 'Axe Layer 0 Graphics', 0.5, 0.5);
	layer0.x -= 250;
	layer0.y -= 250;
	var layer1 = self.createAsset('layer1', 'Axe Layer 1 Graphics', 0.5, 0.5);
	layer1.x -= 200;
	layer1.y -= 200;
	var layer2 = self.createAsset('layer2', 'Axe Layer 2 Graphics', 0.5, 0.5);
	layer2.x -= 200;
	layer2.y -= 200;
	var layer3 = self.createAsset('layer3', 'Axe Layer 3 Graphics', 0.5, 0.5);
	layer3.x -= 200;
	layer3.y -= 200;
	var layer4 = self.createAsset('layer4', 'Axe Layer 4 Graphics', 0.5, 0.5);
	layer4.x -= 200;
	layer4.y -= 200;
	var layer5 = self.createAsset('layer5', 'Axe Layer 5 Graphics', 0.5, 0.5);
	layer5.x -= 200;
	layer5.y -= 200;
});
var Box = Container.expand(function () {
	var self = Container.call(this);
	Box.prototype.createTopAndBottomPieces = function () {
		var topPiece = new TopBoxPiece();
		topPiece.x = this.x;
		topPiece.y = this.y - this.height / 4;
		topPiece.width = this.width;
		topPiece.height = this.height / 2;
		var bottomPiece = new BottomBoxPiece();
		bottomPiece.x = this.x;
		bottomPiece.y = this.y + this.height / 4;
		bottomPiece.width = this.width;
		bottomPiece.height = this.height / 2;
		if (this.parent) {
			this.parent.addChild(topPiece);
			this.parent.addChild(bottomPiece);
		}
	};
	self.spinAndShrink = function () {
		var frames = 50;
		var frameCounter = 0;
		var animationTick = function () {
			self.scale.x -= 1 / frames;
			self.scale.y -= 1 / frames;
			self.rotation += 0.1;
			frameCounter++;
			if (frameCounter >= frames) {
				LK.off('tick', animationTick);
				self.destroy();
			}
		};
		LK.on('tick', animationTick);
	};
	self.explode = function () {
		for (var i = 0; i < 20; i++) {
			var piece = new BoxPiece();
			piece.x = self.x;
			piece.y = self.y;
			if (self.parent) {
				self.parent.addChild(piece);
			}
		}
		self.destroy();
	};
	LK.on('tick', function () {
		if (self.velocityY !== 0) {
			self.y += self.velocityY;
		}
	});
	self.velocityY = 0;
	var boxGraphics = self.createAsset('box', 'Box Graphics', 0.5, 0.5);
	self.enlargeBox = function () {
		var frames = 0;
		var animationTick = function () {
			self.scale.x += 0.01;
			self.scale.y += 0.01;
			frames++;
			if (self.width >= LK.stage.width || self.height >= LK.stage.height) {
				LK.off('tick', animationTick);
				self.destroy();
			}
		};
		LK.on('tick', animationTick);
	};
	var lastTapTime = 0;
	var tapCount = 0;
	self.isDoubleClicked = false;
	var startY;
	var isSwipingUp = false;
	self.on('down', function (obj) {
		var currentTime = Date.now();
		if (currentTime - lastTapTime < 300) {
			tapCount++;
			if (tapCount === 2) {
				console.log('Box double clicked');
				self.isDoubleClicked = true;
				tapCount = 0;
			}
		} else {
			tapCount = 1;
		}
		lastTapTime = currentTime;
		this.startPos = obj.event.getLocalPosition(self.parent);
		startY = this.startPos.y;
		self.swipeStartX = this.startPos.x;
		self.swipeEndX = null;
		self.swipeDirection = null;
	});
	self.on('move', function (obj) {
		var currentY = self.parent ? obj.event.getLocalPosition(self.parent).y : 0;
		var currentX = self.parent ? obj.event.getLocalPosition(self.parent).x : 0;
		if (startY - currentY > 100) {
			isSwipingUp = true;
		}
		if (self.swipeStartX != null) {
			if (self.swipeDirection === null) {
				self.swipeEndX = currentX;
			}
		}
	});
	self.on('up', function (obj) {
		if (isSwipingUp) {
			console.log('Box swiped up');
			self.emit('swipeUp');
			self.velocityY = -30;
			isSwipingUp = false;
		}
		if (self.swipeEndX != null && Math.abs(self.swipeEndX - self.swipeStartX) > self.width / 2) {
			console.log('Box sliced');
			self.emit('slice');
			self.createTopAndBottomPieces();
			self.isSliced = true;
			self.destroy();
		}
		self.swipeStartX = null;
		self.swipeEndX = null;
		self.swipeDirection = null;
	});
});
var Axe = Container.expand(function () {
	var self = Container.call(this);
	var axeGraphics = self.createAsset('axe', 'Axe Graphics', 1, 1);
	self.rotationSpeed = 0.05;
	var dragNode = null;
	var startDragPos = null;
	self.on('down', function (obj) {
		dragNode = self;
		startDragPos = obj.event.getLocalPosition(self.parent);
	});
	self.on('move', function (obj) {
		if (dragNode) {
			var currentPos = self.parent ? obj.event.getLocalPosition(self.parent) : {
				x: 0.5,
				y: 0.5
			};
			dragNode.x = currentPos.x + 200;
			dragNode.y = currentPos.y + 200;
		}
	});
	self.on('up', function (obj) {
		dragNode = null;
	});
	var maxRotation = Math.PI / 4;
	var rotationDirection = 1;
	LK.on('tick', function () {
		self.rotation += rotationDirection * self.rotationSpeed;
		if (Math.abs(self.rotation) >= maxRotation) {
			rotationDirection *= -1;
		}
	});
});
var DeadoraliveMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('deadoralive', 'Deadoralive Graphics', 0.5, 0.5);
	var startY;
	var targetY;
	var isSwiping = false;
	self.on('down', function (obj) {
		startY = obj.event.getLocalPosition(self.parent).y;
		targetY = self.y - 300;
	});
	self.on('move', function (obj) {
		var currentY = obj.event.getLocalPosition(LK.stageContainer).y;
		if (startY - currentY > 20) {
			isSwiping = true;
		}
	});
	self.on('up', function (obj) {
		if (isSwiping) {
			LK.on('tick', function () {
				if (self.y > targetY) {
					self.y -= 5;
					if (self.y < targetY) {
						self.y = targetY;
						LK.off('tick');
					}
				}
			});
		}
		isSwiping = false;
	});
});
var DeadMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('deadmessage', 'Dead Graphics', 0.5, 0.5);
});
var AliveMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('alivemessage', 'Alive Graphics', 0.5, 0.5);
});
var Kitty = Container.expand(function () {
	var self = Container.call(this);
	self.isDead = false;
	self.alpha = 1;
	var ghostlyMovement = function () {
		self.y += Math.sin(LK.ticks / 5) * 2;
	};
	LK.on('tick', ghostlyMovement);
	var kitty = self.createAsset('alive', 'Kitty Graphics', 0.5, 0.5);
});
var DeadKitty = Container.expand(function () {
	var self = Container.call(this);
	self.alpha = 0.5;
	var ghostlyMovement = function () {
		self.y += Math.sin(LK.ticks / 10) * 0.5;
	};
	LK.on('tick', ghostlyMovement);
	var deadkitty = self.createAsset('dead', 'Dead Kitty Graphics', 0.5, 0.5);
});
var Lid = Container.expand(function () {
	var self = Container.call(this);
	var lidGraphics = self.createAsset('lid', 'Lid Graphics', 0.5, 0.5);
	var dragNode = null;
	var startDragPos = null;
	self.on('down', function (obj) {
		dragNode = self;
		startDragPos = obj.event.getLocalPosition(self.parent);
	});
	self.on('move', function (obj) {
		if (dragNode && self.parent) {
			var currentPos = self.parent ? obj.event.getLocalPosition(self.parent) : {
				x: 0.5,
				y: 0.5
			};
			dragNode.x = currentPos.x - lidGraphics.width / 2;
			dragNode.y = currentPos.y - lidGraphics.height / 2;
		}
	});
	self.on('up', function (obj) {
		dragNode = null;
	});
});
var gameResetCount = 0;
var gameDoubleClickSolve = false;
var gameAxeSolve = false;
var gameSwipeSolve = false;
var gameSliceSolve = false;
var gameButtonSolve = false;
var gameDrainSolve = false;
var Game = Container.expand(function () {
	var self = Container.call(this);
	gameResetCount += 1;
	console.log('Game Reset', gameResetCount);
	console.log('DoubleClickSolve', gameDoubleClickSolve);
	console.log('AxeSolve', gameAxeSolve);
	console.log('SwipeSolve', gameSwipeSolve);
	console.log('SliceSolve', gameSliceSolve);
	console.log('ButtonSolve', gameButtonSolve);
	console.log('DrainSolve', gameDrainSolve);
	self.axeIntersected = false;
	var axe = self.addChild(new Axe());
	var axeLayers = self.addChild(new AxeLayers());
	axeLayers.x = axe.x = LK.stage.width - axe.width / 2 - 100 + 200;
	axeLayers.y = axe.y = LK.stage.height - axe.height / 2 - 100 + 200;
	axe.zIndex = -1;
	var gameSolvesScore = gameDoubleClickSolve + gameAxeSolve + gameSwipeSolve + gameSliceSolve + gameButtonSolve + gameDrainSolve;
	LK.gui.topCenter.removeChildren();
	var scoreIcon = new ScoreIcon();
	scoreIcon.x = -80;
	scoreIcon.y += 37;
	LK.gui.topCenter.addChild(scoreIcon);
	var scoreMessage = new Text2(gameSolvesScore + ' / 6', {
		size: 60,
		fill: '#ffffff'
	});
	scoreMessage.anchor.set(0.5, 0);
	scoreMessage.x = scoreIcon.width / 2 + 10;
	LK.gui.topCenter.addChild(scoreMessage);
	var messageText = new Text2('(Open the box to find out...)', {
		size: 60,
		fill: '#ffffff'
	});
	messageText.anchor.set(.5, .5);
	messageText.y += 1500;
	LK.gui.topCenter.addChild(messageText);
	var kitty = self.addChild(new Kitty());
	self.isDead = Math.random() < 0.5;
	kitty.x = LK.stage.width / 2;
	kitty.y = LK.stage.height / 2 - 100;
	var shadow = self.addChild(new Shadow());
	shadow.x = kitty.x;
	shadow.y = kitty.y + 250;
	var deadkitty = self.addChild(new DeadKitty());
	deadkitty.x = LK.stage.width / 2;
	deadkitty.y = LK.stage.height / 2 - 100;
	var cap = self.addChild(new Cap());
	cap.x = 300;
	cap.y = 2400;
	var lid = self.addChild(new Lid());
	lid.x = cap.x;
	lid.y = cap.y;
	var redbutton = self.addChild(new RedButton());
	redbutton.x = LK.stage.width / 2;
	redbutton.y = 600;
	redbutton.on('down', function () {
		redbutton.isTouched = true;
	});
	var deadoralivemessage = self.addChild(new DeadoraliveMessage());
	deadoralivemessage.x = LK.stage.width / 2;
	deadoralivemessage.y = 600;
	var deadMessage = self.addChild(new DeadMessage());
	deadMessage.x = LK.stage.width / 2;
	deadMessage.y = LK.stage.height - 700 - deadMessage.height / 2;
	deadMessage.visible = false;
	var aliveMessage = self.addChild(new AliveMessage());
	aliveMessage.x = LK.stage.width / 2;
	aliveMessage.y = LK.stage.height - 700 - aliveMessage.height / 2;
	aliveMessage.visible = false;
	var box = self.addChild(new Box());
	box.x = LK.stage.width / 2;
	box.y = LK.stage.height / 2;
	var finalScreen = self.addChild(new FinalScreen());
	finalScreen.visible = false;
	if (self.isDead) {
		kitty.visible = false;
		deadkitty.visible = true;
	} else {
		kitty.visible = true;
		deadkitty.visible = false;
	}
	LK.on('tick', function () {
		if (gameSolvesScore === 6) {
			finalScreen.visible = true;
			messageText.setText('');
			LK.setTimeout(function () {
				LK.showGameOver();
				finalScreen.visible = false;
			}, 5000);
		}
		if (redbutton.isTouched) {
			if (box) {
				box.enlargeBox();
				box = null;
				LK.setTimeout(function () {
					if (self.isDead) {
						deadMessage.visible = true;
					} else {
						aliveMessage.visible = true;
					}
				}, 2000);
				gameButtonSolve = true;
				LK.setTimeout(function () {
					messageText.setText('(BOOOM! Nice one...still more to find...)');
				}, 1500);
				LK.setTimeout(function () {
					LK.stage.removeChildren();
					console.log('Game is restarted');
					var newGame = new Game();
					LK.stage.addChild(newGame);
					messageText.setText('');
				}, 5000);
			}
			redbutton.isTouched = false;
		}
		if (axe.intersects(box) && !self.axeIntersected) {
			gameAxeSolve = true;
			self.axeIntersected = true;
			messageText.setText('(Chop chop! Is there any other way left?)');
			box.explode();
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && box.isDoubleClicked) {
			messageText.setText('(Double click...how original! Try a different way!)');
			gameDoubleClickSolve = true;
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
			box.destroy();
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
		}
		if (box && cap.x < 1) {
			box.spinAndShrink();
			messageText.setText('(Down the drain! I bet you can find another way...)');
			gameDrainSolve = true;
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && (box.y + box.height < 0 || box.y > LK.stage.height || cap.y + cap.height < 0 || cap.y > LK.stage.height || cap.x < 1)) {
			messageText.setText('(Swipe up, classic...Try again!)');
			gameSwipeSolve = true;
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && box.isSliced) {
			messageText.setText('(Clean cut! Try something else...)');
			gameSliceSolve = true;
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
			box.destroy();
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
		}
	});
});
 var ScoreIcon = Container.expand(function () {
	var self = Container.call(this);
	var iconGraphics = self.createAsset('scoreIcon', 'Score Icon Graphics', 0.5, 0.5);
});
var FinalScreen = Container.expand(function () {
	var self = Container.call(this);
	var finalScreenGraphics = self.createAsset('finalscreen', 'Final Screen Graphics', 0.5, 0.5);
	finalScreenGraphics.x = LK.stage.width / 2;
	finalScreenGraphics.y = LK.stage.height / 2;
	self.visible = false;
});
var BoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var pieceGraphics = self.createAsset('boxPiece', 'Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 20;
	self.velocityY = (Math.random() - 0.5) * 20;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var BottomBoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var bottomBoxPieceGraphics = self.createAsset('bottomBoxPiece', 'Bottom Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 60;
	self.velocityY = (Math.random() - 0.5) * 60;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var Shadow = Container.expand(function () {
	var self = Container.call(this);
	var shadowGraphics = self.createAsset('shadow', 'Shadow Graphics', 0.5, 0.5);
});
var TopBoxPiece = Container.expand(function () {
	var self = Container.call(this);
	var topBoxPieceGraphics = self.createAsset('topBoxPiece', 'Top Box Piece Graphics', 0.5, 0.5);
	self.velocityX = (Math.random() - 0.5) * 60;
	self.velocityY = (Math.random() - 0.5) * 60;
	LK.on('tick', function () {
		self.x += self.velocityX;
		self.y += self.velocityY;
		self.rotation += 0.1;
	});
});
var Cap = Container.expand(function () {
	var self = Container.call(this);
	var capGraphics = self.createAsset('cap', 'Cap Graphics', 0.5, 0.5);
	var startY;
	var isSwipingUp = false;
	self.on('down', function (obj) {
		startY = obj.event.getLocalPosition(self.parent).y;
	});
	self.on('move', function (obj) {
		var currentY = self.parent ? obj.event.getLocalPosition(self.parent).y : 0;
		if (startY - currentY > 50) {
			isSwipingUp = true;
		}
	});
	self.on('up', function (obj) {
		if (isSwipingUp && self.parent) {
			console.log('Cap swiped up');
			self.emit('swipeUp');
			self.moveUp = true;
			self.rotateAndMoveUp = true;
			isSwipingUp = false;
		}
	});
	LK.on('tick', function () {
		if (self.rotateAndMoveUp) {
			self.y -= 10;
			self.x -= 10;
			self.rotation -= 0.05;
			if (self.y <= self.startY - 400) {
				self.rotateAndMoveUp = false;
			}
		}
	});
});
var RedButton = Container.expand(function () {
	var self = Container.call(this);
	var buttonGraphics = self.createAsset('redbutton', 'Red Button Graphics', 0.5, 0.5);
});
var AxeLayers = Container.expand(function () {
	var self = Container.call(this);
	var lastTapTime = 0;
	self.on('down', function (obj) {
		var currentTime = Date.now();
		var tapLength = currentTime - lastTapTime;
		if (tapLength < 500 && tapLength > 0) {
			if (self.children.length > 0) {
				self.removeChildAt(self.children.length - 1);
			}
			if (self.children.length === 0) {
				self.destroy();
			}
		}
		lastTapTime = currentTime;
	});
	var layer0 = self.createAsset('layer0', 'Axe Layer 0 Graphics', 0.5, 0.5);
	layer0.x -= 250;
	layer0.y -= 250;
	var layer1 = self.createAsset('layer1', 'Axe Layer 1 Graphics', 0.5, 0.5);
	layer1.x -= 200;
	layer1.y -= 200;
	var layer2 = self.createAsset('layer2', 'Axe Layer 2 Graphics', 0.5, 0.5);
	layer2.x -= 200;
	layer2.y -= 200;
	var layer3 = self.createAsset('layer3', 'Axe Layer 3 Graphics', 0.5, 0.5);
	layer3.x -= 200;
	layer3.y -= 200;
	var layer4 = self.createAsset('layer4', 'Axe Layer 4 Graphics', 0.5, 0.5);
	layer4.x -= 200;
	layer4.y -= 200;
	var layer5 = self.createAsset('layer5', 'Axe Layer 5 Graphics', 0.5, 0.5);
	layer5.x -= 200;
	layer5.y -= 200;
});
var Box = Container.expand(function () {
	var self = Container.call(this);
	Box.prototype.createTopAndBottomPieces = function () {
		var topPiece = new TopBoxPiece();
		topPiece.x = this.x;
		topPiece.y = this.y - this.height / 4;
		topPiece.width = this.width;
		topPiece.height = this.height / 2;
		var bottomPiece = new BottomBoxPiece();
		bottomPiece.x = this.x;
		bottomPiece.y = this.y + this.height / 4;
		bottomPiece.width = this.width;
		bottomPiece.height = this.height / 2;
		if (this.parent) {
			this.parent.addChild(topPiece);
			this.parent.addChild(bottomPiece);
		}
	};
	self.spinAndShrink = function () {
		var frames = 50;
		var frameCounter = 0;
		var animationTick = function () {
			self.scale.x -= 1 / frames;
			self.scale.y -= 1 / frames;
			self.rotation += 0.1;
			frameCounter++;
			if (frameCounter >= frames) {
				LK.off('tick', animationTick);
				self.destroy();
			}
		};
		LK.on('tick', animationTick);
	};
	self.explode = function () {
		for (var i = 0; i < 20; i++) {
			var piece = new BoxPiece();
			piece.x = self.x;
			piece.y = self.y;
			if (self.parent) {
				self.parent.addChild(piece);
			}
		}
		self.destroy();
	};
	LK.on('tick', function () {
		if (self.velocityY !== 0) {
			self.y += self.velocityY;
		}
	});
	self.velocityY = 0;
	var boxGraphics = self.createAsset('box', 'Box Graphics', 0.5, 0.5);
	self.enlargeBox = function () {
		var frames = 0;
		var animationTick = function () {
			self.scale.x += 0.01;
			self.scale.y += 0.01;
			frames++;
			if (self.width >= LK.stage.width || self.height >= LK.stage.height) {
				LK.off('tick', animationTick);
				self.destroy();
			}
		};
		LK.on('tick', animationTick);
	};
	var lastTapTime = 0;
	var tapCount = 0;
	self.isDoubleClicked = false;
	var startY;
	var isSwipingUp = false;
	self.on('down', function (obj) {
		var currentTime = Date.now();
		if (currentTime - lastTapTime < 300) {
			tapCount++;
			if (tapCount === 2) {
				console.log('Box double clicked');
				self.isDoubleClicked = true;
				tapCount = 0;
			}
		} else {
			tapCount = 1;
		}
		lastTapTime = currentTime;
		this.startPos = obj.event.getLocalPosition(self.parent);
		startY = this.startPos.y;
		self.swipeStartX = this.startPos.x;
		self.swipeEndX = null;
		self.swipeDirection = null;
	});
	self.on('move', function (obj) {
		var currentY = self.parent ? obj.event.getLocalPosition(self.parent).y : 0;
		var currentX = self.parent ? obj.event.getLocalPosition(self.parent).x : 0;
		if (startY - currentY > 100) {
			isSwipingUp = true;
		}
		if (self.swipeStartX != null) {
			if (self.swipeDirection === null) {
				self.swipeEndX = currentX;
			}
		}
	});
	self.on('up', function (obj) {
		if (isSwipingUp) {
			console.log('Box swiped up');
			self.emit('swipeUp');
			self.velocityY = -30;
			isSwipingUp = false;
		}
		if (self.swipeEndX != null && Math.abs(self.swipeEndX - self.swipeStartX) > self.width / 2) {
			console.log('Box sliced');
			self.emit('slice');
			self.createTopAndBottomPieces();
			self.isSliced = true;
			self.destroy();
		}
		self.swipeStartX = null;
		self.swipeEndX = null;
		self.swipeDirection = null;
	});
});
var Axe = Container.expand(function () {
	var self = Container.call(this);
	var axeGraphics = self.createAsset('axe', 'Axe Graphics', 1, 1);
	self.rotationSpeed = 0.05;
	var dragNode = null;
	var startDragPos = null;
	self.on('down', function (obj) {
		dragNode = self;
		startDragPos = obj.event.getLocalPosition(self.parent);
	});
	self.on('move', function (obj) {
		if (dragNode) {
			var currentPos = self.parent ? obj.event.getLocalPosition(self.parent) : {
				x: 0.5,
				y: 0.5
			};
			dragNode.x = currentPos.x + 200;
			dragNode.y = currentPos.y + 200;
		}
	});
	self.on('up', function (obj) {
		dragNode = null;
	});
	var maxRotation = Math.PI / 4;
	var rotationDirection = 1;
	LK.on('tick', function () {
		self.rotation += rotationDirection * self.rotationSpeed;
		if (Math.abs(self.rotation) >= maxRotation) {
			rotationDirection *= -1;
		}
	});
});
var DeadoraliveMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('deadoralive', 'Deadoralive Graphics', 0.5, 0.5);
	var startY;
	var targetY;
	var isSwiping = false;
	self.on('down', function (obj) {
		startY = obj.event.getLocalPosition(self.parent).y;
		targetY = self.y - 300;
	});
	self.on('move', function (obj) {
		var currentY = obj.event.getLocalPosition(LK.stageContainer).y;
		if (startY - currentY > 20) {
			isSwiping = true;
		}
	});
	self.on('up', function (obj) {
		if (isSwiping) {
			LK.on('tick', function () {
				if (self.y > targetY) {
					self.y -= 5;
					if (self.y < targetY) {
						self.y = targetY;
						LK.off('tick');
					}
				}
			});
		}
		isSwiping = false;
	});
});
var DeadMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('deadmessage', 'Dead Graphics', 0.5, 0.5);
});
var AliveMessage = Container.expand(function () {
	var self = Container.call(this);
	var messageGraphics = self.createAsset('alivemessage', 'Alive Graphics', 0.5, 0.5);
});
var Kitty = Container.expand(function () {
	var self = Container.call(this);
	self.isDead = false;
	self.alpha = 1;
	var ghostlyMovement = function () {
		self.y += Math.sin(LK.ticks / 5) * 2;
	};
	LK.on('tick', ghostlyMovement);
	var kitty = self.createAsset('alive', 'Kitty Graphics', 0.5, 0.5);
});
var DeadKitty = Container.expand(function () {
	var self = Container.call(this);
	self.alpha = 0.5;
	var ghostlyMovement = function () {
		self.y += Math.sin(LK.ticks / 10) * 0.5;
	};
	LK.on('tick', ghostlyMovement);
	var deadkitty = self.createAsset('dead', 'Dead Kitty Graphics', 0.5, 0.5);
});
var Lid = Container.expand(function () {
	var self = Container.call(this);
	var lidGraphics = self.createAsset('lid', 'Lid Graphics', 0.5, 0.5);
	var dragNode = null;
	var startDragPos = null;
	self.on('down', function (obj) {
		dragNode = self;
		startDragPos = obj.event.getLocalPosition(self.parent);
	});
	self.on('move', function (obj) {
		if (dragNode && self.parent) {
			var currentPos = self.parent ? obj.event.getLocalPosition(self.parent) : {
				x: 0.5,
				y: 0.5
			};
			dragNode.x = currentPos.x - lidGraphics.width / 2;
			dragNode.y = currentPos.y - lidGraphics.height / 2;
		}
	});
	self.on('up', function (obj) {
		dragNode = null;
	});
});
var gameResetCount = 0;
var gameDoubleClickSolve = false;
var gameAxeSolve = false;
var gameSwipeSolve = false;
var gameSliceSolve = false;
var gameButtonSolve = false;
var gameDrainSolve = false;
var Game = Container.expand(function () {
	var self = Container.call(this);
	gameResetCount += 1;
	console.log('Game Reset', gameResetCount);
	console.log('DoubleClickSolve', gameDoubleClickSolve);
	console.log('AxeSolve', gameAxeSolve);
	console.log('SwipeSolve', gameSwipeSolve);
	console.log('SliceSolve', gameSliceSolve);
	console.log('ButtonSolve', gameButtonSolve);
	console.log('DrainSolve', gameDrainSolve);
	self.axeIntersected = false;
	var axe = self.addChild(new Axe());
	var axeLayers = self.addChild(new AxeLayers());
	axeLayers.x = axe.x = LK.stage.width - axe.width / 2 - 100 + 200;
	axeLayers.y = axe.y = LK.stage.height - axe.height / 2 - 100 + 200;
	axe.zIndex = -1;
	var gameSolvesScore = gameDoubleClickSolve + gameAxeSolve + gameSwipeSolve + gameSliceSolve + gameButtonSolve + gameDrainSolve;
	LK.gui.topCenter.removeChildren();
	var scoreIcon = new ScoreIcon();
	scoreIcon.x = -80;
	scoreIcon.y += 37;
	LK.gui.topCenter.addChild(scoreIcon);
	var scoreMessage = new Text2(gameSolvesScore + ' / 6', {
		size: 60,
		fill: '#ffffff'
	});
	scoreMessage.anchor.set(0.5, 0);
	scoreMessage.x = scoreIcon.width / 2 + 10;
	LK.gui.topCenter.addChild(scoreMessage);
	var messageText = new Text2('(Open the box to find out...)', {
		size: 60,
		fill: '#ffffff'
	});
	messageText.anchor.set(.5, .5);
	messageText.y += 1500;
	LK.gui.topCenter.addChild(messageText);
	var kitty = self.addChild(new Kitty());
	self.isDead = Math.random() < 0.5;
	kitty.x = LK.stage.width / 2;
	kitty.y = LK.stage.height / 2 - 100;
	var shadow = self.addChild(new Shadow());
	shadow.x = kitty.x;
	shadow.y = kitty.y + 250;
	var deadkitty = self.addChild(new DeadKitty());
	deadkitty.x = LK.stage.width / 2;
	deadkitty.y = LK.stage.height / 2 - 100;
	var cap = self.addChild(new Cap());
	cap.x = 300;
	cap.y = 2400;
	var lid = self.addChild(new Lid());
	lid.x = cap.x;
	lid.y = cap.y;
	var redbutton = self.addChild(new RedButton());
	redbutton.x = LK.stage.width / 2;
	redbutton.y = 600;
	redbutton.on('down', function () {
		redbutton.isTouched = true;
	});
	var deadoralivemessage = self.addChild(new DeadoraliveMessage());
	deadoralivemessage.x = LK.stage.width / 2;
	deadoralivemessage.y = 600;
	var deadMessage = self.addChild(new DeadMessage());
	deadMessage.x = LK.stage.width / 2;
	deadMessage.y = LK.stage.height - 700 - deadMessage.height / 2;
	deadMessage.visible = false;
	var aliveMessage = self.addChild(new AliveMessage());
	aliveMessage.x = LK.stage.width / 2;
	aliveMessage.y = LK.stage.height - 700 - aliveMessage.height / 2;
	aliveMessage.visible = false;
	var box = self.addChild(new Box());
	box.x = LK.stage.width / 2;
	box.y = LK.stage.height / 2;
	var finalScreen = self.addChild(new FinalScreen());
	finalScreen.visible = false;
	if (self.isDead) {
		kitty.visible = false;
		deadkitty.visible = true;
	} else {
		kitty.visible = true;
		deadkitty.visible = false;
	}
	LK.on('tick', function () {
		if (gameSolvesScore === 6) {
			finalScreen.visible = true;
			messageText.setText('');
			LK.setTimeout(function () {
				LK.showGameOver();
				finalScreen.visible = false;
			}, 5000);
		}
		if (redbutton.isTouched) {
			if (box) {
				box.enlargeBox();
				box = null;
				LK.setTimeout(function () {
					if (self.isDead) {
						deadMessage.visible = true;
					} else {
						aliveMessage.visible = true;
					}
				}, 2000);
				gameButtonSolve = true;
				LK.setTimeout(function () {
					messageText.setText('(BOOOM! Nice one...still more to find...)');
				}, 1500);
				LK.setTimeout(function () {
					LK.stage.removeChildren();
					console.log('Game is restarted');
					var newGame = new Game();
					LK.stage.addChild(newGame);
					messageText.setText('');
				}, 5000);
			}
			redbutton.isTouched = false;
		}
		if (axe.intersects(box) && !self.axeIntersected) {
			gameAxeSolve = true;
			self.axeIntersected = true;
			messageText.setText('(Chop chop! Is there any other way left?)');
			box.explode();
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && box.isDoubleClicked) {
			messageText.setText('(Double click...how original! Try a different way!)');
			gameDoubleClickSolve = true;
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
			box.destroy();
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
		}
		if (box && cap.x < 1) {
			box.spinAndShrink();
			messageText.setText('(Down the drain! I bet you can find another way...)');
			gameDrainSolve = true;
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && (box.y + box.height < 0 || box.y > LK.stage.height || cap.y + cap.height < 0 || cap.y > LK.stage.height || cap.x < 1)) {
			messageText.setText('(Swipe up, classic...Try again!)');
			gameSwipeSolve = true;
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
		}
		if (box && box.isSliced) {
			messageText.setText('(Clean cut! Try something else...)');
			gameSliceSolve = true;
			LK.setTimeout(function () {
				LK.stage.removeChildren();
				console.log('Game is restarted');
				var newGame = new Game();
				LK.stage.addChild(newGame);
				messageText.setText('');
			}, 3000);
			box.destroy();
			box = null;
			if (self.isDead) {
				deadMessage.visible = true;
			} else {
				aliveMessage.visible = true;
			}
		}
	});
});
 
 
 
 
 
 
 
 
 8-bit. cartoon. red button. do not touch! Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 
 
 
 8-bit. cartoon. black tub stopper with chain. in game asset.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 8-bit. cartoon. axe. in game asset. no shadow.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 
 
 Break in case of emergency square. Ax drawing inside. simple. 8-bit. cartoon. blackand white.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 
 
 Delete