User prompt
Add angry birds music
User prompt
Whe use blue bird on level 6, 7, 8 and 9
User prompt
İf we touch the screen blue bird launch a copies
User prompt
İf you touch the screen after throwing the blue bird, 2 copies of the blue bird will be created, one above and one below
User prompt
Delete blocks on level 10
User prompt
When level 6 we always use blue bird
User prompt
When level 6 we use blue bird
User prompt
Make level 10 hardest
User prompt
Add 5 more block on level 10
User prompt
İn level 10 use a King pig
User prompt
Add level 8 level 9 and level 10 if we complete level 10 the game will end use less block
User prompt
Add level 5 level 6 and level 7 they could be easy and if we complete level 7 the game will end use less block
User prompt
İf pigs are down they die
User prompt
Add a physic for pigs
User prompt
Add a physic for blocks
User prompt
Add level 4 it could be easy and if we complete level 4 the game will end use less block
User prompt
Add level 3, it could ve east and if we complete level 3 the game will end
User prompt
Add level 3 and if we complete level 3 the game will end
User prompt
Add level 3 and if we complete level 3 the game will end
User prompt
Add level 3 and of we complete level 3 the game will end
User prompt
Add 3 more bird
User prompt
Add level 2 and of we complete level 2 the game will end
User prompt
Add level 2 when we completed level 2 game end
User prompt
Add 1 more bird
User prompt
Add 1 more bird
/**** * 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.launched = false; self.gravity = 0.3; self.bounce = 0.3; self.update = function () { if (self.launched) { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Ground collision if (self.y > 2600) { self.y = 2600; self.velocityY *= -self.bounce; self.velocityX *= 0.8; if (Math.abs(self.velocityY) < 2) { self.velocityY = 0; } } // Side boundaries if (self.x < 0 || self.x > 2048) { self.velocityX *= -self.bounce; } } }; self.launch = function (velX, velY) { self.launched = true; self.velocityX = velX; self.velocityY = velY; LK.getSound('launch').play(); }; return self; }); var Block = Container.expand(function (type) { var self = Container.call(this); var assetName = type + 'Block'; var blockGraphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.health = type === 'wood' ? 50 : type === 'stone' ? 100 : 30; // ice is weakest self.destroyed = false; // Physics properties self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.bounce = 0.4; self.friction = 0.8; self.mass = type === 'stone' ? 3 : type === 'wood' ? 2 : 1; // ice is lightest self.isStatic = true; // blocks start as static until hit self.update = function () { if (!self.isStatic && !self.destroyed) { // Apply gravity self.velocityY += self.gravity; // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Ground collision if (self.y > 2580) { // account for block height self.y = 2580; self.velocityY *= -self.bounce; self.velocityX *= self.friction; if (Math.abs(self.velocityY) < 1) { self.velocityY = 0; self.isStatic = true; // become static again when settled } } // Side boundaries if (self.x < 60 || self.x > 1988) { // account for block width self.velocityX *= -self.bounce; } // Friction when moving slowly if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) { self.velocityX *= 0.9; } } }; self.applyForce = function (forceX, forceY) { self.isStatic = false; // become dynamic when force is applied self.velocityX += forceX / self.mass; self.velocityY += forceY / self.mass; }; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0 && !self.destroyed) { self.destroyed = true; LK.effects.flashObject(self, 0xff0000, 200); LK.getSound('hit').play(); LK.setScore(LK.getScore() + 10); scoreText.setText(LK.getScore()); } }; return self; }); var Pig = Container.expand(function () { var self = Container.call(this); var pigGraphics = self.attachAsset('pig', { anchorX: 0.5, anchorY: 0.5 }); self.health = 100; self.destroyed = false; // Physics properties self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.bounce = 0.4; self.friction = 0.8; self.mass = 1.5; // pigs have moderate mass self.isStatic = true; // pigs start as static until hit self.update = function () { if (!self.isStatic && !self.destroyed) { // Apply gravity self.velocityY += self.gravity; // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Ground collision if (self.y > 2580) { // account for pig height self.y = 2580; self.velocityY *= -self.bounce; self.velocityX *= self.friction; if (Math.abs(self.velocityY) < 1) { self.velocityY = 0; self.isStatic = true; // become static again when settled } } // Side boundaries if (self.x < 50 || self.x > 1998) { // account for pig width self.velocityX *= -self.bounce; } // Friction when moving slowly if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) { self.velocityX *= 0.9; } } }; self.applyForce = function (forceX, forceY) { self.isStatic = false; // become dynamic when force is applied self.velocityX += forceX / self.mass; self.velocityY += forceY / self.mass; }; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0 && !self.destroyed) { self.destroyed = true; LK.effects.flashObject(self, 0xffff00, 300); LK.getSound('destroy').play(); LK.setScore(LK.getScore() + 100); scoreText.setText(LK.getScore()); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game variables var birds = []; var pigs = []; var blocks = []; var currentBird = null; var slingshot = null; var isDragging = false; var trajectoryDots = []; var slingshotX = 200; var slingshotY = 2400; var birdsRemaining = 8; var level = 1; // UI Elements var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var birdsText = new Text2('Birds: 8', { size: 50, fill: 0xFFFFFF }); birdsText.anchor.set(0, 0); birdsText.x = 100; birdsText.y = 100; LK.gui.topLeft.addChild(birdsText); var levelText = new Text2('Level: 1', { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(1, 0); levelText.x = -100; levelText.y = 100; LK.gui.topRight.addChild(levelText); // Create ground var ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 1, x: 0, y: 2732 })); // Create clouds for background atmosphere var cloud1 = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: 300, y: 400, alpha: 0.8 })); var cloud2 = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: 800, y: 300, alpha: 0.7 })); var cloud3 = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: 1400, y: 450, alpha: 0.6 })); var cloud4 = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: 1800, y: 350, alpha: 0.8 })); // Create slingshot slingshot = game.addChild(LK.getAsset('slingshot', { anchorX: 0.5, anchorY: 1, x: slingshotX, y: slingshotY })); // Create level structures function createLevel1() { // Create pigs var pig1 = game.addChild(new Pig()); pig1.x = 1400; pig1.y = 2300; pigs.push(pig1); var pig2 = game.addChild(new Pig()); pig2.x = 1600; pig2.y = 2200; pigs.push(pig2); // Additional pigs var pig3 = game.addChild(new Pig()); pig3.x = 1250; pig3.y = 2300; pigs.push(pig3); var pig4 = game.addChild(new Pig()); pig4.x = 1400; pig4.y = 2100; pigs.push(pig4); var pig5 = game.addChild(new Pig()); pig5.x = 1750; pig5.y = 2200; pigs.push(pig5); // Create structure var block1 = game.addChild(new Block('wood')); block1.x = 1300; block1.y = 2350; blocks.push(block1); var block2 = game.addChild(new Block('wood')); block2.x = 1500; block2.y = 2350; blocks.push(block2); var block3 = game.addChild(new Block('stone')); block3.x = 1400; block3.y = 2250; blocks.push(block3); var block4 = game.addChild(new Block('ice')); block4.x = 1600; block4.y = 2300; blocks.push(block4); // Additional foundation blocks var block5 = game.addChild(new Block('wood')); block5.x = 1200; block5.y = 2350; blocks.push(block5); var block6 = game.addChild(new Block('wood')); block6.x = 1700; block6.y = 2350; blocks.push(block6); // Upper level blocks var block7 = game.addChild(new Block('ice')); block7.x = 1350; block7.y = 2200; blocks.push(block7); var block8 = game.addChild(new Block('ice')); block8.x = 1450; block8.y = 2200; blocks.push(block8); // Top blocks var block9 = game.addChild(new Block('stone')); block9.x = 1400; block9.y = 2150; blocks.push(block9); // Side tower blocks var block10 = game.addChild(new Block('wood')); block10.x = 1750; block10.y = 2300; blocks.push(block10); var block11 = game.addChild(new Block('ice')); block11.x = 1750; block11.y = 2250; blocks.push(block11); } // Initialize first bird function createNewBird() { if (birdsRemaining > 0) { currentBird = game.addChild(new Bird()); currentBird.x = slingshotX; currentBird.y = slingshotY - 100; birds.push(currentBird); } } // Trajectory calculation function calculateTrajectory(startX, startY, velX, velY) { var dots = []; var x = startX; var y = startY; var vx = velX; var vy = velY; var gravity = 0.3; for (var i = 0; i < 50; i += 3) { dots.push({ x: x, y: y }); vx *= 0.99; vy += gravity; x += vx * 3; y += vy * 3; if (y > 2600 || x > 2048) break; } return dots; } // Clear trajectory dots function clearTrajectory() { for (var i = 0; i < trajectoryDots.length; i++) { trajectoryDots[i].destroy(); } trajectoryDots = []; } // Show trajectory dots function showTrajectory(dots) { clearTrajectory(); for (var i = 0; i < dots.length; i++) { var dot = game.addChild(LK.getAsset('trajectory', { anchorX: 0.5, anchorY: 0.5, x: dots[i].x, y: dots[i].y, alpha: 0.5 })); trajectoryDots.push(dot); } } // Check collisions function checkCollisions() { for (var i = 0; i < birds.length; i++) { var bird = birds[i]; if (!bird.launched) continue; // Check bird vs pigs for (var j = 0; j < pigs.length; j++) { var pig = pigs[j]; if (!pig.destroyed && bird.intersects(pig)) { var damage = Math.abs(bird.velocityX) + Math.abs(bird.velocityY); pig.takeDamage(damage * 2); // Apply physics force to pig based on bird's velocity and mass var forceX = bird.velocityX * 0.6; var forceY = bird.velocityY * 0.6; pig.applyForce(forceX, forceY); bird.velocityX *= 0.3; bird.velocityY *= 0.3; } } // Check bird vs blocks for (var k = 0; k < blocks.length; k++) { var block = blocks[k]; if (!block.destroyed && bird.intersects(block)) { var damage = Math.abs(bird.velocityX) + Math.abs(bird.velocityY); block.takeDamage(damage); // Apply physics force to block based on bird's velocity and mass var forceX = bird.velocityX * 0.8; var forceY = bird.velocityY * 0.8; block.applyForce(forceX, forceY); bird.velocityX *= 0.5; bird.velocityY *= 0.5; } } // Check block vs block collisions for (var m = 0; m < blocks.length; m++) { var block1 = blocks[m]; if (block1.destroyed || block1.isStatic) continue; for (var n = m + 1; n < blocks.length; n++) { var block2 = blocks[n]; if (block2.destroyed) continue; if (block1.intersects(block2)) { // Calculate collision response var dx = block2.x - block1.x; var dy = block2.y - block1.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { // Normalize collision vector dx /= distance; dy /= distance; // Separate blocks var overlap = (block1.width + block2.width) / 2 - distance; if (overlap > 0) { block1.x -= dx * overlap * 0.5; block1.y -= dy * overlap * 0.5; block2.x += dx * overlap * 0.5; block2.y += dy * overlap * 0.5; } // Exchange velocities based on mass var totalMass = block1.mass + block2.mass; var v1 = block1.velocityX * dx + block1.velocityY * dy; var v2 = block2.velocityX * dx + block2.velocityY * dy; var newV1 = ((block1.mass - block2.mass) * v1 + 2 * block2.mass * v2) / totalMass; var newV2 = ((block2.mass - block1.mass) * v2 + 2 * block1.mass * v1) / totalMass; block1.velocityX += (newV1 - v1) * dx * 0.8; block1.velocityY += (newV1 - v1) * dy * 0.8; if (!block2.isStatic) { block2.velocityX += (newV2 - v2) * dx * 0.8; block2.velocityY += (newV2 - v2) * dy * 0.8; } else { // Make static block dynamic if hit hard enough var impact = Math.abs(newV1 - v1); if (impact > 2) { block2.applyForce((newV2 - v2) * dx * block2.mass, (newV2 - v2) * dy * block2.mass); } } } } } } // Check pig vs pig collisions for (var p = 0; p < pigs.length; p++) { var pig1 = pigs[p]; if (pig1.destroyed || pig1.isStatic) continue; for (var q = p + 1; q < pigs.length; q++) { var pig2 = pigs[q]; if (pig2.destroyed) continue; if (pig1.intersects(pig2)) { // Calculate collision response var dx = pig2.x - pig1.x; var dy = pig2.y - pig1.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { // Normalize collision vector dx /= distance; dy /= distance; // Separate pigs var overlap = (pig1.width + pig2.width) / 2 - distance; if (overlap > 0) { pig1.x -= dx * overlap * 0.5; pig1.y -= dy * overlap * 0.5; pig2.x += dx * overlap * 0.5; pig2.y += dy * overlap * 0.5; } // Exchange velocities based on mass var totalMass = pig1.mass + pig2.mass; var v1 = pig1.velocityX * dx + pig1.velocityY * dy; var v2 = pig2.velocityX * dx + pig2.velocityY * dy; var newV1 = ((pig1.mass - pig2.mass) * v1 + 2 * pig2.mass * v2) / totalMass; var newV2 = ((pig2.mass - pig1.mass) * v2 + 2 * pig1.mass * v1) / totalMass; pig1.velocityX += (newV1 - v1) * dx * 0.7; pig1.velocityY += (newV1 - v1) * dy * 0.7; if (!pig2.isStatic) { pig2.velocityX += (newV2 - v2) * dx * 0.7; pig2.velocityY += (newV2 - v2) * dy * 0.7; } else { // Make static pig dynamic if hit hard enough var impact = Math.abs(newV1 - v1); if (impact > 1.5) { pig2.applyForce((newV2 - v2) * dx * pig2.mass, (newV2 - v2) * dy * pig2.mass); } } } } } } // Check pig vs block collisions for (var r = 0; r < pigs.length; r++) { var pig = pigs[r]; if (pig.destroyed || pig.isStatic) continue; for (var s = 0; s < blocks.length; s++) { var block = blocks[s]; if (block.destroyed) continue; if (pig.intersects(block)) { // Calculate collision response var dx = block.x - pig.x; var dy = block.y - pig.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { // Normalize collision vector dx /= distance; dy /= distance; // Separate pig and block var overlap = (pig.width + block.width) / 2 - distance; if (overlap > 0) { pig.x -= dx * overlap * 0.5; pig.y -= dy * overlap * 0.5; block.x += dx * overlap * 0.5; block.y += dy * overlap * 0.5; } // Exchange velocities based on mass var totalMass = pig.mass + block.mass; var v1 = pig.velocityX * dx + pig.velocityY * dy; var v2 = block.velocityX * dx + block.velocityY * dy; var newV1 = ((pig.mass - block.mass) * v1 + 2 * block.mass * v2) / totalMass; var newV2 = ((block.mass - pig.mass) * v2 + 2 * pig.mass * v1) / totalMass; pig.velocityX += (newV1 - v1) * dx * 0.6; pig.velocityY += (newV1 - v1) * dy * 0.6; if (!block.isStatic) { block.velocityX += (newV2 - v2) * dx * 0.6; block.velocityY += (newV2 - v2) * dy * 0.6; } else { // Make static block dynamic if hit hard enough var impact = Math.abs(newV1 - v1); if (impact > 1.8) { block.applyForce((newV2 - v2) * dx * block.mass, (newV2 - v2) * dy * block.mass); } } } } } } } } // Check win condition function checkWinCondition() { var allPigsDestroyed = true; for (var i = 0; i < pigs.length; i++) { if (!pigs[i].destroyed) { allPigsDestroyed = false; break; } } if (allPigsDestroyed) { if (level === 1) { // Progress to level 2 LK.setTimeout(function () { level = 2; levelText.setText('Level: ' + level); birdsRemaining = 8; birdsText.setText('Birds: ' + birdsRemaining); // Clear existing objects for (var i = 0; i < blocks.length; i++) { blocks[i].destroy(); } blocks = []; for (var j = 0; j < pigs.length; j++) { pigs[j].destroy(); } pigs = []; for (var k = 0; k < birds.length; k++) { birds[k].destroy(); } birds = []; currentBird = null; // Initialize level 2 initializeLevel(); createNewBird(); }, 1000); } else if (level === 2) { // Progress to level 3 LK.setTimeout(function () { level = 3; levelText.setText('Level: ' + level); birdsRemaining = 8; birdsText.setText('Birds: ' + birdsRemaining); // Clear existing objects for (var i = 0; i < blocks.length; i++) { blocks[i].destroy(); } blocks = []; for (var j = 0; j < pigs.length; j++) { pigs[j].destroy(); } pigs = []; for (var k = 0; k < birds.length; k++) { birds[k].destroy(); } birds = []; currentBird = null; // Initialize level 3 initializeLevel(); createNewBird(); }, 1000); } else if (level === 3) { // Progress to level 4 LK.setTimeout(function () { level = 4; levelText.setText('Level: ' + level); birdsRemaining = 8; birdsText.setText('Birds: ' + birdsRemaining); // Clear existing objects for (var i = 0; i < blocks.length; i++) { blocks[i].destroy(); } blocks = []; for (var j = 0; j < pigs.length; j++) { pigs[j].destroy(); } pigs = []; for (var k = 0; k < birds.length; k++) { birds[k].destroy(); } birds = []; currentBird = null; // Initialize level 4 initializeLevel(); createNewBird(); }, 1000); } else if (level === 4) { // Game completed LK.setTimeout(function () { LK.showYouWin(); }, 1000); } } else if (birdsRemaining <= 0 && (!currentBird || currentBird.launched && Math.abs(currentBird.velocityX) < 1 && Math.abs(currentBird.velocityY) < 1)) { LK.setTimeout(function () { LK.showGameOver(); }, 1000); } } // Game event handlers game.down = function (x, y, obj) { if (currentBird && !currentBird.launched) { isDragging = true; } }; game.move = function (x, y, obj) { if (isDragging && currentBird && !currentBird.launched) { var maxDistance = 150; var deltaX = slingshotX - x; var deltaY = slingshotY - 100 - y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); if (distance > maxDistance) { deltaX = deltaX / distance * maxDistance; deltaY = deltaY / distance * maxDistance; } currentBird.x = slingshotX - deltaX; currentBird.y = slingshotY - 100 - deltaY; // Show trajectory var velX = deltaX * 0.2; var velY = deltaY * 0.2; var trajectoryPoints = calculateTrajectory(currentBird.x, currentBird.y, velX, velY); showTrajectory(trajectoryPoints); } }; game.up = function (x, y, obj) { if (isDragging && currentBird && !currentBird.launched) { isDragging = false; clearTrajectory(); var deltaX = slingshotX - currentBird.x; var deltaY = slingshotY - 100 - currentBird.y; if (Math.abs(deltaX) > 5 || Math.abs(deltaY) > 5) { currentBird.launch(deltaX * 0.2, deltaY * 0.2); birdsRemaining--; birdsText.setText('Birds: ' + birdsRemaining); LK.setTimeout(function () { createNewBird(); }, 2000); } } }; // Main game update game.update = function () { checkCollisions(); checkWinCondition(); // Remove destroyed objects for (var i = blocks.length - 1; i >= 0; i--) { if (blocks[i].destroyed) { blocks[i].destroy(); blocks.splice(i, 1); } } for (var j = pigs.length - 1; j >= 0; j--) { if (pigs[j].destroyed) { pigs[j].alpha = Math.max(0, pigs[j].alpha - 0.02); if (pigs[j].alpha <= 0) { pigs[j].destroy(); pigs.splice(j, 1); } } } }; // Create level 2 structures function createLevel2() { // Create more pigs for level 2 var pig1 = game.addChild(new Pig()); pig1.x = 1300; pig1.y = 2300; pigs.push(pig1); var pig2 = game.addChild(new Pig()); pig2.x = 1500; pig2.y = 2300; pigs.push(pig2); var pig3 = game.addChild(new Pig()); pig3.x = 1700; pig3.y = 2300; pigs.push(pig3); var pig4 = game.addChild(new Pig()); pig4.x = 1400; pig4.y = 2150; pigs.push(pig4); var pig5 = game.addChild(new Pig()); pig5.x = 1600; pig5.y = 2150; pigs.push(pig5); var pig6 = game.addChild(new Pig()); pig6.x = 1500; pig6.y = 2000; pigs.push(pig6); // Create more complex structure for level 2 // Base foundation var block1 = game.addChild(new Block('stone')); block1.x = 1250; block1.y = 2350; blocks.push(block1); var block2 = game.addChild(new Block('stone')); block2.x = 1350; block2.y = 2350; blocks.push(block2); var block3 = game.addChild(new Block('stone')); block3.x = 1450; block3.y = 2350; blocks.push(block3); var block4 = game.addChild(new Block('stone')); block4.x = 1550; block4.y = 2350; blocks.push(block4); var block5 = game.addChild(new Block('stone')); block5.x = 1650; block5.y = 2350; blocks.push(block5); var block6 = game.addChild(new Block('stone')); block6.x = 1750; block6.y = 2350; blocks.push(block6); // Second level var block7 = game.addChild(new Block('wood')); block7.x = 1300; block7.y = 2250; blocks.push(block7); var block8 = game.addChild(new Block('wood')); block8.x = 1400; block8.y = 2250; blocks.push(block8); var block9 = game.addChild(new Block('wood')); block9.x = 1500; block9.y = 2250; blocks.push(block9); var block10 = game.addChild(new Block('wood')); block10.x = 1600; block10.y = 2250; blocks.push(block10); var block11 = game.addChild(new Block('wood')); block11.x = 1700; block11.y = 2250; blocks.push(block11); // Third level var block12 = game.addChild(new Block('ice')); block12.x = 1350; block12.y = 2150; blocks.push(block12); var block13 = game.addChild(new Block('ice')); block13.x = 1450; block13.y = 2150; blocks.push(block13); var block14 = game.addChild(new Block('ice')); block14.x = 1550; block14.y = 2150; blocks.push(block14); var block15 = game.addChild(new Block('ice')); block15.x = 1650; block15.y = 2150; blocks.push(block15); // Top level var block16 = game.addChild(new Block('wood')); block16.x = 1400; block16.y = 2050; blocks.push(block16); var block17 = game.addChild(new Block('wood')); block17.x = 1500; block17.y = 2050; blocks.push(block17); var block18 = game.addChild(new Block('wood')); block18.x = 1600; block18.y = 2050; blocks.push(block18); } // Create level 3 structures function createLevel3() { // Create simple structure with fewer pigs for easier level var pig1 = game.addChild(new Pig()); pig1.x = 1400; pig1.y = 2300; pigs.push(pig1); var pig2 = game.addChild(new Pig()); pig2.x = 1600; pig2.y = 2300; pigs.push(pig2); var pig3 = game.addChild(new Pig()); pig3.x = 1500; pig3.y = 2150; pigs.push(pig3); // Simple structure for level 3 // Base blocks var block1 = game.addChild(new Block('wood')); block1.x = 1350; block1.y = 2350; blocks.push(block1); var block2 = game.addChild(new Block('wood')); block2.x = 1450; block2.y = 2350; blocks.push(block2); var block3 = game.addChild(new Block('wood')); block3.x = 1550; block3.y = 2350; blocks.push(block3); var block4 = game.addChild(new Block('wood')); block4.x = 1650; block4.y = 2350; blocks.push(block4); // Upper blocks var block5 = game.addChild(new Block('ice')); block5.x = 1400; block5.y = 2250; blocks.push(block5); var block6 = game.addChild(new Block('ice')); block6.x = 1500; block6.y = 2250; blocks.push(block6); var block7 = game.addChild(new Block('ice')); block7.x = 1600; block7.y = 2250; blocks.push(block7); // Top block var block8 = game.addChild(new Block('stone')); block8.x = 1500; block8.y = 2200; blocks.push(block8); } // Create level 4 structures function createLevel4() { // Create minimal structure with fewer blocks and pigs for easy final level var pig1 = game.addChild(new Pig()); pig1.x = 1500; pig1.y = 2300; pigs.push(pig1); var pig2 = game.addChild(new Pig()); pig2.x = 1500; pig2.y = 2200; pigs.push(pig2); // Minimal structure for level 4 - fewer blocks // Base blocks var block1 = game.addChild(new Block('ice')); block1.x = 1450; block1.y = 2350; blocks.push(block1); var block2 = game.addChild(new Block('ice')); block2.x = 1550; block2.y = 2350; blocks.push(block2); // Single upper block var block3 = game.addChild(new Block('wood')); block3.x = 1500; block3.y = 2250; blocks.push(block3); } // Initialize level based on current level function initializeLevel() { if (level === 1) { createLevel1(); } else if (level === 2) { createLevel2(); } else if (level === 3) { createLevel3(); } else if (level === 4) { createLevel4(); } } // Initialize level initializeLevel(); createNewBird();
===================================================================
--- original.js
+++ change.js
@@ -116,8 +116,50 @@
anchorY: 0.5
});
self.health = 100;
self.destroyed = false;
+ // Physics properties
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.gravity = 0.3;
+ self.bounce = 0.4;
+ self.friction = 0.8;
+ self.mass = 1.5; // pigs have moderate mass
+ self.isStatic = true; // pigs start as static until hit
+ self.update = function () {
+ if (!self.isStatic && !self.destroyed) {
+ // Apply gravity
+ self.velocityY += self.gravity;
+ // Apply velocity
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Ground collision
+ if (self.y > 2580) {
+ // account for pig height
+ self.y = 2580;
+ self.velocityY *= -self.bounce;
+ self.velocityX *= self.friction;
+ if (Math.abs(self.velocityY) < 1) {
+ self.velocityY = 0;
+ self.isStatic = true; // become static again when settled
+ }
+ }
+ // Side boundaries
+ if (self.x < 50 || self.x > 1998) {
+ // account for pig width
+ self.velocityX *= -self.bounce;
+ }
+ // Friction when moving slowly
+ if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) {
+ self.velocityX *= 0.9;
+ }
+ }
+ };
+ self.applyForce = function (forceX, forceY) {
+ self.isStatic = false; // become dynamic when force is applied
+ self.velocityX += forceX / self.mass;
+ self.velocityY += forceY / self.mass;
+ };
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0 && !self.destroyed) {
self.destroyed = true;
@@ -353,8 +395,14 @@
var pig = pigs[j];
if (!pig.destroyed && bird.intersects(pig)) {
var damage = Math.abs(bird.velocityX) + Math.abs(bird.velocityY);
pig.takeDamage(damage * 2);
+ // Apply physics force to pig based on bird's velocity and mass
+ var forceX = bird.velocityX * 0.6;
+ var forceY = bird.velocityY * 0.6;
+ pig.applyForce(forceX, forceY);
+ bird.velocityX *= 0.3;
+ bird.velocityY *= 0.3;
}
}
// Check bird vs blocks
for (var k = 0; k < blocks.length; k++) {
@@ -415,8 +463,100 @@
}
}
}
}
+ // Check pig vs pig collisions
+ for (var p = 0; p < pigs.length; p++) {
+ var pig1 = pigs[p];
+ if (pig1.destroyed || pig1.isStatic) continue;
+ for (var q = p + 1; q < pigs.length; q++) {
+ var pig2 = pigs[q];
+ if (pig2.destroyed) continue;
+ if (pig1.intersects(pig2)) {
+ // Calculate collision response
+ var dx = pig2.x - pig1.x;
+ var dy = pig2.y - pig1.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ // Normalize collision vector
+ dx /= distance;
+ dy /= distance;
+ // Separate pigs
+ var overlap = (pig1.width + pig2.width) / 2 - distance;
+ if (overlap > 0) {
+ pig1.x -= dx * overlap * 0.5;
+ pig1.y -= dy * overlap * 0.5;
+ pig2.x += dx * overlap * 0.5;
+ pig2.y += dy * overlap * 0.5;
+ }
+ // Exchange velocities based on mass
+ var totalMass = pig1.mass + pig2.mass;
+ var v1 = pig1.velocityX * dx + pig1.velocityY * dy;
+ var v2 = pig2.velocityX * dx + pig2.velocityY * dy;
+ var newV1 = ((pig1.mass - pig2.mass) * v1 + 2 * pig2.mass * v2) / totalMass;
+ var newV2 = ((pig2.mass - pig1.mass) * v2 + 2 * pig1.mass * v1) / totalMass;
+ pig1.velocityX += (newV1 - v1) * dx * 0.7;
+ pig1.velocityY += (newV1 - v1) * dy * 0.7;
+ if (!pig2.isStatic) {
+ pig2.velocityX += (newV2 - v2) * dx * 0.7;
+ pig2.velocityY += (newV2 - v2) * dy * 0.7;
+ } else {
+ // Make static pig dynamic if hit hard enough
+ var impact = Math.abs(newV1 - v1);
+ if (impact > 1.5) {
+ pig2.applyForce((newV2 - v2) * dx * pig2.mass, (newV2 - v2) * dy * pig2.mass);
+ }
+ }
+ }
+ }
+ }
+ }
+ // Check pig vs block collisions
+ for (var r = 0; r < pigs.length; r++) {
+ var pig = pigs[r];
+ if (pig.destroyed || pig.isStatic) continue;
+ for (var s = 0; s < blocks.length; s++) {
+ var block = blocks[s];
+ if (block.destroyed) continue;
+ if (pig.intersects(block)) {
+ // Calculate collision response
+ var dx = block.x - pig.x;
+ var dy = block.y - pig.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ // Normalize collision vector
+ dx /= distance;
+ dy /= distance;
+ // Separate pig and block
+ var overlap = (pig.width + block.width) / 2 - distance;
+ if (overlap > 0) {
+ pig.x -= dx * overlap * 0.5;
+ pig.y -= dy * overlap * 0.5;
+ block.x += dx * overlap * 0.5;
+ block.y += dy * overlap * 0.5;
+ }
+ // Exchange velocities based on mass
+ var totalMass = pig.mass + block.mass;
+ var v1 = pig.velocityX * dx + pig.velocityY * dy;
+ var v2 = block.velocityX * dx + block.velocityY * dy;
+ var newV1 = ((pig.mass - block.mass) * v1 + 2 * block.mass * v2) / totalMass;
+ var newV2 = ((block.mass - pig.mass) * v2 + 2 * pig.mass * v1) / totalMass;
+ pig.velocityX += (newV1 - v1) * dx * 0.6;
+ pig.velocityY += (newV1 - v1) * dy * 0.6;
+ if (!block.isStatic) {
+ block.velocityX += (newV2 - v2) * dx * 0.6;
+ block.velocityY += (newV2 - v2) * dy * 0.6;
+ } else {
+ // Make static block dynamic if hit hard enough
+ var impact = Math.abs(newV1 - v1);
+ if (impact > 1.8) {
+ block.applyForce((newV2 - v2) * dx * block.mass, (newV2 - v2) * dy * block.mass);
+ }
+ }
+ }
+ }
+ }
+ }
}
}
// Check win condition
function checkWinCondition() {
Green pig no angry. In-Game asset. 2d. High contrast. No shadows
Angry birds red. In-Game asset. 2d. High contrast. No shadows
Blue glass block. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Wood block. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Gray stone block. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Angry birds slingshot. In-Game asset. 2d. High contrast. No shadows
Cloud. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Angry birds 2 King pig. In-Game asset. 2d. High contrast. No shadows
Angry birds blue bird. In-Game asset. 2d. High contrast. No shadows
Angry birds vertical poster. In-Game asset. 2d. High contrast. No shadows
Angry birds logo. In-Game asset. 2d. High contrast. No shadows