Code edit (6 edits merged)
Please save this source code
User prompt
create right of the mouseKill counter a graphical mousetail asset
User prompt
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() * 3; self.y += 2.5 + Math.random() * 0.5; self.tickFallCounter++; } else { LK.off('tick', self.animateTick); } }; every final rotation should be possible and have the same chances
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
self.animateTick = function () { if (self.tickCounter < consumptionDuration) {} else if (self.tickFallCounter < 60) {} else { LK.off('tick', self.animateTick); } }; I want a shivering animation between 25 and -25 degrees. Then I want the tail to fall down and stay there.
Code edit (1 edits merged)
Please save this source code
User prompt
destroy the tick Listener of MouseTail, when the tickCounter is above 60
User prompt
when a MouseTail is spawned, make a tick animation for it for 60 ticks
Code edit (6 edits merged)
Please save this source code
User prompt
give muosetail a random rotation.
User prompt
when a mouse or turtleMouse is eaten, they leave their tail at their position
Code edit (3 edits merged)
Please save this source code
User prompt
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; ressourcesNuts++; break; } wait 300 ticks, before ressourcesNuts is incremented
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: mouseSpawnTime2r is not defined' in this line: 'if (tickCounter % mouseSpawnTime2r == 0) {' Line Number: 283
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: mice[i] is undefined' in this line: 'nutcrackers[j].mouthTimer = mice[i].turtleMouse ? 300 : 180;' Line Number: 336
Code edit (5 edits merged)
Please save this source code
User prompt
add a new class names turtleMouse. give it everything you gave the mouse class
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: mice[i] is undefined' in this line: 'if (mice[i].x > 2048 + mice[i].width) {' Line Number: 303
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: mice[i] is undefined' in this line: 'if (mice[i] && mice[i].x > 2048 + mice[i].width) {' Line Number: 307
var RoyalCheese = Container.expand(function () { var self = Container.call(this); 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 -= 50; self.lowerJaw.y += 25; self.mouthUp = true; self.chewAnimation = function () { if (!self.freeMouth) { var chewRange = 75; var chewSpeed = 3; if (self.mouthUp) { if (self.upperJaw.y > -chewRange) { self.upperJaw.y -= chewSpeed; } else { self.mouthUp = false; } } else { if (self.upperJaw.y < -50) { self.upperJaw.y += chewSpeed; } else { self.mouthUp = true; } } } }; self.isDragged = false; self.isReady = false; var yLevels = [1710, 1530, 1310]; self.move = function () { if (self.mouthTimer && self.mouthTimer > 0) { self.mouthTimer--; self.chewAnimation(); if (self.mouthTimer === 0) { self.freeMouth = true; self.upperJaw.y = -50; } } if (self.resourceIncrementTimer && self.resourceIncrementTimer > 0) { self.resourceIncrementTimer--; if (self.resourceIncrementTimer === 0) { ressourcesNuts++; } } if (!self.isDragged && !yLevels.includes(self.y)) { if (self.y < yLevels[0]) { self.y += 5; } else { self.y -= 5; } if (yLevels.some(level => self.y >= level && self.y - 5 < level)) { self.y = yLevels.find(level => self.y >= level && self.y - 5 < level); self.isReady = true; } } }; self.on('down', function (obj) { if (self.freeMouth) { var pos = obj.event.getLocalPosition(self.parent); self.y = pos.y; self.x = pos.x; self.isDragged = true; self.isReady = false; draggedObject = self; } }); }); 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.reachedCheese = false; self.consumptionDuration = 180; 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 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.mouseTail.y -= 25; self.reachedCheese = false; self.consumptionDuration = 300; 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 + 80; self.y = y - 120; 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 { LK.off('tick', self.animateTick); } }; }); 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.y = 200; var dragObject = null; self.on('down', function (obj) { if (ressourcesNuts >= 3) { var pos = obj.event.getLocalPosition(self.parent); dragObject = new Nutcracker(); self.parent.addChild(dragObject); dragObject.y = pos.y + 200; dragObject.x = pos.x; } }); stage.on('up', function (obj) { var pos = obj.event.getLocalPosition(self); if (dragObject) { if (pos.y > 200) { var newNutcracker = new Nutcracker(); newNutcracker.x = pos.x; newNutcracker.y = pos.y + 200; self.parent.addChild(newNutcracker); nutcrackers.push(newNutcracker); dragObject.destroy(); dragObject = null; ressourcesNuts -= 3; } else { dragObject.destroy(); dragObject = null; } } }); stage.on('move', function (obj) { if (dragObject) { var pos = obj.event.getLocalPosition(self); dragObject.x = pos.x; dragObject.y = pos.y + 200; } }); }); var draggedObject = null; var ressourcesNuts = 3; var Game = Container.expand(function () { var self = Container.call(this); var yLevels = [2500, 2240, 1930]; var background = self.createAsset('background', 'Background Graphics', 0, 0); self.addChildAt(background, 0); var buildingMenu = self.addChild(new BuildingMenu()); self.addChild(buildingMenu); var nutsCounter = new Text2(ressourcesNuts.toString(), { size: 200, fill: "brown" }); nutsCounter.anchor.set(0.5, 0); nutsCounter.x = 1700; nutsCounter.y = 100; self.addChild(nutsCounter); var nutcrackers = []; var mousetraps = []; var mice = []; var rollingNuts = []; var fecalBalls = []; var royalCheeses = []; var nutcrackerButton = self.addChild(new NutcrackerButton(nutcrackers)); LK.gui.topCenter.addChild(nutcrackerButton); var tickCounter = 0; var yLevels = [2500, 2240, 1930]; yLevels.forEach(function (yLevel) { var newCheese = new RoyalCheese(); newCheese.x = 2000; newCheese.y = yLevel; royalCheeses.push(newCheese); self.addChild(newCheese); }); var mouseSpawnTimer = 360; var mouseSpawnTimer2 = 25200; var mouseTurtleSpawnTimer = 3600; var fecalBallSpawnTimer = 3600; if (Math.random() > 0.5) { mouseTurtleSpawnTimer = 14400; } else { fecalBallSpawnTimer = 14400; } var miceKills = 0; var miceTickCounter = new Text2(miceKills.toString(), { size: 200, fill: "#ccc" }); miceTickCounter.anchor.set(0.5, 0); miceTickCounter.x = 300; miceTickCounter.y = 100; self.addChild(miceTickCounter); var mousetailGraphic = LK.getAsset('mouseTail', 'Mouse Tail Graphic', 0.5, 0.5); mousetailGraphic.x = miceTickCounter.x + miceTickCounter.width + 50; mousetailGraphic.y = miceTickCounter.y; self.addChild(mousetailGraphic); LK.on('tick', function () { tickCounter++; nutsCounter.setText(ressourcesNuts.toString()); 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, 120); } 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 = 600; } mouseSpawnTimer2 = Math.max(mouseSpawnTimer2 - 3, 60); } 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 % 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); } for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].x > 575) { nutcrackers[j].x = 575; } else if (nutcrackers[j].x < -600) { nutcrackers[j].x = -600; } } for (var i = 0; i < nutcrackers.length; i++) { nutcrackers[i].move(); } for (var i = 0; i < mousetraps.length; i++) { mousetraps[i].activate(); } for (var i = mice.length - 1; i >= 0; i--) { mice[i].move(); for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].isReady && nutcrackers[j].freeMouth && !nutcrackers[j].isDragged && mice[i].intersects(nutcrackers[j])) { if (mice[i].children.length > 3) { var cheese = mice[i].removeChildAt(3); self.addChild(cheese); cheese.x = mice[i].x; cheese.y = mice[i].y; cheese.abducted = false; } nutcrackers[j].freeMouth = false; nutcrackers[j].mouthTimer = mice[i].consumptionDuration; miceKills++; miceTickCounter.setText(miceKills.toString()); var mouseTail = new MouseTail(mice[i].x, mice[i].y, 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; royalCheeses[c].abducted = true; royalCheeses[c].parent.removeChild(royalCheeses[c]); mice[i].addChild(royalCheeses[c]); royalCheeses[c].x = 0; royalCheeses[c].y = 0; break; } } if (mice[i] && mice[i].x > 2048 + mice[i].width) { mice[i].destroy(); mice.splice(i, 1); } else if (mice[i] && mice[i].reachedCheese && mice[i] && mice[i].x + 100 < 0) { LK.showGameOver(); break; } } for (var i = fecalBalls.length - 1; i >= 0; i--) { fecalBalls[i].move(); for (var j = 0; j < nutcrackers.length; j++) { if (nutcrackers[j].isReady && fecalBalls[i].intersects(nutcrackers[j])) { var mousePosX = fecalBalls[i].x; var mousePosY = fecalBalls[i].y; animateNutcrackerPushedBack(nutcrackers[j], 300); var newMouse = new Mouse(); newMouse.x = mousePosX; newMouse.y = mousePosY; mice.push(newMouse); 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(); 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 animateNutcrackerPushedBack(nutcracker, distance) { var animationStep = distance / 30; var targetX = Math.min(575, nutcracker.x + distance); nutcracker.isReady = false; var animationTick; var animationInterval = LK.setInterval(function () { animationTick++; if (nutcracker.x < targetX) { nutcracker.x += animationStep; } else { nutcracker.x = targetX; nutcracker.isReady = 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 - 1000; draggedObject.y = pos.y - 600; } }); });
===================================================================
--- original.js
+++ change.js
@@ -297,9 +297,9 @@
miceTickCounter.anchor.set(0.5, 0);
miceTickCounter.x = 300;
miceTickCounter.y = 100;
self.addChild(miceTickCounter);
- var mousetailGraphic = LK.getAsset('mousetailGraphic', 'Mouse Tail Graphic', 0.5, 0.5);
+ var mousetailGraphic = LK.getAsset('mouseTail', 'Mouse Tail Graphic', 0.5, 0.5);
mousetailGraphic.x = miceTickCounter.x + miceTickCounter.width + 50;
mousetailGraphic.y = miceTickCounter.y;
self.addChild(mousetailGraphic);
LK.on('tick', function () {
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