Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls Snow Golf Adventure
Initial prompt
Toca snow golf (2010). The powerpuff girls are walking up the snow hill with footprints. And they got a golf bag. Tap on the powerpuff girls to make the ball to the hole. Finish all 3 levels and then a video comes out. Tap the play button to make the screen come to life. It will be a powerpuff girls saying we did it scene at the end.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Footprint = Container.expand(function (x, y) { var self = Container.call(this); var graphics = self.attachAsset('footprint', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; self.alpha = 0.6; return self; }); var GolfBall = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var graphics = self.attachAsset('golfBall', { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.velocityX = (targetX - startX) * 0.05; self.velocityY = (targetY - startY) * 0.05; self.friction = 0.98; self.isRolling = true; self.update = function () { if (!self.isRolling) return; self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) { self.isRolling = false; } // Check hole collision if (self.intersects(currentHole)) { self.isRolling = false; LK.getSound('holeSuccess').play(); LK.setScore(LK.getScore() + 100); scoreText.setText('Score: ' + LK.getScore()); tween(self, { alpha: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 500, onFinish: function onFinish() { self.destroy(); nextLevel(); } }); } // Bounds checking if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; return self; }); var PowerpuffGirl = Container.expand(function (character, color, startX) { var self = Container.call(this); var graphics = self.attachAsset(character, { anchorX: 0.5, anchorY: 1.0 }); self.x = startX; self.y = 2200; self.character = character; self.isMoving = false; self.walkSpeed = 2; self.startWalk = function () { self.isMoving = true; tween(self, { y: 1800 }, { duration: 3000, easing: tween.easeOut }); }; self.down = function (x, y, obj) { if (!gameStarted || gameCompleted) return; launchGolfBall(self.x, self.y - 50); LK.getSound('golfHit').play(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var gameStarted = false; var gameCompleted = false; var currentLevel = 1; var maxLevels = 3; // Characters var blossom, bubbles, buttercup; var currentHole; var playButton; var golfBalls = []; var footprints = []; var obstacles = []; // UI var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var levelText = new Text2('Level 1', { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); levelText.x = 150; levelText.y = 50; LK.gui.topLeft.addChild(levelText); var instructionText = new Text2('Tap a Powerpuff Girl to launch golf ball!', { size: 45, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionText); // Create snow ground var snowGround = game.addChild(LK.getAsset('snowGround', { x: 0, y: 2332, anchorX: 0, anchorY: 0 })); // Initialize characters blossom = game.addChild(new PowerpuffGirl('blossom', 0xff69b4, 300)); bubbles = game.addChild(new PowerpuffGirl('bubbles', 0x87ceeb, 1024)); buttercup = game.addChild(new PowerpuffGirl('buttercup', 0x90ee90, 1700)); function createLevel(levelNum) { // Clear existing obstacles for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].destroy(); obstacles.splice(i, 1); } // Create hole for current level if (currentHole) { currentHole.destroy(); } var holePositions = [{ x: 1024, y: 1600 }, // Level 1 { x: 1500, y: 1400 }, // Level 2 { x: 600, y: 1200 } // Level 3 ]; var holePos = holePositions[levelNum - 1]; currentHole = game.addChild(LK.getAsset('golfHole', { x: holePos.x, y: holePos.y, anchorX: 0.5, anchorY: 0.5 })); // Create obstacles based on level if (levelNum >= 2) { var mound1 = game.addChild(LK.getAsset('snowMound', { x: 800, y: 1800, anchorX: 0.5, anchorY: 0.5 })); obstacles.push(mound1); } if (levelNum >= 3) { var icePatch1 = game.addChild(LK.getAsset('icePatch', { x: 1200, y: 1600, anchorX: 0.5, anchorY: 0.5 })); obstacles.push(icePatch1); var mound2 = game.addChild(LK.getAsset('snowMound', { x: 400, y: 1500, anchorX: 0.5, anchorY: 0.5 })); obstacles.push(mound2); } } function launchGolfBall(startX, startY) { var newBall = new GolfBall(startX, startY, currentHole.x, currentHole.y); golfBalls.push(newBall); game.addChild(newBall); } function nextLevel() { currentLevel++; if (currentLevel > maxLevels) { completeGame(); return; } levelText.setText('Level ' + currentLevel); LK.setTimeout(function () { createLevel(currentLevel); }, 1000); } function completeGame() { gameCompleted = true; instructionText.setText('Congratulations! All levels complete!'); // Create play button for victory video playButton = game.addChild(LK.getAsset('playButton', { x: 1024, y: 1366, anchorX: 0.5, anchorY: 0.5 })); var playText = new Text2('PLAY VICTORY VIDEO', { size: 30, fill: 0xFFFFFF }); playText.anchor.set(0.5, 0.5); playText.x = 1024; playText.y = 1366; game.addChild(playText); playButton.down = function (x, y, obj) { showVictoryVideo(); }; } function showVictoryVideo() { // Victory celebration animation LK.effects.flashScreen(0xffd700, 2000); var victoryText = new Text2('WE DID IT!', { size: 120, fill: 0xFFD700 }); victoryText.anchor.set(0.5, 0.5); victoryText.x = 1024; victoryText.y = 1000; victoryText.alpha = 0; game.addChild(victoryText); tween(victoryText, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 1000 }); // Animate characters celebrating tween(blossom, { y: blossom.y - 100 }, { duration: 500, easing: tween.bounceOut }); tween(bubbles, { y: bubbles.y - 100 }, { duration: 600, easing: tween.bounceOut }); tween(buttercup, { y: buttercup.y - 100 }, { duration: 700, easing: tween.bounceOut }); LK.setTimeout(function () { LK.showYouWin(); }, 3000); } function createFootprint(x, y) { var footprint = new Footprint(x + Math.random() * 40 - 20, y + Math.random() * 20 - 10); footprints.push(footprint); game.addChild(footprint); tween(footprint, { alpha: 0 }, { duration: 5000, onFinish: function onFinish() { footprint.destroy(); var index = footprints.indexOf(footprint); if (index > -1) { footprints.splice(index, 1); } } }); } // Start the game LK.setTimeout(function () { gameStarted = true; createLevel(1); blossom.startWalk(); bubbles.startWalk(); buttercup.startWalk(); }, 1000); // Game update loop game.update = function () { // Create footprints while characters are moving if (LK.ticks % 20 === 0 && !gameCompleted) { if (blossom.isMoving) createFootprint(blossom.x, blossom.y); if (bubbles.isMoving) createFootprint(bubbles.x, bubbles.y); if (buttercup.isMoving) createFootprint(buttercup.x, buttercup.y); } // Clean up golf balls that are off screen for (var i = golfBalls.length - 1; i >= 0; i--) { var ball = golfBalls[i]; if (ball.destroyed || ball.x < -100 || ball.x > 2148 || ball.y < -100 || ball.y > 2832) { if (!ball.destroyed) { ball.destroy(); } golfBalls.splice(i, 1); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Footprint = Container.expand(function (x, y) {
var self = Container.call(this);
var graphics = self.attachAsset('footprint', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = x;
self.y = y;
self.alpha = 0.6;
return self;
});
var GolfBall = Container.expand(function (startX, startY, targetX, targetY) {
var self = Container.call(this);
var graphics = self.attachAsset('golfBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.velocityX = (targetX - startX) * 0.05;
self.velocityY = (targetY - startY) * 0.05;
self.friction = 0.98;
self.isRolling = true;
self.update = function () {
if (!self.isRolling) return;
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) {
self.isRolling = false;
}
// Check hole collision
if (self.intersects(currentHole)) {
self.isRolling = false;
LK.getSound('holeSuccess').play();
LK.setScore(LK.getScore() + 100);
scoreText.setText('Score: ' + LK.getScore());
tween(self, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 500,
onFinish: function onFinish() {
self.destroy();
nextLevel();
}
});
}
// Bounds checking
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
};
return self;
});
var PowerpuffGirl = Container.expand(function (character, color, startX) {
var self = Container.call(this);
var graphics = self.attachAsset(character, {
anchorX: 0.5,
anchorY: 1.0
});
self.x = startX;
self.y = 2200;
self.character = character;
self.isMoving = false;
self.walkSpeed = 2;
self.startWalk = function () {
self.isMoving = true;
tween(self, {
y: 1800
}, {
duration: 3000,
easing: tween.easeOut
});
};
self.down = function (x, y, obj) {
if (!gameStarted || gameCompleted) return;
launchGolfBall(self.x, self.y - 50);
LK.getSound('golfHit').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var gameStarted = false;
var gameCompleted = false;
var currentLevel = 1;
var maxLevels = 3;
// Characters
var blossom, bubbles, buttercup;
var currentHole;
var playButton;
var golfBalls = [];
var footprints = [];
var obstacles = [];
// UI
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var levelText = new Text2('Level 1', {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
levelText.x = 150;
levelText.y = 50;
LK.gui.topLeft.addChild(levelText);
var instructionText = new Text2('Tap a Powerpuff Girl to launch golf ball!', {
size: 45,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
// Create snow ground
var snowGround = game.addChild(LK.getAsset('snowGround', {
x: 0,
y: 2332,
anchorX: 0,
anchorY: 0
}));
// Initialize characters
blossom = game.addChild(new PowerpuffGirl('blossom', 0xff69b4, 300));
bubbles = game.addChild(new PowerpuffGirl('bubbles', 0x87ceeb, 1024));
buttercup = game.addChild(new PowerpuffGirl('buttercup', 0x90ee90, 1700));
function createLevel(levelNum) {
// Clear existing obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
// Create hole for current level
if (currentHole) {
currentHole.destroy();
}
var holePositions = [{
x: 1024,
y: 1600
},
// Level 1
{
x: 1500,
y: 1400
},
// Level 2
{
x: 600,
y: 1200
} // Level 3
];
var holePos = holePositions[levelNum - 1];
currentHole = game.addChild(LK.getAsset('golfHole', {
x: holePos.x,
y: holePos.y,
anchorX: 0.5,
anchorY: 0.5
}));
// Create obstacles based on level
if (levelNum >= 2) {
var mound1 = game.addChild(LK.getAsset('snowMound', {
x: 800,
y: 1800,
anchorX: 0.5,
anchorY: 0.5
}));
obstacles.push(mound1);
}
if (levelNum >= 3) {
var icePatch1 = game.addChild(LK.getAsset('icePatch', {
x: 1200,
y: 1600,
anchorX: 0.5,
anchorY: 0.5
}));
obstacles.push(icePatch1);
var mound2 = game.addChild(LK.getAsset('snowMound', {
x: 400,
y: 1500,
anchorX: 0.5,
anchorY: 0.5
}));
obstacles.push(mound2);
}
}
function launchGolfBall(startX, startY) {
var newBall = new GolfBall(startX, startY, currentHole.x, currentHole.y);
golfBalls.push(newBall);
game.addChild(newBall);
}
function nextLevel() {
currentLevel++;
if (currentLevel > maxLevels) {
completeGame();
return;
}
levelText.setText('Level ' + currentLevel);
LK.setTimeout(function () {
createLevel(currentLevel);
}, 1000);
}
function completeGame() {
gameCompleted = true;
instructionText.setText('Congratulations! All levels complete!');
// Create play button for victory video
playButton = game.addChild(LK.getAsset('playButton', {
x: 1024,
y: 1366,
anchorX: 0.5,
anchorY: 0.5
}));
var playText = new Text2('PLAY VICTORY VIDEO', {
size: 30,
fill: 0xFFFFFF
});
playText.anchor.set(0.5, 0.5);
playText.x = 1024;
playText.y = 1366;
game.addChild(playText);
playButton.down = function (x, y, obj) {
showVictoryVideo();
};
}
function showVictoryVideo() {
// Victory celebration animation
LK.effects.flashScreen(0xffd700, 2000);
var victoryText = new Text2('WE DID IT!', {
size: 120,
fill: 0xFFD700
});
victoryText.anchor.set(0.5, 0.5);
victoryText.x = 1024;
victoryText.y = 1000;
victoryText.alpha = 0;
game.addChild(victoryText);
tween(victoryText, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 1000
});
// Animate characters celebrating
tween(blossom, {
y: blossom.y - 100
}, {
duration: 500,
easing: tween.bounceOut
});
tween(bubbles, {
y: bubbles.y - 100
}, {
duration: 600,
easing: tween.bounceOut
});
tween(buttercup, {
y: buttercup.y - 100
}, {
duration: 700,
easing: tween.bounceOut
});
LK.setTimeout(function () {
LK.showYouWin();
}, 3000);
}
function createFootprint(x, y) {
var footprint = new Footprint(x + Math.random() * 40 - 20, y + Math.random() * 20 - 10);
footprints.push(footprint);
game.addChild(footprint);
tween(footprint, {
alpha: 0
}, {
duration: 5000,
onFinish: function onFinish() {
footprint.destroy();
var index = footprints.indexOf(footprint);
if (index > -1) {
footprints.splice(index, 1);
}
}
});
}
// Start the game
LK.setTimeout(function () {
gameStarted = true;
createLevel(1);
blossom.startWalk();
bubbles.startWalk();
buttercup.startWalk();
}, 1000);
// Game update loop
game.update = function () {
// Create footprints while characters are moving
if (LK.ticks % 20 === 0 && !gameCompleted) {
if (blossom.isMoving) createFootprint(blossom.x, blossom.y);
if (bubbles.isMoving) createFootprint(bubbles.x, bubbles.y);
if (buttercup.isMoving) createFootprint(buttercup.x, buttercup.y);
}
// Clean up golf balls that are off screen
for (var i = golfBalls.length - 1; i >= 0; i--) {
var ball = golfBalls[i];
if (ball.destroyed || ball.x < -100 || ball.x > 2148 || ball.y < -100 || ball.y > 2832) {
if (!ball.destroyed) {
ball.destroy();
}
golfBalls.splice(i, 1);
}
}
};