/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.patrolPoints = []; self.currentTarget = 0; self.detectionRadius = 80; self.update = function () { if (self.patrolPoints.length === 0) return; var target = self.patrolPoints[self.currentTarget]; var dx = target.x - self.x; var dy = target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 10) { self.currentTarget = (self.currentTarget + 1) % self.patrolPoints.length; } else { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; return self; }); var Cheese = Container.expand(function () { var self = Container.call(this); var cheeseGraphics = self.attachAsset('cheese', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; return self; }); var KitchenObstacle = Container.expand(function (assetType) { var self = Container.call(this); var obstacleGraphics = self.attachAsset(assetType, { anchorX: 0.5, anchorY: 0.5 }); self.isHazard = assetType === 'stove'; return self; }); var Mouse = Container.expand(function () { var self = Container.call(this); var mouseGraphics = self.attachAsset('mouse', { anchorX: 0.5, anchorY: 0.5 }); self.hasCheese = false; self.carriedCheese = null; self.speed = 3; self.targetX = 0; self.targetY = 0; self.update = function () { // Move towards target position var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } // Update carried cheese position if (self.carriedCheese) { self.carriedCheese.x = self.x; self.carriedCheese.y = self.y - 25; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2F4F2F }); /**** * Game Code ****/ var mice = []; var cheeseList = []; var cat; var mouseHole; var obstacles = []; var isDragging = false; var lastMousePositions = []; // Create score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create mouse hole mouseHole = game.addChild(LK.getAsset('mouseHole', { anchorX: 0.5, anchorY: 0.5, x: 150, y: 2600 })); // Create three mice for (var i = 0; i < 3; i++) { var mouse = game.addChild(new Mouse()); mouse.x = 200 + i * 80; mouse.y = 2500; mouse.targetX = mouse.x; mouse.targetY = mouse.y; mice.push(mouse); lastMousePositions.push({ x: mouse.x, y: mouse.y }); } // Create kitchen counters var counter1 = game.addChild(new KitchenObstacle('kitchenCounter')); counter1.x = 500; counter1.y = 800; obstacles.push(counter1); var counter2 = game.addChild(new KitchenObstacle('kitchenCounter')); counter2.x = 1200; counter2.y = 1200; obstacles.push(counter2); var counter3 = game.addChild(new KitchenObstacle('kitchenCounter')); counter3.x = 800; counter3.y = 1800; obstacles.push(counter3); // Create stove hazard var stove = game.addChild(new KitchenObstacle('stove')); stove.x = 1600; stove.y = 900; obstacles.push(stove); // Create rolling pin obstacle var rollingPin = game.addChild(new KitchenObstacle('rollingPin')); rollingPin.x = 600; rollingPin.y = 1500; obstacles.push(rollingPin); // Create cheese pieces var cheesePositions = [{ x: 500, y: 750 }, { x: 1200, y: 1150 }, { x: 800, y: 1750 }, { x: 300, y: 1000 }, { x: 1500, y: 1400 }, { x: 1000, y: 2200 }, { x: 700, y: 600 }, { x: 1400, y: 800 }]; for (var i = 0; i < cheesePositions.length; i++) { var cheese = game.addChild(new Cheese()); cheese.x = cheesePositions[i].x; cheese.y = cheesePositions[i].y; cheeseList.push(cheese); } // Create cat cat = game.addChild(new Cat()); cat.x = 1000; cat.y = 1000; cat.patrolPoints = [{ x: 400, y: 600 }, { x: 1000, y: 600 }, { x: 1600, y: 600 }, { x: 1600, y: 1200 }, { x: 1000, y: 1200 }, { x: 400, y: 1200 }, { x: 400, y: 1800 }, { x: 1000, y: 1800 }, { x: 1600, y: 1800 }]; function handleMove(x, y, obj) { if (isDragging) { // Calculate movement delta var deltaX = x - mice[0].targetX; var deltaY = y - mice[0].targetY; // Move all mice together maintaining their relative positions for (var i = 0; i < mice.length; i++) { var mouse = mice[i]; var relativeX = mouse.x - mice[0].x; var relativeY = mouse.y - mice[0].y; mouse.targetX = x + relativeX; mouse.targetY = y + relativeY; // Keep mice within bounds mouse.targetX = Math.max(50, Math.min(1998, mouse.targetX)); mouse.targetY = Math.max(50, Math.min(2682, mouse.targetY)); } } } game.move = handleMove; game.down = function (x, y, obj) { isDragging = true; handleMove(x, y, obj); }; game.up = function (x, y, obj) { isDragging = false; }; game.update = function () { // Check cheese collection for (var i = cheeseList.length - 1; i >= 0; i--) { var cheese = cheeseList[i]; if (cheese.collected) continue; for (var j = 0; j < mice.length; j++) { var mouse = mice[j]; if (!mouse.hasCheese && mouse.intersects(cheese)) { // Mouse picks up cheese mouse.hasCheese = true; mouse.carriedCheese = cheese; cheese.collected = true; LK.getSound('collect').play(); break; } } } // Check mouse hole delivery for (var i = 0; i < mice.length; i++) { var mouse = mice[i]; if (mouse.hasCheese && mouse.intersects(mouseHole)) { // Deliver cheese LK.setScore(LK.getScore() + 10); scoreTxt.setText('Score: ' + LK.getScore()); // Remove cheese and reset mouse mouse.carriedCheese.destroy(); for (var j = cheeseList.length - 1; j >= 0; j--) { if (cheeseList[j] === mouse.carriedCheese) { cheeseList.splice(j, 1); break; } } mouse.hasCheese = false; mouse.carriedCheese = null; } } // Check cat catching mice for (var i = 0; i < mice.length; i++) { var mouse = mice[i]; var dx = cat.x - mouse.x; var dy = cat.y - mouse.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < cat.detectionRadius) { // Cat caught a mouse LK.getSound('caught').play(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } // Check win condition if (cheeseList.length === 0) { LK.showYouWin(); return; } // Increase difficulty over time if (LK.ticks % 1800 === 0) { // Every 30 seconds cat.speed += 0.2; if (cat.speed > 4) cat.speed = 4; } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,299 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Cat = Container.expand(function () {
+ var self = Container.call(this);
+ var catGraphics = self.attachAsset('cat', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.patrolPoints = [];
+ self.currentTarget = 0;
+ self.detectionRadius = 80;
+ self.update = function () {
+ if (self.patrolPoints.length === 0) return;
+ var target = self.patrolPoints[self.currentTarget];
+ var dx = target.x - self.x;
+ var dy = target.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 10) {
+ self.currentTarget = (self.currentTarget + 1) % self.patrolPoints.length;
+ } else {
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ }
+ };
+ return self;
+});
+var Cheese = Container.expand(function () {
+ var self = Container.call(this);
+ var cheeseGraphics = self.attachAsset('cheese', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ return self;
+});
+var KitchenObstacle = Container.expand(function (assetType) {
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset(assetType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isHazard = assetType === 'stove';
+ return self;
+});
+var Mouse = Container.expand(function () {
+ var self = Container.call(this);
+ var mouseGraphics = self.attachAsset('mouse', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.hasCheese = false;
+ self.carriedCheese = null;
+ self.speed = 3;
+ self.targetX = 0;
+ self.targetY = 0;
+ self.update = function () {
+ // Move towards target position
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 5) {
+ self.x += dx / distance * self.speed;
+ self.y += dy / distance * self.speed;
+ }
+ // Update carried cheese position
+ if (self.carriedCheese) {
+ self.carriedCheese.x = self.x;
+ self.carriedCheese.y = self.y - 25;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2F4F2F
+});
+
+/****
+* Game Code
+****/
+var mice = [];
+var cheeseList = [];
+var cat;
+var mouseHole;
+var obstacles = [];
+var isDragging = false;
+var lastMousePositions = [];
+// Create score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Create mouse hole
+mouseHole = game.addChild(LK.getAsset('mouseHole', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 150,
+ y: 2600
+}));
+// Create three mice
+for (var i = 0; i < 3; i++) {
+ var mouse = game.addChild(new Mouse());
+ mouse.x = 200 + i * 80;
+ mouse.y = 2500;
+ mouse.targetX = mouse.x;
+ mouse.targetY = mouse.y;
+ mice.push(mouse);
+ lastMousePositions.push({
+ x: mouse.x,
+ y: mouse.y
+ });
+}
+// Create kitchen counters
+var counter1 = game.addChild(new KitchenObstacle('kitchenCounter'));
+counter1.x = 500;
+counter1.y = 800;
+obstacles.push(counter1);
+var counter2 = game.addChild(new KitchenObstacle('kitchenCounter'));
+counter2.x = 1200;
+counter2.y = 1200;
+obstacles.push(counter2);
+var counter3 = game.addChild(new KitchenObstacle('kitchenCounter'));
+counter3.x = 800;
+counter3.y = 1800;
+obstacles.push(counter3);
+// Create stove hazard
+var stove = game.addChild(new KitchenObstacle('stove'));
+stove.x = 1600;
+stove.y = 900;
+obstacles.push(stove);
+// Create rolling pin obstacle
+var rollingPin = game.addChild(new KitchenObstacle('rollingPin'));
+rollingPin.x = 600;
+rollingPin.y = 1500;
+obstacles.push(rollingPin);
+// Create cheese pieces
+var cheesePositions = [{
+ x: 500,
+ y: 750
+}, {
+ x: 1200,
+ y: 1150
+}, {
+ x: 800,
+ y: 1750
+}, {
+ x: 300,
+ y: 1000
+}, {
+ x: 1500,
+ y: 1400
+}, {
+ x: 1000,
+ y: 2200
+}, {
+ x: 700,
+ y: 600
+}, {
+ x: 1400,
+ y: 800
+}];
+for (var i = 0; i < cheesePositions.length; i++) {
+ var cheese = game.addChild(new Cheese());
+ cheese.x = cheesePositions[i].x;
+ cheese.y = cheesePositions[i].y;
+ cheeseList.push(cheese);
+}
+// Create cat
+cat = game.addChild(new Cat());
+cat.x = 1000;
+cat.y = 1000;
+cat.patrolPoints = [{
+ x: 400,
+ y: 600
+}, {
+ x: 1000,
+ y: 600
+}, {
+ x: 1600,
+ y: 600
+}, {
+ x: 1600,
+ y: 1200
+}, {
+ x: 1000,
+ y: 1200
+}, {
+ x: 400,
+ y: 1200
+}, {
+ x: 400,
+ y: 1800
+}, {
+ x: 1000,
+ y: 1800
+}, {
+ x: 1600,
+ y: 1800
+}];
+function handleMove(x, y, obj) {
+ if (isDragging) {
+ // Calculate movement delta
+ var deltaX = x - mice[0].targetX;
+ var deltaY = y - mice[0].targetY;
+ // Move all mice together maintaining their relative positions
+ for (var i = 0; i < mice.length; i++) {
+ var mouse = mice[i];
+ var relativeX = mouse.x - mice[0].x;
+ var relativeY = mouse.y - mice[0].y;
+ mouse.targetX = x + relativeX;
+ mouse.targetY = y + relativeY;
+ // Keep mice within bounds
+ mouse.targetX = Math.max(50, Math.min(1998, mouse.targetX));
+ mouse.targetY = Math.max(50, Math.min(2682, mouse.targetY));
+ }
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ isDragging = true;
+ handleMove(x, y, obj);
+};
+game.up = function (x, y, obj) {
+ isDragging = false;
+};
+game.update = function () {
+ // Check cheese collection
+ for (var i = cheeseList.length - 1; i >= 0; i--) {
+ var cheese = cheeseList[i];
+ if (cheese.collected) continue;
+ for (var j = 0; j < mice.length; j++) {
+ var mouse = mice[j];
+ if (!mouse.hasCheese && mouse.intersects(cheese)) {
+ // Mouse picks up cheese
+ mouse.hasCheese = true;
+ mouse.carriedCheese = cheese;
+ cheese.collected = true;
+ LK.getSound('collect').play();
+ break;
+ }
+ }
+ }
+ // Check mouse hole delivery
+ for (var i = 0; i < mice.length; i++) {
+ var mouse = mice[i];
+ if (mouse.hasCheese && mouse.intersects(mouseHole)) {
+ // Deliver cheese
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Remove cheese and reset mouse
+ mouse.carriedCheese.destroy();
+ for (var j = cheeseList.length - 1; j >= 0; j--) {
+ if (cheeseList[j] === mouse.carriedCheese) {
+ cheeseList.splice(j, 1);
+ break;
+ }
+ }
+ mouse.hasCheese = false;
+ mouse.carriedCheese = null;
+ }
+ }
+ // Check cat catching mice
+ for (var i = 0; i < mice.length; i++) {
+ var mouse = mice[i];
+ var dx = cat.x - mouse.x;
+ var dy = cat.y - mouse.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < cat.detectionRadius) {
+ // Cat caught a mouse
+ LK.getSound('caught').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Check win condition
+ if (cheeseList.length === 0) {
+ LK.showYouWin();
+ return;
+ }
+ // Increase difficulty over time
+ if (LK.ticks % 1800 === 0) {
+ // Every 30 seconds
+ cat.speed += 0.2;
+ if (cat.speed > 4) cat.speed = 4;
+ }
+};
\ No newline at end of file