Code edit (16 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: draggedObject is null' in this line: 'draggedObject.alpha = 1;' Line Number: 117
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: draggedObject is null' in this line: 'draggedObject.alpha = 0.75;' Line Number: 129
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: self.yLevels is undefined' in this line: 'self.y = self.yLevels.find(level => level === self.y) || self.yLevels[0];' Line Number: 214
Code edit (1 edits merged)
Please save this source code
var NutBomb = Container.expand(function () { var self = Container.call(this); var nutBombGraphics = self.createAsset('nutBomb', 'Nut Bomb Graphics', .5, .5); self.move = function () { var fallSpeed = 5 + 1 * self.fallCounter / 3; self.y += fallSpeed; self.fallCounter = (self.fallCounter || 0) + 1; }; }); var RoyalCheese = Container.expand(function () { var self = Container.call(this); self.moveToYLevel = function (targetYLevel) { self.canNotBeStolen = true; var moveSpeed = 5; var moveInterval = LK.setInterval(function () { if (self.y <= targetYLevel) { self.y += moveSpeed; if (self.y >= targetYLevel) { self.y = targetYLevel; self.canNotBeStolen = false; LK.clearInterval(moveInterval); } } else if (self.y > targetYLevel) { self.y -= moveSpeed; if (self.y <= targetYLevel) { self.y = targetYLevel; self.canNotBeStolen = false; LK.clearInterval(moveInterval); } } }, 1000 / 60); }; var cheeseGraphics = self.createAsset('royalCheese', 'Royal Cheese Graphics', .5, .5); self.abducted = false; }); var RollingNut = Container.expand(function () { var self = Container.call(this); var rollingNutGraphics = self.createAsset('rollingNut', 'Rolling Nut Graphics', .5, .5); self.move = function () { self.x += 2; self.rotation += 0.1; }; }); var Nutcracker = Container.expand(function () { var self = Container.call(this); self.freeMouth = true; self.upperJaw = self.createAsset('upperJaw', 'Nutcracker Upper Jaw', .5, .5); self.lowerJaw = self.createAsset('lowerJaw', 'Nutcracker Lower Jaw', .5, .5); self.upperJaw.y -= 100; self.mouthUp = true; self.chewAnimation = function () { if (!self.freeMouth) { var chewRange = 150; var chewSpeed = 3; if (self.mouthUp) { if (self.upperJaw.y > -chewRange) { self.upperJaw.y -= chewSpeed; } else { self.mouthUp = false; } } else { if (self.upperJaw.y < -100) { self.upperJaw.y += chewSpeed; } else { self.mouthUp = true; } } } }; self.isDragged = false; self.isDraggable = true; self.isReady = false; var yLevels = [2570, 2070, 1570]; self.move = function () { if (self.mouthTimer && self.mouthTimer > 0) { self.mouthTimer--; self.chewAnimation(); if (self.mouthTimer === 0) { self.freeMouth = true; self.upperJaw.y = -100; } } if (self.resourceIncrementTimer && self.resourceIncrementTimer > 0) { self.resourceIncrementTimer--; if (self.resourceIncrementTimer === 0) { ressourcesNuts++; } } if (!self.isDragged && !yLevels.includes(self.y)) { var fallSpeed = 5 + 1 * self.fallCounter / 3; if (fallSpeed > 15) { self.deadlyFallSpeed = false; if (self.deadlyFallSpeed && !self.fallAsset) { self.fallAsset = self.createAsset('fallAsset', 'Extra Asset Graphics', .5, 0.6); } } else { if (self.fallAsset) { self.fallAsset.destroy(); self.fallAsset = null; } self.deadlyFallSpeed = false; } if (self.y < yLevels[0]) { self.y += fallSpeed; } else { self.y -= fallSpeed; } if (yLevels.some(level => self.y >= level && self.y - fallSpeed < level)) { self.y = yLevels.find(level => self.y >= level && self.y - fallSpeed < level); self.fallCounter = 0; self.deadlyFallSpeed = false; if (self.fallAsset) { self.fallAsset.destroy(); self.fallAsset = null; } self.isReady = true; } self.fallCounter = (self.fallCounter || 0) + 1; } }; self.on('down', function (obj) { if (self.freeMouth && self.isDraggable) { var pos = obj.event.getLocalPosition(self.parent); self.y = pos.y; self.x = pos.x; self.isDragged = true; self.isReady = false; draggedObject = self; self.fallCounter = 0; self.deadlyFallSpeed = false; } }); }); var MouseTrap = Container.expand(function () { var self = Container.call(this); var mousetrapGraphics = self.createAsset('mousetrap', 'Mouse Trap Graphics', .5, .5); self.activate = function () {}; }); var Mouse = Container.expand(function () { var self = Container.call(this); self.name = "mouse"; self.mouseTail = self.createAsset('mouseTail', 'Mouse Graphics', .5, .5); self.mouseBody = self.createAsset('mouseBody', 'Mouse Graphics', .5, .5); self.mouseHead = self.createAsset('mouseHead', 'Mouse Graphics', .5, .5); self.mouseHead.y -= 90; self.mouseHead.x += 10; self.mouseTail.x -= 50; self.mouseTail.y -= 10; self.consumptionDuration = 180; self.reachedCheese = false; self.royalCheese = null; self.move = function () { if (self.reachedCheese) { self.x -= 1; if (self.width > 0) { self.width = -150; } } else { self.x += 2; } var tailRotationSpeed = 0.020; var tailRotationRange = 20 * (Math.PI / 180); if (self.tailRotationDirection === undefined) { self.tailRotationDirection = 1; } if (self.mouseTail.rotation > tailRotationRange) { self.tailRotationDirection = -1; } else if (self.mouseTail.rotation < -tailRotationRange) { self.tailRotationDirection = 1; } self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection; self.mouseTail.y -= self.tailRotationDirection / 3; self.mouseHead.rotation += tailRotationSpeed * self.tailRotationDirection / 3; self.mouseHead.x += self.tailRotationDirection / 3; self.mouseHead.y += self.tailRotationDirection / 10; }; }); var MouseJumper = Container.expand(function () { var self = Container.call(this); self.name = "mouseJumper"; self.mouseTail = self.createAsset('mouseJumper', 'Mouse Jumper Graphics', .5, .5); self.consumptionDuration = 180; self.jumpTimer = 150; var yLevels = [2570, 2070, 1570]; self.reachedCheese = false; self.royalCheese = null; self.move = function () { var direction = self.reachedCheese ? -1 : 1; if (self.jumpTimer > 0) { self.jumpTimer--; } else { self.jumpTimer = 160; var jumpHeight = -900 + self.y; var jumpDistance = 500; self.jumpTo = function (targetX, targetY, callback) { var jumpSpeedX = (targetX - self.x) / 30 * direction; var jumpSpeedY = Math.abs(targetY - self.y) / 30; var jumpTick = 0; var jumpInterval = LK.setInterval(function () { jumpTick++; self.x += jumpSpeedX; if (jumpTick <= 15) { self.y -= jumpSpeedY; } else { self.y += jumpSpeedY; } if (jumpTick >= 30) { LK.clearInterval(jumpInterval); if (callback) callback(); } }, 1000 / 60); }; self.jumpTo(self.x + jumpDistance, jumpHeight, function () { self.y = self.yLevels.find(level => level === self.y) || self.yLevels[0]; }); } }; }); var TurtleMouse = Container.expand(function () { var self = Container.call(this); self.name = "turtleMouse"; self.mouseTail = self.createAsset('turtleMouseTail', 'Turtle Mouse Graphics', .5, .5); self.MouseBody = self.createAsset('turtleMouseBody', 'Turtle Mouse Graphics', .5, .5); self.mouseTail.x -= 75; self.consumptionDuration = 300; self.mouseTail.y -= 25; self.reachedCheese = false; self.royalCheese = null; self.move = function () { if (self.reachedCheese) { self.x -= 1; if (self.width > 0) { self.width = -200; } } else { self.x += 1; } var tailRotationSpeed = 0.020; var tailRotationRange = 20 * (Math.PI / 180); if (self.tailRotationDirection === undefined) { self.tailRotationDirection = 1; } if (self.mouseTail.rotation > tailRotationRange) { self.tailRotationDirection = -1; } else if (self.mouseTail.rotation < -tailRotationRange) { self.tailRotationDirection = 1; } self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection; self.mouseTail.y -= self.tailRotationDirection / 3; }; }); var FecalBall = Container.expand(function () { var self = Container.call(this); self.mouseTail = self.createAsset('mouseTail', 'Mouse Graphics', .5, .5); self.fecalBall = self.createAsset('fecalBall', 'Fecal Ball Graphics', .5, .5); self.mouseTail.x -= 50; self.mouseTail.y -= 25; self.move = function () { self.x += 5; self.fecalBall.rotation += 0.1; var tailRotationSpeed = 0.020; var tailRotationRange = 20 * (Math.PI / 180); if (self.tailRotationDirection === undefined) { self.tailRotationDirection = 1; } if (self.mouseTail.rotation > tailRotationRange) { self.tailRotationDirection = -1; } else if (self.mouseTail.rotation < -tailRotationRange) { self.tailRotationDirection = 1; } self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection; self.mouseTail.y -= self.tailRotationDirection / 3; }; }); var MouseTail = Container.expand(function (x, y, name, consumptionDuration) { var self = Container.call(this); self.mouseTail = self.createAsset(name + 'Tail', name + ' Tail Graphics', .5, .5); self.x = x; self.y = y; self.tickCounter = 0; self.tickFallCounter = 0; self.animateTick = function () { if (self.tickCounter < consumptionDuration) { var shiverAngle = 10 * Math.sin(self.tickCounter * 0.2); self.mouseTail.rotation = shiverAngle * (Math.PI / 180); self.tickCounter++; } else if (self.tickFallCounter < 60) { self.mouseTail.rotation += Math.PI / 60 * (Math.random() * 6 - 3); self.y += 2.5 + Math.random() * 0.5; self.tickFallCounter++; } else if (self.alpha > 0) { self.alpha -= 1 / 1800; } else { LK.off('tick', self.animateTick); self.destroy(); } }; }); var BuildingMenu = Container.expand(function () { var self = Container.call(this); self.y = 0; self.x = 1024; var menuBackground = self.createAsset('menuBackground', 'Building Menu Background', 0.5, 0); self.addChild(menuBackground); }); var NutcrackerButton = Container.expand(function (nutcrackers) { var self = Container.call(this); var buttonGraphics = self.createAsset('nutcrackerButton', 'Nutcracker Build Button', 0.5, 0); self.addChild(buttonGraphics); self.costText = new Text2((3 + nutcrackers.length).toString(), { size: 100, fill: "goldenrod" }); self.costText.anchor.set(0.5, 0); self.costText.x = self.x; self.costText.y = self.y + 200; self.addChild(self.costText); var dragObject = null; self.on('down', function (obj) { if (ressourcesNuts >= 3 + nutcrackers.length) { var pos = obj.event.getLocalPosition(self.parent); dragObject = new Nutcracker(); self.parent.addChild(dragObject); dragObject.y = pos.y; dragObject.x = pos.x; } }); stage.on('up', function (obj) { var pos = obj.event.getLocalPosition(self); if (dragObject) { if (pos.y > 400) { ressourcesNuts -= 3 + nutcrackers.length; var newNutcracker = new Nutcracker(); newNutcracker.x = pos.x + 1000; newNutcracker.y = pos.y + 300; self.parent.addChild(newNutcracker); nutcrackers.push(newNutcracker); dragObject.destroy(); dragObject = null; self.costText.setText((3 + nutcrackers.length).toString()); } else { dragObject.destroy(); dragObject = null; } } }); stage.on('move', function (obj) { if (dragObject) { var pos = obj.event.getLocalPosition(self); dragObject.x = pos.x + 1000; dragObject.y = pos.y + 300; } }); }); var NutBombButton = Container.expand(function (nutbombs) { var self = Container.call(this); var buttonGraphics = self.createAsset('nutBombButton', 'NutBomb Build Button', 0.5, 0); self.addChild(buttonGraphics); self.costText = new Text2("1", { size: 100, fill: "goldenrod" }); self.costText.anchor.set(0.5, 0); self.costText.x = self.x; self.costText.y = self.y + 200; self.addChild(self.costText); var dragObject = null; self.on('down', function (obj) { if (ressourcesNuts >= 1) { var pos = obj.event.getLocalPosition(self.parent); dragObject = new NutBomb(); self.parent.addChild(dragObject); dragObject.y = pos.y; dragObject.x = pos.x; } }); stage.on('up', function (obj) { var pos = obj.event.getLocalPosition(self); if (dragObject) { if (pos.y > 400) { ressourcesNuts -= 1; var newNutBomb = new NutBomb(); newNutBomb.x = pos.x + 1000; newNutBomb.y = pos.y + 300; self.parent.addChild(newNutBomb); nutbombs.push(newNutBomb); dragObject.destroy(); dragObject = null; } else { dragObject.destroy(); dragObject = null; } } }); stage.on('move', function (obj) { if (dragObject) { var pos = obj.event.getLocalPosition(self); dragObject.x = pos.x + 1000; dragObject.y = pos.y + 300; } }); }); var draggedObject = null; var ressourcesNuts = 0; var Game = Container.expand(function () { var self = Container.call(this); var yLevels = [2570, 2070, 1570]; var background = self.createAsset('background', 'Background Graphics', 0, 0); background.y = -2000; self.addChildAt(background, 0); var buildingMenu = self.addChild(new BuildingMenu()); var nutsCounter = new Text2(ressourcesNuts.toString(), { size: 200, fill: "#FDA53F" }); nutsCounter.anchor.set(0.5, 0); nutsCounter.x = 1700; nutsCounter.y = 100; self.addChild(nutsCounter); var nutGraphic = LK.getAsset('rollingNut', 'Nut Graphic', 0.5, 0.5); nutGraphic.x = nutsCounter.x + nutsCounter.width + nutGraphic.width; nutGraphic.y = nutsCounter.y + 100; nutGraphic.height = 200; nutGraphic.width = 200; self.addChild(nutGraphic); var nutcrackers = []; var nutbombs = []; var mousetraps = []; var mice = []; var rollingNuts = []; var fecalBalls = []; var royalCheeses = []; var firstNutcracker = new Nutcracker(); firstNutcracker.x = 1024; firstNutcracker.y = yLevels[1]; firstNutcracker.isReady = true; nutcrackers.push(firstNutcracker); self.addChild(firstNutcracker); var nutcrackerButton = new NutcrackerButton(nutcrackers); nutcrackerButton.x = 1024 - 100; nutcrackerButton.y = 300; self.addChild(nutcrackerButton); var nutBombButton = new NutBombButton(nutbombs); nutBombButton.x = 1024 + 100; nutBombButton.y = 300; self.addChild(nutBombButton); var tickCounter = 0; yLevels.forEach(function (yLevel) { var newCheese = new RoyalCheese(); newCheese.x = 2000; newCheese.y = yLevel; newCheese.currentYLevel = yLevel; royalCheeses.push(newCheese); self.addChild(newCheese); }); var mouseSpawnTimer = 360; var mouseSpawnTimer2 = 25200; var mouseTurtleSpawnTimer = 3600; var mouseJumperSpawnTimer = 3600; var fecalBallSpawnTimer = 3600; if (Math.random() > 0.33) { if (Math.random() > 0.5) { mouseTurtleSpawnTimer = 14400; mouseJumperSpawnTimer = 25200; } else { mouseTurtleSpawnTimer = 25200; mouseJumperSpawnTimer = 14400; } } else if (Math.random() > 0.5) { if (Math.random() > 0.5) { fecalBallSpawnTimer = 14400; mouseJumperSpawnTimer = 25200; } else { fecalBallSpawnTimer = 25200; mouseJumperSpawnTimer = 14400; } } else { if (Math.random() > 0.5) { mouseTurtleSpawnTimer = 14400; fecalBallSpawnTimer = 25200; } else { mouseTurtleSpawnTimer = 25200; fecalBallSpawnTimer = 14400; } } var miceKills = 0; var miceTickCounter = new Text2(miceKills.toString(), { size: 200, fill: "#ccc" }); miceTickCounter.anchor.set(0.5, 0); miceTickCounter.x = 380; miceTickCounter.y = 100; self.addChild(miceTickCounter); var mousetailGraphic = LK.getAsset('mouseTail', 'Mouse Tail Graphic', 0.5, 0.5); mousetailGraphic.x = miceTickCounter.x - miceTickCounter.width - 150; mousetailGraphic.y = miceTickCounter.y + 100; mousetailGraphic.width = -250; mousetailGraphic.height = 250; self.addChild(mousetailGraphic); var collisionTick = false; LK.on('tick', function () { tickCounter++; if (tickCounter % 6 === 0) { collisionTick = true; } else { collisionTick = false; } nutsCounter.setText(ressourcesNuts.toString()); if (tickCounter % 6600 === 0 || tickCounter % 6900 === 0) { var newMouse = new Mouse(); newMouse.x = 0 - newMouse.width; newMouse.y = yLevels[0]; mice.push(newMouse); self.addChild(newMouse); var newMouse2 = new Mouse(); newMouse2.x = 0 - newMouse2.width; newMouse2.y = yLevels[1]; mice.push(newMouse2); self.addChild(newMouse2); var newMouse3 = new Mouse(); newMouse3.x = 0 - newMouse3.width; newMouse3.y = yLevels[2]; mice.push(newMouse3); self.addChild(newMouse3); } if (tickCounter % mouseSpawnTimer == 0) { var newMouse = new Mouse(); newMouse.x = 0 - newMouse.width; newMouse.y = yLevels[Math.floor(Math.random() * yLevels.length)]; mice.push(newMouse); self.addChild(newMouse); mouseSpawnTimer = Math.max(mouseSpawnTimer - 2, 240); } if (tickCounter % mouseSpawnTimer2 == 0) { var newMouse = new Mouse(); newMouse.x = 0 - newMouse.width; newMouse.y = yLevels[Math.floor(Math.random() * yLevels.length)]; mice.push(newMouse); self.addChild(newMouse); if (mouseSpawnTimer2 > 3600) { mouseSpawnTimer2 = 900; } mouseSpawnTimer2 = Math.max(Math.round(mouseSpawnTimer2 * 0.99, 240)); } if (tickCounter % fecalBallSpawnTimer * 10 == 0) { var newFecalBall = new FecalBall(); newFecalBall.x = 0 - newFecalBall.width; newFecalBall.y = yLevels[Math.floor(Math.random() * yLevels.length)]; fecalBalls.push(newFecalBall); self.addChild(newFecalBall); if (fecalBallSpawnTimer > 3600) { fecalBallSpawnTimer = 3600; } fecalBallSpawnTimer = Math.max(Math.round(fecalBallSpawnTimer * 0.9), 300); } if (tickCounter % mouseTurtleSpawnTimer * 10 == 0) { var newMouseTurtle = new TurtleMouse(); newMouseTurtle.x = 0 - newMouseTurtle.width; newMouseTurtle.y = yLevels[Math.floor(Math.random() * yLevels.length)]; mice.push(newMouseTurtle); self.addChild(newMouseTurtle); if (mouseTurtleSpawnTimer > 3600) { mouseTurtleSpawnTimer = 3600; } mouseTurtleSpawnTimer = Math.max(Math.round(mouseTurtleSpawnTimer * 0.9), 300); } if (tickCounter % mouseJumperSpawnTimer * 10 == 0) { var newMouseJumper = new MouseJumper(); newMouseJumper.x = 0 - newMouseJumper.width; newMouseJumper.y = yLevels[Math.floor(Math.random() * yLevels.length)]; mice.push(newMouseJumper); self.addChild(newMouseJumper); if (mouseJumperSpawnTimer > 3600) { mouseJumperSpawnTimer = 3600; } mouseJumperSpawnTimer = Math.max(Math.round(mouseJumperSpawnTimer * 0.9), 300); } if (tickCounter % 1200 == 0) { var newRollingNut = new RollingNut(); newRollingNut.x = 0 - newRollingNut.width; newRollingNut.y = yLevels[Math.floor(Math.random() * yLevels.length)]; rollingNuts.push(newRollingNut); self.addChild(newRollingNut); } if (collisionTick) { for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].x > 1800) { nutcrackers[j].x = 1800; } else if (nutcrackers[j].x < 200) { nutcrackers[j].x = 200; } } for (var c = 0; c < royalCheeses.length; c++) { if (royalCheeses[c].x > 2000) { royalCheeses[c].x = 2000; } } } for (var i = 0; i < nutcrackers.length; i++) { nutcrackers[i].move(); } for (var i = 0; i < nutbombs.length; i++) { nutbombs[i].move(); if (collisionTick) { if (nutbombs[i].y + nutbombs[i].height < 0) { nutbombs[i].destroy(); nutbombs.splice(i, 1); } } } for (var i = mice.length - 1; i >= 0; i--) { mice[i].move(); if (collisionTick) { for (var n = 0; n < nutbombs.length; n++) { if (mice[i].intersects(nutbombs[n])) { if (mice[i].royalCheese) { var cheese = mice[i].removeChild(mice[i].royalCheese); self.addChild(cheese); mice[i].royalCheese = null; cheese.x = mice[i].x; cheese.y = mice[i].y - 50; cheese.abducted = false; cheese.moveToYLevel(cheese.currentYLevel); } miceKills++; miceTickCounter.setText(miceKills.toString()); var mouseTail = new MouseTail(mice[i].x - 50, mice[i].y, mice[i].name, mice[i].consumptionDuration); self.addChild(mouseTail); mice[i].destroy(); mice.splice(i, 1); } } for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].deadlyFallSpeed && mice[i].intersects(nutcrackers[j])) { if (mice[i].royalCheese) { var cheese = mice[i].removeChild(mice[i].royalCheese); self.addChild(cheese); mice[i].royalCheese = null; cheese.x = mice[i].x; cheese.y = mice[i].y - 50; cheese.abducted = false; cheese.moveToYLevel(cheese.currentYLevel); } miceKills++; miceTickCounter.setText(miceKills.toString()); var mouseTail = new MouseTail(mice[i].x - 50, mice[i].y, mice[i].name, mice[i].consumptionDuration); self.addChild(mouseTail); mice[i].destroy(); mice.splice(i, 1); break; } else if (nutcrackers[j].isReady && nutcrackers[j].freeMouth && !nutcrackers[j].isDragged && mice[i].intersects(nutcrackers[j])) { if (mice[i].royalCheese) { var cheese = mice[i].removeChild(mice[i].royalCheese); self.addChild(cheese); mice[i].royalCheese = null; cheese.x = mice[i].x; cheese.y = mice[i].y - 50; cheese.abducted = false; cheese.moveToYLevel(cheese.currentYLevel); } nutcrackers[j].freeMouth = false; nutcrackers[j].mouthTimer = mice[i].consumptionDuration; miceKills++; miceTickCounter.setText(miceKills.toString()); var mouseTail = new MouseTail(nutcrackers[j].x - 40, nutcrackers[j].y - 100, mice[i].name, mice[i].consumptionDuration); self.addChild(mouseTail); LK.on('tick', function () { mouseTail.animateTick(); }); mice[i].destroy(); mice.splice(i, 1); break; } } for (var c = 0; c < royalCheeses.length; c++) { if (mice[i] && mice[i].intersects(royalCheeses[c])) { mice[i].reachedCheese = true; if (!royalCheeses[c].abducted && !royalCheeses[c].canNotBeStolen && mice[i].royalCheese === null) { royalCheeses[c].abducted = true; royalCheeses[c].parent.removeChild(royalCheeses[c]); mice[i].royalCheese = mice[i].addChild(royalCheeses[c]); royalCheeses[c].x = 60; royalCheeses[c].y = -60; break; } } } if (mice[i] && mice[i].x > 2048 + mice[i].width) { mice[i].reachedCheese = true; } else if (mice[i] && mice[i].reachedCheese && mice[i] && mice[i].x < 0 - 100) { if (mice[i].royalCheese) { LK.showGameOver(); break; } mice[i].destroy(); mice.splice(i, 1); } } } for (var i = fecalBalls.length - 1; i >= 0; i--) { fecalBalls[i].move(); if (collisionTick) { for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].isReady && fecalBalls[i].intersects(nutcrackers[j])) { var mousePosX = fecalBalls[i].x - 50; var mousePosY = fecalBalls[i].y; animateObjectPushedBack(nutcrackers[j], 250 + Math.random() * 100, 1800); var newMouse = new Mouse(); newMouse.x = mousePosX; newMouse.y = mousePosY; mice.push(newMouse); self.addChild(newMouse); fecalBalls[i].destroy(); fecalBalls.splice(i, 1); break; } } for (var c = 0; c < royalCheeses.length; c++) { if (fecalBalls[i] && fecalBalls[i].intersects(royalCheeses[c])) { if (!royalCheeses[c].abducted) { animateObjectPushedBack(royalCheeses[c], 250 + Math.random() * 100, 2000); } var mousePosX = fecalBalls[i].x - 50; var mousePosY = fecalBalls[i].y; var newMouse = new Mouse(); mice.push(newMouse); newMouse.x = mousePosX; newMouse.y = mousePosY; self.addChild(newMouse); fecalBalls[i].destroy(); fecalBalls.splice(i, 1); break; } } if (fecalBalls[i] && fecalBalls[i].x > 2048 + fecalBalls[i].width) { fecalBalls[i].destroy(); fecalBalls.splice(i, 1); } } } for (var i = rollingNuts.length - 1; i >= 0; i--) { rollingNuts[i].move(); if (collisionTick) { for (var c = 0; c < royalCheeses.length; c++) { if (!royalCheeses[c].abducted && rollingNuts[i].intersects(royalCheeses[c])) { animateObjectPushedBack(royalCheeses[c], 100, 2000); } } for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].isReady && nutcrackers[j].freeMouth && !nutcrackers[j].isDragged && rollingNuts[i].intersects(nutcrackers[j])) { rollingNuts[i].destroy(); rollingNuts.splice(i, 1); nutcrackers[j].freeMouth = false; nutcrackers[j].mouthTimer = 300; nutcrackers[j].resourceIncrementTimer = 300; break; } } if (rollingNuts[i] && rollingNuts[i].x > 2048 + rollingNuts[i].width) { rollingNuts[i].destroy(); rollingNuts.splice(i, 1); } } } }); function animateObjectPushedBack(object, distance, maxDistance) { var animationStep = distance / 30; var targetX = Math.min(maxDistance, object.x + distance); object.isReady = false; object.isDraggable = false; var animationTick; var animationInterval = LK.setInterval(function () { animationTick++; if (object.x < targetX) { object.x += animationStep; } else { object.x = targetX; object.isReady = true; object.isDraggable = true; LK.clearInterval(animationInterval); } }, 1000 / 60); } stage.on('up', function (obj) { if (draggedObject) { var pos = obj.event.getLocalPosition(self); draggedObject.isDragged = false; draggedObject.isReady = false; draggedObject = null; } }); stage.on('move', function (obj) { if (draggedObject) { var pos = obj.event.getLocalPosition(self); draggedObject.x = pos.x; draggedObject.y = pos.y; } }); });
var NutBomb = Container.expand(function () {
var self = Container.call(this);
var nutBombGraphics = self.createAsset('nutBomb', 'Nut Bomb Graphics', .5, .5);
self.move = function () {
var fallSpeed = 5 + 1 * self.fallCounter / 3;
self.y += fallSpeed;
self.fallCounter = (self.fallCounter || 0) + 1;
};
});
var RoyalCheese = Container.expand(function () {
var self = Container.call(this);
self.moveToYLevel = function (targetYLevel) {
self.canNotBeStolen = true;
var moveSpeed = 5;
var moveInterval = LK.setInterval(function () {
if (self.y <= targetYLevel) {
self.y += moveSpeed;
if (self.y >= targetYLevel) {
self.y = targetYLevel;
self.canNotBeStolen = false;
LK.clearInterval(moveInterval);
}
} else if (self.y > targetYLevel) {
self.y -= moveSpeed;
if (self.y <= targetYLevel) {
self.y = targetYLevel;
self.canNotBeStolen = false;
LK.clearInterval(moveInterval);
}
}
}, 1000 / 60);
};
var cheeseGraphics = self.createAsset('royalCheese', 'Royal Cheese Graphics', .5, .5);
self.abducted = false;
});
var RollingNut = Container.expand(function () {
var self = Container.call(this);
var rollingNutGraphics = self.createAsset('rollingNut', 'Rolling Nut Graphics', .5, .5);
self.move = function () {
self.x += 2;
self.rotation += 0.1;
};
});
var Nutcracker = Container.expand(function () {
var self = Container.call(this);
self.freeMouth = true;
self.upperJaw = self.createAsset('upperJaw', 'Nutcracker Upper Jaw', .5, .5);
self.lowerJaw = self.createAsset('lowerJaw', 'Nutcracker Lower Jaw', .5, .5);
self.upperJaw.y -= 100;
self.mouthUp = true;
self.chewAnimation = function () {
if (!self.freeMouth) {
var chewRange = 150;
var chewSpeed = 3;
if (self.mouthUp) {
if (self.upperJaw.y > -chewRange) {
self.upperJaw.y -= chewSpeed;
} else {
self.mouthUp = false;
}
} else {
if (self.upperJaw.y < -100) {
self.upperJaw.y += chewSpeed;
} else {
self.mouthUp = true;
}
}
}
};
self.isDragged = false;
self.isDraggable = true;
self.isReady = false;
var yLevels = [2570, 2070, 1570];
self.move = function () {
if (self.mouthTimer && self.mouthTimer > 0) {
self.mouthTimer--;
self.chewAnimation();
if (self.mouthTimer === 0) {
self.freeMouth = true;
self.upperJaw.y = -100;
}
}
if (self.resourceIncrementTimer && self.resourceIncrementTimer > 0) {
self.resourceIncrementTimer--;
if (self.resourceIncrementTimer === 0) {
ressourcesNuts++;
}
}
if (!self.isDragged && !yLevels.includes(self.y)) {
var fallSpeed = 5 + 1 * self.fallCounter / 3;
if (fallSpeed > 15) {
self.deadlyFallSpeed = false;
if (self.deadlyFallSpeed && !self.fallAsset) {
self.fallAsset = self.createAsset('fallAsset', 'Extra Asset Graphics', .5, 0.6);
}
} else {
if (self.fallAsset) {
self.fallAsset.destroy();
self.fallAsset = null;
}
self.deadlyFallSpeed = false;
}
if (self.y < yLevels[0]) {
self.y += fallSpeed;
} else {
self.y -= fallSpeed;
}
if (yLevels.some(level => self.y >= level && self.y - fallSpeed < level)) {
self.y = yLevels.find(level => self.y >= level && self.y - fallSpeed < level);
self.fallCounter = 0;
self.deadlyFallSpeed = false;
if (self.fallAsset) {
self.fallAsset.destroy();
self.fallAsset = null;
}
self.isReady = true;
}
self.fallCounter = (self.fallCounter || 0) + 1;
}
};
self.on('down', function (obj) {
if (self.freeMouth && self.isDraggable) {
var pos = obj.event.getLocalPosition(self.parent);
self.y = pos.y;
self.x = pos.x;
self.isDragged = true;
self.isReady = false;
draggedObject = self;
self.fallCounter = 0;
self.deadlyFallSpeed = false;
}
});
});
var MouseTrap = Container.expand(function () {
var self = Container.call(this);
var mousetrapGraphics = self.createAsset('mousetrap', 'Mouse Trap Graphics', .5, .5);
self.activate = function () {};
});
var Mouse = Container.expand(function () {
var self = Container.call(this);
self.name = "mouse";
self.mouseTail = self.createAsset('mouseTail', 'Mouse Graphics', .5, .5);
self.mouseBody = self.createAsset('mouseBody', 'Mouse Graphics', .5, .5);
self.mouseHead = self.createAsset('mouseHead', 'Mouse Graphics', .5, .5);
self.mouseHead.y -= 90;
self.mouseHead.x += 10;
self.mouseTail.x -= 50;
self.mouseTail.y -= 10;
self.consumptionDuration = 180;
self.reachedCheese = false;
self.royalCheese = null;
self.move = function () {
if (self.reachedCheese) {
self.x -= 1;
if (self.width > 0) {
self.width = -150;
}
} else {
self.x += 2;
}
var tailRotationSpeed = 0.020;
var tailRotationRange = 20 * (Math.PI / 180);
if (self.tailRotationDirection === undefined) {
self.tailRotationDirection = 1;
}
if (self.mouseTail.rotation > tailRotationRange) {
self.tailRotationDirection = -1;
} else if (self.mouseTail.rotation < -tailRotationRange) {
self.tailRotationDirection = 1;
}
self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection;
self.mouseTail.y -= self.tailRotationDirection / 3;
self.mouseHead.rotation += tailRotationSpeed * self.tailRotationDirection / 3;
self.mouseHead.x += self.tailRotationDirection / 3;
self.mouseHead.y += self.tailRotationDirection / 10;
};
});
var MouseJumper = Container.expand(function () {
var self = Container.call(this);
self.name = "mouseJumper";
self.mouseTail = self.createAsset('mouseJumper', 'Mouse Jumper Graphics', .5, .5);
self.consumptionDuration = 180;
self.jumpTimer = 150;
var yLevels = [2570, 2070, 1570];
self.reachedCheese = false;
self.royalCheese = null;
self.move = function () {
var direction = self.reachedCheese ? -1 : 1;
if (self.jumpTimer > 0) {
self.jumpTimer--;
} else {
self.jumpTimer = 160;
var jumpHeight = -900 + self.y;
var jumpDistance = 500;
self.jumpTo = function (targetX, targetY, callback) {
var jumpSpeedX = (targetX - self.x) / 30 * direction;
var jumpSpeedY = Math.abs(targetY - self.y) / 30;
var jumpTick = 0;
var jumpInterval = LK.setInterval(function () {
jumpTick++;
self.x += jumpSpeedX;
if (jumpTick <= 15) {
self.y -= jumpSpeedY;
} else {
self.y += jumpSpeedY;
}
if (jumpTick >= 30) {
LK.clearInterval(jumpInterval);
if (callback) callback();
}
}, 1000 / 60);
};
self.jumpTo(self.x + jumpDistance, jumpHeight, function () {
self.y = self.yLevels.find(level => level === self.y) || self.yLevels[0];
});
}
};
});
var TurtleMouse = Container.expand(function () {
var self = Container.call(this);
self.name = "turtleMouse";
self.mouseTail = self.createAsset('turtleMouseTail', 'Turtle Mouse Graphics', .5, .5);
self.MouseBody = self.createAsset('turtleMouseBody', 'Turtle Mouse Graphics', .5, .5);
self.mouseTail.x -= 75;
self.consumptionDuration = 300;
self.mouseTail.y -= 25;
self.reachedCheese = false;
self.royalCheese = null;
self.move = function () {
if (self.reachedCheese) {
self.x -= 1;
if (self.width > 0) {
self.width = -200;
}
} else {
self.x += 1;
}
var tailRotationSpeed = 0.020;
var tailRotationRange = 20 * (Math.PI / 180);
if (self.tailRotationDirection === undefined) {
self.tailRotationDirection = 1;
}
if (self.mouseTail.rotation > tailRotationRange) {
self.tailRotationDirection = -1;
} else if (self.mouseTail.rotation < -tailRotationRange) {
self.tailRotationDirection = 1;
}
self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection;
self.mouseTail.y -= self.tailRotationDirection / 3;
};
});
var FecalBall = Container.expand(function () {
var self = Container.call(this);
self.mouseTail = self.createAsset('mouseTail', 'Mouse Graphics', .5, .5);
self.fecalBall = self.createAsset('fecalBall', 'Fecal Ball Graphics', .5, .5);
self.mouseTail.x -= 50;
self.mouseTail.y -= 25;
self.move = function () {
self.x += 5;
self.fecalBall.rotation += 0.1;
var tailRotationSpeed = 0.020;
var tailRotationRange = 20 * (Math.PI / 180);
if (self.tailRotationDirection === undefined) {
self.tailRotationDirection = 1;
}
if (self.mouseTail.rotation > tailRotationRange) {
self.tailRotationDirection = -1;
} else if (self.mouseTail.rotation < -tailRotationRange) {
self.tailRotationDirection = 1;
}
self.mouseTail.rotation += tailRotationSpeed * self.tailRotationDirection;
self.mouseTail.y -= self.tailRotationDirection / 3;
};
});
var MouseTail = Container.expand(function (x, y, name, consumptionDuration) {
var self = Container.call(this);
self.mouseTail = self.createAsset(name + 'Tail', name + ' Tail Graphics', .5, .5);
self.x = x;
self.y = y;
self.tickCounter = 0;
self.tickFallCounter = 0;
self.animateTick = function () {
if (self.tickCounter < consumptionDuration) {
var shiverAngle = 10 * Math.sin(self.tickCounter * 0.2);
self.mouseTail.rotation = shiverAngle * (Math.PI / 180);
self.tickCounter++;
} else if (self.tickFallCounter < 60) {
self.mouseTail.rotation += Math.PI / 60 * (Math.random() * 6 - 3);
self.y += 2.5 + Math.random() * 0.5;
self.tickFallCounter++;
} else if (self.alpha > 0) {
self.alpha -= 1 / 1800;
} else {
LK.off('tick', self.animateTick);
self.destroy();
}
};
});
var BuildingMenu = Container.expand(function () {
var self = Container.call(this);
self.y = 0;
self.x = 1024;
var menuBackground = self.createAsset('menuBackground', 'Building Menu Background', 0.5, 0);
self.addChild(menuBackground);
});
var NutcrackerButton = Container.expand(function (nutcrackers) {
var self = Container.call(this);
var buttonGraphics = self.createAsset('nutcrackerButton', 'Nutcracker Build Button', 0.5, 0);
self.addChild(buttonGraphics);
self.costText = new Text2((3 + nutcrackers.length).toString(), {
size: 100,
fill: "goldenrod"
});
self.costText.anchor.set(0.5, 0);
self.costText.x = self.x;
self.costText.y = self.y + 200;
self.addChild(self.costText);
var dragObject = null;
self.on('down', function (obj) {
if (ressourcesNuts >= 3 + nutcrackers.length) {
var pos = obj.event.getLocalPosition(self.parent);
dragObject = new Nutcracker();
self.parent.addChild(dragObject);
dragObject.y = pos.y;
dragObject.x = pos.x;
}
});
stage.on('up', function (obj) {
var pos = obj.event.getLocalPosition(self);
if (dragObject) {
if (pos.y > 400) {
ressourcesNuts -= 3 + nutcrackers.length;
var newNutcracker = new Nutcracker();
newNutcracker.x = pos.x + 1000;
newNutcracker.y = pos.y + 300;
self.parent.addChild(newNutcracker);
nutcrackers.push(newNutcracker);
dragObject.destroy();
dragObject = null;
self.costText.setText((3 + nutcrackers.length).toString());
} else {
dragObject.destroy();
dragObject = null;
}
}
});
stage.on('move', function (obj) {
if (dragObject) {
var pos = obj.event.getLocalPosition(self);
dragObject.x = pos.x + 1000;
dragObject.y = pos.y + 300;
}
});
});
var NutBombButton = Container.expand(function (nutbombs) {
var self = Container.call(this);
var buttonGraphics = self.createAsset('nutBombButton', 'NutBomb Build Button', 0.5, 0);
self.addChild(buttonGraphics);
self.costText = new Text2("1", {
size: 100,
fill: "goldenrod"
});
self.costText.anchor.set(0.5, 0);
self.costText.x = self.x;
self.costText.y = self.y + 200;
self.addChild(self.costText);
var dragObject = null;
self.on('down', function (obj) {
if (ressourcesNuts >= 1) {
var pos = obj.event.getLocalPosition(self.parent);
dragObject = new NutBomb();
self.parent.addChild(dragObject);
dragObject.y = pos.y;
dragObject.x = pos.x;
}
});
stage.on('up', function (obj) {
var pos = obj.event.getLocalPosition(self);
if (dragObject) {
if (pos.y > 400) {
ressourcesNuts -= 1;
var newNutBomb = new NutBomb();
newNutBomb.x = pos.x + 1000;
newNutBomb.y = pos.y + 300;
self.parent.addChild(newNutBomb);
nutbombs.push(newNutBomb);
dragObject.destroy();
dragObject = null;
} else {
dragObject.destroy();
dragObject = null;
}
}
});
stage.on('move', function (obj) {
if (dragObject) {
var pos = obj.event.getLocalPosition(self);
dragObject.x = pos.x + 1000;
dragObject.y = pos.y + 300;
}
});
});
var draggedObject = null;
var ressourcesNuts = 0;
var Game = Container.expand(function () {
var self = Container.call(this);
var yLevels = [2570, 2070, 1570];
var background = self.createAsset('background', 'Background Graphics', 0, 0);
background.y = -2000;
self.addChildAt(background, 0);
var buildingMenu = self.addChild(new BuildingMenu());
var nutsCounter = new Text2(ressourcesNuts.toString(), {
size: 200,
fill: "#FDA53F"
});
nutsCounter.anchor.set(0.5, 0);
nutsCounter.x = 1700;
nutsCounter.y = 100;
self.addChild(nutsCounter);
var nutGraphic = LK.getAsset('rollingNut', 'Nut Graphic', 0.5, 0.5);
nutGraphic.x = nutsCounter.x + nutsCounter.width + nutGraphic.width;
nutGraphic.y = nutsCounter.y + 100;
nutGraphic.height = 200;
nutGraphic.width = 200;
self.addChild(nutGraphic);
var nutcrackers = [];
var nutbombs = [];
var mousetraps = [];
var mice = [];
var rollingNuts = [];
var fecalBalls = [];
var royalCheeses = [];
var firstNutcracker = new Nutcracker();
firstNutcracker.x = 1024;
firstNutcracker.y = yLevels[1];
firstNutcracker.isReady = true;
nutcrackers.push(firstNutcracker);
self.addChild(firstNutcracker);
var nutcrackerButton = new NutcrackerButton(nutcrackers);
nutcrackerButton.x = 1024 - 100;
nutcrackerButton.y = 300;
self.addChild(nutcrackerButton);
var nutBombButton = new NutBombButton(nutbombs);
nutBombButton.x = 1024 + 100;
nutBombButton.y = 300;
self.addChild(nutBombButton);
var tickCounter = 0;
yLevels.forEach(function (yLevel) {
var newCheese = new RoyalCheese();
newCheese.x = 2000;
newCheese.y = yLevel;
newCheese.currentYLevel = yLevel;
royalCheeses.push(newCheese);
self.addChild(newCheese);
});
var mouseSpawnTimer = 360;
var mouseSpawnTimer2 = 25200;
var mouseTurtleSpawnTimer = 3600;
var mouseJumperSpawnTimer = 3600;
var fecalBallSpawnTimer = 3600;
if (Math.random() > 0.33) {
if (Math.random() > 0.5) {
mouseTurtleSpawnTimer = 14400;
mouseJumperSpawnTimer = 25200;
} else {
mouseTurtleSpawnTimer = 25200;
mouseJumperSpawnTimer = 14400;
}
} else if (Math.random() > 0.5) {
if (Math.random() > 0.5) {
fecalBallSpawnTimer = 14400;
mouseJumperSpawnTimer = 25200;
} else {
fecalBallSpawnTimer = 25200;
mouseJumperSpawnTimer = 14400;
}
} else {
if (Math.random() > 0.5) {
mouseTurtleSpawnTimer = 14400;
fecalBallSpawnTimer = 25200;
} else {
mouseTurtleSpawnTimer = 25200;
fecalBallSpawnTimer = 14400;
}
}
var miceKills = 0;
var miceTickCounter = new Text2(miceKills.toString(), {
size: 200,
fill: "#ccc"
});
miceTickCounter.anchor.set(0.5, 0);
miceTickCounter.x = 380;
miceTickCounter.y = 100;
self.addChild(miceTickCounter);
var mousetailGraphic = LK.getAsset('mouseTail', 'Mouse Tail Graphic', 0.5, 0.5);
mousetailGraphic.x = miceTickCounter.x - miceTickCounter.width - 150;
mousetailGraphic.y = miceTickCounter.y + 100;
mousetailGraphic.width = -250;
mousetailGraphic.height = 250;
self.addChild(mousetailGraphic);
var collisionTick = false;
LK.on('tick', function () {
tickCounter++;
if (tickCounter % 6 === 0) {
collisionTick = true;
} else {
collisionTick = false;
}
nutsCounter.setText(ressourcesNuts.toString());
if (tickCounter % 6600 === 0 || tickCounter % 6900 === 0) {
var newMouse = new Mouse();
newMouse.x = 0 - newMouse.width;
newMouse.y = yLevels[0];
mice.push(newMouse);
self.addChild(newMouse);
var newMouse2 = new Mouse();
newMouse2.x = 0 - newMouse2.width;
newMouse2.y = yLevels[1];
mice.push(newMouse2);
self.addChild(newMouse2);
var newMouse3 = new Mouse();
newMouse3.x = 0 - newMouse3.width;
newMouse3.y = yLevels[2];
mice.push(newMouse3);
self.addChild(newMouse3);
}
if (tickCounter % mouseSpawnTimer == 0) {
var newMouse = new Mouse();
newMouse.x = 0 - newMouse.width;
newMouse.y = yLevels[Math.floor(Math.random() * yLevels.length)];
mice.push(newMouse);
self.addChild(newMouse);
mouseSpawnTimer = Math.max(mouseSpawnTimer - 2, 240);
}
if (tickCounter % mouseSpawnTimer2 == 0) {
var newMouse = new Mouse();
newMouse.x = 0 - newMouse.width;
newMouse.y = yLevels[Math.floor(Math.random() * yLevels.length)];
mice.push(newMouse);
self.addChild(newMouse);
if (mouseSpawnTimer2 > 3600) {
mouseSpawnTimer2 = 900;
}
mouseSpawnTimer2 = Math.max(Math.round(mouseSpawnTimer2 * 0.99, 240));
}
if (tickCounter % fecalBallSpawnTimer * 10 == 0) {
var newFecalBall = new FecalBall();
newFecalBall.x = 0 - newFecalBall.width;
newFecalBall.y = yLevels[Math.floor(Math.random() * yLevels.length)];
fecalBalls.push(newFecalBall);
self.addChild(newFecalBall);
if (fecalBallSpawnTimer > 3600) {
fecalBallSpawnTimer = 3600;
}
fecalBallSpawnTimer = Math.max(Math.round(fecalBallSpawnTimer * 0.9), 300);
}
if (tickCounter % mouseTurtleSpawnTimer * 10 == 0) {
var newMouseTurtle = new TurtleMouse();
newMouseTurtle.x = 0 - newMouseTurtle.width;
newMouseTurtle.y = yLevels[Math.floor(Math.random() * yLevels.length)];
mice.push(newMouseTurtle);
self.addChild(newMouseTurtle);
if (mouseTurtleSpawnTimer > 3600) {
mouseTurtleSpawnTimer = 3600;
}
mouseTurtleSpawnTimer = Math.max(Math.round(mouseTurtleSpawnTimer * 0.9), 300);
}
if (tickCounter % mouseJumperSpawnTimer * 10 == 0) {
var newMouseJumper = new MouseJumper();
newMouseJumper.x = 0 - newMouseJumper.width;
newMouseJumper.y = yLevels[Math.floor(Math.random() * yLevels.length)];
mice.push(newMouseJumper);
self.addChild(newMouseJumper);
if (mouseJumperSpawnTimer > 3600) {
mouseJumperSpawnTimer = 3600;
}
mouseJumperSpawnTimer = Math.max(Math.round(mouseJumperSpawnTimer * 0.9), 300);
}
if (tickCounter % 1200 == 0) {
var newRollingNut = new RollingNut();
newRollingNut.x = 0 - newRollingNut.width;
newRollingNut.y = yLevels[Math.floor(Math.random() * yLevels.length)];
rollingNuts.push(newRollingNut);
self.addChild(newRollingNut);
}
if (collisionTick) {
for (var j = 0; j < nutcrackers.length; j++) {
if (nutcrackers[j].x > 1800) {
nutcrackers[j].x = 1800;
} else if (nutcrackers[j].x < 200) {
nutcrackers[j].x = 200;
}
}
for (var c = 0; c < royalCheeses.length; c++) {
if (royalCheeses[c].x > 2000) {
royalCheeses[c].x = 2000;
}
}
}
for (var i = 0; i < nutcrackers.length; i++) {
nutcrackers[i].move();
}
for (var i = 0; i < nutbombs.length; i++) {
nutbombs[i].move();
if (collisionTick) {
if (nutbombs[i].y + nutbombs[i].height < 0) {
nutbombs[i].destroy();
nutbombs.splice(i, 1);
}
}
}
for (var i = mice.length - 1; i >= 0; i--) {
mice[i].move();
if (collisionTick) {
for (var n = 0; n < nutbombs.length; n++) {
if (mice[i].intersects(nutbombs[n])) {
if (mice[i].royalCheese) {
var cheese = mice[i].removeChild(mice[i].royalCheese);
self.addChild(cheese);
mice[i].royalCheese = null;
cheese.x = mice[i].x;
cheese.y = mice[i].y - 50;
cheese.abducted = false;
cheese.moveToYLevel(cheese.currentYLevel);
}
miceKills++;
miceTickCounter.setText(miceKills.toString());
var mouseTail = new MouseTail(mice[i].x - 50, mice[i].y, mice[i].name, mice[i].consumptionDuration);
self.addChild(mouseTail);
mice[i].destroy();
mice.splice(i, 1);
}
}
for (var j = 0; j < nutcrackers.length; j++) {
if (nutcrackers[j].deadlyFallSpeed && mice[i].intersects(nutcrackers[j])) {
if (mice[i].royalCheese) {
var cheese = mice[i].removeChild(mice[i].royalCheese);
self.addChild(cheese);
mice[i].royalCheese = null;
cheese.x = mice[i].x;
cheese.y = mice[i].y - 50;
cheese.abducted = false;
cheese.moveToYLevel(cheese.currentYLevel);
}
miceKills++;
miceTickCounter.setText(miceKills.toString());
var mouseTail = new MouseTail(mice[i].x - 50, mice[i].y, mice[i].name, mice[i].consumptionDuration);
self.addChild(mouseTail);
mice[i].destroy();
mice.splice(i, 1);
break;
} else if (nutcrackers[j].isReady && nutcrackers[j].freeMouth && !nutcrackers[j].isDragged && mice[i].intersects(nutcrackers[j])) {
if (mice[i].royalCheese) {
var cheese = mice[i].removeChild(mice[i].royalCheese);
self.addChild(cheese);
mice[i].royalCheese = null;
cheese.x = mice[i].x;
cheese.y = mice[i].y - 50;
cheese.abducted = false;
cheese.moveToYLevel(cheese.currentYLevel);
}
nutcrackers[j].freeMouth = false;
nutcrackers[j].mouthTimer = mice[i].consumptionDuration;
miceKills++;
miceTickCounter.setText(miceKills.toString());
var mouseTail = new MouseTail(nutcrackers[j].x - 40, nutcrackers[j].y - 100, mice[i].name, mice[i].consumptionDuration);
self.addChild(mouseTail);
LK.on('tick', function () {
mouseTail.animateTick();
});
mice[i].destroy();
mice.splice(i, 1);
break;
}
}
for (var c = 0; c < royalCheeses.length; c++) {
if (mice[i] && mice[i].intersects(royalCheeses[c])) {
mice[i].reachedCheese = true;
if (!royalCheeses[c].abducted && !royalCheeses[c].canNotBeStolen && mice[i].royalCheese === null) {
royalCheeses[c].abducted = true;
royalCheeses[c].parent.removeChild(royalCheeses[c]);
mice[i].royalCheese = mice[i].addChild(royalCheeses[c]);
royalCheeses[c].x = 60;
royalCheeses[c].y = -60;
break;
}
}
}
if (mice[i] && mice[i].x > 2048 + mice[i].width) {
mice[i].reachedCheese = true;
} else if (mice[i] && mice[i].reachedCheese && mice[i] && mice[i].x < 0 - 100) {
if (mice[i].royalCheese) {
LK.showGameOver();
break;
}
mice[i].destroy();
mice.splice(i, 1);
}
}
}
for (var i = fecalBalls.length - 1; i >= 0; i--) {
fecalBalls[i].move();
if (collisionTick) {
for (var j = 0; j < nutcrackers.length; j++) {
if (nutcrackers[j].isReady && fecalBalls[i].intersects(nutcrackers[j])) {
var mousePosX = fecalBalls[i].x - 50;
var mousePosY = fecalBalls[i].y;
animateObjectPushedBack(nutcrackers[j], 250 + Math.random() * 100, 1800);
var newMouse = new Mouse();
newMouse.x = mousePosX;
newMouse.y = mousePosY;
mice.push(newMouse);
self.addChild(newMouse);
fecalBalls[i].destroy();
fecalBalls.splice(i, 1);
break;
}
}
for (var c = 0; c < royalCheeses.length; c++) {
if (fecalBalls[i] && fecalBalls[i].intersects(royalCheeses[c])) {
if (!royalCheeses[c].abducted) {
animateObjectPushedBack(royalCheeses[c], 250 + Math.random() * 100, 2000);
}
var mousePosX = fecalBalls[i].x - 50;
var mousePosY = fecalBalls[i].y;
var newMouse = new Mouse();
mice.push(newMouse);
newMouse.x = mousePosX;
newMouse.y = mousePosY;
self.addChild(newMouse);
fecalBalls[i].destroy();
fecalBalls.splice(i, 1);
break;
}
}
if (fecalBalls[i] && fecalBalls[i].x > 2048 + fecalBalls[i].width) {
fecalBalls[i].destroy();
fecalBalls.splice(i, 1);
}
}
}
for (var i = rollingNuts.length - 1; i >= 0; i--) {
rollingNuts[i].move();
if (collisionTick) {
for (var c = 0; c < royalCheeses.length; c++) {
if (!royalCheeses[c].abducted && rollingNuts[i].intersects(royalCheeses[c])) {
animateObjectPushedBack(royalCheeses[c], 100, 2000);
}
}
for (var j = 0; j < nutcrackers.length; j++) {
if (nutcrackers[j].isReady && nutcrackers[j].freeMouth && !nutcrackers[j].isDragged && rollingNuts[i].intersects(nutcrackers[j])) {
rollingNuts[i].destroy();
rollingNuts.splice(i, 1);
nutcrackers[j].freeMouth = false;
nutcrackers[j].mouthTimer = 300;
nutcrackers[j].resourceIncrementTimer = 300;
break;
}
}
if (rollingNuts[i] && rollingNuts[i].x > 2048 + rollingNuts[i].width) {
rollingNuts[i].destroy();
rollingNuts.splice(i, 1);
}
}
}
});
function animateObjectPushedBack(object, distance, maxDistance) {
var animationStep = distance / 30;
var targetX = Math.min(maxDistance, object.x + distance);
object.isReady = false;
object.isDraggable = false;
var animationTick;
var animationInterval = LK.setInterval(function () {
animationTick++;
if (object.x < targetX) {
object.x += animationStep;
} else {
object.x = targetX;
object.isReady = true;
object.isDraggable = true;
LK.clearInterval(animationInterval);
}
}, 1000 / 60);
}
stage.on('up', function (obj) {
if (draggedObject) {
var pos = obj.event.getLocalPosition(self);
draggedObject.isDragged = false;
draggedObject.isReady = false;
draggedObject = null;
}
});
stage.on('move', function (obj) {
if (draggedObject) {
var pos = obj.event.getLocalPosition(self);
draggedObject.x = pos.x;
draggedObject.y = pos.y;
}
});
});
Nut cracker, side view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mouse trap, side view, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a rolling nut, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round giant snowball, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white background