User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1460
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1458
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: 1458
User prompt
Please fix the bug: 'cloudGraphics is not defined' in or related to this line: 'self.addChild(cloudGraphics);' Line Number: 185
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseSpeed')' in or related to this line: 'entity.speed = (config.baseSpeed || 1) + Math.random() * (config.speedVariation || 0);' Line Number: 531
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: 1493
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: 1493
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: 1492
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Bird1Movement is not defined' in or related to this line: 'Bird1Movement(self, birdGraphics);' Line Number: 68
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: checkCollisions is not defined' in or related to this line: 'checkCollisions(this, {' Line Number: 503
User prompt
Please fix the bug: 'ReferenceError: updateMovement is not defined' in or related to this line: 'updateMovement(this, {' Line Number: 464
Code edit (1 edits merged)
Please save this source code
User prompt
list all layers
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'game.layers.ufo.addChild(ufo);' Line Number: 533
User prompt
Please fix the bug: 'spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1001
User prompt
Please fix the bug: 'spawnBird1 is not defined' in or related to this line: 'spawnBird1();' Line Number: 993
User prompt
Please fix the bug: 'light1 is not defined' in or related to this line: 'if (game.children.includes(light1)) {' Line Number: 975
User prompt
Please fix the bug: 'BirdMovement is not defined' in or related to this line: 'Bird2Movement.prototype = Object.create(BirdMovement.prototype);' Line Number: 599
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'clouds')' in or related to this line: 'game.layers.clouds.addChild(cloud);' Line Number: 532
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Background class to represent the background image var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(backgroundGraphics); }); // 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 }); // Apply movement system Bird1Movement(self, birdGraphics); self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); // 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 }); // Apply movement system Bird2Movement(self, birdGraphics); self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); // This is a duplicate checkInteractions function that has been consolidated elsewhere // Layer z-index management is handled by the layerStructure configuration // Layer structure and initialization is already handled at the beginning of the file // Consolidated checkInteractions function is inserted below // Bird2Movement class to handle Bird2 movement // Bird2Movement class to handle Bird2 movement // 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 // 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 }); // 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 () { updateMovement(self, { movementType: 'sinusoidal', amplitude: 0.125, frequency: 100, offset: 50 }); }; }); // Jet class to represent a jet flying across the screen var Jet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-right', { anchorX: 0.5, anchorY: 0.5 }); // Apply movement system JetMovement(self, jetGraphics); self.onDestroy = function () { LK.getSound('jetSound').stop(); // Ensure sound stops when jet is destroyed }; self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); var JetLeft = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-left', { anchorX: 0.5, anchorY: 0.5 }); // Apply movement system with fixed left direction JetMovement(self, jetGraphics); self.direction = -1; // Always left self.onDestroy = function () { LK.getSound('jetSound').stop(); }; }); var JetRight = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-right', { anchorX: 0.5, anchorY: 0.5 }); // Apply movement system with fixed right direction JetMovement(self, jetGraphics); self.direction = 1; // Always right self.onDestroy = function () { LK.getSound('jetSound').stop(); }; }); // 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(); // Apply movement system LaserMovement(self, laserGraphics, startX, startY, targetX, targetY); return self; }); // Light1 class to represent a light object var Light1 = Container.expand(function () { var self = Container.call(this); var lightGraphics = self.attachAsset('light1', { anchorX: 0.5, anchorY: 0.5, alpha: 0.2 // Set transparency to 20% }); self.x = 450, self.y = 440; self.update = function () { // Add any specific update logic for the light here }; self.pulse = new Light1Pulse(lightGraphics); self.pulse.startPulsating(); }); // Mirror class to manage score display var Mirror = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 14 // Rotate image right 15 degrees }); var scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = 40; // Move score text up by 20px scoreText.x = -145; // Move score text left by 10px scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // Mirror1 class to represent the mirror image var Mirror1 = Container.expand(function () { var self = Container.call(this); var mirror1Graphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(mirror1Graphics); }); // 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 }; // Start the pulsating effect for the reticle startPulsating(self); }); // Reticle1 class to represent the reticle image var Reticle1 = Container.expand(function () { var self = Container.call(this); var reticle1Graphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(reticle1Graphics); }); // ScoreImage class to represent the score image var ScoreImage = Container.expand(function () { var self = Container.call(this); var scoreImageGraphics = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(scoreImageGraphics); }); // 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, rotation: Math.PI / -12 }); self.update = function () { // Add any specific update logic for stack1 here }; }); // 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 }); self.pulse = new SunPulse(sunGraphics); self.pulse.startPulsating(); }); // 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 stroke: 0x000000, // Add a black stroke strokeThickness: 15 // Set stroke thickness to 15px }); self.update = function () { // Add any specific update logic for the tree here }; }); // Tree2 class to represent the second type of tree var Tree2 = Container.expand(function () { var self = Container.call(this); var tree2Graphics = self.attachAsset('tree2', { anchorX: 0.5, anchorY: 1 }); self.addChild(tree2Graphics); }); // UFO class to represent a UFO var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); // Apply movement system UFOMovement(self, ufoGraphics); self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); // UFO2 class to represent the second type of UFO var UFO2 = Container.expand(function () { var self = Container.call(this); var ufo2Graphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); // Apply movement system UFOMovement(self, ufo2Graphics); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function Bird1Movement(bird, birdGraphics) { createMovementSystem(bird, birdGraphics, { baseSpeed: 1, speedVariation: 1.6, useWaveMotion: true, waveAmplitude: 6.5, waveFrequency: 100, horizontalMovement: false, textures: { left: 'bird1-left', right: 'bird1-right' }, respawnPosition: 'top', sounds: { move: 'wings1', destroy: null }, scoreValue: 10, entityType: 'bird1' }); } // Bird2Movement class to handle Bird2 movement // Bird2Movement class to handle Bird2 movement // Consolidated checkInteractions function is inserted below // Layer structure and initialization is already handled at the beginning of the file // Layer z-index management is handled by the layerStructure configuration // This is a duplicate checkInteractions function that has been consolidated elsewhere // Add base BirdMovement class (missing) // Initialize global variables // Movement system is now handled by js/movements.js // CloudMovement class to handle cloud movement and fade effects function createMovementSystem(entity, graphics, config) { entity.speed = (config.baseSpeed || 1) + Math.random() * (config.speedVariation || 0); entity.lastY = entity.y; entity.lastX = entity.x; entity.direction = config.direction || (Math.random() < 0.5 ? 1 : -1); if (config.sounds && config.sounds.move) { LK.getSound(config.sounds.move).play({ loop: true }); } entity.update = function () { if (config.horizontalMovement) { entity.x += entity.speed * entity.direction; if (config.useWaveMotion) { entity.y = config.baseY + Math.sin(entity.x / config.waveFrequency) * config.waveAmplitude; } } else { entity.y += entity.speed; if (config.useWaveMotion) { entity.x += Math.sin(entity.y / config.waveFrequency) * config.waveAmplitude; } } // Handle off-screen behavior if (entity.lastY <= 2732 && entity.y > 2732 || config.horizontalMovement && (entity.x > 2048 + entity.width / 2 || entity.x < -entity.width / 2)) { if (config.sounds && config.sounds.destroy) { LK.getSound(config.sounds.destroy).stop(); } if (config.respawnPosition === 'top') { entity.y = -entity.height; entity.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048; } else if (config.respawnPosition === 'random') { entity.y = Math.random() * 2732; entity.x = Math.random() < 0.5 ? 0 : 2048; } else if (config.respawnPosition === 'side') { entity.x = entity.direction > 0 ? -entity.width : 2048 + entity.width; } if (config.onRespawn) { config.onRespawn(entity); } } // Update graphics if (graphics && config.textures) { if (entity.lastX <= entity.x) { graphics.texture = LK.getAsset(config.textures.right, {}).texture; } else if (entity.lastX > entity.x) { graphics.texture = LK.getAsset(config.textures.left, {}).texture; } } entity.lastX = entity.x; entity.lastY = entity.y; }; entity.destroy = function () { if (config.sounds) { if (config.sounds.move) { LK.getSound(config.sounds.move).stop(); } if (config.sounds.destroy) { LK.getSound(config.sounds.destroy).stop(); } } if (config.onDestroy) { config.onDestroy(entity); } }; } function Bird2Movement(bird, birdGraphics) { createMovementSystem(bird, birdGraphics, { baseSpeed: 1, speedVariation: 1.6, useWaveMotion: true, waveAmplitude: 6.5, waveFrequency: 100, horizontalMovement: false, textures: { left: 'bird2-left', right: 'bird2-right' }, respawnPosition: 'random', sounds: { move: 'wings1', destroy: null }, scoreValue: 10, entityType: 'bird2' }); } var CloudMovement = function CloudMovement(cloud, cloudGraphics) { this.cloud = cloud; this.cloudGraphics = cloudGraphics; this.hasAccelerated = false; this.lastIntersecting = false; createMovementSystem(cloud, cloudGraphics, { baseSpeed: Math.random() * 0.55 + 0.25, horizontalMovement: true, useWaveMotion: false, entityType: 'cloud', screenBounds: { width: 2048, height: 2732 }, respawnPosition: 'side', onRespawn: function onRespawn(entity) { entity.x = entity.direction > 0 ? -entity.width / 2 : 2048 + entity.width / 2; } }); var originalUpdate = this.cloud.update; this.cloud.update = function () { originalUpdate.call(this); // 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; this.hasAccelerated = true; } break; } else if (this.hasAccelerated && !this.intersects(clouds[i])) { this.speed /= 1.5; this.hasAccelerated = false; } } // Check if the cloud intersects with the sun if (!this.lastIntersecting && this.intersects(sun)) { this.speed *= 2; if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } } else if (this.lastIntersecting && !this.intersects(sun)) { this.speed /= 2; if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } } this.lastIntersecting = this.intersects(sun); }.bind(this.cloud); }; var birds = []; var clouds = []; var ufo = null; var score = 0; var scoreDisplay = null; // Initialize game layers with a single, organized structure // Add missing game.layers initialization game.layers = { background: new Container(), clouds: new Container(), ufo: new Container(), jetLeft: new Container(), jetRight: new Container(), birds: new Container(), enemies: new Container(), laser: new Container(), reticle: new Container(), grassBack: new Container(), grassFront: new Container() }; // Add these layers to the game Object.keys(game.layers).forEach(function (key) { game.addChild(game.layers[key]); }); // Duplicate game.layers initialization removed /** * Creates and adds a UFO to the game * @returns {Object} The created UFO object */ function addUFO() { if (ufo) { return ufo; } // Create new UFO instance var ufo = new UFO(); // Add to UFO layer game.layers.ufo.addChild(ufo); // Add to enemies layer for collision detection game.layers.enemies.addChild(ufo); // Set initial position (either left or right side of screen) ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; ufo.y = Math.random() * (2732 / 2 - ufo.height); // Play UFO sound LK.getSound('ufo1').play(); return ufo; } // Bird spawning functions // Add missing spawn functions function spawnBird1() { var bird = new Bird1(); bird.x = Math.random() * 2048; bird.y = -bird.height; birds.push(bird); game.layers.birds.addChild(bird); game.layers.enemies.addChild(bird); return bird; } function spawnBird2() { var bird = new Bird2(); bird.x = Math.random() * 2048; bird.y = -bird.height; birds.push(bird); game.layers.birds.addChild(bird); game.layers.enemies.addChild(bird); return bird; } // Consolidated bird spawning functions // Consolidated bird spawning functions are inserted below // Jet timer function var jetTimer = LK.setTimeout(function () { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2 - jet.height); // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); game.jetSoundPlayed = true; } jetTimer = LK.setTimeout(arguments.callee, 5000); }, Math.random() * 5000 + 5000); // Cloud initialization for (var i = 0; i < 4; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); clouds.push(cloud); game.layers.clouds.addChild(cloud); } // Handle click/tap events game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.layers.reticle.addChild(new Reticle()); } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x - 140, cat.y - 440, x, y); game.layers.laser.addChild(laser); }; // This is a duplicate checkInteractions function that has been consolidated elsewhere // Object placements are handled in the main initialization section // This is a duplicate addUFO function that has been consolidated elsewhere // Consolidated bird spawning functions // Consolidated bird spawning functions are inserted below var jetTimer = LK.setTimeout(function () { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2 - jet.height); // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); game.jetSoundPlayed = true; } jetTimer = LK.setTimeout(arguments.callee, 5000); }, Math.random() * 5000 + 5000); for (var i = 0; i < 4; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); clouds.push(cloud); game.layers.clouds.addChild(cloud); } game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.layers.reticle.addChild(new Reticle()); } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x - 140, cat.y - 440, x, y); game.layers.laser.addChild(laser); }; // This is a duplicate checkInteractions function that has been consolidated elsewhere // Layer structure and initialization is already handled at the beginning of the file // Layer z-index management is handled by the layerStructure configuration // The spawn functions for UFO, Bird1, Bird2, and Jet are already defined earlier in the code // Layer z-index management is handled by the layerStructure configuration // The game.down function is already defined earlier in the code game.addChild(game.layers.enemies); Bird2Movement.prototype = Object.create(BirdMovement.prototype); Bird2Movement.prototype.constructor = Bird2Movement; // CloudMovement class to handle cloud movement and fade effects var CloudMovement = function CloudMovement(cloud, cloudGraphics) { this.cloud = cloud; this.cloudGraphics = cloudGraphics; this.hasAccelerated = false; this.lastIntersecting = false; createMovementSystem(cloud, cloudGraphics, { baseSpeed: Math.random() * 0.55 + 0.25, horizontalMovement: true, useWaveMotion: false, entityType: 'cloud', screenBounds: { width: 2048, height: 2732 }, respawnPosition: 'side', onRespawn: function onRespawn(entity) { entity.x = entity.direction > 0 ? -entity.width / 2 : 2048 + entity.width / 2; } }); var originalUpdate = this.cloud.update; this.cloud.update = function () { originalUpdate.call(this); // 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; this.hasAccelerated = true; } break; } else if (this.hasAccelerated && !this.intersects(clouds[i])) { this.speed /= 1.5; this.hasAccelerated = false; } } // Check if the cloud intersects with the sun if (!this.lastIntersecting && this.intersects(sun)) { this.speed *= 2; if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } } else if (this.lastIntersecting && !this.intersects(sun)) { this.speed /= 2; if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } } this.lastIntersecting = this.intersects(sun); }.bind(this.cloud); }; // UFOMovement class to handle UFO movement // UFOMovement has been moved to js/movements.js // Generic Pulse class that can be used for both Sun and Light1 var Pulse = function Pulse(graphics, scaleMax, duration) { this.graphics = graphics; this.scaleMax = scaleMax || 1.1; this.duration = duration || 1000; this.startPulsating = function () { function pulsate() { tween(this.graphics, { scaleX: this.scaleMax, scaleY: this.scaleMax }, { duration: this.duration, easing: tween.easeInOut, onFinish: function () { tween(this.graphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: this.duration, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; // Light1Pulse now uses the generic Pulse class var Light1Pulse = function Light1Pulse(lightGraphics) { return new Pulse(lightGraphics, 1.6, 1500); }; // SunPulse now uses the generic Pulse class var SunPulse = function SunPulse(sunGraphics) { return new Pulse(sunGraphics, 1.1, 1000); }; var bird2; // Define bird2 variable in the global scope // Bird2Effects class to handle effects and animations for Bird2 // Consolidated function to create a pulsating effect function startPulsating(target, duration) { duration = duration || 888; function pulsate() { tween(target, { scaleX: 1.1, // Use consistent scale value 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 UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music function playSoundEffect(soundName, action) { var volume = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var sound = LK.getSound(soundName); switch (action) { case 'play': sound.play({ volume: volume, loops: loops }); break; case 'stop': sound.stop(); break; case 'pause': sound.pause(); break; } } var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 50000); } }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; /** * Bird1 movement configuration */ function BirdMovement(bird, birdGraphics, birdType) { createMovementSystem(bird, birdGraphics, { baseSpeed: 1, speedVariation: 1.6, useWaveMotion: true, waveAmplitude: 6.5, waveFrequency: 100, horizontalMovement: false, textures: { left: "".concat(birdType, "-left"), right: "".concat(birdType, "-right") }, respawnPosition: birdType === 'bird1' ? 'top' : 'random', sounds: { move: 'wings1', destroy: null }, scoreValue: 10, entityType: birdType }); } /** * Bird2 movement configuration */ function UFOMovement(ufo, ufoGraphics) { createMovementSystem(ufo, ufoGraphics, { baseSpeed: 3, speedVariation: 0, useWaveMotion: true, waveAmplitude: 50, waveFrequency: 100, horizontalMovement: true, baseY: 100, textures: null, sounds: { move: 'ufo1', destroy: null }, onDestroy: function onDestroy(entity) { entity.destroy(); ufo = null; handleUFOReappearance(); }, scoreValue: 20, entityType: 'ufo' }); } /** * Jet movement configuration */ function JetMovement(jet, jetGraphics) { createMovementSystem(jet, jetGraphics, { baseSpeed: 8, speedVariation: 0, useWaveMotion: true, waveAmplitude: 100, waveFrequency: 100, horizontalMovement: true, baseY: 300, textures: { left: 'jet-left', right: 'jet-right' }, respawnPosition: 'side', sounds: { move: 'jetSound', destroy: 'jetSound' }, onDestroy: function onDestroy(entity) { jet = null; handleJetReappearance(); }, entityType: 'jet' }); } /** * Laser movement configuration */ function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) { // 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 laser.vx = dx / distance * speed; laser.vy = dy / distance * speed; // Set initial position laser.x = startX; laser.y = startY; // Apply movement system with laser-specific configuration createMovementSystem(laser, laserGraphics, { entityType: 'laser', sounds: { move: 'laser2', destroy: null }, scoreValue: 0, screenBounds: { width: 2048, height: 2732 } }); return laser; } // CloudMovement class is already defined earlier in the file var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { // Apply swooping animation effect tween(this.bird, { rotation: Math.sin(this.bird.y / 100) * 0.2 }, { duration: 1000, easing: tween.easeInOut }); // Apply scale pulsing effect when moving fast if (Math.abs(this.bird.x - this.bird.lastX) > 5) { tween(this.bird, { scaleX: 1.1, scaleY: 1.1 }, { duration: 500, easing: tween.easeOut, onFinish: function () { tween(this.bird, { scaleX: 1.0, scaleY: 1.0 }, { duration: 500, easing: tween.easeIn }); }.bind(this) }); } }; }; var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2 - 100; game.layers.background.addChild(background); 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 birds = []; game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.layers.reticle.addChild(new Reticle()); } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point game.layers.laser.addChild(laser); }; 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.layers.reticle.addChild(new Reticle()); } if (obj.event) { var x = obj.event.x; var y = obj.event.y; } game.reticle.x = x; game.reticle.y = y; }; // Initialize sun and light1 var sun = game.layers.background.addChild(new Sun()); sun.x = 1800; sun.y = 300; var light1 = game.layers.background.addChild(new Light1()); light1.x = 450; light1.y = 440; // Add a sun to the game in the top left corner // Duplicate sun placement removed // Duplicate light1 placement removed // Move light1 down by 210px // Ensure light1 is added to the game before setting its index if (game.children.includes(light1)) { game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun // Add score display var scoreDisplay = game.addChild(new Mirror()); scoreDisplay.x = 1700; scoreDisplay.y = 300; } // Function to add a UFO to the game // 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.layers.clouds.addChild(cloud); // No need to add cloud directly to game since it's already in the clouds layer } var bird1; // Define bird1 variable in the global scope // Initialize birds spawnBird1(); spawnBird2(); 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 // Start UFO 3 seconds after game loads var ufoTimer = LK.setTimeout(function () { ufo = addUFO(); }, 3000); // Function to handle UFO reappearance logic // Function to handle UFO reappearance logic function handleUFOReappearance() { if (!ufo) { // Start a timer for the UFO to reappear 10-20 seconds after it leaves the screen ufoTimer = LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 10000 + 10000); } } // Initialize a timer to add a Jet at a random time between 5 and 10 seconds var jet; // Define the jet variable in the global scope var jetTimer = LK.setTimeout(function () { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; // Start from either the far right or left edge of the screen jet.y = Math.random() * (2732 / 2 - jet.height); // Random initial y position within the top half of the screen // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); // Play jet sound when it appears game.jetSoundPlayed = true; // Ensure it only plays once } // Reset the timer for the Jet to reappear every 5 seconds after it leaves the screen jetTimer = LK.setTimeout(arguments.callee, 5000); }, Math.random() * 5000 + 5000); // Initial interval for Jet appearances 5-10 seconds after page load // Initialize enemy movement systems function initEnemyMovement(enemy) { if (enemy instanceof Bird1) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1'); } if (enemy instanceof Bird2) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2'); } if (enemy instanceof UFO) { enemy.movementSystem = new UFOMovement(enemy, enemy.graphics); } } // Main game loop function gameTick() { game.layers.enemies.children.forEach(function (enemy) { var _enemy$movementSystem; (_enemy$movementSystem = enemy.movementSystem) === null || _enemy$movementSystem === void 0 || _enemy$movementSystem.update(); }); checkInteractions(); requestAnimationFrame(gameTick); } /** * Main game update function * Uses the unified movement system for all entities */ game.update = function () { // Update all clouds for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } // Ensure at least 3 clouds are visible while (clouds.length < 3) { 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.layers.clouds.addChild(cloud); } // Update all birds birds.forEach(function (bird) { bird.update(); }); // Ensure we have enough birds while (birds.length < 3) { if (birds.length % 2 === 0) { spawnBird1(); } else { spawnBird2(); } } // Update all lasers game.layers.laser.children.forEach(function (laser) { laser.update(); }); // Update UFO if it exists if (ufo) { ufo.update(); } // Check for all interactions between game entities checkInteractions(); }; // Function to spawn a third kind of bird // Consolidated bird spawning functions are inserted below // Ensure there are always 3 birds on screen // Initialize enemy movement systems game.update = function () { // Update each bird birds.forEach(function (bird, index) { bird.update(); // Check for intersections with other birds birds.forEach(function (otherBird, otherIndex) { if (index !== otherIndex && !bird.lastIntersecting && bird.intersects(otherBird)) { // Calculate bounce direction var dx = bird.x - otherBird.x; var dy = bird.y - otherBird.y; var distance = Math.sqrt(dx * dx + dy * dy); var bounceFactor = 5; // Adjust bounce factor for desired effect // Apply bounce with acceleration bird.x += dx / distance * bounceFactor; bird.y += dy / distance * bounceFactor; otherBird.x -= dx / distance * bounceFactor; otherBird.y -= dy / distance * bounceFactor; // Mark as intersecting bird.lastIntersecting = true; otherBird.lastIntersecting = true; } }); // Reset intersection state bird.lastIntersecting = birds.some(function (otherBird, otherIndex) { return index !== otherIndex && bird.intersects(otherBird); }); // 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 } }); }; // Note: Tree and stack1 are already added to their respective layers earlier in the code // This section is redundant and can be removed var score = 0; // Add the grass floor to the game var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom // Note: grassFront and mirror are already added to their respective layers earlier in the code // This section is redundant and can be removed as it causes duplicate rendering // 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: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 50000); } }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Ensure cat is added to the game before setting its index if (game.children.includes(cat)) { game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value } // 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: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { return LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 20000); } }); }, Math.random() * 30000 + 50000); } // Proper event chaining }); }, 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); }); /** * Check for interactions between game entities */ function checkInteractions() { // Lasers vs Enemies game.layers.laser.children.forEach(function (laser) { game.layers.enemies.children.forEach(function (enemy) { if (laser.intersects(enemy)) { // Use the handleLaserCollision method if available if (enemy.handleLaserCollision) { enemy.handleLaserCollision(laser); } else { enemy.destroy(); laser.destroy(); } // Add score based on entity's score value if (enemy.getScoreValue) { var _scoreDisplay; score += enemy.getScoreValue(); (_scoreDisplay = scoreDisplay) === null || _scoreDisplay === void 0 || _scoreDisplay.updateScore(score); } } }); }); // UFO vs Enemies var ufo = game.layers.enemies.children.find(function (child) { return child instanceof UFO; }); if (ufo) { game.layers.enemies.children.forEach(function (enemy) { if (enemy !== ufo && ufo.intersects(enemy)) { enemy.destroy(); LK.getSound('electro').play(); } }); } } /**** * Utility Functions ****/ /** * Simple movement update function that works with the consolidated movement system * This is kept for backward compatibility with existing code that uses it */ function updateMovement(obj, params) { // If the object already has a movement system applied, use that if (typeof obj.update === 'function' && obj.speed !== undefined) { obj.speed = params.speed || obj.speed; obj.direction = params.direction || obj.direction; return; } // Otherwise apply simple movement obj.x += params.speed * params.direction; if (params.boundaryCheck) { handleScreenBoundaries(obj, params.boundaryWidth); } } function updateDirection(obj, graphics, rightAsset, leftAsset) { graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture; } function handleScreenBoundaries(obj, screenWidth) { if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) { obj.x = -obj.width / 2; } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) { obj.x = screenWidth + obj.width / 2; } } function handleCollisions(obj, others, collisionHandler) { others.forEach(function (other) { if (other !== obj && obj.intersects(other)) { collisionHandler(obj, other); } }); } function handleSunInteraction(obj, sun, enterHandler, exitHandler) { var intersecting = obj.intersects(sun); if (!obj.lastIntersecting && intersecting) { enterHandler(obj); } else if (obj.lastIntersecting && !intersecting) { exitHandler(obj); } obj.lastIntersecting = intersecting; } function handleDestruction(obj, sounds) { if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) { sounds.forEach(function (sound) { return LK.getSound(sound).stop(); }); obj.destroy(); } } // Updated Cloud update method self.cloud.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction, boundaryCheck: true, boundaryWidth: 2048 }); handleCollisions(this, clouds, function (cloud, other) { if (!cloud.hasAccelerated) { cloud.speed *= 1.5; cloud.hasAccelerated = true; } }); handleSunInteraction(this, sun, function (cloud) { cloud.speed *= 2; tween(cloud.cloudGraphics, { alpha: 0.5 }, { duration: 3000 }); }, function (cloud) { cloud.speed /= 2; tween(cloud.cloudGraphics, { alpha: 1.0 }, { duration: 3000 }); }); this.lastX = this.x; }; // Updated Jet update method self.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction }); updateDirection(this, jetGraphics, 'jet-right', 'jet-left'); handleDestruction(this, ['jetSound']); }; // Note: Tree and stack1 are already added to their respective layers earlier in the code // This section is redundant and can be removed var score = 0; // Add the grass floor to the game var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom // Note: grassFront and mirror are already added to their respective layers earlier in the code
===================================================================
--- original.js
+++ change.js
@@ -5,27 +5,54 @@
/****
* Classes
****/
+// Background class to represent the background image
+var Background = Container.expand(function () {
+ var self = Container.call(this);
+ var backgroundGraphics = self.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(backgroundGraphics);
+});
// 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);
+ // Apply movement system
+ Bird1Movement(self, birdGraphics);
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
+ }
+ };
});
// 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);
+ // Apply movement system
+ Bird2Movement(self, birdGraphics);
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
+ }
+ };
});
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Layer z-index management is handled by the layerStructure configuration
+// Layer structure and initialization is already handled at the beginning of the file
+// Consolidated checkInteractions function is inserted below
+// Bird2Movement class to handle Bird2 movement
+// Bird2Movement class to handle Bird2 movement
// Cat class to manage cat behavior
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
@@ -46,63 +73,8 @@
});
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', {
@@ -114,32 +86,8 @@
// 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);
@@ -149,14 +97,60 @@
});
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
+ updateMovement(self, {
+ movementType: 'sinusoidal',
+ amplitude: 0.125,
+ frequency: 100,
+ offset: 50
+ });
};
});
+// Jet class to represent a jet flying across the screen
+var Jet = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-right', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Apply movement system
+ JetMovement(self, jetGraphics);
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop(); // Ensure sound stops when jet is destroyed
+ };
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
+ }
+ };
+});
+var JetLeft = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-left', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Apply movement system with fixed left direction
+ JetMovement(self, jetGraphics);
+ self.direction = -1; // Always left
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop();
+ };
+});
+var JetRight = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-right', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Apply movement system with fixed right direction
+ JetMovement(self, jetGraphics);
+ self.direction = 1; // Always right
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop();
+ };
+});
// 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', {
@@ -165,212 +159,548 @@
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();
- }
- };
+ // Apply movement system
+ LaserMovement(self, laserGraphics, startX, startY, targetX, targetY);
+ return self;
});
-// Reticle class to manage reticle behavior
-var Reticle = Container.expand(function () {
+// Light1 class to represent a light object
+var Light1 = Container.expand(function () {
var self = Container.call(this);
- var reticleGraphics = self.attachAsset('reticle1', {
+ var lightGraphics = self.attachAsset('light1', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ alpha: 0.2 // Set transparency to 20%
});
+ self.x = 450, self.y = 440;
self.update = function () {
- // Add any specific update logic for the reticle here
+ // Add any specific update logic for the light here
};
+ self.pulse = new Light1Pulse(lightGraphics);
+ self.pulse.startPulsating();
});
-// ScoreDisplay class to manage score display
-var ScoreDisplay = Container.expand(function () {
+// Mirror class to manage score display
+var Mirror = Container.expand(function () {
var self = Container.call(this);
- var scoreGraphics = self.attachAsset('scoreImage', {
+ var scoreGraphics = self.attachAsset('mirror1', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ rotation: Math.PI / 14 // Rotate image right 15 degrees
});
var scoreText = new Text2('0', {
size: 175,
- fill: 0x00FF00,
+ fill: 0x800080,
font: "Courier New, Courier, monospace",
// Segmented clock style font
- stroke: 0x000000,
- strokeThickness: 5,
+ stroke: 0x00FF00,
+ strokeThickness: 15,
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;
+ scoreText.y = 40; // Move score text up by 20px
+ scoreText.x = -145; // Move score text left by 10px
+ scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
});
+// Mirror1 class to represent the mirror image
+var Mirror1 = Container.expand(function () {
+ var self = Container.call(this);
+ var mirror1Graphics = self.attachAsset('mirror1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(mirror1Graphics);
+});
+// 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
+ };
+ // Start the pulsating effect for the reticle
+ startPulsating(self);
+});
+// Reticle1 class to represent the reticle image
+var Reticle1 = Container.expand(function () {
+ var self = Container.call(this);
+ var reticle1Graphics = self.attachAsset('reticle1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(reticle1Graphics);
+});
+// ScoreImage class to represent the score image
+var ScoreImage = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreImageGraphics = self.attachAsset('scoreImage', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(scoreImageGraphics);
+});
+// 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,
+ rotation: Math.PI / -12
+ });
+ 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
+ self.pulse = new SunPulse(sunGraphics);
+ self.pulse.startPulsating();
});
// 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
+ antialias: true,
+ // Apply antialias effect
+ stroke: 0x000000,
+ // Add a black stroke
+ strokeThickness: 15 // Set stroke thickness to 15px
});
self.update = function () {
// Add any specific update logic for the tree here
};
});
-// UFO class to represent a UFO flying across the screen
+// Tree2 class to represent the second type of tree
+var Tree2 = Container.expand(function () {
+ var self = Container.call(this);
+ var tree2Graphics = self.attachAsset('tree2', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.addChild(tree2Graphics);
+});
+// UFO class to represent a UFO
var UFO = Container.expand(function () {
var self = Container.call(this);
- var ufoGraphics = self.attachAsset('ufo', {
+ var ufoGraphics = self.attachAsset('ufo2', {
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;
+ // Apply movement system
+ UFOMovement(self, ufoGraphics);
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
}
- self.lastX = self.x; // Update lastX after movement
};
});
+// UFO2 class to represent the second type of UFO
+var UFO2 = Container.expand(function () {
+ var self = Container.call(this);
+ var ufo2Graphics = self.attachAsset('ufo2', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Apply movement system
+ UFOMovement(self, ufo2Graphics);
+});
/****
* 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
+ backgroundColor: 0x000000
});
/****
* Game Code
****/
-// Function to create a pulsating effect
-// Bird2Effects class to handle effects and animations for Bird2
-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;
+function Bird1Movement(bird, birdGraphics) {
+ createMovementSystem(bird, birdGraphics, {
+ baseSpeed: 1,
+ speedVariation: 1.6,
+ useWaveMotion: true,
+ waveAmplitude: 6.5,
+ waveFrequency: 100,
+ horizontalMovement: false,
+ textures: {
+ left: 'bird1-left',
+ right: 'bird1-right'
+ },
+ respawnPosition: 'top',
+ sounds: {
+ move: 'wings1',
+ destroy: null
+ },
+ scoreValue: 10,
+ entityType: 'bird1'
+ });
+}
+// Bird2Movement class to handle Bird2 movement
+// Bird2Movement class to handle Bird2 movement
+// Consolidated checkInteractions function is inserted below
+// Layer structure and initialization is already handled at the beginning of the file
+// Layer z-index management is handled by the layerStructure configuration
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Add base BirdMovement class (missing)
+// Initialize global variables
+// Movement system is now handled by js/movements.js
+// CloudMovement class to handle cloud movement and fade effects
+function createMovementSystem(entity, graphics, config) {
+ entity.speed = (config.baseSpeed || 1) + Math.random() * (config.speedVariation || 0);
+ entity.lastY = entity.y;
+ entity.lastX = entity.x;
+ entity.direction = config.direction || (Math.random() < 0.5 ? 1 : -1);
+ if (config.sounds && config.sounds.move) {
+ LK.getSound(config.sounds.move).play({
+ loop: true
+ });
+ }
+ entity.update = function () {
+ if (config.horizontalMovement) {
+ entity.x += entity.speed * entity.direction;
+ if (config.useWaveMotion) {
+ entity.y = config.baseY + Math.sin(entity.x / config.waveFrequency) * config.waveAmplitude;
+ }
+ } else {
+ entity.y += entity.speed;
+ if (config.useWaveMotion) {
+ entity.x += Math.sin(entity.y / config.waveFrequency) * config.waveAmplitude;
+ }
}
- 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;
+ // Handle off-screen behavior
+ if (entity.lastY <= 2732 && entity.y > 2732 || config.horizontalMovement && (entity.x > 2048 + entity.width / 2 || entity.x < -entity.width / 2)) {
+ if (config.sounds && config.sounds.destroy) {
+ LK.getSound(config.sounds.destroy).stop();
}
+ if (config.respawnPosition === 'top') {
+ entity.y = -entity.height;
+ entity.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
+ } else if (config.respawnPosition === 'random') {
+ entity.y = Math.random() * 2732;
+ entity.x = Math.random() < 0.5 ? 0 : 2048;
+ } else if (config.respawnPosition === 'side') {
+ entity.x = entity.direction > 0 ? -entity.width : 2048 + entity.width;
+ }
+ if (config.onRespawn) {
+ config.onRespawn(entity);
+ }
}
- this.lastY = this.y; // Update lastY after movement
- this.lastX = this.x; // Update lastX after movement
+ // Update graphics
+ if (graphics && config.textures) {
+ if (entity.lastX <= entity.x) {
+ graphics.texture = LK.getAsset(config.textures.right, {}).texture;
+ } else if (entity.lastX > entity.x) {
+ graphics.texture = LK.getAsset(config.textures.left, {}).texture;
+ }
+ }
+ entity.lastX = entity.x;
+ entity.lastY = entity.y;
};
-};
-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;
+ entity.destroy = function () {
+ if (config.sounds) {
+ if (config.sounds.move) {
+ LK.getSound(config.sounds.move).stop();
}
+ if (config.sounds.destroy) {
+ LK.getSound(config.sounds.destroy).stop();
+ }
}
- 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
+ if (config.onDestroy) {
+ config.onDestroy(entity);
}
- this.lastY = this.y; // Update lastY after movement
};
-};
+}
+function Bird2Movement(bird, birdGraphics) {
+ createMovementSystem(bird, birdGraphics, {
+ baseSpeed: 1,
+ speedVariation: 1.6,
+ useWaveMotion: true,
+ waveAmplitude: 6.5,
+ waveFrequency: 100,
+ horizontalMovement: false,
+ textures: {
+ left: 'bird2-left',
+ right: 'bird2-right'
+ },
+ respawnPosition: 'random',
+ sounds: {
+ move: 'wings1',
+ destroy: null
+ },
+ scoreValue: 10,
+ entityType: 'bird2'
+ });
+}
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.hasAccelerated = false;
+ this.lastIntersecting = false;
+ createMovementSystem(cloud, cloudGraphics, {
+ baseSpeed: Math.random() * 0.55 + 0.25,
+ horizontalMovement: true,
+ useWaveMotion: false,
+ entityType: 'cloud',
+ screenBounds: {
+ width: 2048,
+ height: 2732
+ },
+ respawnPosition: 'side',
+ onRespawn: function onRespawn(entity) {
+ entity.x = entity.direction > 0 ? -entity.width / 2 : 2048 + entity.width / 2;
+ }
+ });
+ var originalUpdate = this.cloud.update;
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;
+ originalUpdate.call(this);
+ // 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;
+ this.hasAccelerated = true;
+ }
+ break;
+ } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
+ this.speed /= 1.5;
+ this.hasAccelerated = false;
+ }
}
+ // Check if the cloud intersects with the sun
+ if (!this.lastIntersecting && this.intersects(sun)) {
+ this.speed *= 2;
+ if (this.cloudGraphics) {
+ tween(this.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
+ }
+ } else if (this.lastIntersecting && !this.intersects(sun)) {
+ this.speed /= 2;
+ if (this.cloudGraphics) {
+ tween(this.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
+ }
+ }
+ this.lastIntersecting = this.intersects(sun);
+ }.bind(this.cloud);
+};
+var birds = [];
+var clouds = [];
+var ufo = null;
+var score = 0;
+var scoreDisplay = null;
+// Initialize game layers with a single, organized structure
+// Add missing game.layers initialization
+game.layers = {
+ background: new Container(),
+ clouds: new Container(),
+ ufo: new Container(),
+ jetLeft: new Container(),
+ jetRight: new Container(),
+ birds: new Container(),
+ enemies: new Container(),
+ laser: new Container(),
+ reticle: new Container(),
+ grassBack: new Container(),
+ grassFront: new Container()
+};
+// Add these layers to the game
+Object.keys(game.layers).forEach(function (key) {
+ game.addChild(game.layers[key]);
+});
+// Duplicate game.layers initialization removed
+/**
+* Creates and adds a UFO to the game
+* @returns {Object} The created UFO object
+*/
+function addUFO() {
+ if (ufo) {
+ return ufo;
+ }
+ // Create new UFO instance
+ var ufo = new UFO();
+ // Add to UFO layer
+ game.layers.ufo.addChild(ufo);
+ // Add to enemies layer for collision detection
+ game.layers.enemies.addChild(ufo);
+ // Set initial position (either left or right side of screen)
+ ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2;
+ ufo.y = Math.random() * (2732 / 2 - ufo.height);
+ // Play UFO sound
+ LK.getSound('ufo1').play();
+ return ufo;
+}
+// Bird spawning functions
+// Add missing spawn functions
+function spawnBird1() {
+ var bird = new Bird1();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ birds.push(bird);
+ game.layers.birds.addChild(bird);
+ game.layers.enemies.addChild(bird);
+ return bird;
+}
+function spawnBird2() {
+ var bird = new Bird2();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ birds.push(bird);
+ game.layers.birds.addChild(bird);
+ game.layers.enemies.addChild(bird);
+ return bird;
+}
+// Consolidated bird spawning functions
+// Consolidated bird spawning functions are inserted below
+// Jet timer function
+var jetTimer = LK.setTimeout(function () {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2 - jet.height);
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
+ }
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true);
+ game.jetSoundPlayed = true;
+ }
+ jetTimer = LK.setTimeout(arguments.callee, 5000);
+}, Math.random() * 5000 + 5000);
+// Cloud initialization
+for (var i = 0; i < 4; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2);
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+}
+// Handle click/tap events
+game.down = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = game.layers.reticle.addChild(new Reticle());
+ }
+ game.reticle.x = x;
+ game.reticle.y = y;
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ game.layers.laser.addChild(laser);
+};
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Object placements are handled in the main initialization section
+// This is a duplicate addUFO function that has been consolidated elsewhere
+// Consolidated bird spawning functions
+// Consolidated bird spawning functions are inserted below
+var jetTimer = LK.setTimeout(function () {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2 - jet.height);
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
+ }
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true);
+ game.jetSoundPlayed = true;
+ }
+ jetTimer = LK.setTimeout(arguments.callee, 5000);
+}, Math.random() * 5000 + 5000);
+for (var i = 0; i < 4; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2);
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+}
+game.down = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = game.layers.reticle.addChild(new Reticle());
+ }
+ game.reticle.x = x;
+ game.reticle.y = y;
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ game.layers.laser.addChild(laser);
+};
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Layer structure and initialization is already handled at the beginning of the file
+// Layer z-index management is handled by the layerStructure configuration
+// The spawn functions for UFO, Bird1, Bird2, and Jet are already defined earlier in the code
+// Layer z-index management is handled by the layerStructure configuration
+// The game.down function is already defined earlier in the code
+game.addChild(game.layers.enemies);
+Bird2Movement.prototype = Object.create(BirdMovement.prototype);
+Bird2Movement.prototype.constructor = Bird2Movement;
+// CloudMovement class to handle cloud movement and fade effects
+var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
+ this.cloud = cloud;
+ this.cloudGraphics = cloudGraphics;
+ this.hasAccelerated = false;
+ this.lastIntersecting = false;
+ createMovementSystem(cloud, cloudGraphics, {
+ baseSpeed: Math.random() * 0.55 + 0.25,
+ horizontalMovement: true,
+ useWaveMotion: false,
+ entityType: 'cloud',
+ screenBounds: {
+ width: 2048,
+ height: 2732
+ },
+ respawnPosition: 'side',
+ onRespawn: function onRespawn(entity) {
+ entity.x = entity.direction > 0 ? -entity.width / 2 : 2048 + entity.width / 2;
+ }
+ });
+ var originalUpdate = this.cloud.update;
+ this.cloud.update = function () {
+ originalUpdate.call(this);
// 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
+ this.speed *= 1.5;
+ this.hasAccelerated = true;
}
break;
} else if (this.hasAccelerated && !this.intersects(clouds[i])) {
- this.speed /= 1.5; // Reset speed to original
- this.hasAccelerated = false; // Reset acceleration state
+ this.speed /= 1.5;
+ this.hasAccelerated = false;
}
}
// Check if the cloud intersects with the sun
if (!this.lastIntersecting && this.intersects(sun)) {
- this.speed *= 2; // Double the speed when touching the sun
+ this.speed *= 2;
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 0.5
}, {
@@ -378,9 +708,9 @@
easing: tween.linear
});
}
} else if (this.lastIntersecting && !this.intersects(sun)) {
- this.speed /= 2; // Reset speed to original when not touching the sun
+ this.speed /= 2;
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 1.0
}, {
@@ -389,52 +719,291 @@
});
}
}
this.lastIntersecting = this.intersects(sun);
- this.lastX = this.x; // Update lastX after movement
- };
+ }.bind(this.cloud);
};
-var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird2 here
+// UFOMovement class to handle UFO movement
+// UFOMovement has been moved to js/movements.js
+// Generic Pulse class that can be used for both Sun and Light1
+var Pulse = function Pulse(graphics, scaleMax, duration) {
+ this.graphics = graphics;
+ this.scaleMax = scaleMax || 1.1;
+ this.duration = duration || 1000;
+ this.startPulsating = function () {
+ function pulsate() {
+ tween(this.graphics, {
+ scaleX: this.scaleMax,
+ scaleY: this.scaleMax
+ }, {
+ duration: this.duration,
+ easing: tween.easeInOut,
+ onFinish: function () {
+ tween(this.graphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: this.duration,
+ easing: tween.easeInOut,
+ onFinish: pulsate.bind(this)
+ });
+ }.bind(this)
+ });
+ }
+ pulsate.call(this);
};
};
-// 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
- };
+// Light1Pulse now uses the generic Pulse class
+var Light1Pulse = function Light1Pulse(lightGraphics) {
+ return new Pulse(lightGraphics, 1.6, 1500);
};
-function startPulsating(target) {
+// SunPulse now uses the generic Pulse class
+var SunPulse = function SunPulse(sunGraphics) {
+ return new Pulse(sunGraphics, 1.1, 1000);
+};
+var bird2; // Define bird2 variable in the global scope
+// Bird2Effects class to handle effects and animations for Bird2
+// Consolidated function to create a pulsating effect
+function startPulsating(target, duration) {
+ duration = duration || 888;
function pulsate() {
tween(target, {
scaleX: 1.1,
+ // Use consistent scale value
scaleY: 1.1
}, {
- duration: 444,
+ duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
scaleX: 1.0,
scaleY: 1.0
}, {
- duration: 444,
+ duration: duration,
easing: tween.easeInOut,
onFinish: pulsate
});
}
});
}
pulsate();
}
+var UFOSound = function UFOSound() {
+ this.play = function () {
+ LK.getSound('ufo1').play();
+ };
+};
+// BackgroundMusic class to manage background music
+function playSoundEffect(soundName, action) {
+ var volume = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
+ var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
+ var sound = LK.getSound(soundName);
+ switch (action) {
+ case 'play':
+ sound.play({
+ volume: volume,
+ loops: loops
+ });
+ break;
+ case 'stop':
+ sound.stop();
+ break;
+ case 'pause':
+ sound.pause();
+ break;
+ }
+}
+var BackgroundMusic = function BackgroundMusic() {
+ this.play = function () {
+ LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 50000);
+ }
+ });
+ };
+};
+// LaserSound class to manage laser sound effects
+var LaserSound = function LaserSound() {
+ this.play = function () {
+ LK.getSound('laser1').play();
+ };
+};
+/**
+* Bird1 movement configuration
+*/
+function BirdMovement(bird, birdGraphics, birdType) {
+ createMovementSystem(bird, birdGraphics, {
+ baseSpeed: 1,
+ speedVariation: 1.6,
+ useWaveMotion: true,
+ waveAmplitude: 6.5,
+ waveFrequency: 100,
+ horizontalMovement: false,
+ textures: {
+ left: "".concat(birdType, "-left"),
+ right: "".concat(birdType, "-right")
+ },
+ respawnPosition: birdType === 'bird1' ? 'top' : 'random',
+ sounds: {
+ move: 'wings1',
+ destroy: null
+ },
+ scoreValue: 10,
+ entityType: birdType
+ });
+}
+/**
+* Bird2 movement configuration
+*/
+function UFOMovement(ufo, ufoGraphics) {
+ createMovementSystem(ufo, ufoGraphics, {
+ baseSpeed: 3,
+ speedVariation: 0,
+ useWaveMotion: true,
+ waveAmplitude: 50,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: 100,
+ textures: null,
+ sounds: {
+ move: 'ufo1',
+ destroy: null
+ },
+ onDestroy: function onDestroy(entity) {
+ entity.destroy();
+ ufo = null;
+ handleUFOReappearance();
+ },
+ scoreValue: 20,
+ entityType: 'ufo'
+ });
+}
+/**
+* Jet movement configuration
+*/
+function JetMovement(jet, jetGraphics) {
+ createMovementSystem(jet, jetGraphics, {
+ baseSpeed: 8,
+ speedVariation: 0,
+ useWaveMotion: true,
+ waveAmplitude: 100,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: 300,
+ textures: {
+ left: 'jet-left',
+ right: 'jet-right'
+ },
+ respawnPosition: 'side',
+ sounds: {
+ move: 'jetSound',
+ destroy: 'jetSound'
+ },
+ onDestroy: function onDestroy(entity) {
+ jet = null;
+ handleJetReappearance();
+ },
+ entityType: 'jet'
+ });
+}
+/**
+* Laser movement configuration
+*/
+function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) {
+ // 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
+ laser.vx = dx / distance * speed;
+ laser.vy = dy / distance * speed;
+ // Set initial position
+ laser.x = startX;
+ laser.y = startY;
+ // Apply movement system with laser-specific configuration
+ createMovementSystem(laser, laserGraphics, {
+ entityType: 'laser',
+ sounds: {
+ move: 'laser2',
+ destroy: null
+ },
+ scoreValue: 0,
+ screenBounds: {
+ width: 2048,
+ height: 2732
+ }
+ });
+ return laser;
+}
+// CloudMovement class is already defined earlier in the file
+var Bird2Effects = function Bird2Effects(bird) {
+ this.bird = bird;
+ this.applyEffects = function () {
+ // Apply swooping animation effect
+ tween(this.bird, {
+ rotation: Math.sin(this.bird.y / 100) * 0.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ // Apply scale pulsing effect when moving fast
+ if (Math.abs(this.bird.x - this.bird.lastX) > 5) {
+ tween(this.bird, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function () {
+ tween(this.bird, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ }.bind(this)
+ });
+ }
+ };
+};
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
-background.y = 2732 / 2 - 200;
+background.y = 2732 / 2 - 100;
+game.layers.background.addChild(background);
game.addChild(background);
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
var self = this;
@@ -449,35 +1018,17 @@
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 = game.layers.reticle.addChild(new Reticle());
}
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 laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
+ game.layers.laser.addChild(laser);
};
var VOLUME_BGM1 = 0.02;
var VOLUME_BREEZE1 = 0.02;
var VOLUME_CRICKET1 = 0.02;
@@ -486,195 +1037,247 @@
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());
+ game.reticle = game.layers.reticle.addChild(new Reticle());
}
if (obj.event) {
var x = obj.event.x;
var y = obj.event.y;
}
game.reticle.x = x;
game.reticle.y = y;
};
+// Initialize sun and light1
+var sun = game.layers.background.addChild(new Sun());
+sun.x = 1800;
+sun.y = 300;
+var light1 = game.layers.background.addChild(new Light1());
+light1.x = 450;
+light1.y = 440;
// 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;
+// Duplicate sun placement removed
+// Duplicate light1 placement removed // Move light1 down by 210px
+// Ensure light1 is added to the game before setting its index
+if (game.children.includes(light1)) {
+ game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun
+ // Add score display
+ var scoreDisplay = game.addChild(new Mirror());
+ scoreDisplay.x = 1700;
+ scoreDisplay.y = 300;
}
+// Function to add a UFO to the game
// 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
+ game.layers.clouds.addChild(cloud);
+ // No need to add cloud directly to game since it's already in the clouds layer
}
+var bird1; // Define bird1 variable in the global scope
// Initialize birds
spawnBird1();
spawnBird2();
+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
+// Start UFO 3 seconds after game loads
var ufoTimer = LK.setTimeout(function () {
- addUFO();
-}, Math.random() * 10000 + 20000);
+ ufo = addUFO();
+}, 3000);
+// Function to handle UFO reappearance logic
+// Function to handle UFO reappearance logic
+function handleUFOReappearance() {
+ if (!ufo) {
+ // Start a timer for the UFO to reappear 10-20 seconds after it leaves the screen
+ ufoTimer = LK.setTimeout(function () {
+ ufo = addUFO();
+ }, Math.random() * 10000 + 10000);
+ }
+}
+// Initialize a timer to add a Jet at a random time between 5 and 10 seconds
+var jet; // Define the jet variable in the global scope
+var jetTimer = LK.setTimeout(function () {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; // Start from either the far right or left edge of the screen
+ jet.y = Math.random() * (2732 / 2 - jet.height); // Random initial y position within the top half of the screen
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
+ }
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true); // Play jet sound when it appears
+ game.jetSoundPlayed = true; // Ensure it only plays once
+ }
+ // Reset the timer for the Jet to reappear every 5 seconds after it leaves the screen
+ jetTimer = LK.setTimeout(arguments.callee, 5000);
+}, Math.random() * 5000 + 5000); // Initial interval for Jet appearances 5-10 seconds after page load
+// Initialize enemy movement systems
+function initEnemyMovement(enemy) {
+ if (enemy instanceof Bird1) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1');
+ }
+ if (enemy instanceof Bird2) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2');
+ }
+ if (enemy instanceof UFO) {
+ enemy.movementSystem = new UFOMovement(enemy, enemy.graphics);
+ }
+}
+// Main game loop
+function gameTick() {
+ game.layers.enemies.children.forEach(function (enemy) {
+ var _enemy$movementSystem;
+ (_enemy$movementSystem = enemy.movementSystem) === null || _enemy$movementSystem === void 0 || _enemy$movementSystem.update();
+ });
+ checkInteractions();
+ requestAnimationFrame(gameTick);
+}
+/**
+* Main game update function
+* Uses the unified movement system for all entities
+*/
game.update = function () {
+ // Update all clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
+ // Ensure at least 3 clouds are visible
+ while (clouds.length < 3) {
+ 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.layers.clouds.addChild(cloud);
+ }
+ // Update all birds
+ birds.forEach(function (bird) {
+ bird.update();
+ });
+ // Ensure we have enough birds
+ while (birds.length < 3) {
+ if (birds.length % 2 === 0) {
+ spawnBird1();
+ } else {
+ spawnBird2();
+ }
+ }
+ // Update all lasers
+ game.layers.laser.children.forEach(function (laser) {
+ laser.update();
+ });
+ // Update UFO if it exists
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
+ ufo.update();
}
- // Removed auto-targeting update function
+ // Check for all interactions between game entities
+ checkInteractions();
};
// 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);
-}
+// Consolidated bird spawning functions are inserted below
// Ensure there are always 3 birds on screen
+// Initialize enemy movement systems
game.update = function () {
// Update each bird
- birds.forEach(function (bird) {
+ birds.forEach(function (bird, index) {
bird.update();
+ // Check for intersections with other birds
+ birds.forEach(function (otherBird, otherIndex) {
+ if (index !== otherIndex && !bird.lastIntersecting && bird.intersects(otherBird)) {
+ // Calculate bounce direction
+ var dx = bird.x - otherBird.x;
+ var dy = bird.y - otherBird.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var bounceFactor = 5; // Adjust bounce factor for desired effect
+ // Apply bounce with acceleration
+ bird.x += dx / distance * bounceFactor;
+ bird.y += dy / distance * bounceFactor;
+ otherBird.x -= dx / distance * bounceFactor;
+ otherBird.y -= dy / distance * bounceFactor;
+ // Mark as intersecting
+ bird.lastIntersecting = true;
+ otherBird.lastIntersecting = true;
+ }
+ });
+ // Reset intersection state
+ bird.lastIntersecting = birds.some(function (otherBird, otherIndex) {
+ return index !== otherIndex && bird.intersects(otherBird);
+ });
// 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
+// Note: Tree and stack1 are already added to their respective layers earlier in the code
+// This section is redundant and can be removed
var score = 0;
// Add the grass floor to the game
-var grassBack = new GrassBack();
+var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer
grassBack.x = 1020;
grassBack.y = 2735; // Position grassBack at the bottom
-game.addChild(grassBack);
-var grassBackChildIndex = Math.min(9, game.getChildIndex(tree) - 1);
-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 = game.getChildIndex(tree) + 1;
-game.setChildIndex(grassFront, grassFrontChildIndex); // Set grassFront 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
+// Note: grassFront and mirror are already added to their respective layers earlier in the code
+// This section is redundant and can be removed as it causes duplicate rendering
// 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,
+ loop: false,
fade: {
start: 0,
end: 1,
duration: 4000
},
- onEnd: onBgm1End
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 50000);
+ }
});
}, 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.x = 230; // Move the cat 20px to the 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
+// Ensure cat is added to the game before setting its index
+if (game.children.includes(cat)) {
+ game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+}
// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
LK.playMusic('bgm1', {
loop: false,
// Play once
@@ -695,9 +1298,35 @@
end: 0.5,
// Set to the lowest volume
duration: 4000
},
- onEnd: onEnd // Set the onEnd function to replay bgm1
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ return LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(onBgm1End, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 20000);
+ }
+ });
+ }, Math.random() * 30000 + 50000);
+ } // Proper event chaining
});
}, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
}
});
@@ -724,5 +1353,144 @@
}, 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);
-});
\ No newline at end of file
+});
+/**
+* Check for interactions between game entities
+*/
+function checkInteractions() {
+ // Lasers vs Enemies
+ game.layers.laser.children.forEach(function (laser) {
+ game.layers.enemies.children.forEach(function (enemy) {
+ if (laser.intersects(enemy)) {
+ // Use the handleLaserCollision method if available
+ if (enemy.handleLaserCollision) {
+ enemy.handleLaserCollision(laser);
+ } else {
+ enemy.destroy();
+ laser.destroy();
+ }
+ // Add score based on entity's score value
+ if (enemy.getScoreValue) {
+ var _scoreDisplay;
+ score += enemy.getScoreValue();
+ (_scoreDisplay = scoreDisplay) === null || _scoreDisplay === void 0 || _scoreDisplay.updateScore(score);
+ }
+ }
+ });
+ });
+ // UFO vs Enemies
+ var ufo = game.layers.enemies.children.find(function (child) {
+ return child instanceof UFO;
+ });
+ if (ufo) {
+ game.layers.enemies.children.forEach(function (enemy) {
+ if (enemy !== ufo && ufo.intersects(enemy)) {
+ enemy.destroy();
+ LK.getSound('electro').play();
+ }
+ });
+ }
+}
+/****
+* Utility Functions
+****/
+/**
+* Simple movement update function that works with the consolidated movement system
+* This is kept for backward compatibility with existing code that uses it
+*/
+function updateMovement(obj, params) {
+ // If the object already has a movement system applied, use that
+ if (typeof obj.update === 'function' && obj.speed !== undefined) {
+ obj.speed = params.speed || obj.speed;
+ obj.direction = params.direction || obj.direction;
+ return;
+ }
+ // Otherwise apply simple movement
+ obj.x += params.speed * params.direction;
+ if (params.boundaryCheck) {
+ handleScreenBoundaries(obj, params.boundaryWidth);
+ }
+}
+function updateDirection(obj, graphics, rightAsset, leftAsset) {
+ graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture;
+}
+function handleScreenBoundaries(obj, screenWidth) {
+ if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) {
+ obj.x = -obj.width / 2;
+ } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) {
+ obj.x = screenWidth + obj.width / 2;
+ }
+}
+function handleCollisions(obj, others, collisionHandler) {
+ others.forEach(function (other) {
+ if (other !== obj && obj.intersects(other)) {
+ collisionHandler(obj, other);
+ }
+ });
+}
+function handleSunInteraction(obj, sun, enterHandler, exitHandler) {
+ var intersecting = obj.intersects(sun);
+ if (!obj.lastIntersecting && intersecting) {
+ enterHandler(obj);
+ } else if (obj.lastIntersecting && !intersecting) {
+ exitHandler(obj);
+ }
+ obj.lastIntersecting = intersecting;
+}
+function handleDestruction(obj, sounds) {
+ if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) {
+ sounds.forEach(function (sound) {
+ return LK.getSound(sound).stop();
+ });
+ obj.destroy();
+ }
+}
+// Updated Cloud update method
+self.cloud.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction,
+ boundaryCheck: true,
+ boundaryWidth: 2048
+ });
+ handleCollisions(this, clouds, function (cloud, other) {
+ if (!cloud.hasAccelerated) {
+ cloud.speed *= 1.5;
+ cloud.hasAccelerated = true;
+ }
+ });
+ handleSunInteraction(this, sun, function (cloud) {
+ cloud.speed *= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000
+ });
+ }, function (cloud) {
+ cloud.speed /= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000
+ });
+ });
+ this.lastX = this.x;
+};
+// Updated Jet update method
+self.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction
+ });
+ updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
+ handleDestruction(this, ['jetSound']);
+};
+// Note: Tree and stack1 are already added to their respective layers earlier in the code
+// This section is redundant and can be removed
+var score = 0;
+// Add the grass floor to the game
+var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer
+grassBack.x = 1020;
+grassBack.y = 2735; // Position grassBack at the bottom
+// Note: grassFront and mirror are already added to their respective layers earlier in the code
\ No newline at end of file
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
wings1
Sound effect
ufo1
Sound effect
cricket1
Sound effect
frog1
Sound effect
bgm1
Music
breeze1
Sound effect
songbird1
Sound effect
laser1
Sound effect
teslacoil
Sound effect
chitter
Sound effect
laser2
Sound effect
dead1
Sound effect
electro
Sound effect