Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls: Hide and Seek Challenge
Initial prompt
The powerpuff girls: tap on level 1 chicken, or level 2 sheep, or level 3 pig to get started. Where is it hiding tap on it 20 times. Before the time runs out. Till the powerpuff girls say I’ve got you. Hahahaha.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Animal = Container.expand(function (type) { var self = Container.call(this); var animalSprite = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.animalType = type; self.isHiding = false; self.hide = function () { self.isHiding = true; var hideX = Math.random() * (2048 - 100) + 50; var hideY = Math.random() * (2732 - 400) + 200; // Avoid UI areas tween(self, { x: hideX, y: hideY }, { duration: 300, onFinish: function onFinish() { self.isHiding = false; } }); }; self.down = function (x, y, obj) { if (!self.isHiding && gameState === 'playing') { tapsCount++; updateTapCounter(); LK.getSound('tap').play(); // Flash effect tween(animalSprite, { scaleX: 1.3, scaleY: 1.3 }, { duration: 100 }); tween(animalSprite, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100 }); if (tapsCount >= 20) { winLevel(); } else { self.hide(); } } }; return self; }); var LevelButton = Container.expand(function (level, animal, color) { var self = Container.call(this); var button = self.attachAsset('levelButton', { anchorX: 0.5, anchorY: 0.5 }); button.tint = color; var levelText = new Text2('Level ' + level, { size: 40, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0.3); self.addChild(levelText); var animalText = new Text2(animal, { size: 32, fill: 0xFFFFFF }); animalText.anchor.set(0.5, 0.7); self.addChild(animalText); self.level = level; self.down = function (x, y, obj) { startLevel(self.level); LK.getSound('tap').play(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game state variables var gameState = 'menu'; // 'menu', 'playing', 'won', 'lost' var currentLevel = 1; var tapsCount = 0; var timeRemaining = 0; var maxTime = 0; var currentAnimal = null; // UI elements var levelButtons = []; var tapCounterText = null; var timerBarBg = null; var timerBar = null; var timerText = null; var titleText = null; var instructionText = null; // Level configurations var levelConfigs = { 1: { animal: 'chicken', time: 60000, name: 'Chicken' }, 2: { animal: 'sheep', time: 45000, name: 'Sheep' }, 3: { animal: 'pig', time: 30000, name: 'Pig' } }; function initializeMenu() { gameState = 'menu'; // Clear existing elements game.removeChildren(); // Title titleText = new Text2('Powerpuff Girls\nHide and Seek Challenge', { size: 60, fill: 0xFF1493 }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 500; game.addChild(titleText); // Instructions instructionText = new Text2('Find and tap the hidden animal 20 times!\nChoose your difficulty level:', { size: 40, fill: 0x000000 }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 2048 / 2; instructionText.y = 800; game.addChild(instructionText); // Level buttons levelButtons = []; var buttonColors = [0xFF69B4, 0xFF4500, 0x8A2BE2]; for (var i = 1; i <= 3; i++) { var button = new LevelButton(i, levelConfigs[i].name, buttonColors[i - 1]); button.x = 2048 / 2; button.y = 1200 + (i - 1) * 200; levelButtons.push(button); game.addChild(button); } } function startLevel(level) { gameState = 'playing'; currentLevel = level; tapsCount = 0; var config = levelConfigs[level]; maxTime = config.time; timeRemaining = maxTime; // Clear menu game.removeChildren(); // Create animal currentAnimal = new Animal(config.animal); currentAnimal.x = 2048 / 2; currentAnimal.y = 2732 / 2; game.addChild(currentAnimal); // Hide animal initially LK.setTimeout(function () { currentAnimal.hide(); }, 1000); setupGameUI(); } function setupGameUI() { // Tap counter tapCounterText = new Text2('Taps: 0/20', { size: 50, fill: 0xFFFFFF }); tapCounterText.anchor.set(0.5, 0); LK.gui.top.addChild(tapCounterText); // Timer background timerBarBg = LK.getAsset('timerBg', { anchorX: 0.5, anchorY: 0 }); timerBarBg.x = 2048 / 2; timerBarBg.y = 100; game.addChild(timerBarBg); // Timer bar timerBar = LK.getAsset('timerBar', { anchorX: 0, anchorY: 0 }); timerBar.x = timerBarBg.x - timerBarBg.width / 2; timerBar.y = timerBarBg.y; game.addChild(timerBar); // Timer text timerText = new Text2('Time: ' + Math.ceil(timeRemaining / 1000), { size: 35, fill: 0xFFFFFF }); timerText.anchor.set(0.5, 0.5); timerText.x = timerBarBg.x; timerText.y = timerBarBg.y + timerBarBg.height / 2; game.addChild(timerText); } function updateTapCounter() { if (tapCounterText) { tapCounterText.setText('Taps: ' + tapsCount + '/20'); } } function updateTimer() { if (gameState === 'playing' && timeRemaining > 0) { timeRemaining -= 16.67; // Approximately 60 FPS var timePercent = timeRemaining / maxTime; var newWidth = 600 * timePercent; if (timerBar) { timerBar.width = Math.max(0, newWidth); // Change color based on time remaining if (timePercent > 0.5) { timerBar.tint = 0x32CD32; // Green } else if (timePercent > 0.25) { timerBar.tint = 0xFFD700; // Yellow } else { timerBar.tint = 0xFF4500; // Red } } if (timerText) { timerText.setText('Time: ' + Math.ceil(timeRemaining / 1000)); } if (timeRemaining <= 0) { loseLevel(); } } } function winLevel() { gameState = 'won'; LK.getSound('victory').play(); // Victory message var victoryText = new Text2("I've got you. Hahahaha!\n\nLevel " + currentLevel + " Complete!\nTap to return to menu", { size: 50, fill: 0x00FF00 }); victoryText.anchor.set(0.5, 0.5); victoryText.x = 2048 / 2; victoryText.y = 2732 / 2; game.addChild(victoryText); // Flash effect LK.effects.flashScreen(0x00FF00, 1000); LK.setTimeout(function () { initializeMenu(); }, 3000); } function loseLevel() { gameState = 'lost'; LK.getSound('fail').play(); // Failure message var failText = new Text2('Time\'s up!\n\nTry again!\nTap to return to menu', { size: 50, fill: 0xFF0000 }); failText.anchor.set(0.5, 0.5); failText.x = 2048 / 2; failText.y = 2732 / 2; game.addChild(failText); // Flash effect LK.effects.flashScreen(0xFF0000, 1000); LK.setTimeout(function () { initializeMenu(); }, 3000); } // Touch handler for returning to menu after win/lose game.down = function (x, y, obj) { if (gameState === 'won' || gameState === 'lost') { initializeMenu(); } }; // Main game update loop game.update = function () { if (gameState === 'playing') { updateTimer(); } }; // Initialize the game initializeMenu(); LK.playMusic('bgMusic');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Animal = Container.expand(function (type) {
var self = Container.call(this);
var animalSprite = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.animalType = type;
self.isHiding = false;
self.hide = function () {
self.isHiding = true;
var hideX = Math.random() * (2048 - 100) + 50;
var hideY = Math.random() * (2732 - 400) + 200; // Avoid UI areas
tween(self, {
x: hideX,
y: hideY
}, {
duration: 300,
onFinish: function onFinish() {
self.isHiding = false;
}
});
};
self.down = function (x, y, obj) {
if (!self.isHiding && gameState === 'playing') {
tapsCount++;
updateTapCounter();
LK.getSound('tap').play();
// Flash effect
tween(animalSprite, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100
});
tween(animalSprite, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
if (tapsCount >= 20) {
winLevel();
} else {
self.hide();
}
}
};
return self;
});
var LevelButton = Container.expand(function (level, animal, color) {
var self = Container.call(this);
var button = self.attachAsset('levelButton', {
anchorX: 0.5,
anchorY: 0.5
});
button.tint = color;
var levelText = new Text2('Level ' + level, {
size: 40,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0.3);
self.addChild(levelText);
var animalText = new Text2(animal, {
size: 32,
fill: 0xFFFFFF
});
animalText.anchor.set(0.5, 0.7);
self.addChild(animalText);
self.level = level;
self.down = function (x, y, obj) {
startLevel(self.level);
LK.getSound('tap').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var gameState = 'menu'; // 'menu', 'playing', 'won', 'lost'
var currentLevel = 1;
var tapsCount = 0;
var timeRemaining = 0;
var maxTime = 0;
var currentAnimal = null;
// UI elements
var levelButtons = [];
var tapCounterText = null;
var timerBarBg = null;
var timerBar = null;
var timerText = null;
var titleText = null;
var instructionText = null;
// Level configurations
var levelConfigs = {
1: {
animal: 'chicken',
time: 60000,
name: 'Chicken'
},
2: {
animal: 'sheep',
time: 45000,
name: 'Sheep'
},
3: {
animal: 'pig',
time: 30000,
name: 'Pig'
}
};
function initializeMenu() {
gameState = 'menu';
// Clear existing elements
game.removeChildren();
// Title
titleText = new Text2('Powerpuff Girls\nHide and Seek Challenge', {
size: 60,
fill: 0xFF1493
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 500;
game.addChild(titleText);
// Instructions
instructionText = new Text2('Find and tap the hidden animal 20 times!\nChoose your difficulty level:', {
size: 40,
fill: 0x000000
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 2048 / 2;
instructionText.y = 800;
game.addChild(instructionText);
// Level buttons
levelButtons = [];
var buttonColors = [0xFF69B4, 0xFF4500, 0x8A2BE2];
for (var i = 1; i <= 3; i++) {
var button = new LevelButton(i, levelConfigs[i].name, buttonColors[i - 1]);
button.x = 2048 / 2;
button.y = 1200 + (i - 1) * 200;
levelButtons.push(button);
game.addChild(button);
}
}
function startLevel(level) {
gameState = 'playing';
currentLevel = level;
tapsCount = 0;
var config = levelConfigs[level];
maxTime = config.time;
timeRemaining = maxTime;
// Clear menu
game.removeChildren();
// Create animal
currentAnimal = new Animal(config.animal);
currentAnimal.x = 2048 / 2;
currentAnimal.y = 2732 / 2;
game.addChild(currentAnimal);
// Hide animal initially
LK.setTimeout(function () {
currentAnimal.hide();
}, 1000);
setupGameUI();
}
function setupGameUI() {
// Tap counter
tapCounterText = new Text2('Taps: 0/20', {
size: 50,
fill: 0xFFFFFF
});
tapCounterText.anchor.set(0.5, 0);
LK.gui.top.addChild(tapCounterText);
// Timer background
timerBarBg = LK.getAsset('timerBg', {
anchorX: 0.5,
anchorY: 0
});
timerBarBg.x = 2048 / 2;
timerBarBg.y = 100;
game.addChild(timerBarBg);
// Timer bar
timerBar = LK.getAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
timerBar.x = timerBarBg.x - timerBarBg.width / 2;
timerBar.y = timerBarBg.y;
game.addChild(timerBar);
// Timer text
timerText = new Text2('Time: ' + Math.ceil(timeRemaining / 1000), {
size: 35,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0.5);
timerText.x = timerBarBg.x;
timerText.y = timerBarBg.y + timerBarBg.height / 2;
game.addChild(timerText);
}
function updateTapCounter() {
if (tapCounterText) {
tapCounterText.setText('Taps: ' + tapsCount + '/20');
}
}
function updateTimer() {
if (gameState === 'playing' && timeRemaining > 0) {
timeRemaining -= 16.67; // Approximately 60 FPS
var timePercent = timeRemaining / maxTime;
var newWidth = 600 * timePercent;
if (timerBar) {
timerBar.width = Math.max(0, newWidth);
// Change color based on time remaining
if (timePercent > 0.5) {
timerBar.tint = 0x32CD32; // Green
} else if (timePercent > 0.25) {
timerBar.tint = 0xFFD700; // Yellow
} else {
timerBar.tint = 0xFF4500; // Red
}
}
if (timerText) {
timerText.setText('Time: ' + Math.ceil(timeRemaining / 1000));
}
if (timeRemaining <= 0) {
loseLevel();
}
}
}
function winLevel() {
gameState = 'won';
LK.getSound('victory').play();
// Victory message
var victoryText = new Text2("I've got you. Hahahaha!\n\nLevel " + currentLevel + " Complete!\nTap to return to menu", {
size: 50,
fill: 0x00FF00
});
victoryText.anchor.set(0.5, 0.5);
victoryText.x = 2048 / 2;
victoryText.y = 2732 / 2;
game.addChild(victoryText);
// Flash effect
LK.effects.flashScreen(0x00FF00, 1000);
LK.setTimeout(function () {
initializeMenu();
}, 3000);
}
function loseLevel() {
gameState = 'lost';
LK.getSound('fail').play();
// Failure message
var failText = new Text2('Time\'s up!\n\nTry again!\nTap to return to menu', {
size: 50,
fill: 0xFF0000
});
failText.anchor.set(0.5, 0.5);
failText.x = 2048 / 2;
failText.y = 2732 / 2;
game.addChild(failText);
// Flash effect
LK.effects.flashScreen(0xFF0000, 1000);
LK.setTimeout(function () {
initializeMenu();
}, 3000);
}
// Touch handler for returning to menu after win/lose
game.down = function (x, y, obj) {
if (gameState === 'won' || gameState === 'lost') {
initializeMenu();
}
};
// Main game update loop
game.update = function () {
if (gameState === 'playing') {
updateTimer();
}
};
// Initialize the game
initializeMenu();
LK.playMusic('bgMusic');