Code edit (1 edits merged)
Please save this source code
User prompt
Muddy Treasure Hunt
Initial prompt
Toca hiding in the mud (2016). The powerpuff girls know a lot about being successful puddle jumpers. If you jump in the mud you must wear your wellies. Use your finger to dig around the mud, they’ll be crabs, frogs, chameleons, or worms inside. Tap the green done sign to see the powerpuff girls jump high.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Creature = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.found = false; var creatureGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.reveal = function () { if (!self.found) { self.found = true; self.visible = true; tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, easing: tween.bounceOut }); LK.getSound('found').play(); LK.setScore(LK.getScore() + 10); foundCreatures++; updateScore(); } }; self.visible = false; return self; }); var DoneButton = Container.expand(function () { var self = Container.call(this); self.visible = false; var buttonGraphics = self.attachAsset('doneButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('DONE', { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (self.visible) { startCelebration(); } }; return self; }); var MudTile = Container.expand(function () { var self = Container.call(this); self.cleared = false; var mudGraphics = self.attachAsset('mudOverlay', { anchorX: 0.5, anchorY: 0.5 }); self.clear = function () { if (!self.cleared) { self.cleared = true; clearedTiles++; tween(self, { alpha: 0 }, { duration: 200 }); LK.getSound('dig').play(); } }; return self; }); var PowerpuffGirl = Container.expand(function () { var self = Container.call(this); var girlGraphics = self.attachAsset('powerpuffGirl', { anchorX: 0.5, anchorY: 0.5 }); self.jump = function () { var originalY = self.y; tween(self, { y: originalY - 200 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { y: originalY }, { duration: 500, easing: tween.bounceOut }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x4A4A4A }); /**** * Game Code ****/ var mudTiles = []; var creatures = []; var powerpuffGirls = []; var foundCreatures = 0; var clearedTiles = 0; var totalTiles = 0; var currentLevel = 1; var isDragging = false; var celebrationStarted = false; // Create mud background var mudBackground = game.addChild(LK.getAsset('mud', { x: 0, y: 0 })); // Create score display var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // Create creatures found display var creaturesText = new Text2('Creatures Found: 0', { size: 40, fill: 0xFFFFFF }); creaturesText.anchor.set(0.5, 0); creaturesText.y = 80; LK.gui.top.addChild(creaturesText); // Create done button var doneButton = game.addChild(new DoneButton()); doneButton.x = 2048 - 150; doneButton.y = 2732 - 100; // Create powerpuff girls for (var i = 0; i < 3; i++) { var girl = game.addChild(new PowerpuffGirl()); girl.x = 300 + i * 200; girl.y = 2732 - 200; girl.visible = false; powerpuffGirls.push(girl); } function initLevel() { // Clear existing elements for (var i = 0; i < mudTiles.length; i++) { mudTiles[i].destroy(); } for (var i = 0; i < creatures.length; i++) { creatures[i].destroy(); } mudTiles = []; creatures = []; foundCreatures = 0; clearedTiles = 0; celebrationStarted = false; // Create mud tiles grid var tileSize = 100; var rows = Math.floor(2732 / tileSize); var cols = Math.floor(2048 / tileSize); for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { var tile = game.addChild(new MudTile()); tile.x = col * tileSize + tileSize / 2; tile.y = row * tileSize + tileSize / 2; mudTiles.push(tile); } } totalTiles = mudTiles.length; // Create creatures randomly var creatureTypes = ['crab', 'frog', 'chameleon', 'worm']; var numCreatures = Math.min(15 + currentLevel * 3, 30); for (var i = 0; i < numCreatures; i++) { var creature = game.addChild(new Creature(creatureTypes[Math.floor(Math.random() * creatureTypes.length)])); creature.x = Math.random() * (2048 - 160) + 80; creature.y = Math.random() * (2732 - 160) + 80; creatures.push(creature); } doneButton.visible = false; for (var i = 0; i < powerpuffGirls.length; i++) { powerpuffGirls[i].visible = false; } } function updateScore() { scoreText.setText('Score: ' + LK.getScore()); creaturesText.setText('Creatures Found: ' + foundCreatures); } function checkProgress() { var progressPercent = clearedTiles / totalTiles; if (progressPercent > 0.3 && !doneButton.visible) { doneButton.visible = true; tween(doneButton, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, easing: tween.bounceOut }); } } function startCelebration() { if (celebrationStarted) return; celebrationStarted = true; doneButton.visible = false; // Show powerpuff girls for (var i = 0; i < powerpuffGirls.length; i++) { powerpuffGirls[i].visible = true; var delay = i * 200; LK.setTimeout(function (girl) { return function () { girl.jump(); }; }(powerpuffGirls[i]), delay); } LK.getSound('celebration').play(); // Start next level after celebration LK.setTimeout(function () { currentLevel++; initLevel(); }, 3000); } function handleDig(x, y) { // Check mud tiles for (var i = 0; i < mudTiles.length; i++) { var tile = mudTiles[i]; if (!tile.cleared) { var dx = x - tile.x; var dy = y - tile.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 80) { tile.clear(); } } } // Check creatures for (var i = 0; i < creatures.length; i++) { var creature = creatures[i]; if (!creature.found) { var dx = x - creature.x; var dy = y - creature.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 60) { creature.reveal(); } } } } game.down = function (x, y, obj) { isDragging = true; handleDig(x, y); }; game.move = function (x, y, obj) { if (isDragging) { handleDig(x, y); } }; game.up = function (x, y, obj) { isDragging = false; }; game.update = function () { checkProgress(); }; // Initialize first level initLevel();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Creature = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.found = false;
var creatureGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.reveal = function () {
if (!self.found) {
self.found = true;
self.visible = true;
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.bounceOut
});
LK.getSound('found').play();
LK.setScore(LK.getScore() + 10);
foundCreatures++;
updateScore();
}
};
self.visible = false;
return self;
});
var DoneButton = Container.expand(function () {
var self = Container.call(this);
self.visible = false;
var buttonGraphics = self.attachAsset('doneButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('DONE', {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (self.visible) {
startCelebration();
}
};
return self;
});
var MudTile = Container.expand(function () {
var self = Container.call(this);
self.cleared = false;
var mudGraphics = self.attachAsset('mudOverlay', {
anchorX: 0.5,
anchorY: 0.5
});
self.clear = function () {
if (!self.cleared) {
self.cleared = true;
clearedTiles++;
tween(self, {
alpha: 0
}, {
duration: 200
});
LK.getSound('dig').play();
}
};
return self;
});
var PowerpuffGirl = Container.expand(function () {
var self = Container.call(this);
var girlGraphics = self.attachAsset('powerpuffGirl', {
anchorX: 0.5,
anchorY: 0.5
});
self.jump = function () {
var originalY = self.y;
tween(self, {
y: originalY - 200
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
y: originalY
}, {
duration: 500,
easing: tween.bounceOut
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4A4A4A
});
/****
* Game Code
****/
var mudTiles = [];
var creatures = [];
var powerpuffGirls = [];
var foundCreatures = 0;
var clearedTiles = 0;
var totalTiles = 0;
var currentLevel = 1;
var isDragging = false;
var celebrationStarted = false;
// Create mud background
var mudBackground = game.addChild(LK.getAsset('mud', {
x: 0,
y: 0
}));
// Create score display
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create creatures found display
var creaturesText = new Text2('Creatures Found: 0', {
size: 40,
fill: 0xFFFFFF
});
creaturesText.anchor.set(0.5, 0);
creaturesText.y = 80;
LK.gui.top.addChild(creaturesText);
// Create done button
var doneButton = game.addChild(new DoneButton());
doneButton.x = 2048 - 150;
doneButton.y = 2732 - 100;
// Create powerpuff girls
for (var i = 0; i < 3; i++) {
var girl = game.addChild(new PowerpuffGirl());
girl.x = 300 + i * 200;
girl.y = 2732 - 200;
girl.visible = false;
powerpuffGirls.push(girl);
}
function initLevel() {
// Clear existing elements
for (var i = 0; i < mudTiles.length; i++) {
mudTiles[i].destroy();
}
for (var i = 0; i < creatures.length; i++) {
creatures[i].destroy();
}
mudTiles = [];
creatures = [];
foundCreatures = 0;
clearedTiles = 0;
celebrationStarted = false;
// Create mud tiles grid
var tileSize = 100;
var rows = Math.floor(2732 / tileSize);
var cols = Math.floor(2048 / tileSize);
for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
var tile = game.addChild(new MudTile());
tile.x = col * tileSize + tileSize / 2;
tile.y = row * tileSize + tileSize / 2;
mudTiles.push(tile);
}
}
totalTiles = mudTiles.length;
// Create creatures randomly
var creatureTypes = ['crab', 'frog', 'chameleon', 'worm'];
var numCreatures = Math.min(15 + currentLevel * 3, 30);
for (var i = 0; i < numCreatures; i++) {
var creature = game.addChild(new Creature(creatureTypes[Math.floor(Math.random() * creatureTypes.length)]));
creature.x = Math.random() * (2048 - 160) + 80;
creature.y = Math.random() * (2732 - 160) + 80;
creatures.push(creature);
}
doneButton.visible = false;
for (var i = 0; i < powerpuffGirls.length; i++) {
powerpuffGirls[i].visible = false;
}
}
function updateScore() {
scoreText.setText('Score: ' + LK.getScore());
creaturesText.setText('Creatures Found: ' + foundCreatures);
}
function checkProgress() {
var progressPercent = clearedTiles / totalTiles;
if (progressPercent > 0.3 && !doneButton.visible) {
doneButton.visible = true;
tween(doneButton, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.bounceOut
});
}
}
function startCelebration() {
if (celebrationStarted) return;
celebrationStarted = true;
doneButton.visible = false;
// Show powerpuff girls
for (var i = 0; i < powerpuffGirls.length; i++) {
powerpuffGirls[i].visible = true;
var delay = i * 200;
LK.setTimeout(function (girl) {
return function () {
girl.jump();
};
}(powerpuffGirls[i]), delay);
}
LK.getSound('celebration').play();
// Start next level after celebration
LK.setTimeout(function () {
currentLevel++;
initLevel();
}, 3000);
}
function handleDig(x, y) {
// Check mud tiles
for (var i = 0; i < mudTiles.length; i++) {
var tile = mudTiles[i];
if (!tile.cleared) {
var dx = x - tile.x;
var dy = y - tile.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 80) {
tile.clear();
}
}
}
// Check creatures
for (var i = 0; i < creatures.length; i++) {
var creature = creatures[i];
if (!creature.found) {
var dx = x - creature.x;
var dy = y - creature.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 60) {
creature.reveal();
}
}
}
}
game.down = function (x, y, obj) {
isDragging = true;
handleDig(x, y);
};
game.move = function (x, y, obj) {
if (isDragging) {
handleDig(x, y);
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
game.update = function () {
checkProgress();
};
// Initialize first level
initLevel();