/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var RegularToy = Container.expand(function (toyType) { var self = Container.call(this); var toyGraphics = self.attachAsset(toyType, { anchorX: 0.5, anchorY: 0.5 }); self.isDragging = false; self.startX = 0; self.startY = 0; self.velocityX = 0; self.velocityY = 0; self.friction = 0.95; self.down = function (x, y, obj) { self.isDragging = true; self.startX = x; self.startY = y; self.velocityX = 0; self.velocityY = 0; }; self.up = function (x, y, obj) { if (self.isDragging) { var deltaX = x - self.startX; var deltaY = y - self.startY; self.velocityX = deltaX * 0.3; self.velocityY = deltaY * 0.3; self.isDragging = false; } }; self.update = function () { if (!self.isDragging) { self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; // Check if toy is off screen if (self.x < -100 || self.x > 2148 || self.y < -100 || self.y > 2832) { self.markForRemoval = true; } } }; return self; }); var SpecialToy = Container.expand(function (toyType) { var self = Container.call(this); var toyGraphics = self.attachAsset(toyType, { anchorX: 0.5, anchorY: 0.5 }); self.toyType = toyType; self.isDragging = false; self.startX = 0; self.startY = 0; self.velocityX = 0; self.velocityY = 0; self.friction = 0.95; self.isAnimating = false; self.down = function (x, y, obj) { if (!self.isAnimating) { self.triggerSpecialEffect(); } self.isDragging = true; self.startX = x; self.startY = y; self.velocityX = 0; self.velocityY = 0; }; self.up = function (x, y, obj) { if (self.isDragging) { var deltaX = x - self.startX; var deltaY = y - self.startY; if (Math.abs(deltaX) > 20 || Math.abs(deltaY) > 20) { self.velocityX = deltaX * 0.3; self.velocityY = deltaY * 0.3; } self.isDragging = false; } }; self.triggerSpecialEffect = function () { if (self.isAnimating) return; self.isAnimating = true; LK.setScore(LK.getScore() + 50); scoreTxt.setText(LK.getScore()); if (self.toyType === 'gameController') { LK.getSound('beep').play(); LK.effects.flashObject(self, 0x00FF00, 500); } else if (self.toyType === 'cuckooClock') { LK.getSound('cuckoo').play(); tween(self, { scaleX: 1.3, scaleY: 1.3 }, { duration: 300, easing: tween.easeOut }); tween(self, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeIn }); } else if (self.toyType === 'toyTruck') { LK.getSound('truck').play(); var originalX = self.x; tween(self, { x: self.x + 100 }, { duration: 500, easing: tween.easeOut }); tween(self, { x: originalX }, { duration: 500, easing: tween.easeIn }); } else if (self.toyType === 'chatteringTeeth') { LK.getSound('chatter').play(); for (var i = 0; i < 6; i++) { var delay = i * 100; setTimeout(function () { tween(self, { rotation: 0.2 }, { duration: 50 }); tween(self, { rotation: -0.2 }, { duration: 50 }); tween(self, { rotation: 0 }, { duration: 50 }); }, delay); } } setTimeout(function () { self.isAnimating = false; }, 1000); }; self.update = function () { if (!self.isDragging && !self.isAnimating) { self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; // Check if toy is off screen if (self.x < -100 || self.x > 2148 || self.y < -100 || self.y > 2832) { self.markForRemoval = true; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFB6C1 }); /**** * Game Code ****/ var regularToys = []; var specialToys = []; var draggedToy = null; var level = 1; var toysCleared = 0; var totalToysInLevel = 15; // Create toy box background var toyBoxBg = game.addChild(LK.getAsset('toyBox', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); // Create score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -300; scoreTxt.y = 50; // Create level display var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); levelTxt.x = 120; levelTxt.y = 50; // Create progress display var progressTxt = new Text2('Toys Left: ' + totalToysInLevel, { size: 50, fill: 0xFFFFFF }); progressTxt.anchor.set(0.5, 0); LK.gui.top.addChild(progressTxt); progressTxt.y = 120; function createRegularToy() { var toyTypes = ['regularToy1', 'regularToy2', 'regularToy3', 'regularToy4']; var randomType = toyTypes[Math.floor(Math.random() * toyTypes.length)]; var toy = new RegularToy(randomType); // Random position within toy box area toy.x = 400 + Math.random() * 1200; toy.y = 700 + Math.random() * 1000; regularToys.push(toy); game.addChild(toy); } function createSpecialToy() { var specialTypes = ['gameController', 'cuckooClock', 'toyTruck', 'chatteringTeeth']; var randomType = specialTypes[Math.floor(Math.random() * specialTypes.length)]; var toy = new SpecialToy(randomType); // Random position within toy box area toy.x = 400 + Math.random() * 1200; toy.y = 700 + Math.random() * 1000; specialToys.push(toy); game.addChild(toy); } function initializeLevel() { // Clear existing toys for (var i = regularToys.length - 1; i >= 0; i--) { regularToys[i].destroy(); } for (var i = specialToys.length - 1; i >= 0; i--) { specialToys[i].destroy(); } regularToys = []; specialToys = []; toysCleared = 0; totalToysInLevel = 12 + level * 3; // Create regular toys (70% of total) var regularCount = Math.floor(totalToysInLevel * 0.7); for (var i = 0; i < regularCount; i++) { createRegularToy(); } // Create special toys (30% of total) var specialCount = totalToysInLevel - regularCount; for (var i = 0; i < specialCount; i++) { createSpecialToy(); } levelTxt.setText('Level: ' + level); progressTxt.setText('Toys Left: ' + totalToysInLevel); } game.move = function (x, y, obj) { if (draggedToy && draggedToy.isDragging) { draggedToy.x = x; draggedToy.y = y; } }; game.down = function (x, y, obj) { // Find the topmost toy at this position var allToys = regularToys.concat(specialToys); for (var i = allToys.length - 1; i >= 0; i--) { var toy = allToys[i]; var bounds = toy.getBounds(); if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) { draggedToy = toy; break; } } }; game.up = function (x, y, obj) { draggedToy = null; }; game.update = function () { // Update regular toys for (var i = regularToys.length - 1; i >= 0; i--) { var toy = regularToys[i]; if (toy.markForRemoval) { toy.destroy(); regularToys.splice(i, 1); toysCleared++; LK.setScore(LK.getScore() + 10); LK.getSound('clear').play(); } } // Update special toys for (var i = specialToys.length - 1; i >= 0; i--) { var toy = specialToys[i]; if (toy.markForRemoval) { toy.destroy(); specialToys.splice(i, 1); toysCleared++; LK.setScore(LK.getScore() + 25); LK.getSound('clear').play(); } } // Update UI scoreTxt.setText('Score: ' + LK.getScore()); var toysLeft = totalToysInLevel - toysCleared; progressTxt.setText('Toys Left: ' + toysLeft); // Check level completion if (toysCleared >= totalToysInLevel) { level++; if (level > 5) { LK.showYouWin(); } else { initializeLevel(); } } // Spawn new toys occasionally to maintain challenge if (LK.ticks % 300 === 0 && regularToys.length + specialToys.length < totalToysInLevel) { if (Math.random() < 0.7) { createRegularToy(); } else { createSpecialToy(); } } }; // Initialize first level initializeLevel();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,328 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var RegularToy = Container.expand(function (toyType) {
+ var self = Container.call(this);
+ var toyGraphics = self.attachAsset(toyType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isDragging = false;
+ self.startX = 0;
+ self.startY = 0;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.friction = 0.95;
+ self.down = function (x, y, obj) {
+ self.isDragging = true;
+ self.startX = x;
+ self.startY = y;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ };
+ self.up = function (x, y, obj) {
+ if (self.isDragging) {
+ var deltaX = x - self.startX;
+ var deltaY = y - self.startY;
+ self.velocityX = deltaX * 0.3;
+ self.velocityY = deltaY * 0.3;
+ self.isDragging = false;
+ }
+ };
+ self.update = function () {
+ if (!self.isDragging) {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ // Check if toy is off screen
+ if (self.x < -100 || self.x > 2148 || self.y < -100 || self.y > 2832) {
+ self.markForRemoval = true;
+ }
+ }
+ };
+ return self;
+});
+var SpecialToy = Container.expand(function (toyType) {
+ var self = Container.call(this);
+ var toyGraphics = self.attachAsset(toyType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.toyType = toyType;
+ self.isDragging = false;
+ self.startX = 0;
+ self.startY = 0;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.friction = 0.95;
+ self.isAnimating = false;
+ self.down = function (x, y, obj) {
+ if (!self.isAnimating) {
+ self.triggerSpecialEffect();
+ }
+ self.isDragging = true;
+ self.startX = x;
+ self.startY = y;
+ self.velocityX = 0;
+ self.velocityY = 0;
+ };
+ self.up = function (x, y, obj) {
+ if (self.isDragging) {
+ var deltaX = x - self.startX;
+ var deltaY = y - self.startY;
+ if (Math.abs(deltaX) > 20 || Math.abs(deltaY) > 20) {
+ self.velocityX = deltaX * 0.3;
+ self.velocityY = deltaY * 0.3;
+ }
+ self.isDragging = false;
+ }
+ };
+ self.triggerSpecialEffect = function () {
+ if (self.isAnimating) return;
+ self.isAnimating = true;
+ LK.setScore(LK.getScore() + 50);
+ scoreTxt.setText(LK.getScore());
+ if (self.toyType === 'gameController') {
+ LK.getSound('beep').play();
+ LK.effects.flashObject(self, 0x00FF00, 500);
+ } else if (self.toyType === 'cuckooClock') {
+ LK.getSound('cuckoo').play();
+ tween(self, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ } else if (self.toyType === 'toyTruck') {
+ LK.getSound('truck').play();
+ var originalX = self.x;
+ tween(self, {
+ x: self.x + 100
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ x: originalX
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ } else if (self.toyType === 'chatteringTeeth') {
+ LK.getSound('chatter').play();
+ for (var i = 0; i < 6; i++) {
+ var delay = i * 100;
+ setTimeout(function () {
+ tween(self, {
+ rotation: 0.2
+ }, {
+ duration: 50
+ });
+ tween(self, {
+ rotation: -0.2
+ }, {
+ duration: 50
+ });
+ tween(self, {
+ rotation: 0
+ }, {
+ duration: 50
+ });
+ }, delay);
+ }
+ }
+ setTimeout(function () {
+ self.isAnimating = false;
+ }, 1000);
+ };
+ self.update = function () {
+ if (!self.isDragging && !self.isAnimating) {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ // Check if toy is off screen
+ if (self.x < -100 || self.x > 2148 || self.y < -100 || self.y > 2832) {
+ self.markForRemoval = true;
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xFFB6C1
+});
+
+/****
+* Game Code
+****/
+var regularToys = [];
+var specialToys = [];
+var draggedToy = null;
+var level = 1;
+var toysCleared = 0;
+var totalToysInLevel = 15;
+// Create toy box background
+var toyBoxBg = game.addChild(LK.getAsset('toyBox', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1366
+}));
+// Create score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreTxt);
+scoreTxt.x = -300;
+scoreTxt.y = 50;
+// Create level display
+var levelTxt = new Text2('Level: 1', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+levelTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(levelTxt);
+levelTxt.x = 120;
+levelTxt.y = 50;
+// Create progress display
+var progressTxt = new Text2('Toys Left: ' + totalToysInLevel, {
+ size: 50,
+ fill: 0xFFFFFF
+});
+progressTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(progressTxt);
+progressTxt.y = 120;
+function createRegularToy() {
+ var toyTypes = ['regularToy1', 'regularToy2', 'regularToy3', 'regularToy4'];
+ var randomType = toyTypes[Math.floor(Math.random() * toyTypes.length)];
+ var toy = new RegularToy(randomType);
+ // Random position within toy box area
+ toy.x = 400 + Math.random() * 1200;
+ toy.y = 700 + Math.random() * 1000;
+ regularToys.push(toy);
+ game.addChild(toy);
+}
+function createSpecialToy() {
+ var specialTypes = ['gameController', 'cuckooClock', 'toyTruck', 'chatteringTeeth'];
+ var randomType = specialTypes[Math.floor(Math.random() * specialTypes.length)];
+ var toy = new SpecialToy(randomType);
+ // Random position within toy box area
+ toy.x = 400 + Math.random() * 1200;
+ toy.y = 700 + Math.random() * 1000;
+ specialToys.push(toy);
+ game.addChild(toy);
+}
+function initializeLevel() {
+ // Clear existing toys
+ for (var i = regularToys.length - 1; i >= 0; i--) {
+ regularToys[i].destroy();
+ }
+ for (var i = specialToys.length - 1; i >= 0; i--) {
+ specialToys[i].destroy();
+ }
+ regularToys = [];
+ specialToys = [];
+ toysCleared = 0;
+ totalToysInLevel = 12 + level * 3;
+ // Create regular toys (70% of total)
+ var regularCount = Math.floor(totalToysInLevel * 0.7);
+ for (var i = 0; i < regularCount; i++) {
+ createRegularToy();
+ }
+ // Create special toys (30% of total)
+ var specialCount = totalToysInLevel - regularCount;
+ for (var i = 0; i < specialCount; i++) {
+ createSpecialToy();
+ }
+ levelTxt.setText('Level: ' + level);
+ progressTxt.setText('Toys Left: ' + totalToysInLevel);
+}
+game.move = function (x, y, obj) {
+ if (draggedToy && draggedToy.isDragging) {
+ draggedToy.x = x;
+ draggedToy.y = y;
+ }
+};
+game.down = function (x, y, obj) {
+ // Find the topmost toy at this position
+ var allToys = regularToys.concat(specialToys);
+ for (var i = allToys.length - 1; i >= 0; i--) {
+ var toy = allToys[i];
+ var bounds = toy.getBounds();
+ if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
+ draggedToy = toy;
+ break;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ draggedToy = null;
+};
+game.update = function () {
+ // Update regular toys
+ for (var i = regularToys.length - 1; i >= 0; i--) {
+ var toy = regularToys[i];
+ if (toy.markForRemoval) {
+ toy.destroy();
+ regularToys.splice(i, 1);
+ toysCleared++;
+ LK.setScore(LK.getScore() + 10);
+ LK.getSound('clear').play();
+ }
+ }
+ // Update special toys
+ for (var i = specialToys.length - 1; i >= 0; i--) {
+ var toy = specialToys[i];
+ if (toy.markForRemoval) {
+ toy.destroy();
+ specialToys.splice(i, 1);
+ toysCleared++;
+ LK.setScore(LK.getScore() + 25);
+ LK.getSound('clear').play();
+ }
+ }
+ // Update UI
+ scoreTxt.setText('Score: ' + LK.getScore());
+ var toysLeft = totalToysInLevel - toysCleared;
+ progressTxt.setText('Toys Left: ' + toysLeft);
+ // Check level completion
+ if (toysCleared >= totalToysInLevel) {
+ level++;
+ if (level > 5) {
+ LK.showYouWin();
+ } else {
+ initializeLevel();
+ }
+ }
+ // Spawn new toys occasionally to maintain challenge
+ if (LK.ticks % 300 === 0 && regularToys.length + specialToys.length < totalToysInLevel) {
+ if (Math.random() < 0.7) {
+ createRegularToy();
+ } else {
+ createSpecialToy();
+ }
+ }
+};
+// Initialize first level
+initializeLevel();
\ No newline at end of file