Code edit (1 edits merged)
Please save this source code
User prompt
Tidy Up Time
Initial prompt
Toca tidy up (2004). The powerpuff girls’s bedroom is full of 6 toys. Use your finger to drag and drop the toy frog, or the toy Violet cat, or the monkey toy, or a toy dinosaur, or a plate of jelly, or a maraca into the toy basket. Tap the red toy basket jump to make 6 toys go all over the floor again.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Toy = Container.expand(function (toyType, startX, startY) {
var self = Container.call(this);
self.toyType = toyType;
self.isCollected = false;
self.startX = startX;
self.startY = startY;
var toyGraphics = self.attachAsset(toyType, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.down = function (x, y, obj) {
if (!self.isCollected) {
dragToy = self;
self.alpha = 0.8;
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100
});
}
};
self.collectToy = function () {
self.isCollected = true;
self.alpha = 0;
toysCollected++;
LK.getSound('collect').play();
tween(self, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200
});
if (toysCollected >= 6) {
allToysCollected = true;
}
};
self.resetToy = function (newX, newY) {
self.isCollected = false;
self.alpha = 1;
self.scaleX = 1;
self.scaleY = 1;
self.x = newX;
self.y = newY;
self.startX = newX;
self.startY = newY;
};
return self;
});
var ToyBasket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('toyBasket', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 1024;
self.y = 1800;
self.down = function (x, y, obj) {
if (allToysCollected) {
self.scatterToys();
}
};
self.scatterToys = function () {
LK.getSound('scatter').play();
tween(self, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 150,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
for (var i = 0; i < toys.length; i++) {
var toy = toys[i];
var newX = 200 + Math.random() * 1600;
var newY = 800 + Math.random() * 800;
toy.resetToy(newX, newY);
}
toysCollected = 0;
allToysCollected = false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xffffff
});
/****
* Game Code
****/
game.setBackgroundColor(0xffe6f2);
var toys = [];
var toyBasket;
var dragToy = null;
var toysCollected = 0;
var allToysCollected = false;
var toyTypes = ['frog', 'cat', 'monkey', 'dinosaur', 'jelly', 'maraca'];
var toyPositions = [{
x: 300,
y: 1000
}, {
x: 800,
y: 1200
}, {
x: 1500,
y: 900
}, {
x: 400,
y: 1600
}, {
x: 1200,
y: 1400
}, {
x: 1700,
y: 1100
}];
for (var i = 0; i < toyTypes.length; i++) {
var toy = new Toy(toyTypes[i], toyPositions[i].x, toyPositions[i].y);
toys.push(toy);
game.addChild(toy);
}
toyBasket = new ToyBasket();
game.addChild(toyBasket);
var titleText = new Text2('Tidy Up Time!', {
size: 80,
fill: 0xFF3366
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 100;
var instructionText = new Text2('Drag toys to the red basket!', {
size: 50,
fill: 0x666666
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 200;
var completedText = new Text2('Tap the basket to scatter toys!', {
size: 60,
fill: 0x44AA44
});
completedText.anchor.set(0.5, 1);
completedText.alpha = 0;
LK.gui.bottom.addChild(completedText);
completedText.y = -100;
function handleMove(x, y, obj) {
if (dragToy) {
dragToy.x = x;
dragToy.y = y;
}
}
game.move = handleMove;
game.up = function (x, y, obj) {
if (dragToy) {
var distance = Math.sqrt(Math.pow(dragToy.x - toyBasket.x, 2) + Math.pow(dragToy.y - toyBasket.y, 2));
if (distance < 200) {
dragToy.collectToy();
} else {
tween(dragToy, {
x: dragToy.startX,
y: dragToy.startY
}, {
duration: 300
});
}
tween(dragToy, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
dragToy.alpha = 1;
dragToy = null;
}
};
game.update = function () {
if (allToysCollected) {
if (completedText.alpha < 1) {
completedText.alpha += 0.02;
}
instructionText.alpha = Math.max(0, instructionText.alpha - 0.02);
} else {
if (completedText.alpha > 0) {
completedText.alpha -= 0.02;
}
if (instructionText.alpha < 1) {
instructionText.alpha += 0.02;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,210 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Toy = Container.expand(function (toyType, startX, startY) {
+ var self = Container.call(this);
+ self.toyType = toyType;
+ self.isCollected = false;
+ self.startX = startX;
+ self.startY = startY;
+ var toyGraphics = self.attachAsset(toyType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = startX;
+ self.y = startY;
+ self.down = function (x, y, obj) {
+ if (!self.isCollected) {
+ dragToy = self;
+ self.alpha = 0.8;
+ tween(self, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 100
+ });
+ }
+ };
+ self.collectToy = function () {
+ self.isCollected = true;
+ self.alpha = 0;
+ toysCollected++;
+ LK.getSound('collect').play();
+ tween(self, {
+ scaleX: 1.5,
+ scaleY: 1.5
+ }, {
+ duration: 200
+ });
+ if (toysCollected >= 6) {
+ allToysCollected = true;
+ }
+ };
+ self.resetToy = function (newX, newY) {
+ self.isCollected = false;
+ self.alpha = 1;
+ self.scaleX = 1;
+ self.scaleY = 1;
+ self.x = newX;
+ self.y = newY;
+ self.startX = newX;
+ self.startY = newY;
+ };
+ return self;
+});
+var ToyBasket = Container.expand(function () {
+ var self = Container.call(this);
+ var basketGraphics = self.attachAsset('toyBasket', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = 1024;
+ self.y = 1800;
+ self.down = function (x, y, obj) {
+ if (allToysCollected) {
+ self.scatterToys();
+ }
+ };
+ self.scatterToys = function () {
+ LK.getSound('scatter').play();
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 0.8
+ }, {
+ duration: 150,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 150
+ });
+ }
+ });
+ for (var i = 0; i < toys.length; i++) {
+ var toy = toys[i];
+ var newX = 200 + Math.random() * 1600;
+ var newY = 800 + Math.random() * 800;
+ toy.resetToy(newX, newY);
+ }
+ toysCollected = 0;
+ allToysCollected = false;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xffffff
+});
+
+/****
+* Game Code
+****/
+game.setBackgroundColor(0xffe6f2);
+var toys = [];
+var toyBasket;
+var dragToy = null;
+var toysCollected = 0;
+var allToysCollected = false;
+var toyTypes = ['frog', 'cat', 'monkey', 'dinosaur', 'jelly', 'maraca'];
+var toyPositions = [{
+ x: 300,
+ y: 1000
+}, {
+ x: 800,
+ y: 1200
+}, {
+ x: 1500,
+ y: 900
+}, {
+ x: 400,
+ y: 1600
+}, {
+ x: 1200,
+ y: 1400
+}, {
+ x: 1700,
+ y: 1100
+}];
+for (var i = 0; i < toyTypes.length; i++) {
+ var toy = new Toy(toyTypes[i], toyPositions[i].x, toyPositions[i].y);
+ toys.push(toy);
+ game.addChild(toy);
+}
+toyBasket = new ToyBasket();
+game.addChild(toyBasket);
+var titleText = new Text2('Tidy Up Time!', {
+ size: 80,
+ fill: 0xFF3366
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 100;
+var instructionText = new Text2('Drag toys to the red basket!', {
+ size: 50,
+ fill: 0x666666
+});
+instructionText.anchor.set(0.5, 0);
+LK.gui.top.addChild(instructionText);
+instructionText.y = 200;
+var completedText = new Text2('Tap the basket to scatter toys!', {
+ size: 60,
+ fill: 0x44AA44
+});
+completedText.anchor.set(0.5, 1);
+completedText.alpha = 0;
+LK.gui.bottom.addChild(completedText);
+completedText.y = -100;
+function handleMove(x, y, obj) {
+ if (dragToy) {
+ dragToy.x = x;
+ dragToy.y = y;
+ }
+}
+game.move = handleMove;
+game.up = function (x, y, obj) {
+ if (dragToy) {
+ var distance = Math.sqrt(Math.pow(dragToy.x - toyBasket.x, 2) + Math.pow(dragToy.y - toyBasket.y, 2));
+ if (distance < 200) {
+ dragToy.collectToy();
+ } else {
+ tween(dragToy, {
+ x: dragToy.startX,
+ y: dragToy.startY
+ }, {
+ duration: 300
+ });
+ }
+ tween(dragToy, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200
+ });
+ dragToy.alpha = 1;
+ dragToy = null;
+ }
+};
+game.update = function () {
+ if (allToysCollected) {
+ if (completedText.alpha < 1) {
+ completedText.alpha += 0.02;
+ }
+ instructionText.alpha = Math.max(0, instructionText.alpha - 0.02);
+ } else {
+ if (completedText.alpha > 0) {
+ completedText.alpha -= 0.02;
+ }
+ if (instructionText.alpha < 1) {
+ instructionText.alpha += 0.02;
+ }
+ }
+};
\ No newline at end of file