Code edit (1 edits merged)
Please save this source code
User prompt
Pango's Lost Teddy
Initial prompt
Pango the blue raccoon stories π: Pango says βI lost my teddy.β Tap on teddy when you spot it behind 1 drawer, tap to tickle Pango π, tap to kiss Pango π, now Pango is sleeping tap on the lamp to turn it off
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Drawer = Container.expand(function () {
var self = Container.call(this);
var drawerGraphics = self.attachAsset('drawer', {
anchorX: 0.5,
anchorY: 0.5
});
self.hasBeenSearched = false;
self.containsTeddy = false;
self.search = function () {
if (!self.hasBeenSearched) {
self.hasBeenSearched = true;
drawerGraphics.tint = 0x8B7355;
return self.containsTeddy;
}
return false;
};
self.down = function (x, y, obj) {
if (!self.hasBeenSearched && gameState === 'searching') {
var foundTeddy = self.search();
if (foundTeddy) {
onTeddyFound();
}
}
};
return self;
});
var InteractiveArea = Container.expand(function () {
var self = Container.call(this);
self.areaType = 'tickle';
self.isActive = false;
self.activate = function (type) {
self.areaType = type;
self.isActive = true;
var asset = type === 'tickle' ? 'tickleArea' : 'kissArea';
var graphics = self.attachAsset(asset, {
anchorX: 0.5,
anchorY: 0.5
});
graphics.alpha = 0.3;
// Pulse animation
var pulseUp = function pulseUp() {
tween(graphics, {
alpha: 0.6
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: pulseDown
});
};
var pulseDown = function pulseDown() {
tween(graphics, {
alpha: 0.3
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: pulseUp
});
};
pulseUp();
};
self.deactivate = function () {
self.isActive = false;
self.visible = false;
};
self.down = function (x, y, obj) {
if (self.isActive) {
if (self.areaType === 'tickle' && gameState === 'tickling') {
pango.giggle();
tickleCount++;
if (tickleCount >= 3) {
startKissing();
}
} else if (self.areaType === 'kissing' && gameState === 'kissing') {
LK.getSound('kiss').play();
kissCount++;
if (kissCount >= 2) {
startBedtime();
}
}
}
};
return self;
});
var Lamp = Container.expand(function () {
var self = Container.call(this);
var lampGraphics = self.attachAsset('lamp', {
anchorX: 0.5,
anchorY: 0.5
});
self.isOn = true;
self.turnOff = function () {
if (self.isOn) {
self.isOn = false;
lampGraphics.tint = 0x666666;
LK.getSound('lampClick').play();
return true;
}
return false;
};
self.down = function (x, y, obj) {
if (gameState === 'bedtime' && self.isOn) {
var turnedOff = self.turnOff();
if (turnedOff) {
onLampTurnedOff();
}
}
};
return self;
});
var Pango = Container.expand(function () {
var self = Container.call(this);
var pangoGraphics = self.attachAsset('pango', {
anchorX: 0.5,
anchorY: 0.5
});
self.isHappy = false;
self.isSleeping = false;
self.showSadExpression = function () {
pangoGraphics.tint = 0x6495ED;
self.isHappy = false;
};
self.showHappyExpression = function () {
pangoGraphics.tint = 0x4A90E2;
self.isHappy = true;
// Bounce animation when happy
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeIn
});
};
self.giggle = function () {
if (self.isHappy) {
// Wiggle animation
tween(self, {
rotation: 0.1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(self, {
rotation: -0.1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(self, {
rotation: 0
}, {
duration: 100,
easing: tween.easeInOut
});
LK.getSound('giggle').play();
}
};
self.goToSleep = function () {
self.isSleeping = true;
tween(self, {
y: self.y + 50,
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 1000,
easing: tween.easeOut
});
pangoGraphics.tint = 0x2E5984;
};
return self;
});
var Teddy = Container.expand(function () {
var self = Container.call(this);
var teddyGraphics = self.attachAsset('teddy', {
anchorX: 0.5,
anchorY: 0.5
});
self.isFound = false;
self.isHidden = true;
self.hide = function () {
self.visible = false;
self.isHidden = true;
};
self.reveal = function () {
self.visible = true;
self.isHidden = false;
self.isFound = true;
// Pop animation when found
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.bounceOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameState = 'intro';
var pango;
var teddy;
var drawers = [];
var lamp;
var interactiveArea;
var messageText;
var tickleCount = 0;
var kissCount = 0;
var teddyDrawerIndex = 0;
// Initialize game elements
function initializeGame() {
// Create Pango
pango = game.addChild(new Pango());
pango.x = 1024;
pango.y = 1200;
pango.showSadExpression();
// Create message text
messageText = new Text2('I lost my teddy!', {
size: 80,
fill: 0xFFFFFF
});
messageText.anchor.set(0.5, 0.5);
messageText.x = 1024;
messageText.y = 400;
game.addChild(messageText);
// Create teddy (hidden initially)
teddy = game.addChild(new Teddy());
teddy.hide();
// Create interactive area
interactiveArea = game.addChild(new InteractiveArea());
interactiveArea.visible = false;
// Start the game sequence
LK.setTimeout(function () {
startSearching();
}, 2000);
}
function startSearching() {
gameState = 'searching';
// Update message
messageText.setText('Tap the drawers to find my teddy!');
// Create drawers
var drawerPositions = [{
x: 400,
y: 1000
}, {
x: 800,
y: 1000
}, {
x: 1200,
y: 1000
}, {
x: 1600,
y: 1000
}];
// Randomly select which drawer contains the teddy
teddyDrawerIndex = Math.floor(Math.random() * drawerPositions.length);
for (var i = 0; i < drawerPositions.length; i++) {
var drawer = game.addChild(new Drawer());
drawer.x = drawerPositions[i].x;
drawer.y = drawerPositions[i].y;
if (i === teddyDrawerIndex) {
drawer.containsTeddy = true;
// Position teddy behind this drawer
teddy.x = drawer.x;
teddy.y = drawer.y - 50;
}
drawers.push(drawer);
}
}
function onTeddyFound() {
gameState = 'found';
// Show teddy
teddy.reveal();
// Update Pango's expression
pango.showHappyExpression();
// Update message
messageText.setText('Yay! You found my teddy!');
// Move teddy to Pango
tween(teddy, {
x: pango.x + 100,
y: pango.y
}, {
duration: 1000,
easing: tween.easeOut
});
// Start tickling phase
LK.setTimeout(function () {
startTickling();
}, 2000);
}
function startTickling() {
gameState = 'tickling';
tickleCount = 0;
// Update message
messageText.setText('Tickle me! (Tap 3 times)');
// Show tickle area
interactiveArea.activate('tickle');
interactiveArea.x = pango.x;
interactiveArea.y = pango.y;
interactiveArea.visible = true;
}
function startKissing() {
gameState = 'kissing';
kissCount = 0;
// Update message
messageText.setText('Give me a kiss! (Tap 2 times)');
// Change interactive area to kiss
interactiveArea.deactivate();
interactiveArea.activate('kissing');
interactiveArea.x = pango.x;
interactiveArea.y = pango.y - 100;
interactiveArea.visible = true;
}
function startBedtime() {
gameState = 'bedtime';
// Update message
messageText.setText('I\'m sleepy... Turn off the lamp!');
// Hide interactive area
interactiveArea.deactivate();
// Make Pango lie down
pango.goToSleep();
// Create lamp
lamp = game.addChild(new Lamp());
lamp.x = 1600;
lamp.y = 800;
}
function onLampTurnedOff() {
gameState = 'sleeping';
// Dim the screen
tween(game, {
alpha: 0.3
}, {
duration: 2000,
easing: tween.easeOut
});
// Update message
messageText.setText('Goodnight, Pango!');
// Show completion
LK.setTimeout(function () {
messageText.setText('Sweet dreams...');
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}, 2000);
}
// Initialize the game
initializeGame();
game.update = function () {
// Game logic is handled through event-driven interactions
// No continuous updates needed for this story-based game
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Drawer = Container.expand(function () {
var self = Container.call(this);
var drawerGraphics = self.attachAsset('drawer', {
anchorX: 0.5,
anchorY: 0.5
});
self.hasBeenSearched = false;
self.containsTeddy = false;
self.search = function () {
if (!self.hasBeenSearched) {
self.hasBeenSearched = true;
drawerGraphics.tint = 0x8B7355;
return self.containsTeddy;
}
return false;
};
self.down = function (x, y, obj) {
if (!self.hasBeenSearched && gameState === 'searching') {
var foundTeddy = self.search();
if (foundTeddy) {
onTeddyFound();
}
}
};
return self;
});
var InteractiveArea = Container.expand(function () {
var self = Container.call(this);
self.areaType = 'tickle';
self.isActive = false;
self.activate = function (type) {
self.areaType = type;
self.isActive = true;
var asset = type === 'tickle' ? 'tickleArea' : 'kissArea';
var graphics = self.attachAsset(asset, {
anchorX: 0.5,
anchorY: 0.5
});
graphics.alpha = 0.3;
// Pulse animation
var pulseUp = function pulseUp() {
tween(graphics, {
alpha: 0.6
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: pulseDown
});
};
var pulseDown = function pulseDown() {
tween(graphics, {
alpha: 0.3
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: pulseUp
});
};
pulseUp();
};
self.deactivate = function () {
self.isActive = false;
self.visible = false;
};
self.down = function (x, y, obj) {
if (self.isActive) {
if (self.areaType === 'tickle' && gameState === 'tickling') {
pango.giggle();
tickleCount++;
if (tickleCount >= 3) {
startKissing();
}
} else if (self.areaType === 'kissing' && gameState === 'kissing') {
LK.getSound('kiss').play();
kissCount++;
if (kissCount >= 2) {
startBedtime();
}
}
}
};
return self;
});
var Lamp = Container.expand(function () {
var self = Container.call(this);
var lampGraphics = self.attachAsset('lamp', {
anchorX: 0.5,
anchorY: 0.5
});
self.isOn = true;
self.turnOff = function () {
if (self.isOn) {
self.isOn = false;
lampGraphics.tint = 0x666666;
LK.getSound('lampClick').play();
return true;
}
return false;
};
self.down = function (x, y, obj) {
if (gameState === 'bedtime' && self.isOn) {
var turnedOff = self.turnOff();
if (turnedOff) {
onLampTurnedOff();
}
}
};
return self;
});
var Pango = Container.expand(function () {
var self = Container.call(this);
var pangoGraphics = self.attachAsset('pango', {
anchorX: 0.5,
anchorY: 0.5
});
self.isHappy = false;
self.isSleeping = false;
self.showSadExpression = function () {
pangoGraphics.tint = 0x6495ED;
self.isHappy = false;
};
self.showHappyExpression = function () {
pangoGraphics.tint = 0x4A90E2;
self.isHappy = true;
// Bounce animation when happy
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeIn
});
};
self.giggle = function () {
if (self.isHappy) {
// Wiggle animation
tween(self, {
rotation: 0.1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(self, {
rotation: -0.1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(self, {
rotation: 0
}, {
duration: 100,
easing: tween.easeInOut
});
LK.getSound('giggle').play();
}
};
self.goToSleep = function () {
self.isSleeping = true;
tween(self, {
y: self.y + 50,
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 1000,
easing: tween.easeOut
});
pangoGraphics.tint = 0x2E5984;
};
return self;
});
var Teddy = Container.expand(function () {
var self = Container.call(this);
var teddyGraphics = self.attachAsset('teddy', {
anchorX: 0.5,
anchorY: 0.5
});
self.isFound = false;
self.isHidden = true;
self.hide = function () {
self.visible = false;
self.isHidden = true;
};
self.reveal = function () {
self.visible = true;
self.isHidden = false;
self.isFound = true;
// Pop animation when found
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.bounceOut
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameState = 'intro';
var pango;
var teddy;
var drawers = [];
var lamp;
var interactiveArea;
var messageText;
var tickleCount = 0;
var kissCount = 0;
var teddyDrawerIndex = 0;
// Initialize game elements
function initializeGame() {
// Create Pango
pango = game.addChild(new Pango());
pango.x = 1024;
pango.y = 1200;
pango.showSadExpression();
// Create message text
messageText = new Text2('I lost my teddy!', {
size: 80,
fill: 0xFFFFFF
});
messageText.anchor.set(0.5, 0.5);
messageText.x = 1024;
messageText.y = 400;
game.addChild(messageText);
// Create teddy (hidden initially)
teddy = game.addChild(new Teddy());
teddy.hide();
// Create interactive area
interactiveArea = game.addChild(new InteractiveArea());
interactiveArea.visible = false;
// Start the game sequence
LK.setTimeout(function () {
startSearching();
}, 2000);
}
function startSearching() {
gameState = 'searching';
// Update message
messageText.setText('Tap the drawers to find my teddy!');
// Create drawers
var drawerPositions = [{
x: 400,
y: 1000
}, {
x: 800,
y: 1000
}, {
x: 1200,
y: 1000
}, {
x: 1600,
y: 1000
}];
// Randomly select which drawer contains the teddy
teddyDrawerIndex = Math.floor(Math.random() * drawerPositions.length);
for (var i = 0; i < drawerPositions.length; i++) {
var drawer = game.addChild(new Drawer());
drawer.x = drawerPositions[i].x;
drawer.y = drawerPositions[i].y;
if (i === teddyDrawerIndex) {
drawer.containsTeddy = true;
// Position teddy behind this drawer
teddy.x = drawer.x;
teddy.y = drawer.y - 50;
}
drawers.push(drawer);
}
}
function onTeddyFound() {
gameState = 'found';
// Show teddy
teddy.reveal();
// Update Pango's expression
pango.showHappyExpression();
// Update message
messageText.setText('Yay! You found my teddy!');
// Move teddy to Pango
tween(teddy, {
x: pango.x + 100,
y: pango.y
}, {
duration: 1000,
easing: tween.easeOut
});
// Start tickling phase
LK.setTimeout(function () {
startTickling();
}, 2000);
}
function startTickling() {
gameState = 'tickling';
tickleCount = 0;
// Update message
messageText.setText('Tickle me! (Tap 3 times)');
// Show tickle area
interactiveArea.activate('tickle');
interactiveArea.x = pango.x;
interactiveArea.y = pango.y;
interactiveArea.visible = true;
}
function startKissing() {
gameState = 'kissing';
kissCount = 0;
// Update message
messageText.setText('Give me a kiss! (Tap 2 times)');
// Change interactive area to kiss
interactiveArea.deactivate();
interactiveArea.activate('kissing');
interactiveArea.x = pango.x;
interactiveArea.y = pango.y - 100;
interactiveArea.visible = true;
}
function startBedtime() {
gameState = 'bedtime';
// Update message
messageText.setText('I\'m sleepy... Turn off the lamp!');
// Hide interactive area
interactiveArea.deactivate();
// Make Pango lie down
pango.goToSleep();
// Create lamp
lamp = game.addChild(new Lamp());
lamp.x = 1600;
lamp.y = 800;
}
function onLampTurnedOff() {
gameState = 'sleeping';
// Dim the screen
tween(game, {
alpha: 0.3
}, {
duration: 2000,
easing: tween.easeOut
});
// Update message
messageText.setText('Goodnight, Pango!');
// Show completion
LK.setTimeout(function () {
messageText.setText('Sweet dreams...');
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}, 2000);
}
// Initialize the game
initializeGame();
game.update = function () {
// Game logic is handled through event-driven interactions
// No continuous updates needed for this story-based game
};