User prompt
que la extructura sean cerdos y alrededor las toirres
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'removeChild')' in or related to this line: 'birds[0].parent.removeChild(birds[0]);' Line Number: 267
User prompt
pon un boton en la esquina que aya una flecha para arriba que si le das se reinicie ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
que sean grandes los puercos
User prompt
arriba
User prompt
que los cerdos esten arriba de las torres y alrededor
User prompt
y que desaparezca el pajaro
User prompt
que los pajaros exploten y dejen una textura al principio como d eplumas rojas ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
que sean mas grande los pajaros
User prompt
pon muchas ma storres y que encima ayan cerdos
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'removeChild')' in or related to this line: 'self.parent.removeChild(self);' Line Number: 121
User prompt
que dispare mas largo
User prompt
que cuando toque el suelo rebote
User prompt
que la catapulta este ams alante
User prompt
que tengan ams fuerza
User prompt
pero que solo gane si derribo todas ls torres
Code edit (1 edits merged)
Please save this source code
User prompt
Slingshot Birds
Initial prompt
un juego estilo angry birds
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.isLaunched = false; self.isActive = true; self.gravity = 0.5; self.hasUsedAbility = false; self.update = function () { if (self.isLaunched && self.isActive) { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Check ground collision if (self.y >= groundY - 30) { self.y = groundY - 30; self.velocityX *= 0.5; self.velocityY = -self.velocityY * 0.6; // Bounce with 60% of velocity if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) { self.isActive = false; checkLevelComplete(); } } // Check screen boundaries if (self.x > 2048 + 100) { self.isActive = false; checkLevelComplete(); } } }; self.launch = function (velX, velY) { self.velocityX = velX; self.velocityY = velY; self.isLaunched = true; LK.getSound('launch').play(); }; self.useAbility = function () { if (!self.hasUsedAbility && self.isLaunched) { self.hasUsedAbility = true; // Simple ability: speed boost self.velocityX *= 2.5; self.velocityY *= 2.5; } }; return self; }); var Block = Container.expand(function (type) { var self = Container.call(this); var blockGraphics = self.attachAsset(type === 'wood' ? 'woodBlock' : 'stoneBlock', { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.health = type === 'wood' ? 1 : 2; self.velocityX = 0; self.velocityY = 0; self.isActive = false; self.gravity = 0.3; self.update = function () { if (self.isActive) { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Ground collision if (self.y >= groundY - 50) { self.y = groundY - 50; self.velocityX *= 0.3; self.velocityY = 0; if (Math.abs(self.velocityX) < 0.2) { self.isActive = false; } } } }; self.takeDamage = function (damage, impactX, impactY) { self.health -= damage * 2; LK.getSound('hit').play(); if (self.health <= 0) { self.destroy(); } else { // Add some physics impact self.velocityX = (impactX - self.x) * 0.15; self.velocityY = (impactY - self.y) * 0.15; self.isActive = true; } }; self.destroy = function () { LK.effects.flashObject(self, 0xffff00, 300); tween(self, { alpha: 0, rotation: Math.PI }, { duration: 1000, onFinish: function onFinish() { if (self.parent) { self.parent.removeChild(self); } var blockIndex = blocks.indexOf(self); if (blockIndex !== -1) { blocks.splice(blockIndex, 1); } } }); }; return self; }); var Pig = Container.expand(function () { var self = Container.call(this); var pigGraphics = self.attachAsset('pig', { anchorX: 0.5, anchorY: 0.5 }); self.isDestroyed = false; self.health = 1; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { self.destroy(); } }; self.destroy = function () { if (!self.isDestroyed) { self.isDestroyed = true; LK.effects.flashObject(self, 0xff0000, 500); LK.getSound('destroy').play(); tween(self, { alpha: 0, scaleX: 0.1, scaleY: 0.1 }, { duration: 500, onFinish: function onFinish() { if (self.parent) { self.parent.removeChild(self); } var pigIndex = pigs.indexOf(self); if (pigIndex !== -1) { pigs.splice(pigIndex, 1); } checkLevelComplete(); } }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var groundY = 2732 - 100; var slingshotX = 400; var slingshotY = groundY - 150; var birds = []; var pigs = []; var blocks = []; var currentBird = null; var trajectoryDots = []; var isDragging = false; var dragStartX = 0; var dragStartY = 0; var gameState = 'aiming'; // 'aiming', 'flying', 'waiting' var levelComplete = false; // Create ground var ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 0, x: 0, y: groundY })); // Create slingshot var slingshot = game.addChild(LK.getAsset('slingshot', { anchorX: 0.5, anchorY: 1, x: slingshotX, y: slingshotY })); // Create trajectory dots for (var i = 0; i < 20; i++) { var dot = game.addChild(LK.getAsset('trajectory', { anchorX: 0.5, anchorY: 0.5, alpha: 0 })); trajectoryDots.push(dot); } // Create level structure function createLevel() { // Clear existing level while (birds.length > 0) { birds[0].parent.removeChild(birds[0]); birds.splice(0, 1); } while (pigs.length > 0) { pigs[0].parent.removeChild(pigs[0]); pigs.splice(0, 1); } while (blocks.length > 0) { blocks[0].parent.removeChild(blocks[0]); blocks.splice(0, 1); } // Create birds for (var i = 0; i < 3; i++) { var bird = new Bird(); bird.x = slingshotX - 100 - i * 80; bird.y = slingshotY - 30; birds.push(bird); game.addChild(bird); } // Create structure with blocks and pigs var structureX = 1600; var structureY = groundY; // Create blocks for (var i = 0; i < 3; i++) { var block = new Block('wood'); block.x = structureX + i * 60; block.y = structureY - 50; blocks.push(block); game.addChild(block); } // Create upper level blocks for (var i = 0; i < 2; i++) { var block = new Block('wood'); block.x = structureX + 30 + i * 60; block.y = structureY - 150; blocks.push(block); game.addChild(block); } // Create pigs var pig1 = new Pig(); pig1.x = structureX + 30; pig1.y = structureY - 100; pigs.push(pig1); game.addChild(pig1); var pig2 = new Pig(); pig2.x = structureX + 90; pig2.y = structureY - 100; pigs.push(pig2); game.addChild(pig2); // Set current bird currentBird = birds[0]; currentBird.x = slingshotX; currentBird.y = slingshotY - 30; gameState = 'aiming'; levelComplete = false; } function updateTrajectory(mouseX, mouseY) { var deltaX = mouseX - slingshotX; var deltaY = mouseY - slingshotY; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (distance > 150) { deltaX = deltaX / distance * 150; deltaY = deltaY / distance * 150; } var velocityX = -deltaX * 0.2; var velocityY = -deltaY * 0.2; for (var i = 0; i < trajectoryDots.length; i++) { var t = i * 3; var x = slingshotX + velocityX * t; var y = slingshotY - 30 + velocityY * t + 0.5 * 0.5 * t * t; trajectoryDots[i].x = x; trajectoryDots[i].y = y; trajectoryDots[i].alpha = Math.max(0, 1 - i * 0.05); } } function hideTrajectory() { for (var i = 0; i < trajectoryDots.length; i++) { trajectoryDots[i].alpha = 0; } } function checkCollisions() { if (!currentBird || !currentBird.isLaunched) return; // Check bird-pig collisions for (var i = 0; i < pigs.length; i++) { var pig = pigs[i]; if (!pig.isDestroyed && currentBird.intersects(pig)) { pig.takeDamage(1); currentBird.isActive = false; checkLevelComplete(); return; } } // Check bird-block collisions for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; if (currentBird.intersects(block)) { block.takeDamage(1, currentBird.x, currentBird.y); currentBird.isActive = false; checkLevelComplete(); return; } } } function checkLevelComplete() { if (levelComplete) return; // Check if all blocks are destroyed var activeBlocks = 0; for (var i = 0; i < blocks.length; i++) { activeBlocks++; } if (activeBlocks === 0) { levelComplete = true; LK.setTimeout(function () { LK.showYouWin(); }, 1000); return; } // Check if current bird is inactive and we need next bird if (currentBird && !currentBird.isActive && gameState === 'flying') { gameState = 'waiting'; hideTrajectory(); LK.setTimeout(function () { // Find next bird var nextBirdIndex = birds.indexOf(currentBird) + 1; if (nextBirdIndex < birds.length) { currentBird = birds[nextBirdIndex]; currentBird.x = slingshotX; currentBird.y = slingshotY - 30; gameState = 'aiming'; } else { // No more birds, game over LK.showGameOver(); } }, 1000); } } // Game event handlers game.down = function (x, y, obj) { if (gameState === 'aiming' && currentBird) { isDragging = true; dragStartX = x; dragStartY = y; updateTrajectory(x, y); } }; game.move = function (x, y, obj) { if (isDragging && gameState === 'aiming' && currentBird) { var deltaX = x - slingshotX; var deltaY = y - slingshotY; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (distance > 150) { deltaX = deltaX / distance * 150; deltaY = deltaY / distance * 150; } currentBird.x = slingshotX + deltaX; currentBird.y = slingshotY - 30 + deltaY; updateTrajectory(x, y); } }; game.up = function (x, y, obj) { if (isDragging && gameState === 'aiming' && currentBird) { isDragging = false; var deltaX = currentBird.x - slingshotX; var deltaY = currentBird.y - (slingshotY - 30); var velocityX = -deltaX * 0.2; var velocityY = -deltaY * 0.2; if (Math.abs(velocityX) > 1 || Math.abs(velocityY) > 1) { currentBird.launch(velocityX, velocityY); gameState = 'flying'; hideTrajectory(); } else { currentBird.x = slingshotX; currentBird.y = slingshotY - 30; hideTrajectory(); } } else if (gameState === 'flying' && currentBird) { // Use bird ability currentBird.useAbility(); } }; game.update = function () { checkCollisions(); // Update blocks physics for (var i = 0; i < blocks.length; i++) { var block = blocks[i]; // Check block-pig collisions for (var j = 0; j < pigs.length; j++) { var pig = pigs[j]; if (!pig.isDestroyed && block.intersects(pig)) { pig.takeDamage(1); } } } }; // Initialize level createLevel();
===================================================================
--- original.js
+++ change.js
@@ -103,10 +103,15 @@
rotation: Math.PI
}, {
duration: 1000,
onFinish: function onFinish() {
- self.parent.removeChild(self);
- blocks.splice(blocks.indexOf(self), 1);
+ if (self.parent) {
+ self.parent.removeChild(self);
+ }
+ var blockIndex = blocks.indexOf(self);
+ if (blockIndex !== -1) {
+ blocks.splice(blockIndex, 1);
+ }
}
});
};
return self;
@@ -136,10 +141,15 @@
scaleY: 0.1
}, {
duration: 500,
onFinish: function onFinish() {
- self.parent.removeChild(self);
- pigs.splice(pigs.indexOf(self), 1);
+ if (self.parent) {
+ self.parent.removeChild(self);
+ }
+ var pigIndex = pigs.indexOf(self);
+ if (pigIndex !== -1) {
+ pigs.splice(pigIndex, 1);
+ }
checkLevelComplete();
}
});
}