User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return ufo;' Line Number: 1060 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Fix second game update method with cloud handling and merging functionality from first implementation
User prompt
Fix second game update method with cloud handling and merging functionality from first implementation
User prompt
save the code
User prompt
why is the game not starting or showing?
User prompt
continue with next step, then wait for my input
User prompt
ensure we are using the following plugins: @upit/storage.v1 Fix UpgradeButton update method for proper button state handling ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
continue expanding game bit by bit. save code first ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Fix UpgradeButton update method for proper button state handling
User prompt
✅ Bird Movement Implement Bird1Movement class properly to handle bird movement Implement Bird2Movement class properly to handle bird movement ✅ Spawn Functions Fix spawnBird1 function to properly initialize birds Fix spawnBird2 function to properly initialize birds ✅ Upgrade Buttons Revise upgrade buttons game mechanics Fix UpgradeButton class to properly handle: Interactivity and events Hover effects Down method Move method Up method Update method Fix upgrade buttons initialization in Game Code ✅ IdleManager Fix upgradePointsPerSecond method to properly update values Fix upgradeLaserPower method to properly update values Fix upgradeAutoShooting method to properly update values ✅ Game Mechanics Fix shootLaser function to properly handle laser targeting Fix Storage plugin initialization with proper defaults Improve secondary game update function to handle: Upgrades Button interactivity Improve button setup and initialization in Game Code
User prompt
✅ Implement Bird1Movement class properly to handle bird movement ✅ Implement Bird2Movement class properly to handle bird movement ✅ Fix spawnBird1 function to properly reference and add birds ✅ Fix spawnBird2 function to properly reference and add birds ✅ Fix UpgradeButton class to properly handle interactivity and events ✅ Fix IdleManager's upgradePointsPerSecond method to properly update values ✅ Fix IdleManager's upgradeLaserPower method to properly update values ✅ Fix IdleManager's upgradeAutoShooting method to properly update values ✅ Fix shootLaser function to properly handle lasers and targeting ✅ Fix Storage plugin initialization and defaults ✅ Improve button setup and initialization in Game Code to ensure interactivity ⏪Revert to here SM revise the upgrade buttons game mechanics ✅ Fix storage plugin initialization with proper defaults ✅ Fix UpgradeButton class to properly handle interactivity and hover effects ✅ Fix IdleManager upgradePointsPerSecond function to properly update values ✅ Fix IdleManager upgradeLaserPower function to properly update values ✅ Fix IdleManager upgradeAutoShooting function to properly update values ✅ Fix upgrade buttons initialization in Game Code ✅ Fix Bird1Movement class implementation ✅ Fix Bird2Movement class implementation ✅ Fix spawnBird1 function to properly initialize birds ✅ Fix spawnBird2 function to properly initialize birds ✅ Fix shootLaser function to properly handle laser targeting ✅ Improve secondary game update function to properly handle upgrades SM continue ✅ Fix Bird1Movement class implementation ✅ Fix Bird2Movement class implementation ✅ Fix IdleManager upgradePointsPerSecond function ✅ Fix IdleManager upgradeLaserPower function ✅ Fix IdleManager upgradeAutoShooting function ✅ Fix storage plugin initialization and defaults ✅ Fix UpgradeButton class to properly handle hover effects and interactivity ✅ Fix UpgradeButton down method ✅ Fix UpgradeButton move method ✅ Fix UpgradeButton up method ✅ Fix UpgradeButton update method ✅ Fix spawnBird1 function to properly initialize birds ✅ Fix spawnBird2 function to properly initialize birds ✅ Fix shootLaser function to properly handle laser targeting ✅ Fix upgrade buttons initialization in Game Code 🔄 Fix secondary game update function to handle button interactivity
User prompt
revise the upgrade buttons game mechanics
User prompt
continue
Code edit (1 edits merged)
Please save this source code
User prompt
continue
User prompt
i dont see hover effects, upgraed buttons are still not showing feedback or upgrades. ↪💡 Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1
User prompt
revise the upgrade buttons game mechanics
User prompt
increase the height of the instructions text box by 50px
User prompt
nothing happens when i click upgrade buttons. no feedback, no upgrades.
User prompt
increase width of instructions by 80px
User prompt
make the instructions text container 200px wide, shrink the font a little
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'instructionsText.x = scoreDisplay.x + 220;' Line Number: 1160
User prompt
move instructions text to right of scoreimg
User prompt
how do i upgrade, by shooting, or clicking the buttons? they are still not responding.
User prompt
upgrade buttons are not upgrading
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { upgrades: { pointsPerSecond: { level: 1, cost: 10 }, laserPower: { level: 1, cost: 20 }, autoShooting: { level: 0, cost: 100 } } }); /**** * Classes ****/ // Branch asset // Bird1 class to represent the first kind of bird var Bird1 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird1-right', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new Bird1Movement(self, birdGraphics); }); // Bird2 class to represent the second kind of bird var Bird2 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird2-right', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new Bird2Movement(self, birdGraphics); }); // Cat class to manage cat behavior var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the cat here }; }); // Cloud class to represent cloud behavior var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 // Set default opacity to 80% }); self.movement = new CloudMovement(self, cloudGraphics); }); // CloudMovement class to handle cloud movement and fade effects var CloudMovement = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 // Set default opacity to 80% }); self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8 self.hasAccelerated = false; // Track if the cloud has already accelerated self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left self.lastX = self.x; // Track last X position for future checks self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections self.update = function () { self.x += self.speed * self.direction; // If the cloud moves off-screen, reposition it to the opposite side if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) { self.x = -self.width / 2; } else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.x = 2048 + self.width / 2; } // Check for overlap with other clouds for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== self && self.intersects(clouds[i])) { if (!self.hasAccelerated) { self.speed *= 1.5; // Increase speed by 50% self.hasAccelerated = true; // Mark as accelerated } break; } else if (self.hasAccelerated && !self.intersects(clouds[i])) { self.speed /= 1.5; // Reset speed to original self.hasAccelerated = false; // Reset acceleration state } } // Check if the cloud intersects with the sun if (!self.lastIntersecting && self.intersects(sun)) { self.speed *= 2; // Double the speed when touching the sun tween(cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } else if (self.lastIntersecting && !self.intersects(sun)) { self.speed /= 2; // Reset speed to original when not touching the sun tween(cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } self.lastIntersecting = self.intersects(sun); self.lastX = self.x; // Update lastX after movement }; }); // GrassBack class to represent the grass image var GrassBack = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.addChild(grassGraphics); // Add grass graphics to the container self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; }); // GrassFront class to represent the second grass image var GrassFront = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass-front', { anchorX: 0.5, anchorY: 1 }); self.lastX = self.x; // Initialize lastX for tracking changes on X self.addChild(grass2Graphics); // Add grass2 graphics to the container self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50% self.lastX = self.x; // Update lastX after movement }; }); var IdleManager = Container.expand(function () { var self = Container.call(this); // Idle game resources self.points = storage.points || 0; self.pointsPerSecond = storage.pointsPerSecond || 0.1; self.laserPower = storage.laserPower || 1; self.autoBirdsInterval = null; self.autoShooting = storage.autoShooting || false; // Upgrade costs and multipliers self.upgrades = storage.upgrades || { pointsPerSecond: { level: 1, cost: 10, multiplier: 1.5 }, laserPower: { level: 1, cost: 20, multiplier: 2 }, autoShooting: { level: 0, cost: 100, multiplier: 2 } }; // Generate passive income self.update = function () { self.points += self.pointsPerSecond / 60; // Divide by 60 since update runs at 60fps if (LK.ticks % 60 == 0) { // Update storage every second storage.points = self.points; } if (self.autoShooting && LK.ticks % 90 == 0) { // Auto shoot at a random position every 1.5 seconds var targetX = Math.random() * 2048; var targetY = Math.random() * (2732 / 2); // Target upper half of screen shootLaser(cat.x, cat.y - 430, targetX, targetY); } }; // Upgrade functions self.upgradePointsPerSecond = function () { var upgrade = self.upgrades ? self.upgrades.pointsPerSecond : null; if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) { self.points -= upgrade.cost; self.pointsPerSecond *= 1.2; upgrade.level += 1; upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier); // Save to storage storage.points = self.points; storage.pointsPerSecond = self.pointsPerSecond; // Update storage upgrades storage.upgrades.pointsPerSecond = { level: upgrade.level, cost: upgrade.cost }; return true; } return false; }; self.upgradeLaserPower = function () { var upgrade = self.upgrades ? self.upgrades.laserPower : null; if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) { self.points -= upgrade.cost; self.laserPower *= 1.5; upgrade.level += 1; upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier); // Save to storage storage.points = self.points; storage.laserPower = self.laserPower; // Update storage upgrades storage.upgrades.laserPower = { level: upgrade.level, cost: upgrade.cost }; return true; } return false; }; self.upgradeAutoShooting = function () { var upgrade = self.upgrades ? self.upgrades.autoShooting : null; if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) { self.points -= upgrade.cost; upgrade.level += 1; upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier); self.autoShooting = true; // Save to storage storage.points = self.points; storage.autoShooting = self.autoShooting; // Update storage upgrades storage.upgrades.autoShooting = { level: upgrade.level, cost: upgrade.cost }; return true; } return false; }; return self; }); // Laser class to represent a laser shot from the cat var Laser = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var laserGraphics = self.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0, // Increase brightness by 200% scaleX: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0, scaleY: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0 }); // Play the laser1 sound when the laser is created LK.getSound('laser1').play(); // Calculate direction and speed var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; // Speed of the laser increased by 200% self.vx = dx / distance * speed; self.vy = dy / distance * speed; // Set initial position self.x = startX; self.y = startY; self.lastIntersecting = false; self.power = idleManager ? idleManager.laserPower : 1; // Add trail effect for upgraded lasers if (idleManager && idleManager.laserPower > 1.5) { self.trailTimer = LK.setInterval(function () { var trail = new Container(); var trailGraphics = trail.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0, scaleX: laserGraphics.scaleX * 0.7, scaleY: laserGraphics.scaleY * 0.7, alpha: 0.7 }); trail.x = self.x; trail.y = self.y; game.addChild(trail); tween(trail, { alpha: 0, scaleX: 0.5, scaleY: 0.5 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { trail.destroy(); } }); }, 100); } // Update function to move the laser self.update = function () { self.x += self.vx; self.y += self.vy; // Remove laser if it goes off-screen if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { if (self.trailTimer) { LK.clearInterval(self.trailTimer); } self.destroy(); } }; // Override destroy to clean up var originalDestroy = self.destroy; self.destroy = function () { if (self.trailTimer) { LK.clearInterval(self.trailTimer); } originalDestroy.call(self); }; return self; }); // Reticle class to manage reticle behavior var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Add any specific update logic for the reticle here }; }); // ScoreDisplay class to manage score display var ScoreDisplay = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5, width: 400, height: 450 }); var scoreText = new Text2('0', { size: 100, fill: 0x800080, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x000000, strokeThickness: 5, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); var incomeText = new Text2('0/sec', { size: 60, fill: 0x008800, font: "Arial, sans-serif", stroke: 0x000000, strokeThickness: 3 }); scoreText.anchor.set(0.5, 0); incomeText.anchor.set(0.5, 0); scoreText.y = -130; // Moved up 100px more (was -30) incomeText.y = -30; // Adjusted to maintain spacing (was 70) self.addChild(scoreText); self.addChild(incomeText); self.updateScore = function (newScore) { scoreText.setText(newScore); if (idleManager) { incomeText.setText(idleManager.pointsPerSecond.toFixed(1) + '/sec'); // Visual feedback for score increase if (self.lastScore && newScore > self.lastScore) { tween(scoreText, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(scoreText, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); } self.lastScore = newScore; } }; }); // Stack1 class to represent the stack1 image var Stack1 = Container.expand(function () { var self = Container.call(this); var stackGraphics = self.attachAsset('stack1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Add any specific update logic for stack1 here }; }); // ScoreManager class to manage score logic // ScoreManager class to manage score logic // Sun class to represent a sun in the top right corner var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); startPulsating(self); // Start the pulsating effect }); // Function to create a pulsating effect // Tree class to represent a tree with a 9:16 aspect ratio var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, antialias: true // Apply antialias effect }); self.update = function () { // Add any specific update logic for the tree here }; }); // UFO class to represent a UFO var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new UFOMovement(self, ufoGraphics); }); var UpgradeButton = Container.expand(function (type, x, y) { var self = Container.call(this); self.type = type; self.x = x; self.y = y; // Create button background var buttonBackground = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5, width: 400, height: 120, tint: type === 'pointsPerSecond' ? 0x00AA00 : type === 'laserPower' ? 0xAA0000 : 0x0000AA }); // Create button text self.buttonText = new Text2('', { size: 50, fill: 0xFFFFFF, font: "Arial, sans-serif" }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); // Handle click events self.down = function (x, y, obj) { var upgraded = false; switch (self.type) { case 'pointsPerSecond': upgraded = idleManager.upgradePointsPerSecond(); break; case 'laserPower': upgraded = idleManager.upgradeLaserPower(); break; case 'autoShooting': upgraded = idleManager.upgradeAutoShooting(); break; } if (upgraded) { tween(buttonBackground, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(buttonBackground, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); } }; // Update button text self.update = function () { var upgrade = idleManager.upgrades ? idleManager.upgrades[self.type] : null; var label = ''; if (upgrade && upgrade.cost !== undefined) { switch (self.type) { case 'pointsPerSecond': label = 'Income +20%\nCost: ' + Math.floor(upgrade.cost); break; case 'laserPower': label = 'Laser +50%\nCost: ' + Math.floor(upgrade.cost); break; case 'autoShooting': label = (upgrade.level > 0 ? 'Upgrade Auto' : 'Auto Shoot') + '\nCost: ' + Math.floor(upgrade.cost); break; } } else { // Default label text when upgrade is not defined switch (self.type) { case 'pointsPerSecond': label = 'Income +20%\nCost: 10'; break; case 'laserPower': label = 'Laser +50%\nCost: 20'; break; case 'autoShooting': label = 'Auto Shoot\nCost: 100'; break; } } self.buttonText.setText(label); }; return self; }); /**** * Initialize Game ****/ // Helper function to shoot laser // UFOMovement class to handle UFO movement /**** * Assets LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'}) ****/ // Initialize clouds array var game = new LK.Game({ // No title, no description backgroundColor: 0x000000 // Black }); /**** * Game Code ****/ // Bird2Effects class to handle effects and animations for Bird2 // Function to create a pulsating effect // UFOSound class to manage UFO sound effects // UFOMovement class to handle UFO movement var UFOMovement = function UFOMovement(ufo, ufoGraphics) { this.ufo = ufo; this.ufoGraphics = ufoGraphics; this.ufo.speed = 3.2; // Decrease speed by 20% this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.ufo.lastX = this.ufo.x; // Track last X position for future checks this.ufo.update = function () { this.x += this.speed * this.direction; this.y = 100 + Math.sin(this.x / 70) * 165; // Increase the wave pattern depth by 10% // Stop playing ufo1 sound after UFO leaves the screen if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { this.destroy(); ufo = null; LK.getSound('ufo1').stop(); } this.lastX = this.x; // Update lastX after movement }; }; var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; var Bird1Movement = function Bird1Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = -this.height; this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048; } if (this.birdGraphics) { if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) { this.birdGraphics.texture = LK.getAsset(this.bird.type + '-right', {}).texture; } else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) { this.birdGraphics.texture = LK.getAsset(this.bird.type + '-left', {}).texture; } } this.lastY = this.y; // Update lastY after movement this.lastX = this.x; // Update lastX after movement }; }; var Bird2Movement = function Bird2Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% if (this.birdGraphics) { if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) { this.birdGraphics.texture = LK.getAsset(this.bird.type + '-right', {}).texture; } else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) { this.birdGraphics.texture = LK.getAsset(this.bird.type + '-left', {}).texture; } } this.lastX = this.x; // Update lastX after movement // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = Math.random() * 2732; // Random initial y position within the screen height this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } this.lastY = this.y; // Update lastY after movement }; }; var CloudMovement = function CloudMovement(cloud, cloudGraphics) { this.cloud = cloud; this.cloudGraphics = cloudGraphics; this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8 this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.cloud.lastX = this.cloud.x; // Track last X position for future checks this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections this.cloud.update = function () { this.x += this.speed * this.direction; // If the cloud moves off-screen, reposition it to the opposite side if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) { this.x = -this.width / 2; } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) { this.x = 2048 + this.width / 2; } // Check for overlap with other clouds for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== this && this.intersects(clouds[i])) { if (!this.hasAccelerated) { this.speed *= 1.5; // Increase speed by 50% this.hasAccelerated = true; // Mark as accelerated } break; } else if (this.hasAccelerated && !this.intersects(clouds[i])) { this.speed /= 1.5; // Reset speed to original this.hasAccelerated = false; // Reset acceleration state } } // Check if the cloud intersects with the sun if (!this.lastIntersecting && this.intersects(sun)) { this.speed *= 2; // Double the speed when touching the sun if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } // Double the sun's pulsating rate startPulsating(sun, 444); // Pass the new duration for faster pulsating } else if (this.lastIntersecting && !this.intersects(sun)) { this.speed /= 2; // Reset speed to original when not touching the sun if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } // Reset the sun's pulsating rate to normal startPulsating(sun, 888); // Pass the original duration for normal pulsating } this.lastIntersecting = this.intersects(sun); this.lastX = this.x; // Update lastX after movement }; }; var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird2 here }; }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; function startPulsating(target) { var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888; function pulsate() { tween(target, { scaleX: 1.1, scaleY: 1.1 }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: duration, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); } var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2 - 200; game.addChild(background); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { var self = this; self.score = 0; self.addScore = function (points) { self.score += points; return self.score; }; self.resetScore = function () { self.score = 0; }; self.getScore = function () { return self.score; }; }; var ScoreManager = function ScoreManager() { var self = this; self.score = 0; self.addScore = function (points) { self.score += points; return self.score; }; self.resetScore = function () { self.score = 0; }; self.getScore = function () { return self.score; }; }; var birds = []; game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.addChild(new Reticle()); var reticleChildIndex = 7; if (reticleChildIndex >= 0 && reticleChildIndex < game.children.length) { game.setChildIndex(game.reticle, reticleChildIndex); // Set reticle to be rendered after the tree } } game.reticle.x = x; game.reticle.y = y; shootLaser(cat.x, cat.y - 430, x, y); }; var VOLUME_BGM1 = 0.02; var VOLUME_BREEZE1 = 0.02; var VOLUME_CRICKET1 = 0.02; var VOLUME_FROG1 = 0.02; var VOLUME_SONGBIRD1 = 0.02; var VOLUME_UFO1 = 0.02; var VOLUME_WINGS1 = 0.02; game.move = function (x, y, obj) { if (!game.reticle) { game.reticle = game.addChild(new Reticle()); } if (obj.event) { var x = obj.event.x; var y = obj.event.y; } game.reticle.x = x; game.reticle.y = y; }; // Add a sun to the game in the top left corner var sun = game.addChild(new Sun()); sun.x = 480; sun.y = 590; var sunChildIndex = 1; game.setChildIndex(sun, sunChildIndex); // Set sun to be rendered after the background // Function to add a UFO to the game function addUFO() { var ufo = game.addChild(new UFO()); ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen ufo.y = Math.random() * (2732 - ufo.height); // Random initial y position within the screen height, ensuring it stays within bounds ufo.customUpdate = function () { ufo.update(); }; // Removed ufo sound playing at startup return ufo; } // Initialize clouds array var clouds = []; for (var i = 0; i < 4; i++) { // Add 3 clouds for variety var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen clouds.push(cloud); game.addChild(cloud); var cloudChildIndex = 2; game.setChildIndex(cloud, cloudChildIndex); // Set clouds to be rendered after the sun } // Initialize birds spawnBird1(); spawnBird2(); // Initialize a timer to add a UFO at a random time between 20 and 30 seconds var ufo; // Define the ufo variable in the global scope var laser; // Define the laser variable in the global scope var ufoTimer = LK.setTimeout(function () { addUFO(); }, Math.random() * 5000 + 5000); // Adjusted interval for UFO appearances between 5 to 10 seconds game.update = function () { for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } if (ufo) { ufo.customUpdate(); // Update each laser game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds and UFO birds.forEach(function (bird) { if (!child.lastIntersecting && child.intersects(bird)) { var points = 0; if (bird instanceof Bird1) { points = 5 * child.power; } else if (bird instanceof Bird2 || bird instanceof Bird3) { points = 1 * child.power; } idleManager.points += points; scoreDisplay.updateScore(Math.floor(idleManager.points)); // Update the score display // Visual feedback tween(bird, { alpha: 0, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { bird.destroy(); birds.splice(birds.indexOf(bird), 1); } }); child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }); }); if (ufo && !child.lastIntersecting && child.intersects(ufo)) { score += 25; score.updateScore(score); child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || ufo && child.intersects(ufo); } }); if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) { // Destroy the UFO and set it to null ufo.destroy(); ufo = null; // Start a timer for the UFO to reappear between 30-50 seconds ufoTimer = LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 20000 + 30000); } else {} ufo.lastX = ufo.x; // Update lastX for the UFO } // Removed auto-targeting update function }; // Function to spawn a third kind of bird function spawnBird1() { var bird = new Bird1(); bird.x = Math.random() * 2048; bird.y = -bird.height; bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'Bird1'; // Specific property for Bird1 bird.color = 0x746130; // Specific color for Bird1 LK.setTimeout(function () { game.addChild(bird); var bird1ChildIndex = 4; game.setChildIndex(bird, bird1ChildIndex); // Set Bird1 to be rendered after the laser birds.push(bird); }, 2000); } function spawnBird2() { var bird = new Bird2(); bird.y = Math.random() * 2732; // Random initial y position within the screen height bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'Bird2'; // Specific property for Bird2 bird.color = 0xFFFFFF; // Specific color for Bird2 LK.setTimeout(function () { game.addChild(bird); var bird2ChildIndex = 6; game.setChildIndex(bird, bird2ChildIndex); // Set Bird2 to be rendered after the tree birds.push(bird); }, 2000); } // Ensure there are always 3 birds on screen game.update = function () { // Update idle manager idleManager.update(); // Update upgrade buttons upgradeButtons.forEach(function (button) { button.update(); }); // Update score display with points from idle manager scoreDisplay.updateScore(Math.floor(idleManager.points)); // Automatically spawn birds if there are less than 3 if (birds.length < 3 && LK.ticks % 120 == 0) { var randomChoice = Math.random(); if (randomChoice < 0.5) { spawnBird1(); } else { spawnBird2(); } } // Idle game visual feedback if (LK.ticks % 30 == 0 && idleManager.pointsPerSecond > 0) { // Show floating point indicators for passive income var floatingPoint = new Text2('+' + idleManager.pointsPerSecond.toFixed(1), { size: 40, fill: 0x00FF00, stroke: 0x000000, strokeThickness: 3 }); floatingPoint.anchor.set(0.5, 0.5); floatingPoint.x = scoreDisplay.x + (Math.random() * 100 - 50); floatingPoint.y = scoreDisplay.y + (Math.random() * 60 - 30) + 60; game.addChild(floatingPoint); tween(floatingPoint, { y: floatingPoint.y - 50, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { floatingPoint.destroy(); } }); } // Pulse effect on cat when auto-shooting is enabled if (idleManager.autoShooting && LK.ticks % 90 == 0) { tween(cat, { scaleX: 1.1, scaleY: 1.1 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(cat, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn }); } }); } // Update each bird birds.forEach(function (bird) { bird.update(); // Check if the bird has moved off-screen if (bird.lastY <= 2732 && bird.y > 2732) { bird.y = -bird.height; // Respawn the bird at the top bird.x = Math.random() * 2048; // Randomize the x position bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird } // Check for collisions with lasers game.children.forEach(function (child) { if (child instanceof Laser) { if (!child.lastIntersecting && child.intersects(bird)) { var points = 0; if (bird instanceof Bird1) { points = 5 * child.power; } else if (bird instanceof Bird2) { points = 1 * child.power; } idleManager.points += points; scoreDisplay.updateScore(Math.floor(idleManager.points)); // Visual feedback tween(bird, { alpha: 0, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { bird.destroy(); birds.splice(birds.indexOf(bird), 1); } }); child.destroy(); } child.lastIntersecting = child.intersects(bird); } }); }); }; // Add a tree to the game var tree = game.addChild(new Tree()); tree.x = 2048 / 2 + 500; // Move the tree 500px to the right tree.y = 2765; // Position the tree on the grass // Ensure treeChildIndex is within valid range before setting child index var treeChildIndex = Math.min(7, game.children.length - 1); // Ensure index is within bounds // Only set the child index if the tree is actually a child of the game container if (tree && tree.parent === game && treeChildIndex >= 0 && treeChildIndex < game.children.length) { game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered at index 7 or the last valid index } // Initialize idle game manager var idleManager = new IdleManager(); game.addChild(idleManager); // Create upgrade buttons var upgradeButtons = []; var incomeButton = new UpgradeButton('pointsPerSecond', 1800, 200); var laserButton = new UpgradeButton('laserPower', 1800, 350); var autoButton = new UpgradeButton('autoShooting', 1800, 500); game.addChild(incomeButton); game.addChild(laserButton); game.addChild(autoButton); upgradeButtons.push(incomeButton, laserButton, autoButton); // Initialize score for compatibility var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1650; // Move 500px to the right stack1.y = 2200; // Move down by 800px var stack1ChildIndex = 6; game.setChildIndex(stack1, stack1ChildIndex); // Set stack1 to be rendered at index 9 or the last valid index // Add the grass floor to the game var grassBack = new GrassBack(); grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom game.addChild(grassBack); var grassBackChildIndex = 5; game.setChildIndex(grassBack, grassBackChildIndex); // Set grassBack to be rendered after Bird3 var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2735; // Position grassFront at the bottom game.addChild(grassFront); var grassFrontChildIndex = 8; game.setChildIndex(grassFront, grassFrontChildIndex); // Set grassFront to be rendered at index 8 var scoreDisplay = new ScoreDisplay(); scoreDisplay.x = 2048 / 2 + 520; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185 - 80 - 128; // Move the score display up by 128px game.addChild(scoreDisplay); // Ensure laser is added to the game before setting scoreDisplay's index if (game.children.includes(laser)) { game.setChildIndex(laser, 10); // Set laser to be rendered before the scoreDisplay } // Function to handle bgm1 end event function onBgm1End() { // Set a timer to replay bgm1 after 50-80 seconds var bgmTimer = LK.setTimeout(function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 200; // Position the cat to the far left cat.y = 2732; // Position the cat at the bottom of the screen var catChildIndex = 9; game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: onEnd // Set the onEnd function to replay bgm1 }); }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Initialize random timers for each sound to play between 30-50 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); // Stop the currently playing ambient sound } sound.play(); currentAmbientSound = sound; // Set the current ambient sound // Set a timeout to reset the current ambient sound after it finishes playing LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); // Convert duration from seconds to milliseconds // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000); }, Math.random() * 20000 + 30000); }); // Helper function to shoot laser function shootLaser(startX, startY, targetX, targetY) { var laser = new Laser(startX, startY, targetX, targetY); game.addChild(laser); var laserChildIndex = Math.min(game.getChildIndex(game.reticle) + 2, game.children.length - 1); if (laserChildIndex >= 0 && laserChildIndex < game.children.length) { game.setChildIndex(laser, laserChildIndex); } return laser; }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
upgrades: {
pointsPerSecond: {
level: 1,
cost: 10
},
laserPower: {
level: 1,
cost: 20
},
autoShooting: {
level: 0,
cost: 100
}
}
});
/****
* Classes
****/
// Branch asset
// Bird1 class to represent the first kind of bird
var Bird1 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird1-right', {
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new Bird1Movement(self, birdGraphics);
});
// Bird2 class to represent the second kind of bird
var Bird2 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird2-right', {
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new Bird2Movement(self, birdGraphics);
});
// Cat class to manage cat behavior
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
// Add any specific update logic for the cat here
};
});
// Cloud class to represent cloud behavior
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8 // Set default opacity to 80%
});
self.movement = new CloudMovement(self, cloudGraphics);
});
// CloudMovement class to handle cloud movement and fade effects
var CloudMovement = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8 // Set default opacity to 80%
});
self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
self.hasAccelerated = false; // Track if the cloud has already accelerated
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
self.lastX = self.x; // Track last X position for future checks
self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
self.update = function () {
self.x += self.speed * self.direction;
// If the cloud moves off-screen, reposition it to the opposite side
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
self.x = -self.width / 2;
} else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
}
// Check for overlap with other clouds
for (var i = 0; i < clouds.length; i++) {
if (clouds[i] !== self && self.intersects(clouds[i])) {
if (!self.hasAccelerated) {
self.speed *= 1.5; // Increase speed by 50%
self.hasAccelerated = true; // Mark as accelerated
}
break;
} else if (self.hasAccelerated && !self.intersects(clouds[i])) {
self.speed /= 1.5; // Reset speed to original
self.hasAccelerated = false; // Reset acceleration state
}
}
// Check if the cloud intersects with the sun
if (!self.lastIntersecting && self.intersects(sun)) {
self.speed *= 2; // Double the speed when touching the sun
tween(cloudGraphics, {
alpha: 0.5
}, {
duration: 3000,
easing: tween.linear
});
} else if (self.lastIntersecting && !self.intersects(sun)) {
self.speed /= 2; // Reset speed to original when not touching the sun
tween(cloudGraphics, {
alpha: 1.0
}, {
duration: 3000,
easing: tween.linear
});
}
self.lastIntersecting = self.intersects(sun);
self.lastX = self.x; // Update lastX after movement
};
});
// GrassBack class to represent the grass image
var GrassBack = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass-back', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
// Add any specific update logic for the grass here
// Example: Slightly move the grass to simulate wind effect
self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
};
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.addChild(grassGraphics); // Add grass graphics to the container
self.update = function () {
// Add any specific update logic for the grass here
// Example: Slightly move the grass to simulate wind effect
self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
};
});
// GrassFront class to represent the second grass image
var GrassFront = Container.expand(function () {
var self = Container.call(this);
var grass2Graphics = self.attachAsset('grass-front', {
anchorX: 0.5,
anchorY: 1
});
self.lastX = self.x; // Initialize lastX for tracking changes on X
self.addChild(grass2Graphics); // Add grass2 graphics to the container
self.update = function () {
// Add any specific update logic for the grass here
// Example: Slightly move the grass to simulate wind effect
self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
self.lastX = self.x; // Update lastX after movement
};
});
var IdleManager = Container.expand(function () {
var self = Container.call(this);
// Idle game resources
self.points = storage.points || 0;
self.pointsPerSecond = storage.pointsPerSecond || 0.1;
self.laserPower = storage.laserPower || 1;
self.autoBirdsInterval = null;
self.autoShooting = storage.autoShooting || false;
// Upgrade costs and multipliers
self.upgrades = storage.upgrades || {
pointsPerSecond: {
level: 1,
cost: 10,
multiplier: 1.5
},
laserPower: {
level: 1,
cost: 20,
multiplier: 2
},
autoShooting: {
level: 0,
cost: 100,
multiplier: 2
}
};
// Generate passive income
self.update = function () {
self.points += self.pointsPerSecond / 60; // Divide by 60 since update runs at 60fps
if (LK.ticks % 60 == 0) {
// Update storage every second
storage.points = self.points;
}
if (self.autoShooting && LK.ticks % 90 == 0) {
// Auto shoot at a random position every 1.5 seconds
var targetX = Math.random() * 2048;
var targetY = Math.random() * (2732 / 2); // Target upper half of screen
shootLaser(cat.x, cat.y - 430, targetX, targetY);
}
};
// Upgrade functions
self.upgradePointsPerSecond = function () {
var upgrade = self.upgrades ? self.upgrades.pointsPerSecond : null;
if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) {
self.points -= upgrade.cost;
self.pointsPerSecond *= 1.2;
upgrade.level += 1;
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
// Save to storage
storage.points = self.points;
storage.pointsPerSecond = self.pointsPerSecond;
// Update storage upgrades
storage.upgrades.pointsPerSecond = {
level: upgrade.level,
cost: upgrade.cost
};
return true;
}
return false;
};
self.upgradeLaserPower = function () {
var upgrade = self.upgrades ? self.upgrades.laserPower : null;
if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) {
self.points -= upgrade.cost;
self.laserPower *= 1.5;
upgrade.level += 1;
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
// Save to storage
storage.points = self.points;
storage.laserPower = self.laserPower;
// Update storage upgrades
storage.upgrades.laserPower = {
level: upgrade.level,
cost: upgrade.cost
};
return true;
}
return false;
};
self.upgradeAutoShooting = function () {
var upgrade = self.upgrades ? self.upgrades.autoShooting : null;
if (upgrade && upgrade.cost !== undefined && self.points >= upgrade.cost) {
self.points -= upgrade.cost;
upgrade.level += 1;
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
self.autoShooting = true;
// Save to storage
storage.points = self.points;
storage.autoShooting = self.autoShooting;
// Update storage upgrades
storage.upgrades.autoShooting = {
level: upgrade.level,
cost: upgrade.cost
};
return true;
}
return false;
};
return self;
});
// Laser class to represent a laser shot from the cat
var Laser = Container.expand(function (startX, startY, targetX, targetY) {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
brightness: 2.0,
// Increase brightness by 200%
scaleX: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0,
scaleY: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0
});
// Play the laser1 sound when the laser is created
LK.getSound('laser1').play();
// Calculate direction and speed
var dx = targetX - startX;
var dy = targetY - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 60; // Speed of the laser increased by 200%
self.vx = dx / distance * speed;
self.vy = dy / distance * speed;
// Set initial position
self.x = startX;
self.y = startY;
self.lastIntersecting = false;
self.power = idleManager ? idleManager.laserPower : 1;
// Add trail effect for upgraded lasers
if (idleManager && idleManager.laserPower > 1.5) {
self.trailTimer = LK.setInterval(function () {
var trail = new Container();
var trailGraphics = trail.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
brightness: 2.0,
scaleX: laserGraphics.scaleX * 0.7,
scaleY: laserGraphics.scaleY * 0.7,
alpha: 0.7
});
trail.x = self.x;
trail.y = self.y;
game.addChild(trail);
tween(trail, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
trail.destroy();
}
});
}, 100);
}
// Update function to move the laser
self.update = function () {
self.x += self.vx;
self.y += self.vy;
// Remove laser if it goes off-screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
if (self.trailTimer) {
LK.clearInterval(self.trailTimer);
}
self.destroy();
}
};
// Override destroy to clean up
var originalDestroy = self.destroy;
self.destroy = function () {
if (self.trailTimer) {
LK.clearInterval(self.trailTimer);
}
originalDestroy.call(self);
};
return self;
});
// Reticle class to manage reticle behavior
var Reticle = Container.expand(function () {
var self = Container.call(this);
var reticleGraphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Add any specific update logic for the reticle here
};
});
// ScoreDisplay class to manage score display
var ScoreDisplay = Container.expand(function () {
var self = Container.call(this);
var scoreGraphics = self.attachAsset('scoreImage', {
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 450
});
var scoreText = new Text2('0', {
size: 100,
fill: 0x800080,
font: "Courier New, Courier, monospace",
// Segmented clock style font
stroke: 0x000000,
strokeThickness: 5,
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
var incomeText = new Text2('0/sec', {
size: 60,
fill: 0x008800,
font: "Arial, sans-serif",
stroke: 0x000000,
strokeThickness: 3
});
scoreText.anchor.set(0.5, 0);
incomeText.anchor.set(0.5, 0);
scoreText.y = -130; // Moved up 100px more (was -30)
incomeText.y = -30; // Adjusted to maintain spacing (was 70)
self.addChild(scoreText);
self.addChild(incomeText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
if (idleManager) {
incomeText.setText(idleManager.pointsPerSecond.toFixed(1) + '/sec');
// Visual feedback for score increase
if (self.lastScore && newScore > self.lastScore) {
tween(scoreText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(scoreText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
}
self.lastScore = newScore;
}
};
});
// Stack1 class to represent the stack1 image
var Stack1 = Container.expand(function () {
var self = Container.call(this);
var stackGraphics = self.attachAsset('stack1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Add any specific update logic for stack1 here
};
});
// ScoreManager class to manage score logic
// ScoreManager class to manage score logic
// Sun class to represent a sun in the top right corner
var Sun = Container.expand(function () {
var self = Container.call(this);
var sunGraphics = self.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5
});
startPulsating(self); // Start the pulsating effect
});
// Function to create a pulsating effect
// Tree class to represent a tree with a 9:16 aspect ratio
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
antialias: true // Apply antialias effect
});
self.update = function () {
// Add any specific update logic for the tree here
};
});
// UFO class to represent a UFO
var UFO = Container.expand(function () {
var self = Container.call(this);
var ufoGraphics = self.attachAsset('ufo', {
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new UFOMovement(self, ufoGraphics);
});
var UpgradeButton = Container.expand(function (type, x, y) {
var self = Container.call(this);
self.type = type;
self.x = x;
self.y = y;
// Create button background
var buttonBackground = self.attachAsset('scoreImage', {
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 120,
tint: type === 'pointsPerSecond' ? 0x00AA00 : type === 'laserPower' ? 0xAA0000 : 0x0000AA
});
// Create button text
self.buttonText = new Text2('', {
size: 50,
fill: 0xFFFFFF,
font: "Arial, sans-serif"
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
// Handle click events
self.down = function (x, y, obj) {
var upgraded = false;
switch (self.type) {
case 'pointsPerSecond':
upgraded = idleManager.upgradePointsPerSecond();
break;
case 'laserPower':
upgraded = idleManager.upgradeLaserPower();
break;
case 'autoShooting':
upgraded = idleManager.upgradeAutoShooting();
break;
}
if (upgraded) {
tween(buttonBackground, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(buttonBackground, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
}
};
// Update button text
self.update = function () {
var upgrade = idleManager.upgrades ? idleManager.upgrades[self.type] : null;
var label = '';
if (upgrade && upgrade.cost !== undefined) {
switch (self.type) {
case 'pointsPerSecond':
label = 'Income +20%\nCost: ' + Math.floor(upgrade.cost);
break;
case 'laserPower':
label = 'Laser +50%\nCost: ' + Math.floor(upgrade.cost);
break;
case 'autoShooting':
label = (upgrade.level > 0 ? 'Upgrade Auto' : 'Auto Shoot') + '\nCost: ' + Math.floor(upgrade.cost);
break;
}
} else {
// Default label text when upgrade is not defined
switch (self.type) {
case 'pointsPerSecond':
label = 'Income +20%\nCost: 10';
break;
case 'laserPower':
label = 'Laser +50%\nCost: 20';
break;
case 'autoShooting':
label = 'Auto Shoot\nCost: 100';
break;
}
}
self.buttonText.setText(label);
};
return self;
});
/****
* Initialize Game
****/
// Helper function to shoot laser
// UFOMovement class to handle UFO movement
/****
* Assets
LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
****/
// Initialize clouds array
var game = new LK.Game({
// No title, no description
backgroundColor: 0x000000 // Black
});
/****
* Game Code
****/
// Bird2Effects class to handle effects and animations for Bird2
// Function to create a pulsating effect
// UFOSound class to manage UFO sound effects
// UFOMovement class to handle UFO movement
var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
this.ufo = ufo;
this.ufoGraphics = ufoGraphics;
this.ufo.speed = 3.2; // Decrease speed by 20%
this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
this.ufo.lastX = this.ufo.x; // Track last X position for future checks
this.ufo.update = function () {
this.x += this.speed * this.direction;
this.y = 100 + Math.sin(this.x / 70) * 165; // Increase the wave pattern depth by 10%
// Stop playing ufo1 sound after UFO leaves the screen
if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
this.destroy();
ufo = null;
LK.getSound('ufo1').stop();
}
this.lastX = this.x; // Update lastX after movement
};
};
var UFOSound = function UFOSound() {
this.play = function () {
LK.getSound('ufo1').play();
};
};
// BackgroundMusic class to manage background music
var BackgroundMusic = function BackgroundMusic() {
this.play = function () {
LK.playMusic('bgm1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 4000
},
onEnd: onBgm1End
});
};
};
// LaserSound class to manage laser sound effects
var LaserSound = function LaserSound() {
this.play = function () {
LK.getSound('laser1').play();
};
};
var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
this.bird = bird;
this.birdGraphics = birdGraphics;
this.bird.speed = Math.random() * 1.6 + 1;
this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
this.bird.update = function () {
this.y += this.speed;
this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
// Check if the bird has moved off-screen
if (this.lastY <= 2732 && this.y > 2732) {
this.y = -this.height;
this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
}
if (this.birdGraphics) {
if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) {
this.birdGraphics.texture = LK.getAsset(this.bird.type + '-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
this.birdGraphics.texture = LK.getAsset(this.bird.type + '-left', {}).texture;
}
}
this.lastY = this.y; // Update lastY after movement
this.lastX = this.x; // Update lastX after movement
};
};
var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
this.bird = bird;
this.birdGraphics = birdGraphics;
this.bird.speed = Math.random() * 1.6 + 1;
this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
this.bird.update = function () {
this.y += this.speed;
this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
if (this.birdGraphics) {
if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) {
this.birdGraphics.texture = LK.getAsset(this.bird.type + '-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
this.birdGraphics.texture = LK.getAsset(this.bird.type + '-left', {}).texture;
}
}
this.lastX = this.x; // Update lastX after movement
// Check if the bird has moved off-screen
if (this.lastY <= 2732 && this.y > 2732) {
this.y = Math.random() * 2732; // Random initial y position within the screen height
this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
}
this.lastY = this.y; // Update lastY after movement
};
};
var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
this.cloud = cloud;
this.cloudGraphics = cloudGraphics;
this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated
this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
this.cloud.lastX = this.cloud.x; // Track last X position for future checks
this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
this.cloud.update = function () {
this.x += this.speed * this.direction;
// If the cloud moves off-screen, reposition it to the opposite side
if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
this.x = -this.width / 2;
} else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
this.x = 2048 + this.width / 2;
}
// Check for overlap with other clouds
for (var i = 0; i < clouds.length; i++) {
if (clouds[i] !== this && this.intersects(clouds[i])) {
if (!this.hasAccelerated) {
this.speed *= 1.5; // Increase speed by 50%
this.hasAccelerated = true; // Mark as accelerated
}
break;
} else if (this.hasAccelerated && !this.intersects(clouds[i])) {
this.speed /= 1.5; // Reset speed to original
this.hasAccelerated = false; // Reset acceleration state
}
}
// Check if the cloud intersects with the sun
if (!this.lastIntersecting && this.intersects(sun)) {
this.speed *= 2; // Double the speed when touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 0.5
}, {
duration: 3000,
easing: tween.linear
});
}
// Double the sun's pulsating rate
startPulsating(sun, 444); // Pass the new duration for faster pulsating
} else if (this.lastIntersecting && !this.intersects(sun)) {
this.speed /= 2; // Reset speed to original when not touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 1.0
}, {
duration: 3000,
easing: tween.linear
});
}
// Reset the sun's pulsating rate to normal
startPulsating(sun, 888); // Pass the original duration for normal pulsating
}
this.lastIntersecting = this.intersects(sun);
this.lastX = this.x; // Update lastX after movement
};
};
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
// Add any specific effects or animations for Bird2 here
};
};
// Bird1Effects class to handle effects and animations for Bird1
var Bird1Effects = function Bird1Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
// Add any specific effects or animations for Bird1 here
};
};
function startPulsating(target) {
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
function pulsate() {
tween(target, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: pulsate
});
}
});
}
pulsate();
}
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2 - 200;
game.addChild(background);
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
var self = this;
self.score = 0;
self.addScore = function (points) {
self.score += points;
return self.score;
};
self.resetScore = function () {
self.score = 0;
};
self.getScore = function () {
return self.score;
};
};
var ScoreManager = function ScoreManager() {
var self = this;
self.score = 0;
self.addScore = function (points) {
self.score += points;
return self.score;
};
self.resetScore = function () {
self.score = 0;
};
self.getScore = function () {
return self.score;
};
};
var birds = [];
game.down = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
var reticleChildIndex = 7;
if (reticleChildIndex >= 0 && reticleChildIndex < game.children.length) {
game.setChildIndex(game.reticle, reticleChildIndex); // Set reticle to be rendered after the tree
}
}
game.reticle.x = x;
game.reticle.y = y;
shootLaser(cat.x, cat.y - 430, x, y);
};
var VOLUME_BGM1 = 0.02;
var VOLUME_BREEZE1 = 0.02;
var VOLUME_CRICKET1 = 0.02;
var VOLUME_FROG1 = 0.02;
var VOLUME_SONGBIRD1 = 0.02;
var VOLUME_UFO1 = 0.02;
var VOLUME_WINGS1 = 0.02;
game.move = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
}
if (obj.event) {
var x = obj.event.x;
var y = obj.event.y;
}
game.reticle.x = x;
game.reticle.y = y;
};
// Add a sun to the game in the top left corner
var sun = game.addChild(new Sun());
sun.x = 480;
sun.y = 590;
var sunChildIndex = 1;
game.setChildIndex(sun, sunChildIndex); // Set sun to be rendered after the background
// Function to add a UFO to the game
function addUFO() {
var ufo = game.addChild(new UFO());
ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen
ufo.y = Math.random() * (2732 - ufo.height); // Random initial y position within the screen height, ensuring it stays within bounds
ufo.customUpdate = function () {
ufo.update();
};
// Removed ufo sound playing at startup
return ufo;
}
// Initialize clouds array
var clouds = [];
for (var i = 0; i < 4; i++) {
// Add 3 clouds for variety
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
clouds.push(cloud);
game.addChild(cloud);
var cloudChildIndex = 2;
game.setChildIndex(cloud, cloudChildIndex); // Set clouds to be rendered after the sun
}
// Initialize birds
spawnBird1();
spawnBird2();
// Initialize a timer to add a UFO at a random time between 20 and 30 seconds
var ufo; // Define the ufo variable in the global scope
var laser; // Define the laser variable in the global scope
var ufoTimer = LK.setTimeout(function () {
addUFO();
}, Math.random() * 5000 + 5000); // Adjusted interval for UFO appearances between 5 to 10 seconds
game.update = function () {
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
if (ufo) {
ufo.customUpdate();
// Update each laser
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds and UFO
birds.forEach(function (bird) {
if (!child.lastIntersecting && child.intersects(bird)) {
var points = 0;
if (bird instanceof Bird1) {
points = 5 * child.power;
} else if (bird instanceof Bird2 || bird instanceof Bird3) {
points = 1 * child.power;
}
idleManager.points += points;
scoreDisplay.updateScore(Math.floor(idleManager.points)); // Update the score display
// Visual feedback
tween(bird, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
}
});
child.destroy();
}
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
});
});
if (ufo && !child.lastIntersecting && child.intersects(ufo)) {
score += 25;
score.updateScore(score);
child.destroy();
}
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
}) || ufo && child.intersects(ufo);
}
});
if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
// Destroy the UFO and set it to null
ufo.destroy();
ufo = null;
// Start a timer for the UFO to reappear between 30-50 seconds
ufoTimer = LK.setTimeout(function () {
ufo = addUFO();
}, Math.random() * 20000 + 30000);
} else {}
ufo.lastX = ufo.x; // Update lastX for the UFO
}
// Removed auto-targeting update function
};
// Function to spawn a third kind of bird
function spawnBird1() {
var bird = new Bird1();
bird.x = Math.random() * 2048;
bird.y = -bird.height;
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'Bird1'; // Specific property for Bird1
bird.color = 0x746130; // Specific color for Bird1
LK.setTimeout(function () {
game.addChild(bird);
var bird1ChildIndex = 4;
game.setChildIndex(bird, bird1ChildIndex); // Set Bird1 to be rendered after the laser
birds.push(bird);
}, 2000);
}
function spawnBird2() {
var bird = new Bird2();
bird.y = Math.random() * 2732; // Random initial y position within the screen height
bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'Bird2'; // Specific property for Bird2
bird.color = 0xFFFFFF; // Specific color for Bird2
LK.setTimeout(function () {
game.addChild(bird);
var bird2ChildIndex = 6;
game.setChildIndex(bird, bird2ChildIndex); // Set Bird2 to be rendered after the tree
birds.push(bird);
}, 2000);
}
// Ensure there are always 3 birds on screen
game.update = function () {
// Update idle manager
idleManager.update();
// Update upgrade buttons
upgradeButtons.forEach(function (button) {
button.update();
});
// Update score display with points from idle manager
scoreDisplay.updateScore(Math.floor(idleManager.points));
// Automatically spawn birds if there are less than 3
if (birds.length < 3 && LK.ticks % 120 == 0) {
var randomChoice = Math.random();
if (randomChoice < 0.5) {
spawnBird1();
} else {
spawnBird2();
}
}
// Idle game visual feedback
if (LK.ticks % 30 == 0 && idleManager.pointsPerSecond > 0) {
// Show floating point indicators for passive income
var floatingPoint = new Text2('+' + idleManager.pointsPerSecond.toFixed(1), {
size: 40,
fill: 0x00FF00,
stroke: 0x000000,
strokeThickness: 3
});
floatingPoint.anchor.set(0.5, 0.5);
floatingPoint.x = scoreDisplay.x + (Math.random() * 100 - 50);
floatingPoint.y = scoreDisplay.y + (Math.random() * 60 - 30) + 60;
game.addChild(floatingPoint);
tween(floatingPoint, {
y: floatingPoint.y - 50,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
floatingPoint.destroy();
}
});
}
// Pulse effect on cat when auto-shooting is enabled
if (idleManager.autoShooting && LK.ticks % 90 == 0) {
tween(cat, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(cat, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
}
// Update each bird
birds.forEach(function (bird) {
bird.update();
// Check if the bird has moved off-screen
if (bird.lastY <= 2732 && bird.y > 2732) {
bird.y = -bird.height; // Respawn the bird at the top
bird.x = Math.random() * 2048; // Randomize the x position
bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
}
// Check for collisions with lasers
game.children.forEach(function (child) {
if (child instanceof Laser) {
if (!child.lastIntersecting && child.intersects(bird)) {
var points = 0;
if (bird instanceof Bird1) {
points = 5 * child.power;
} else if (bird instanceof Bird2) {
points = 1 * child.power;
}
idleManager.points += points;
scoreDisplay.updateScore(Math.floor(idleManager.points));
// Visual feedback
tween(bird, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
}
});
child.destroy();
}
child.lastIntersecting = child.intersects(bird);
}
});
});
};
// Add a tree to the game
var tree = game.addChild(new Tree());
tree.x = 2048 / 2 + 500; // Move the tree 500px to the right
tree.y = 2765; // Position the tree on the grass
// Ensure treeChildIndex is within valid range before setting child index
var treeChildIndex = Math.min(7, game.children.length - 1); // Ensure index is within bounds
// Only set the child index if the tree is actually a child of the game container
if (tree && tree.parent === game && treeChildIndex >= 0 && treeChildIndex < game.children.length) {
game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered at index 7 or the last valid index
}
// Initialize idle game manager
var idleManager = new IdleManager();
game.addChild(idleManager);
// Create upgrade buttons
var upgradeButtons = [];
var incomeButton = new UpgradeButton('pointsPerSecond', 1800, 200);
var laserButton = new UpgradeButton('laserPower', 1800, 350);
var autoButton = new UpgradeButton('autoShooting', 1800, 500);
game.addChild(incomeButton);
game.addChild(laserButton);
game.addChild(autoButton);
upgradeButtons.push(incomeButton, laserButton, autoButton);
// Initialize score for compatibility
var score = 0;
// Add stack1 image to the game
var stack1 = game.addChild(new Stack1());
stack1.x = 1650; // Move 500px to the right
stack1.y = 2200; // Move down by 800px
var stack1ChildIndex = 6;
game.setChildIndex(stack1, stack1ChildIndex); // Set stack1 to be rendered at index 9 or the last valid index
// Add the grass floor to the game
var grassBack = new GrassBack();
grassBack.x = 1020;
grassBack.y = 2735; // Position grassBack at the bottom
game.addChild(grassBack);
var grassBackChildIndex = 5;
game.setChildIndex(grassBack, grassBackChildIndex); // Set grassBack to be rendered after Bird3
var grassFront = new GrassFront();
grassFront.x = 1020;
grassFront.y = 2735; // Position grassFront at the bottom
game.addChild(grassFront);
var grassFrontChildIndex = 8;
game.setChildIndex(grassFront, grassFrontChildIndex); // Set grassFront to be rendered at index 8
var scoreDisplay = new ScoreDisplay();
scoreDisplay.x = 2048 / 2 + 520; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 128; // Move the score display up by 128px
game.addChild(scoreDisplay);
// Ensure laser is added to the game before setting scoreDisplay's index
if (game.children.includes(laser)) {
game.setChildIndex(laser, 10); // Set laser to be rendered before the scoreDisplay
}
// Function to handle bgm1 end event
function onBgm1End() {
// Set a timer to replay bgm1 after 50-80 seconds
var bgmTimer = LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 4000
},
onEnd: onBgm1End
});
}, Math.random() * 30000 + 50000);
}
;
// Add the cat to the game
var cat = game.addChild(new Cat());
cat.x = 200; // Position the cat to the far left
cat.y = 2732; // Position the cat at the bottom of the screen
var catChildIndex = 9;
game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass
// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
LK.playMusic('bgm1', {
loop: false,
// Play once
fade: {
start: 0,
end: 0.02,
// Set to the lowest volume
duration: 4000
},
onEnd: function onEnd() {
// Set a timer to replay bgm1 every 20-50 seconds
LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: false,
// Play once
fade: {
start: 0,
end: 0.5,
// Set to the lowest volume
duration: 4000
},
onEnd: onEnd // Set the onEnd function to replay bgm1
});
}, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
}
});
// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
var wingsTimer = LK.setTimeout(function () {
LK.getSound('wings1').play();
wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
}, Math.random() * 20000 + 10000);
// Create an array for all sounds except ufo1, including all birdsong sounds
var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
var currentAmbientSound = null;
// Initialize random timers for each sound to play between 30-50 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
currentAmbientSound.stop(); // Stop the currently playing ambient sound
}
sound.play();
currentAmbientSound = sound; // Set the current ambient sound
// Set a timeout to reset the current ambient sound after it finishes playing
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000); // Convert duration from seconds to milliseconds
// Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
}, Math.random() * 20000 + 30000);
});
// Helper function to shoot laser
function shootLaser(startX, startY, targetX, targetY) {
var laser = new Laser(startX, startY, targetX, targetY);
game.addChild(laser);
var laserChildIndex = Math.min(game.getChildIndex(game.reticle) + 2, game.children.length - 1);
if (laserChildIndex >= 0 && laserChildIndex < game.children.length) {
game.setChildIndex(laser, laserChildIndex);
}
return laser;
}
an orange and white cat facing away from the camera. the cat is sitting straight up and looking up, ready to pounce. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
remove black box
fluffy translucent cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bright sun with wincing cartoon face and a black eye. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a goofy ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red gaming reticle. Minimal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sunny day, hilly landscape. there is an alien invasion taking place in the distance. cities burning.
large AUTUMN SHADES tree with sparse bunches of leaves. branches are exposed, but the tree is tough and old.. true-color, realistic, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
glowing orange sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sideway view of a fighter jet. . . In-Game 2d asset. transparent background. horizontal. No shadows.
shiny purple and black attack ufo.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows