Code edit (1 edits merged)
Please save this source code
User prompt
Pony Care Adventure
Initial prompt
Toca interactive horse (2012). Tap to open the gift to see what’s inside, when the powerpuff girls go in the seat the horse will go neigh, tap on the carrot to feed the horse, tap on the horse to gallop.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Carrot = Container.expand(function () { var self = Container.call(this); var carrotGraphics = self.attachAsset('carrot', { anchorX: 0.5, anchorY: 0.5 }); self.isEaten = false; self.getEaten = function () { if (self.isEaten) return; self.isEaten = true; // Shrinking animation tween(carrotGraphics, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 500, onFinish: function onFinish() { // Respawn after 3 seconds LK.setTimeout(function () { self.isEaten = false; carrotGraphics.scaleX = 1; carrotGraphics.scaleY = 1; carrotGraphics.alpha = 1; }, 3000); } }); }; self.down = function (x, y, obj) { if (!self.isEaten) { self.getEaten(); pony.feed(); } }; return self; }); var GiftBox = Container.expand(function () { var self = Container.call(this); var giftGraphics = self.attachAsset('giftBox', { anchorX: 0.5, anchorY: 0.5 }); self.isOpened = false; self.surpriseItem = null; self.openGift = function () { if (self.isOpened) return; self.isOpened = true; LK.getSound('giftOpen').play(); // Opening animation - rotate and scale tween(giftGraphics, { rotation: Math.PI * 2, scaleX: 1.5, scaleY: 1.5 }, { duration: 600, onFinish: function onFinish() { // Hide gift box giftGraphics.alpha = 0; // Show surprise item self.surpriseItem = self.addChild(LK.getAsset('surpriseItem', { anchorX: 0.5, anchorY: 0.5 })); // Surprise item animation tween(self.surpriseItem, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, onFinish: function onFinish() { tween(self.surpriseItem, { scaleX: 1, scaleY: 1 }, { duration: 300 }); } }); // Reset after 4 seconds LK.setTimeout(function () { self.isOpened = false; giftGraphics.alpha = 1; giftGraphics.rotation = 0; giftGraphics.scaleX = 1; giftGraphics.scaleY = 1; if (self.surpriseItem) { self.surpriseItem.destroy(); self.surpriseItem = null; } }, 4000); } }); }; self.down = function (x, y, obj) { self.openGift(); }; return self; }); var Pony = Container.expand(function () { var self = Container.call(this); var ponyGraphics = self.attachAsset('pony', { anchorX: 0.5, anchorY: 0.5 }); self.isGalloping = false; self.originalX = 0; self.originalY = 0; self.feed = function () { LK.getSound('eating').play(); LK.getSound('happy').play(); // Eating animation - scale up and down tween(ponyGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, onFinish: function onFinish() { tween(ponyGraphics, { scaleX: 1, scaleY: 1 }, { duration: 200 }); } }); }; self.gallop = function () { if (self.isGalloping) return; self.isGalloping = true; LK.getSound('neigh').play(); // Galloping animation - bounce and move var targetX = self.originalX + (Math.random() - 0.5) * 200; var targetY = self.originalY + (Math.random() - 0.5) * 100; tween(self, { x: targetX, y: targetY }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { x: self.originalX, y: self.originalY }, { duration: 600, easing: tween.easeInOut, onFinish: function onFinish() { self.isGalloping = false; } }); } }); // Bounce animation tween(ponyGraphics, { scaleY: 1.3 }, { duration: 200, onFinish: function onFinish() { tween(ponyGraphics, { scaleY: 1 }, { duration: 200 }); } }); }; self.down = function (x, y, obj) { self.gallop(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Create meadow background var meadowBackground = game.addChild(LK.getAsset('meadow', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Create pony in center var pony = game.addChild(new Pony()); pony.x = 1024; pony.y = 1366; pony.originalX = pony.x; pony.originalY = pony.y; // Create carrots around the meadow var carrots = []; var carrotPositions = [{ x: 300, y: 1000 }, { x: 1700, y: 1200 }, { x: 500, y: 1800 }, { x: 1500, y: 1900 }, { x: 800, y: 800 }]; for (var i = 0; i < carrotPositions.length; i++) { var carrot = game.addChild(new Carrot()); carrot.x = carrotPositions[i].x; carrot.y = carrotPositions[i].y; carrots.push(carrot); } // Create gift boxes var giftBoxes = []; var giftPositions = [{ x: 200, y: 1500 }, { x: 1800, y: 1000 }, { x: 1000, y: 2200 }, { x: 1400, y: 600 }]; for (var i = 0; i < giftPositions.length; i++) { var giftBox = game.addChild(new GiftBox()); giftBox.x = giftPositions[i].x; giftBox.y = giftPositions[i].y; giftBoxes.push(giftBox); } // Add floating animation to pony var ponyFloatTimer = LK.setInterval(function () { if (!pony.isGalloping) { tween(pony, { y: pony.originalY + 10 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(pony, { y: pony.originalY - 10 }, { duration: 1000, easing: tween.easeInOut }); } }); } }, 2000); // Add subtle animation to carrots var carrotAnimationTimer = LK.setInterval(function () { for (var i = 0; i < carrots.length; i++) { var carrot = carrots[i]; if (!carrot.isEaten) { tween(carrot, { rotation: 0.1 }, { duration: 500, onFinish: function onFinish() { tween(carrot, { rotation: -0.1 }, { duration: 500, onFinish: function onFinish() { tween(carrot, { rotation: 0 }, { duration: 500 }); } }); } }); } } }, 3000); // Add sparkle effect to gift boxes var giftSparkleTimer = LK.setInterval(function () { for (var i = 0; i < giftBoxes.length; i++) { var giftBox = giftBoxes[i]; if (!giftBox.isOpened) { tween(giftBox, { scaleX: 1.1, scaleY: 1.1 }, { duration: 400, onFinish: function onFinish() { tween(giftBox, { scaleX: 1, scaleY: 1 }, { duration: 400 }); } }); } } }, 2500); game.update = function () { // Continuous gameplay - no win/lose conditions // Just maintain the interactive experience };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Carrot = Container.expand(function () {
var self = Container.call(this);
var carrotGraphics = self.attachAsset('carrot', {
anchorX: 0.5,
anchorY: 0.5
});
self.isEaten = false;
self.getEaten = function () {
if (self.isEaten) return;
self.isEaten = true;
// Shrinking animation
tween(carrotGraphics, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
// Respawn after 3 seconds
LK.setTimeout(function () {
self.isEaten = false;
carrotGraphics.scaleX = 1;
carrotGraphics.scaleY = 1;
carrotGraphics.alpha = 1;
}, 3000);
}
});
};
self.down = function (x, y, obj) {
if (!self.isEaten) {
self.getEaten();
pony.feed();
}
};
return self;
});
var GiftBox = Container.expand(function () {
var self = Container.call(this);
var giftGraphics = self.attachAsset('giftBox', {
anchorX: 0.5,
anchorY: 0.5
});
self.isOpened = false;
self.surpriseItem = null;
self.openGift = function () {
if (self.isOpened) return;
self.isOpened = true;
LK.getSound('giftOpen').play();
// Opening animation - rotate and scale
tween(giftGraphics, {
rotation: Math.PI * 2,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 600,
onFinish: function onFinish() {
// Hide gift box
giftGraphics.alpha = 0;
// Show surprise item
self.surpriseItem = self.addChild(LK.getAsset('surpriseItem', {
anchorX: 0.5,
anchorY: 0.5
}));
// Surprise item animation
tween(self.surpriseItem, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
onFinish: function onFinish() {
tween(self.surpriseItem, {
scaleX: 1,
scaleY: 1
}, {
duration: 300
});
}
});
// Reset after 4 seconds
LK.setTimeout(function () {
self.isOpened = false;
giftGraphics.alpha = 1;
giftGraphics.rotation = 0;
giftGraphics.scaleX = 1;
giftGraphics.scaleY = 1;
if (self.surpriseItem) {
self.surpriseItem.destroy();
self.surpriseItem = null;
}
}, 4000);
}
});
};
self.down = function (x, y, obj) {
self.openGift();
};
return self;
});
var Pony = Container.expand(function () {
var self = Container.call(this);
var ponyGraphics = self.attachAsset('pony', {
anchorX: 0.5,
anchorY: 0.5
});
self.isGalloping = false;
self.originalX = 0;
self.originalY = 0;
self.feed = function () {
LK.getSound('eating').play();
LK.getSound('happy').play();
// Eating animation - scale up and down
tween(ponyGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(ponyGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
self.gallop = function () {
if (self.isGalloping) return;
self.isGalloping = true;
LK.getSound('neigh').play();
// Galloping animation - bounce and move
var targetX = self.originalX + (Math.random() - 0.5) * 200;
var targetY = self.originalY + (Math.random() - 0.5) * 100;
tween(self, {
x: targetX,
y: targetY
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
x: self.originalX,
y: self.originalY
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isGalloping = false;
}
});
}
});
// Bounce animation
tween(ponyGraphics, {
scaleY: 1.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(ponyGraphics, {
scaleY: 1
}, {
duration: 200
});
}
});
};
self.down = function (x, y, obj) {
self.gallop();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Create meadow background
var meadowBackground = game.addChild(LK.getAsset('meadow', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Create pony in center
var pony = game.addChild(new Pony());
pony.x = 1024;
pony.y = 1366;
pony.originalX = pony.x;
pony.originalY = pony.y;
// Create carrots around the meadow
var carrots = [];
var carrotPositions = [{
x: 300,
y: 1000
}, {
x: 1700,
y: 1200
}, {
x: 500,
y: 1800
}, {
x: 1500,
y: 1900
}, {
x: 800,
y: 800
}];
for (var i = 0; i < carrotPositions.length; i++) {
var carrot = game.addChild(new Carrot());
carrot.x = carrotPositions[i].x;
carrot.y = carrotPositions[i].y;
carrots.push(carrot);
}
// Create gift boxes
var giftBoxes = [];
var giftPositions = [{
x: 200,
y: 1500
}, {
x: 1800,
y: 1000
}, {
x: 1000,
y: 2200
}, {
x: 1400,
y: 600
}];
for (var i = 0; i < giftPositions.length; i++) {
var giftBox = game.addChild(new GiftBox());
giftBox.x = giftPositions[i].x;
giftBox.y = giftPositions[i].y;
giftBoxes.push(giftBox);
}
// Add floating animation to pony
var ponyFloatTimer = LK.setInterval(function () {
if (!pony.isGalloping) {
tween(pony, {
y: pony.originalY + 10
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(pony, {
y: pony.originalY - 10
}, {
duration: 1000,
easing: tween.easeInOut
});
}
});
}
}, 2000);
// Add subtle animation to carrots
var carrotAnimationTimer = LK.setInterval(function () {
for (var i = 0; i < carrots.length; i++) {
var carrot = carrots[i];
if (!carrot.isEaten) {
tween(carrot, {
rotation: 0.1
}, {
duration: 500,
onFinish: function onFinish() {
tween(carrot, {
rotation: -0.1
}, {
duration: 500,
onFinish: function onFinish() {
tween(carrot, {
rotation: 0
}, {
duration: 500
});
}
});
}
});
}
}
}, 3000);
// Add sparkle effect to gift boxes
var giftSparkleTimer = LK.setInterval(function () {
for (var i = 0; i < giftBoxes.length; i++) {
var giftBox = giftBoxes[i];
if (!giftBox.isOpened) {
tween(giftBox, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 400,
onFinish: function onFinish() {
tween(giftBox, {
scaleX: 1,
scaleY: 1
}, {
duration: 400
});
}
});
}
}
}, 2500);
game.update = function () {
// Continuous gameplay - no win/lose conditions
// Just maintain the interactive experience
};