Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls Basketball Showdown
Initial prompt
Toca basketball (2001). The powerpuff girls are having a basketball game. Tap in level 1 red ball, level 2 orange ball, level 3 yellow ball, level 4 green ball, level 5 blue ball, level 6 purple ball to get started. Tap on the powerpuff girl to watch it throw the ball to the hoop.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Basketball = Container.expand(function (startX, startY) { var self = Container.call(this); var ballGraphics = self.attachAsset('basketball', { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.velocityX = (hoopX - startX) * 0.02; self.velocityY = -8; self.gravity = 0.3; self.hasScored = false; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; ballGraphics.rotation += 0.1; // Check hoop collision if (!self.hasScored && self.intersects(hoop) && self.velocityY > 0) { self.hasScored = true; score++; LK.setScore(score); scoreTxt.setText(score); LK.getSound('score').play(); // Flash effect LK.effects.flashObject(hoop, 0x00FF00, 500); // Check level completion if (score >= levelTargets[currentLevel - 1]) { completeLevel(); } } // Remove if off screen if (self.y > 2732 + 100) { self.shouldRemove = true; } }; return self; }); var Hoop = Container.expand(function (x, y) { var self = Container.call(this); var backboardGraphics = self.attachAsset('backboard', { anchorX: 0.5, anchorY: 0.5 }); backboardGraphics.x = 110; backboardGraphics.y = 0; var hoopGraphics = self.attachAsset('hoop', { anchorX: 0.5, anchorY: 0.5 }); self.x = x; self.y = y; return self; }); var LevelBall = Container.expand(function (level, color, x, y) { var self = Container.call(this); var assetName = color + 'Ball'; var ballGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.level = level; self.isUnlocked = false; self.x = x; self.y = y; self.unlock = function () { self.isUnlocked = true; ballGraphics.alpha = 1.0; tween(ballGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, easing: tween.easeOut }); tween(ballGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 300, easing: tween.easeIn }); }; self.lock = function () { self.isUnlocked = false; ballGraphics.alpha = 0.5; ballGraphics.scaleX = 1.0; ballGraphics.scaleY = 1.0; }; self.down = function (x, y, obj) { if (self.isUnlocked) { startLevel(self.level); } }; return self; }); var PowerpuffGirl = Container.expand(function (x, y, color) { var self = Container.call(this); var girlGraphics = self.attachAsset('powerpuffGirl', { anchorX: 0.5, anchorY: 0.5 }); girlGraphics.tint = color; self.x = x; self.y = y; self.canShoot = true; self.shoot = function () { if (!self.canShoot) return; self.canShoot = false; // Animation tween(girlGraphics, { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.easeOut }); tween(girlGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn }); // Create basketball var ball = new Basketball(self.x, self.y); game.addChild(ball); basketballs.push(ball); LK.getSound('shoot').play(); // Reset shoot ability LK.setTimeout(function () { self.canShoot = true; }, 1000); }; self.down = function (x, y, obj) { if (gameState === 'playing') { self.shoot(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var gameState = 'menu'; // 'menu', 'playing' var currentLevel = 1; var maxUnlockedLevel = 1; var score = 0; var levelTargets = [3, 5, 8, 10, 15, 20]; // Targets for each level var levelColors = [0xFF69B4, 0xFF1493, 0xFF69B4, 0xFF1493, 0xFF69B4, 0xFF1493]; // Game objects var levelBalls = []; var powerpuffGirls = []; var basketballs = []; var hoop; var hoopX = 1750; var hoopY = 800; // UI elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var levelTxt = new Text2('Level 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0.5, 0); levelTxt.y = 100; LK.gui.top.addChild(levelTxt); var targetTxt = new Text2('Target: 3', { size: 50, fill: 0xFFFFFF }); targetTxt.anchor.set(0.5, 0); targetTxt.y = 170; LK.gui.top.addChild(targetTxt); var instructionTxt = new Text2('Tap colored balls to select level', { size: 50, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 0.5); instructionTxt.x = 1024; instructionTxt.y = 2400; game.addChild(instructionTxt); // Initialize level selection balls function initializeLevelBalls() { var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']; var startX = 300; var startY = 1200; for (var i = 0; i < 6; i++) { var ball = new LevelBall(i + 1, colors[i], startX + i % 3 * 300, startY + Math.floor(i / 3) * 300); levelBalls.push(ball); game.addChild(ball); } // Unlock first level levelBalls[0].unlock(); } // Initialize gameplay elements function initializeGameplay() { // Create hoop hoop = new Hoop(hoopX, hoopY); game.addChild(hoop); // Create Powerpuff Girls var girlPositions = [{ x: 300, y: 2000 }, { x: 600, y: 2000 }, { x: 900, y: 2000 }]; for (var i = 0; i < 3; i++) { var girl = new PowerpuffGirl(girlPositions[i].x, girlPositions[i].y, levelColors[i]); powerpuffGirls.push(girl); game.addChild(girl); } } // Start a specific level function startLevel(level) { currentLevel = level; gameState = 'playing'; score = 0; LK.setScore(0); // Hide level selection for (var i = 0; i < levelBalls.length; i++) { levelBalls[i].visible = false; } instructionTxt.visible = false; // Show gameplay elements hoop.visible = true; for (var i = 0; i < powerpuffGirls.length; i++) { powerpuffGirls[i].visible = true; } // Update UI levelTxt.setText('Level ' + level); targetTxt.setText('Target: ' + levelTargets[level - 1]); scoreTxt.setText('Score: 0'); // Level-specific modifications if (level > 3) { // Make hoop move for higher levels tween(hoop, { x: hoopX - 200 }, { duration: 2000, easing: tween.easeInOut }); tween(hoop, { x: hoopX + 200 }, { duration: 4000, easing: tween.easeInOut }); } } // Complete current level function completeLevel() { LK.getSound('levelComplete').play(); LK.effects.flashScreen(0x00FF00, 1000); // Unlock next level if (currentLevel < 6) { maxUnlockedLevel = Math.max(maxUnlockedLevel, currentLevel + 1); levelBalls[currentLevel].unlock(); } // Return to menu after delay LK.setTimeout(function () { returnToMenu(); }, 2000); } // Return to level selection menu function returnToMenu() { gameState = 'menu'; // Hide gameplay elements hoop.visible = false; for (var i = 0; i < powerpuffGirls.length; i++) { powerpuffGirls[i].visible = false; } // Clear basketballs for (var i = basketballs.length - 1; i >= 0; i--) { basketballs[i].destroy(); basketballs.splice(i, 1); } // Show level selection for (var i = 0; i < levelBalls.length; i++) { levelBalls[i].visible = true; if (i < maxUnlockedLevel) { levelBalls[i].unlock(); } else { levelBalls[i].lock(); } } instructionTxt.visible = true; // Update UI levelTxt.setText('Select Level'); targetTxt.setText('Tap to play'); scoreTxt.setText('Score: ' + LK.getScore()); } // Initialize game initializeLevelBalls(); initializeGameplay(); // Hide gameplay elements initially hoop.visible = false; for (var i = 0; i < powerpuffGirls.length; i++) { powerpuffGirls[i].visible = false; } // Game update loop game.update = function () { if (gameState === 'playing') { // Update basketballs for (var i = basketballs.length - 1; i >= 0; i--) { var ball = basketballs[i]; if (ball.shouldRemove) { ball.destroy(); basketballs.splice(i, 1); } } // Level-specific updates if (currentLevel > 3 && LK.ticks % 240 === 0) { // Continue hoop movement animation if (hoop.x <= hoopX - 190) { tween(hoop, { x: hoopX + 200 }, { duration: 4000, easing: tween.easeInOut }); } else if (hoop.x >= hoopX + 190) { tween(hoop, { x: hoopX - 200 }, { duration: 4000, easing: tween.easeInOut }); } } } }; // Initial UI setup levelTxt.setText('Select Level'); targetTxt.setText('Tap to play'); scoreTxt.setText('Score: 0');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,361 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Basketball = Container.expand(function (startX, startY) {
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('basketball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = startX;
+ self.y = startY;
+ self.velocityX = (hoopX - startX) * 0.02;
+ self.velocityY = -8;
+ self.gravity = 0.3;
+ self.hasScored = false;
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityY += self.gravity;
+ ballGraphics.rotation += 0.1;
+ // Check hoop collision
+ if (!self.hasScored && self.intersects(hoop) && self.velocityY > 0) {
+ self.hasScored = true;
+ score++;
+ LK.setScore(score);
+ scoreTxt.setText(score);
+ LK.getSound('score').play();
+ // Flash effect
+ LK.effects.flashObject(hoop, 0x00FF00, 500);
+ // Check level completion
+ if (score >= levelTargets[currentLevel - 1]) {
+ completeLevel();
+ }
+ }
+ // Remove if off screen
+ if (self.y > 2732 + 100) {
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
+var Hoop = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ var backboardGraphics = self.attachAsset('backboard', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ backboardGraphics.x = 110;
+ backboardGraphics.y = 0;
+ var hoopGraphics = self.attachAsset('hoop', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = x;
+ self.y = y;
+ return self;
+});
+var LevelBall = Container.expand(function (level, color, x, y) {
+ var self = Container.call(this);
+ var assetName = color + 'Ball';
+ var ballGraphics = self.attachAsset(assetName, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.level = level;
+ self.isUnlocked = false;
+ self.x = x;
+ self.y = y;
+ self.unlock = function () {
+ self.isUnlocked = true;
+ ballGraphics.alpha = 1.0;
+ tween(ballGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(ballGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ };
+ self.lock = function () {
+ self.isUnlocked = false;
+ ballGraphics.alpha = 0.5;
+ ballGraphics.scaleX = 1.0;
+ ballGraphics.scaleY = 1.0;
+ };
+ self.down = function (x, y, obj) {
+ if (self.isUnlocked) {
+ startLevel(self.level);
+ }
+ };
+ return self;
+});
+var PowerpuffGirl = Container.expand(function (x, y, color) {
+ var self = Container.call(this);
+ var girlGraphics = self.attachAsset('powerpuffGirl', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ girlGraphics.tint = color;
+ self.x = x;
+ self.y = y;
+ self.canShoot = true;
+ self.shoot = function () {
+ if (!self.canShoot) return;
+ self.canShoot = false;
+ // Animation
+ tween(girlGraphics, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ tween(girlGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ // Create basketball
+ var ball = new Basketball(self.x, self.y);
+ game.addChild(ball);
+ basketballs.push(ball);
+ LK.getSound('shoot').play();
+ // Reset shoot ability
+ LK.setTimeout(function () {
+ self.canShoot = true;
+ }, 1000);
+ };
+ self.down = function (x, y, obj) {
+ if (gameState === 'playing') {
+ self.shoot();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var gameState = 'menu'; // 'menu', 'playing'
+var currentLevel = 1;
+var maxUnlockedLevel = 1;
+var score = 0;
+var levelTargets = [3, 5, 8, 10, 15, 20]; // Targets for each level
+var levelColors = [0xFF69B4, 0xFF1493, 0xFF69B4, 0xFF1493, 0xFF69B4, 0xFF1493];
+// Game objects
+var levelBalls = [];
+var powerpuffGirls = [];
+var basketballs = [];
+var hoop;
+var hoopX = 1750;
+var hoopY = 800;
+// UI elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var levelTxt = new Text2('Level 1', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+levelTxt.anchor.set(0.5, 0);
+levelTxt.y = 100;
+LK.gui.top.addChild(levelTxt);
+var targetTxt = new Text2('Target: 3', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+targetTxt.anchor.set(0.5, 0);
+targetTxt.y = 170;
+LK.gui.top.addChild(targetTxt);
+var instructionTxt = new Text2('Tap colored balls to select level', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+instructionTxt.anchor.set(0.5, 0.5);
+instructionTxt.x = 1024;
+instructionTxt.y = 2400;
+game.addChild(instructionTxt);
+// Initialize level selection balls
+function initializeLevelBalls() {
+ var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
+ var startX = 300;
+ var startY = 1200;
+ for (var i = 0; i < 6; i++) {
+ var ball = new LevelBall(i + 1, colors[i], startX + i % 3 * 300, startY + Math.floor(i / 3) * 300);
+ levelBalls.push(ball);
+ game.addChild(ball);
+ }
+ // Unlock first level
+ levelBalls[0].unlock();
+}
+// Initialize gameplay elements
+function initializeGameplay() {
+ // Create hoop
+ hoop = new Hoop(hoopX, hoopY);
+ game.addChild(hoop);
+ // Create Powerpuff Girls
+ var girlPositions = [{
+ x: 300,
+ y: 2000
+ }, {
+ x: 600,
+ y: 2000
+ }, {
+ x: 900,
+ y: 2000
+ }];
+ for (var i = 0; i < 3; i++) {
+ var girl = new PowerpuffGirl(girlPositions[i].x, girlPositions[i].y, levelColors[i]);
+ powerpuffGirls.push(girl);
+ game.addChild(girl);
+ }
+}
+// Start a specific level
+function startLevel(level) {
+ currentLevel = level;
+ gameState = 'playing';
+ score = 0;
+ LK.setScore(0);
+ // Hide level selection
+ for (var i = 0; i < levelBalls.length; i++) {
+ levelBalls[i].visible = false;
+ }
+ instructionTxt.visible = false;
+ // Show gameplay elements
+ hoop.visible = true;
+ for (var i = 0; i < powerpuffGirls.length; i++) {
+ powerpuffGirls[i].visible = true;
+ }
+ // Update UI
+ levelTxt.setText('Level ' + level);
+ targetTxt.setText('Target: ' + levelTargets[level - 1]);
+ scoreTxt.setText('Score: 0');
+ // Level-specific modifications
+ if (level > 3) {
+ // Make hoop move for higher levels
+ tween(hoop, {
+ x: hoopX - 200
+ }, {
+ duration: 2000,
+ easing: tween.easeInOut
+ });
+ tween(hoop, {
+ x: hoopX + 200
+ }, {
+ duration: 4000,
+ easing: tween.easeInOut
+ });
+ }
+}
+// Complete current level
+function completeLevel() {
+ LK.getSound('levelComplete').play();
+ LK.effects.flashScreen(0x00FF00, 1000);
+ // Unlock next level
+ if (currentLevel < 6) {
+ maxUnlockedLevel = Math.max(maxUnlockedLevel, currentLevel + 1);
+ levelBalls[currentLevel].unlock();
+ }
+ // Return to menu after delay
+ LK.setTimeout(function () {
+ returnToMenu();
+ }, 2000);
+}
+// Return to level selection menu
+function returnToMenu() {
+ gameState = 'menu';
+ // Hide gameplay elements
+ hoop.visible = false;
+ for (var i = 0; i < powerpuffGirls.length; i++) {
+ powerpuffGirls[i].visible = false;
+ }
+ // Clear basketballs
+ for (var i = basketballs.length - 1; i >= 0; i--) {
+ basketballs[i].destroy();
+ basketballs.splice(i, 1);
+ }
+ // Show level selection
+ for (var i = 0; i < levelBalls.length; i++) {
+ levelBalls[i].visible = true;
+ if (i < maxUnlockedLevel) {
+ levelBalls[i].unlock();
+ } else {
+ levelBalls[i].lock();
+ }
+ }
+ instructionTxt.visible = true;
+ // Update UI
+ levelTxt.setText('Select Level');
+ targetTxt.setText('Tap to play');
+ scoreTxt.setText('Score: ' + LK.getScore());
+}
+// Initialize game
+initializeLevelBalls();
+initializeGameplay();
+// Hide gameplay elements initially
+hoop.visible = false;
+for (var i = 0; i < powerpuffGirls.length; i++) {
+ powerpuffGirls[i].visible = false;
+}
+// Game update loop
+game.update = function () {
+ if (gameState === 'playing') {
+ // Update basketballs
+ for (var i = basketballs.length - 1; i >= 0; i--) {
+ var ball = basketballs[i];
+ if (ball.shouldRemove) {
+ ball.destroy();
+ basketballs.splice(i, 1);
+ }
+ }
+ // Level-specific updates
+ if (currentLevel > 3 && LK.ticks % 240 === 0) {
+ // Continue hoop movement animation
+ if (hoop.x <= hoopX - 190) {
+ tween(hoop, {
+ x: hoopX + 200
+ }, {
+ duration: 4000,
+ easing: tween.easeInOut
+ });
+ } else if (hoop.x >= hoopX + 190) {
+ tween(hoop, {
+ x: hoopX - 200
+ }, {
+ duration: 4000,
+ easing: tween.easeInOut
+ });
+ }
+ }
+ }
+};
+// Initial UI setup
+levelTxt.setText('Select Level');
+targetTxt.setText('Tap to play');
+scoreTxt.setText('Score: 0');
\ No newline at end of file