Code edit (12 edits merged)
Please save this source code
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: 'self.lastX = self.x;' Line Number: 184 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
assign bird images to bird objects, ufo image to ufo object, etc.
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: 'gameInstance = new LK.Game({' Line Number: 1075 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
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: 'var gameInstance = new LK.Game({' Line Number: 956 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (6 edits merged)
Please save this source code
User prompt
find bugs in the code
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'app is not defined' in or related to this line: 'app.stage.addChild(layer);' Line Number: 112
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseSpeed')' in or related to this line: 'self.cloud = {' Line Number: 155
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'baseSpeed is not defined' in or related to this line: 'self.cloud = {' Line Number: 153
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1931
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1496
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1465
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1463
User prompt
Please fix the bug: 'cloudGraphics is not defined' in or related to this line: 'self.addChild(cloudGraphics);' Line Number: 185
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'sounds')' in or related to this line: 'if (config.sounds && config.sounds.move) {' Line Number: 542
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * 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 }; }); // Grass class to represent the grass image var Grass = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass', { 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.label = new Text2('Grass', { size: 50, fill: 0x00FF00 }); self.label.x = 0; // Center label horizontally self.label.y = -grassGraphics.height / 2 - 30; // Position label above the grass self.addChild(self.label); 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 }; }); // Grass2 class to represent the second grass image var Grass2 = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass2', { 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.label = new Text2('Grass2', { size: 50, fill: 0x00FF00 }); self.label.x = 0; // Center label horizontally self.label.y = -grass2Graphics.height / 2 - 30; // Position label above the grass2 self.addChild(self.label); 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 }; }); // 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% }); // 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; // 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) { self.destroy(); } }; }); // 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 }); var scoreText = new Text2('0', { size: 175, fill: 0x00FF00, 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 }); scoreText.y = -100; // Move score text up by 10px scoreText.x = -155; // Move score text right by 10px x = 100; y = 100; self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // 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 flying across the screen var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3.2; // Decrease speed by 20% 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.update = function () { self.x += self.speed * self.direction; self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10% // If the UFO moves off-screen, destroy it and set to null if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.destroy(); ufo = null; } self.lastX = self.x; // Update lastX after movement }; }); /**** * Initialize Game ****/ /**** * 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 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('bird1-right', {}).texture; } else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) { this.birdGraphics.texture = LK.getAsset('bird1-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('bird2-right', {}).texture; } else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) { this.birdGraphics.texture = LK.getAsset('bird2-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 }); } } 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 }); } } 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) { function pulsate() { tween(target, { scaleX: 1.1, scaleY: 1.1 }, { duration: 444, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: 444, 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 = 1; game.setChildIndex(game.reticle, reticleChildIndex); // Set reticle to be rendered after the background } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x, cat.y - 430, x, y); // laser starting point game.addChild(laser); var laserChildIndex = Math.min(game.getChildIndex(game.reticle) + 2, game.children.length - 1); game.setChildIndex(laser, laserChildIndex); // Ensure laser is rendered after the reticle }; 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() * 500; // Random initial y position in the upper part of the screen 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 ufoTimer = LK.setTimeout(function () { addUFO(); }, Math.random() * 10000 + 20000); 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)) { if (bird instanceof Bird1) { score += 5; } else if (bird instanceof Bird2 || bird instanceof Bird3) { score += 1; } scoreDisplay.updateScore(score); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array 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 = game.getChildIndex(tree) + 1; 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 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 } }); }; // 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 var treeChildIndex = Math.min(7, game.children.length - 1); game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered after Bird1 var score = 0; // Add the grass floor to the game var grass = new Grass(); grass.x = 1020; grass.y = 2735; // Position grass at the bottom game.addChild(grass); var grassChildIndex = Math.min(9, game.getChildIndex(tree) - 1); game.setChildIndex(grass, grassChildIndex); // Set grass to be rendered after Bird3 var grass2 = new Grass2(); grass2.x = 1020; grass2.y = 2735; // Position grass2 at the bottom game.addChild(grass2); var grass2ChildIndex = game.getChildIndex(tree) + 1; game.setChildIndex(grass2, grass2ChildIndex); // Set grass2 to be rendered after the tree var scoreDisplay = new ScoreDisplay(); scoreDisplay.x = 2048 / 2 + 520; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185; // Adjust the y-coordinate of the score display game.addChild(scoreDisplay); game.setChildIndex(scoreDisplay, Math.min(9, game.children.length - 1)); // Set score image to be rendered before the cat // 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 = Math.min(10, game.children.length - 1); 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 var config = { sounds: { move: true } }; // Initialize config object with sounds property 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); });
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* 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
};
});
// Grass class to represent the grass image
var Grass = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass', {
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.label = new Text2('Grass', {
size: 50,
fill: 0x00FF00
});
self.label.x = 0; // Center label horizontally
self.label.y = -grassGraphics.height / 2 - 30; // Position label above the grass
self.addChild(self.label);
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
};
});
// Grass2 class to represent the second grass image
var Grass2 = Container.expand(function () {
var self = Container.call(this);
var grass2Graphics = self.attachAsset('grass2', {
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.label = new Text2('Grass2', {
size: 50,
fill: 0x00FF00
});
self.label.x = 0; // Center label horizontally
self.label.y = -grass2Graphics.height / 2 - 30; // Position label above the grass2
self.addChild(self.label);
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
};
});
// 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%
});
// 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;
// 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) {
self.destroy();
}
};
});
// 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
});
var scoreText = new Text2('0', {
size: 175,
fill: 0x00FF00,
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
});
scoreText.y = -100; // Move score text up by 10px
scoreText.x = -155; // Move score text right by 10px
x = 100;
y = 100;
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
});
// 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 flying across the screen
var UFO = Container.expand(function () {
var self = Container.call(this);
var ufoGraphics = self.attachAsset('ufo', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3.2; // Decrease speed by 20%
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.update = function () {
self.x += self.speed * self.direction;
self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10%
// If the UFO moves off-screen, destroy it and set to null
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.destroy();
ufo = null;
}
self.lastX = self.x; // Update lastX after movement
};
});
/****
* Initialize Game
****/
/****
* 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
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('bird1-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
this.birdGraphics.texture = LK.getAsset('bird1-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('bird2-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
this.birdGraphics.texture = LK.getAsset('bird2-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
});
}
} 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
});
}
}
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) {
function pulsate() {
tween(target, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 444,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 444,
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 = 1;
game.setChildIndex(game.reticle, reticleChildIndex); // Set reticle to be rendered after the background
}
game.reticle.x = x;
game.reticle.y = y;
var laser = new Laser(cat.x, cat.y - 430, x, y); // laser starting point
game.addChild(laser);
var laserChildIndex = Math.min(game.getChildIndex(game.reticle) + 2, game.children.length - 1);
game.setChildIndex(laser, laserChildIndex); // Ensure laser is rendered after the reticle
};
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() * 500; // Random initial y position in the upper part of the screen
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 ufoTimer = LK.setTimeout(function () {
addUFO();
}, Math.random() * 10000 + 20000);
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)) {
if (bird instanceof Bird1) {
score += 5;
} else if (bird instanceof Bird2 || bird instanceof Bird3) {
score += 1;
}
scoreDisplay.updateScore(score); // Update the score display
bird.destroy(); // Remove the bird when hit by a laser
birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
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 = game.getChildIndex(tree) + 1;
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 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
}
});
};
// 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
var treeChildIndex = Math.min(7, game.children.length - 1);
game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered after Bird1
var score = 0;
// Add the grass floor to the game
var grass = new Grass();
grass.x = 1020;
grass.y = 2735; // Position grass at the bottom
game.addChild(grass);
var grassChildIndex = Math.min(9, game.getChildIndex(tree) - 1);
game.setChildIndex(grass, grassChildIndex); // Set grass to be rendered after Bird3
var grass2 = new Grass2();
grass2.x = 1020;
grass2.y = 2735; // Position grass2 at the bottom
game.addChild(grass2);
var grass2ChildIndex = game.getChildIndex(tree) + 1;
game.setChildIndex(grass2, grass2ChildIndex); // Set grass2 to be rendered after the tree
var scoreDisplay = new ScoreDisplay();
scoreDisplay.x = 2048 / 2 + 520; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185; // Adjust the y-coordinate of the score display
game.addChild(scoreDisplay);
game.setChildIndex(scoreDisplay, Math.min(9, game.children.length - 1)); // Set score image to be rendered before the cat
// 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 = Math.min(10, game.children.length - 1);
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
var config = {
sounds: {
move: true
}
}; // Initialize config object with sounds property
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);
});
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