User prompt
debug the game
User prompt
apply the sun image to the sun object
Code edit (4 edits merged)
Please save this source code
User prompt
debug the game
User prompt
Assign bird1 image to Bird1 object
User prompt
assign bird1 image to bird1 object, do the same fo bird2, ufo, cloud, and tree.
User prompt
Please fix the bug: 'ReferenceError: birds is not defined' in or related to this line: 'birds.forEach(function (bird) {' Line Number: 496
User prompt
Please fix the bug: 'spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 462
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'Game')' in or related to this line: 'var game = new LK.Game({' Line Number: 339
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'Game')' in or related to this line: 'var game = new LK.Game({' Line Number: 339
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'import')' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 34 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'import')' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 37 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'import')' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 37 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'import')' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 37 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'import')' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 34 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
find bugs in the code
Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 184 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
assign bird images to bird objects, ufo image to ufo object, etc.
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'gameInstance = new LK.Game({' Line Number: 1075 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'var gameInstance = new LK.Game({' Line Number: 956 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Branch asset // Bird1 class to represent the first kind of bird var Bird1 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird1-right', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 1.6 + 1; self.lastY = self.y; // Initialize lastY for tracking changes on Y self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% // Check if the bird has moved off-screen if (self.lastY <= 2732 && self.y > 2732) { self.y = -self.height; self.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048; } if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) { birdGraphics.texture = LK.getAsset('bird1-right', {}).texture; } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) { birdGraphics.texture = LK.getAsset('bird1-left', {}).texture; } self.lastY = self.y; // Update lastY after movement self.lastX = self.x; // Update lastX after movement }; }); // 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.speed = Math.random() * 1.6 + 1; self.lastY = self.y; // Initialize lastY for tracking changes on Y self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) { birdGraphics.texture = LK.getAsset('bird2-right', {}).texture; } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) { birdGraphics.texture = LK.getAsset('bird2-left', {}).texture; } self.lastX = self.x; // Update lastX after movement // Check if the bird has moved off-screen if (self.lastY <= 2732 && self.y > 2732) { self.y = Math.random() * 2732; // Random initial y position within the screen height self.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } self.lastY = self.y; // Update lastY after 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.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 }; }); // CloudMovement class to handle cloud movement and fade effects var CloudMovement = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 // Set default opacity to 80% }); self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8 self.hasAccelerated = false; // Track if the cloud has already accelerated self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left self.lastX = self.x; // Track last X position for future checks self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections self.update = function () { self.x += self.speed * self.direction; // If the cloud moves off-screen, reposition it to the opposite side if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) { self.x = -self.width / 2; } else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.x = 2048 + self.width / 2; } // Check for overlap with other clouds for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== self && self.intersects(clouds[i])) { if (!self.hasAccelerated) { self.speed *= 1.5; // Increase speed by 50% self.hasAccelerated = true; // Mark as accelerated } break; } else if (self.hasAccelerated && !self.intersects(clouds[i])) { self.speed /= 1.5; // Reset speed to original self.hasAccelerated = false; // Reset acceleration state } } // Check if the cloud intersects with the sun if (!self.lastIntersecting && self.intersects(sun)) { self.speed *= 2; // Double the speed when touching the sun tween(cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } else if (self.lastIntersecting && !self.intersects(sun)) { self.speed /= 2; // Reset speed to original when not touching the sun tween(cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } self.lastIntersecting = self.intersects(sun); self.lastX = self.x; // Update lastX after movement }; }); // Grass class to represent the grass image var Grass = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; }); // Grass2 class to represent the second grass image var Grass2 = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass2', { anchorX: 0.5, anchorY: 1 }); self.lastX = self.x; // Initialize lastX for tracking changes on X self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50% self.lastX = self.x; // Update lastX after movement }; }); // Laser class to represent a laser shot from the cat var Laser = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var laserGraphics = self.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 // Increase brightness by 200% }); // Play the laser1 sound when the laser is created LK.getSound('laser1').play(); // Calculate direction and speed var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; // Speed of the laser increased by 200% self.vx = dx / distance * speed; self.vy = dy / distance * speed; // Set initial position self.x = startX; self.y = startY; // Update function to move the laser self.update = function () { self.x += self.vx; self.y += self.vy; // Remove laser if it goes off-screen if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; }); // Reticle class to manage reticle behavior var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Add any specific update logic for the reticle here }; }); // ScoreDisplay class to manage score display var ScoreDisplay = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5 }); var scoreText = new Text2('0', { size: 175, fill: 0x00FF00, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x000000, strokeThickness: 5, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = -100; // Move score text up by 10px scoreText.x = -155; // Move score text right by 10px x = 100; y = 100; self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // ScoreManager class to manage score logic // ScoreManager class to manage score logic // Sun class to represent a sun in the top right corner var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); startPulsating(self); // Start the pulsating effect }); // Function to create a pulsating effect // Tree class to represent a tree with a 9:16 aspect ratio var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, antialias: true // Apply antialias effect }); self.update = function () { // Add any specific update logic for the tree here }; }); // UFO class to represent a UFO flying across the screen var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3.2; // Decrease speed by 20% self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left self.lastX = self.x; // Track last X position for future checks self.update = function () { self.x += self.speed * self.direction; self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10% // If the UFO moves off-screen, destroy it and set to null if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.destroy(); ufo = null; } self.lastX = self.x; // Update lastX after movement }; }); /**** * Initialize Game ****/ /**** * Assets LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'}) ****/ // Initialize clouds array var game = new LK.Game({ // No title, no description backgroundColor: 0x000000 // Black }); /**** * Game Code ****/ // Function to create a pulsating effect // Bird2Effects class to handle effects and animations for Bird2 var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird2 here }; }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; function startPulsating(target) { function pulsate() { tween(target, { scaleX: 1.1, scaleY: 1.1 }, { duration: 444, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: 444, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); } // Define layers var LAYER_BACKGROUND = 0; var LAYER_CLOUDS = 1; var LAYER_BIRDS = 2; var LAYER_UFO = 3; var LAYER_GRASS = 4; var LAYER_CAT = 5; var LAYER_RETICLE = 6; var LAYER_LASER = 7; var LAYER_SCORE = 8; // Function to set layer index function setLayerIndex(object, layer) { game.setChildIndex(object, layer); } // Initialize game objects with layers var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2 - 200; game.addChild(background); setLayerIndex(background, LAYER_BACKGROUND); // Add a sun to the game in the top left corner var sun = game.addChild(new Sun()); sun.x = 480; sun.y = 590; setLayerIndex(sun, LAYER_CLOUDS); // Initialize clouds array var clouds = []; 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.addChild(cloud); setLayerIndex(cloud, LAYER_CLOUDS); } // Initialize birds spawnBird1(); spawnBird2(); // Function to spawn a Bird2 and set its layer function spawnBird2() { var bird = new Bird2(); bird.x = Math.random() * 2048; bird.y = -bird.height; bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'Bird2'; bird.color = 0x746130; LK.setTimeout(function () { game.addChild(bird); setLayerIndex(bird, LAYER_BIRDS); birds.push(bird); }, 2000); } // Function to spawn a bird and set its layer 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'; bird.color = 0x746130; LK.setTimeout(function () { game.addChild(bird); setLayerIndex(bird, LAYER_BIRDS); birds.push(bird); }, 2000); } // Ensure there are always 3 birds on screen game.update = function () { // Update each bird birds.forEach(function (bird) { bird.update(); // Check if the bird has moved off-screen if (bird.lastY <= 2732 && bird.y > 2732) { bird.y = -bird.height; // Respawn the bird at the top bird.x = Math.random() * 2048; // Randomize the x position bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird } }); }; // Add a tree to the game var tree = game.addChild(new Tree()); tree.x = 2048 / 2 + 500; // Move the tree 500px to the right tree.y = 2765; // Position the tree on the grass var treeChildIndex = Math.min(7, game.children.length - 1); game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered after Bird1 var score = 0; // Add the grass floor to the game var grass = new Grass(); grass.x = 1020; grass.y = 2735; game.addChild(grass); setLayerIndex(grass, LAYER_GRASS); var grass2 = new Grass2(); grass2.x = 1020; grass2.y = 2735; // Position grass2 at the bottom game.addChild(grass2); var grass2ChildIndex = game.getChildIndex(tree) + 1; game.setChildIndex(grass2, grass2ChildIndex); // Set grass2 to be rendered after the tree var scoreDisplay = new ScoreDisplay(); scoreDisplay.x = 2048 / 2 + 520; scoreDisplay.y = 2732 - 185; game.addChild(scoreDisplay); setLayerIndex(scoreDisplay, LAYER_SCORE); // Function to handle bgm1 end event function onBgm1End() { // Set a timer to replay bgm1 after 50-80 seconds var bgmTimer = LK.setTimeout(function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 200; // Position the cat to the far left cat.y = 2732; // Position the cat at the bottom of the screen var catChildIndex = Math.min(10, game.children.length - 1); game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: onEnd // Set the onEnd function to replay bgm1 }); }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Initialize random timers for each sound to play between 30-50 seconds 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); });
===================================================================
--- original.js
+++ change.js
@@ -5,2473 +5,559 @@
/****
* Classes
****/
-// CloudMovement class to handle cloud movement and fade effects
-// GrassBack class to represent the grass image
-var GrassBack = Container.expand(function () {
+// Branch asset
+// Bird1 class to represent the first kind of bird
+var Bird1 = Container.expand(function () {
var self = Container.call(this);
- var grassGraphics = self.attachAsset('grass-back', {
+ var birdGraphics = self.attachAsset('bird1-right', {
anchorX: 0.5,
- anchorY: 1
+ anchorY: 0.5
});
+ self.speed = Math.random() * 1.6 + 1;
+ self.lastY = self.y; // Initialize lastY for tracking changes on Y
self.update = function () {
- try {
- // 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
- } catch (error) {
- console.error('Error in grass update:', error);
+ self.y += self.speed;
+ self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ // Check if the bird has moved off-screen
+ if (self.lastY <= 2732 && self.y > 2732) {
+ self.y = -self.height;
+ self.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
}
+ if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
+ birdGraphics.texture = LK.getAsset('bird1-right', {}).texture;
+ } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
+ birdGraphics.texture = LK.getAsset('bird1-left', {}).texture;
+ }
+ self.lastY = self.y; // Update lastY after movement
+ self.lastX = self.x; // Update lastX after movement
};
- self.addChild(grassGraphics); // Add grass graphics to the container
- return self;
});
-// GrassFront class to represent the second grass image
-var GrassFront = Container.expand(function () {
+// Bird2 class to represent the second kind of bird
+var Bird2 = Container.expand(function () {
var self = Container.call(this);
- var grass2Graphics = self.attachAsset('grass-front', {
+ var birdGraphics = self.attachAsset('bird2-right', {
anchorX: 0.5,
- anchorY: 1
+ anchorY: 0.5
});
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- self.addChild(grass2Graphics); // Add grass2 graphics to the container
+ self.speed = Math.random() * 1.6 + 1;
+ self.lastY = self.y; // Initialize lastY for tracking changes on Y
self.update = function () {
- updateMovement(self, {
- movementType: 'sinusoidal',
- amplitude: 0.125,
- frequency: 100,
- offset: 50
- });
+ self.y += self.speed;
+ self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
+ birdGraphics.texture = LK.getAsset('bird2-right', {}).texture;
+ } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
+ birdGraphics.texture = LK.getAsset('bird2-left', {}).texture;
+ }
+ self.lastX = self.x; // Update lastX after movement
+ // Check if the bird has moved off-screen
+ if (self.lastY <= 2732 && self.y > 2732) {
+ self.y = Math.random() * 2732; // Random initial y position within the screen height
+ self.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ }
+ self.lastY = self.y; // Update lastY after movement
};
});
-// Jet class to represent a jet flying across the screen
-var Jet = Container.expand(function () {
+// Cat class to manage cat behavior
+var Cat = Container.expand(function () {
var self = Container.call(this);
- var jetGraphics = self.attachAsset('jet-right', {
- x: 0,
- y: 0
+ var catGraphics = self.attachAsset('cat', {
+ anchorX: 0.5,
+ anchorY: 1
});
- createMovementSystem(self, jetGraphics, {
- speed: 10,
- direction: Math.random() < 0.5 ? -1 : 1,
- boundaryCheck: true,
- boundaryWidth: 2048,
- sounds: {
- move: 'jetSound',
- destroy: 'jetSound'
- },
- onDestroy: function onDestroy() {
- LK.getSound('jetSound').stop();
- handleJetReappearance();
- },
- entityType: 'jet'
- });
self.update = function () {
- this.updateMovement();
- updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
+ // Add any specific update logic for the cat here
};
});
-// Laser class to represent a laser shot from the cat
-var Laser = Container.expand(function (config) {
+// Cloud class to represent cloud behavior
+var Cloud = Container.expand(function () {
var self = Container.call(this);
- var startX = config.startX,
- startY = config.startY,
- targetX = config.targetX,
- targetY = config.targetY;
- var laserGraphics = self.attachAsset('laser2', {
+ var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
- brightness: 2.0 // Increase brightness by 200%
+ alpha: 0.8 // Set default opacity to 80%
});
- // Play the laser1 sound when the laser is created
- LK.getSound('laser1').play();
- // Initializes entity movement parameters
- createMovementSystem(self, laserGraphics, {
- entityType: 'laser',
- sounds: {
- move: 'laser2',
- destroy: null
- },
- scoreValue: 0,
- screenBounds: {
- width: 2048,
- height: 2732
+ 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;
}
- });
- return self;
+ // 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
+ };
});
-// Light1 class to represent a light object
-var Light1 = Container.expand(function () {
+// CloudMovement class to handle cloud movement and fade effects
+var CloudMovement = Container.expand(function () {
var self = Container.call(this);
- var lightGraphics = self.attachAsset('light1', {
+ var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0.2 // Set transparency to 20%
+ alpha: 0.8 // Set default opacity to 80%
});
- self.x = 450, self.y = 440;
+ 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 () {
- try {
- // Add any specific update logic for the light here
- } catch (error) {
- console.error('Error in light update:', error);
+ 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
};
- self.pulse = new Light1Pulse(lightGraphics);
- self.pulse.startPulsating();
});
-// Mirror class to manage score display
-var Mirror = Container.expand(function () {
+// Grass class to represent the grass image
+var Grass = Container.expand(function () {
var self = Container.call(this);
- var scoreGraphics = self.attachAsset('mirror1', {
+ var grassGraphics = self.attachAsset('grass', {
anchorX: 0.5,
- anchorY: 0.5,
- rotation: Math.PI / 14 // Rotate image right 15 degrees
+ anchorY: 1
});
- var scoreText = new Text('0', {
- fontSize: 175,
- fill: 0x800080,
- fontFamily: "Courier New, Courier, monospace",
- 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.text = newScore.toString();
+ 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
};
- return self;
});
-// Mirror1 class to represent the mirror image
-var Mirror1 = Container.expand(function () {
+// Grass2 class to represent the second grass image
+var Grass2 = Container.expand(function () {
var self = Container.call(this);
- var mirror1Graphics = self.attachAsset('mirror1', {
+ var grass2Graphics = self.attachAsset('grass2', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 1
});
- self.addChild(mirror1Graphics);
+ self.lastX = self.x; // Initialize lastX for tracking changes on X
+ self.update = function () {
+ // Add any specific update logic for the grass here
+ // Example: Slightly move the grass to simulate wind effect
+ self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
+ self.lastX = self.x; // Update lastX after movement
+ };
});
-var Reticle = Container.expand(function () {
+// 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 reticleGraphics = self.attachAsset('reticle1', {
+ var laserGraphics = self.attachAsset('laser2', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ brightness: 2.0 // Increase brightness by 200%
});
- var pulse = new Pulse(self, {
- scaleMax: 1.2,
- duration: 800
- });
+ // 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 () {
- try {
- // Update reticle position based on current target if needed
- if (self.target) {
- self.x = self.target.x;
- self.y = self.target.y;
- }
- } catch (error) {
- console.error('Error in reticle update:', error);
+ 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();
}
};
- self.setTarget = function (target) {
- self.target = target;
- };
- self.destroy = function () {
- if (pulse) {
- pulse.stop();
- }
- self.target = null;
- Container.prototype.destroy.call(self);
- };
- // Start the pulsating effect
- pulse.startPulsating();
- return self;
});
-// Reticle1 class to represent the reticle image
-var Reticle1 = Container.expand(function () {
+// Reticle class to manage reticle behavior
+var Reticle = Container.expand(function () {
var self = Container.call(this);
- var reticle1Graphics = self.attachAsset('reticle1', {
+ var reticleGraphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
- self.addChild(reticle1Graphics);
+ self.update = function () {
+ // Add any specific update logic for the reticle here
+ };
});
-// ScoreImage class to represent the score image
-var ScoreImage = Container.expand(function () {
+// ScoreDisplay class to manage score display
+var ScoreDisplay = Container.expand(function () {
var self = Container.call(this);
- var scoreImageGraphics = self.attachAsset('scoreImage', {
+ var scoreGraphics = 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
+ var scoreText = new Text2('0', {
+ size: 175,
+ fill: 0x00FF00,
+ font: "Courier New, Courier, monospace",
+ // Segmented clock style font
+ stroke: 0x000000,
+ strokeThickness: 5,
+ dropShadow: true,
+ dropShadowColor: 0x000000,
+ dropShadowBlur: 5,
+ dropShadowAngle: Math.PI / 6,
+ dropShadowDistance: 6
});
- self.update = function () {
- try {
- // Add any specific update logic for stack1 here
- } catch (error) {
- console.error('Error in stack update:', error);
- }
+ scoreText.y = -100; // Move score text up by 10px
+ scoreText.x = -155; // Move score text right by 10px
+ x = 100;
+ y = 100;
+ self.addChild(scoreText);
+ self.updateScore = function (newScore) {
+ scoreText.setText(newScore);
};
- return self;
});
// 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
});
- self.pulse = new SunPulse(sunGraphics);
- self.pulse.startPulsating();
+ startPulsating(self); // Start the pulsating effect
});
// Function to create a pulsating effect
// Tree class to represent a tree with a 9:16 aspect ratio
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
- antialias: true,
- // Apply antialias effect
- stroke: 0x000000,
- // Add a black stroke
- strokeThickness: 15 // Set stroke thickness to 15px
+ antialias: true // Apply antialias effect
});
self.update = function () {
- try {
- // Add any specific update logic for the tree here
- } catch (error) {
- console.error('Error in tree update:', error);
- }
+ // 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
-// Unified UFO class with improved cleanup
+// UFO class to represent a UFO flying across the screen
var UFO = Container.expand(function () {
var self = Container.call(this);
- var ufoGraphics = self.attachAsset('ufo2', {
+ var ufoGraphics = self.attachAsset('ufo', {
anchorX: 0.5,
anchorY: 0.5
});
- // Initialize movement with cleanup tracking
- self._timers = new Set();
- self._sounds = new Set();
- // Initializes entity movement parameters
- createMovementSystem(self, ufoGraphics, MOVEMENT_CONFIGS.ufo);
- self.setChildIndex = function (index) {
- if (game.children.includes(self)) {
- game.setChildIndex(self, index);
+ self.speed = 3.2; // Decrease speed by 20%
+ self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ self.lastX = self.x; // Track last X position for future checks
+ self.update = function () {
+ self.x += self.speed * self.direction;
+ self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10%
+ // If the UFO moves off-screen, destroy it and set to null
+ if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
+ self.destroy();
+ ufo = null;
}
+ self.lastX = self.x; // Update lastX after movement
};
- self.handleLaserCollision = function (laser) {
- if (!laser) {
- return false;
- }
- EntityManager.cleanup(this);
- return true;
- };
- self.destroy = function () {
- if (this._destroyed) {
- return;
- }
- // Use EntityManager for proper cleanup
- EntityManager.cleanup(this);
- }.bind(self);
- return self;
});
/****
* Initialize Game
****/
-// Game instance already initialized above
-// Layer structure initialization with proper cleanup handling
+/****
+* Assets
+LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
+****/
+// Initialize clouds array
var game = new LK.Game({
- backgroundColor: 0x000000
+ // No title, no description
+ backgroundColor: 0x000000 // Black
});
/****
* Game Code
****/
-// Images
-function _typeof(o) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
- return typeof o;
- } : function (o) {
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
- }, _typeof(o);
-}
-function _regeneratorRuntime() {
- "use strict";
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
- _regeneratorRuntime = function _regeneratorRuntime() {
- return e;
- };
- var t,
- e = {},
- r = Object.prototype,
- n = r.hasOwnProperty,
- o = Object.defineProperty || function (t, e, r) {
- t[e] = r.value;
- },
- i = "function" == typeof Symbol ? Symbol : {},
- a = i.iterator || "@@iterator",
- c = i.asyncIterator || "@@asyncIterator",
- u = i.toStringTag || "@@toStringTag";
- function define(t, e, r) {
- return Object.defineProperty(t, e, {
- value: r,
- enumerable: !0,
- configurable: !0,
- writable: !0
- }), t[e];
- }
- try {
- define({}, "");
- } catch (t) {
- define = function define(t, e, r) {
- return t[e] = r;
- };
- }
- function wrap(t, e, r, n) {
- var i = e && e.prototype instanceof Generator ? e : Generator,
- a = Object.create(i.prototype),
- c = new Context(n || []);
- return o(a, "_invoke", {
- value: makeInvokeMethod(t, r, c)
- }), a;
- }
- function tryCatch(t, e, r) {
- try {
- return {
- type: "normal",
- arg: t.call(e, r)
- };
- } catch (t) {
- return {
- type: "throw",
- arg: t
- };
- }
- }
- e.wrap = wrap;
- var h = "suspendedStart",
- l = "suspendedYield",
- f = "executing",
- s = "completed",
- y = {};
- function Generator() {}
- function GeneratorFunction() {}
- function GeneratorFunctionPrototype() {}
- var p = {};
- define(p, a, function () {
- return this;
- });
- var d = Object.getPrototypeOf,
- v = d && d(d(values([])));
- v && v !== r && n.call(v, a) && (p = v);
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
- function defineIteratorMethods(t) {
- ["next", "throw", "return"].forEach(function (e) {
- define(t, e, function (t) {
- return this._invoke(e, t);
- });
- });
- }
- function AsyncIterator(t, e) {
- function invoke(r, o, i, a) {
- var c = tryCatch(t[r], t, o);
- if ("throw" !== c.type) {
- var u = c.arg,
- h = u.value;
- return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
- invoke("next", t, i, a);
- }, function (t) {
- invoke("throw", t, i, a);
- }) : e.resolve(h).then(function (t) {
- u.value = t, i(u);
- }, function (t) {
- return invoke("throw", t, i, a);
- });
- }
- a(c.arg);
- }
- var r;
- o(this, "_invoke", {
- value: function value(t, n) {
- function callInvokeWithMethodAndArg() {
- return new e(function (e, r) {
- invoke(t, n, e, r);
- });
- }
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
- }
- });
- }
- function makeInvokeMethod(e, r, n) {
- var o = h;
- return function (i, a) {
- if (o === f) {
- throw Error("Generator is already running");
- }
- if (o === s) {
- if ("throw" === i) {
- throw a;
- }
- return {
- value: t,
- done: !0
- };
- }
- for (n.method = i, n.arg = a;;) {
- var c = n.delegate;
- if (c) {
- var u = maybeInvokeDelegate(c, n);
- if (u) {
- if (u === y) {
- continue;
- }
- return u;
- }
- }
- if ("next" === n.method) {
- n.sent = n._sent = n.arg;
- } else if ("throw" === n.method) {
- if (o === h) {
- throw o = s, n.arg;
- }
- n.dispatchException(n.arg);
- } else {
- "return" === n.method && n.abrupt("return", n.arg);
- }
- o = f;
- var p = tryCatch(e, r, n);
- if ("normal" === p.type) {
- if (o = n.done ? s : l, p.arg === y) {
- continue;
- }
- return {
- value: p.arg,
- done: n.done
- };
- }
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
- }
- };
- }
- function maybeInvokeDelegate(e, r) {
- var n = r.method,
- o = e.iterator[n];
- if (o === t) {
- return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
- }
- var i = tryCatch(o, e.iterator, r.arg);
- if ("throw" === i.type) {
- return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
- }
- var a = i.arg;
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
- }
- function pushTryEntry(t) {
- var e = {
- tryLoc: t[0]
- };
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
- }
- function resetTryEntry(t) {
- var e = t.completion || {};
- e.type = "normal", delete e.arg, t.completion = e;
- }
- function Context(t) {
- this.tryEntries = [{
- tryLoc: "root"
- }], t.forEach(pushTryEntry, this), this.reset(!0);
- }
- function values(e) {
- if (e || "" === e) {
- var r = e[a];
- if (r) {
- return r.call(e);
- }
- if ("function" == typeof e.next) {
- return e;
- }
- if (!isNaN(e.length)) {
- var o = -1,
- i = function next() {
- for (; ++o < e.length;) {
- if (n.call(e, o)) {
- return next.value = e[o], next.done = !1, next;
- }
- }
- return next.value = t, next.done = !0, next;
- };
- return i.next = i;
- }
- }
- throw new TypeError(_typeof(e) + " is not iterable");
- }
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
- value: GeneratorFunctionPrototype,
- configurable: !0
- }), o(GeneratorFunctionPrototype, "constructor", {
- value: GeneratorFunction,
- configurable: !0
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
- var e = "function" == typeof t && t.constructor;
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
- }, e.mark = function (t) {
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
- }, e.awrap = function (t) {
- return {
- __await: t
- };
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
- return this;
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
- void 0 === i && (i = Promise);
- var a = new AsyncIterator(wrap(t, r, n, o), i);
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
- return t.done ? t.value : a.next();
- });
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
- return this;
- }), define(g, "toString", function () {
- return "[object Generator]";
- }), e.keys = function (t) {
- var e = Object(t),
- r = [];
- for (var n in e) {
- r.push(n);
- }
- return r.reverse(), function next() {
- for (; r.length;) {
- var t = r.pop();
- if (t in e) {
- return next.value = t, next.done = !1, next;
- }
- }
- return next.done = !0, next;
- };
- }, e.values = values, Context.prototype = {
- constructor: Context,
- reset: function reset(e) {
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) {
- for (var r in this) {
- "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
- }
- }
- },
- stop: function stop() {
- this.done = !0;
- var t = this.tryEntries[0].completion;
- if ("throw" === t.type) {
- throw t.arg;
- }
- return this.rval;
- },
- dispatchException: function dispatchException(e) {
- if (this.done) {
- throw e;
- }
- var r = this;
- function handle(n, o) {
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
- }
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
- var i = this.tryEntries[o],
- a = i.completion;
- if ("root" === i.tryLoc) {
- return handle("end");
- }
- if (i.tryLoc <= this.prev) {
- var c = n.call(i, "catchLoc"),
- u = n.call(i, "finallyLoc");
- if (c && u) {
- if (this.prev < i.catchLoc) {
- return handle(i.catchLoc, !0);
- }
- if (this.prev < i.finallyLoc) {
- return handle(i.finallyLoc);
- }
- } else if (c) {
- if (this.prev < i.catchLoc) {
- return handle(i.catchLoc, !0);
- }
- } else {
- if (!u) {
- throw Error("try statement without catch or finally");
- }
- if (this.prev < i.finallyLoc) {
- return handle(i.finallyLoc);
- }
- }
- }
- }
- },
- abrupt: function abrupt(t, e) {
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
- var o = this.tryEntries[r];
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
- var i = o;
- break;
- }
- }
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
- var a = i ? i.completion : {};
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
- },
- complete: function complete(t, e) {
- if ("throw" === t.type) {
- throw t.arg;
- }
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
- },
- finish: function finish(t) {
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
- var r = this.tryEntries[e];
- if (r.finallyLoc === t) {
- return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
- }
- }
- },
- "catch": function _catch(t) {
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
- var r = this.tryEntries[e];
- if (r.tryLoc === t) {
- var n = r.completion;
- if ("throw" === n.type) {
- var o = n.arg;
- resetTryEntry(r);
- }
- return o;
- }
- }
- throw Error("illegal catch attempt");
- },
- delegateYield: function delegateYield(e, r, n) {
- return this.delegate = {
- iterator: values(e),
- resultName: r,
- nextLoc: n
- }, "next" === this.method && (this.arg = t), y;
- }
- }, e;
-}
-function asyncGeneratorStep(n, t, e, r, o, a, c) {
- try {
- var i = n[a](c),
- u = i.value;
- } catch (n) {
- return void e(n);
- }
- i.done ? t(u) : Promise.resolve(u).then(r, o);
-}
-function _asyncToGenerator(n) {
- return function () {
- var t = this,
- e = arguments;
- return new Promise(function (r, o) {
- var a = n.apply(t, e);
- function _next(n) {
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
- }
- function _throw(n) {
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
- }
- _next(void 0);
- });
- };
-}
-function _createForOfIteratorHelper(r, e) {
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (!t) {
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
- t && (r = t);
- var _n = 0,
- F = function F() {};
- return {
- s: F,
- n: function n() {
- return _n >= r.length ? {
- done: !0
- } : {
- done: !1,
- value: r[_n++]
- };
- },
- e: function e(r) {
- throw r;
- },
- f: F
- };
- }
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
- var o,
- a = !0,
- u = !1;
- return {
- s: function s() {
- t = t.call(r);
- },
- n: function n() {
- var r = t.next();
- return a = r.done, r;
- },
- e: function e(r) {
- u = !0, o = r;
- },
- f: function f() {
- try {
- a || null == t["return"] || t["return"]();
- } finally {
- if (u) {
- throw o;
- }
- }
- }
- };
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
-function _superPropGet(t, o, e, r) {
- var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e);
- return 2 & r && "function" == typeof p ? function (t) {
- return p.apply(e, t);
- } : p;
-}
-function _get() {
- return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
- var p = _superPropBase(e, t);
- if (p) {
- var n = Object.getOwnPropertyDescriptor(p, t);
- return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
- }
- }, _get.apply(null, arguments);
-}
-function _superPropBase(t, o) {
- for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));) {
- ;
- }
- return t;
-}
-function _defineProperties(e, r) {
- for (var t = 0; t < r.length; t++) {
- var o = r[t];
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
- }
-}
-function _createClass(e, r, t) {
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
- writable: !1
- }), e;
-}
-function _toPropertyKey(t) {
- var i = _toPrimitive(t, "string");
- return "symbol" == _typeof(i) ? i : i + "";
-}
-function _toPrimitive(t, r) {
- if ("object" != _typeof(t) || !t) {
- return t;
- }
- var e = t[Symbol.toPrimitive];
- if (void 0 !== e) {
- var i = e.call(t, r || "default");
- if ("object" != _typeof(i)) {
- return i;
- }
- throw new TypeError("@@toPrimitive must return a primitive value.");
- }
- return ("string" === r ? String : Number)(t);
-}
-function _classCallCheck(a, n) {
- if (!(a instanceof n)) {
- throw new TypeError("Cannot call a class as a function");
- }
-}
-function _callSuper(t, o, e) {
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
-}
-function _possibleConstructorReturn(t, e) {
- if (e && ("object" == _typeof(e) || "function" == typeof e)) {
- return e;
- }
- if (void 0 !== e) {
- throw new TypeError("Derived constructors may only return object or undefined");
- }
- return _assertThisInitialized(t);
-}
-function _assertThisInitialized(e) {
- if (void 0 === e) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return e;
-}
-function _isNativeReflectConstruct() {
- try {
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
- } catch (t) {}
- return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
- return !!t;
- })();
-}
-function _getPrototypeOf(t) {
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
- return t.__proto__ || Object.getPrototypeOf(t);
- }, _getPrototypeOf(t);
-}
-function _inherits(t, e) {
- if ("function" != typeof e && null !== e) {
- throw new TypeError("Super expression must either be null or a function");
- }
- t.prototype = Object.create(e && e.prototype, {
- constructor: {
- value: t,
- writable: !0,
- configurable: !0
- }
- }), Object.defineProperty(t, "prototype", {
- writable: !1
- }), e && _setPrototypeOf(t, e);
-}
-function _setPrototypeOf(t, e) {
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
- return t.__proto__ = e, t;
- }, _setPrototypeOf(t, e);
-}
-var assets = {
- scoreImage: {
- type: 'shape',
- width: 100,
- height: 100,
- color: 0xcd1966,
- shape: 'box'
- },
- background: {
- type: 'image',
- width: 2048,
- height: 2732,
- id: '67cb14d582516b65d7d56166'
- },
- bird1Left: {
- type: 'image',
- width: 300,
- height: 295,
- id: '67c8f938120d8830ebbf56ab'
- },
- bird1Right: {
- type: 'image',
- width: 300,
- height: 295,
- id: '67c8f938120d8830ebbf56ab',
- flipX: 1
- },
- bird2Left: {
- type: 'image',
- width: 150,
- height: 168.42,
- id: '67c9027e120d8830ebbf5715',
- flipX: 1
- },
- bird2Right: {
- type: 'image',
- width: 150,
- height: 168.42,
- id: '67c9027e120d8830ebbf5715'
- },
- cat: {
- type: 'image',
- width: 433.13,
- height: 475.89,
- id: '67c8fd9b120d8830ebbf56e9'
- },
- cloud: {
- type: 'image',
- width: 500,
- height: 250,
- id: '67c915be120d8830ebbf582c'
- },
- grassBack: {
- type: 'image',
- width: 2204.72,
- height: 1505.21,
- id: '67c90d44120d8830ebbf57b9'
- },
- grassFront: {
- type: 'image',
- width: 2400,
- height: 1856.25,
- id: '67c90db6120d8830ebbf57c5',
- flipX: 1
- },
- jetLeft: {
- type: 'image',
- width: 200,
- height: 75.78,
- id: '67cbdf3f8f0bb65062649f12',
- flipX: 1
- },
- jetRight: {
- type: 'image',
- width: 200,
- height: 75.78,
- id: '67cbdf3f8f0bb65062649f12'
- },
- laser2: {
- type: 'image',
- width: 100,
- height: 101.19,
- id: '67c9f7067f021452b5f9dcd8'
- },
- light1: {
- type: 'image',
- width: 120,
- height: 120,
- id: '67cbd61a8f0bb65062649e53'
- },
- mirror1: {
- type: 'image',
- width: 500,
- height: 800,
- id: '67cb7aec82516b65d7d56434'
- },
- reticle1: {
- type: 'image',
- width: 400,
- height: 379.69,
- id: '67c935fd120d8830ebbf5944'
- },
- stack1: {
- type: 'image',
- width: 700,
- height: 737.45,
- id: '67cb6ce882516b65d7d563cc'
- },
- sun: {
- type: 'image',
- width: 500,
- height: 500,
- id: '67c92a9f120d8830ebbf58c6'
- },
- tree: {
- type: 'image',
- width: 1900,
- height: 2500,
- id: '67c911c5120d8830ebbf5807',
- flipX: 1
- },
- tree2: {
- type: 'image',
- width: 1900,
- height: 2300,
- id: '67cb5a3d82516b65d7d56300'
- },
- ufo: {
- type: 'image',
- width: 300,
- height: 228.52,
- id: '67c932df120d8830ebbf591b'
- },
- ufo2: {
- type: 'image',
- width: 400,
- height: 162.5,
- id: '67cc62364e271169e42de9e4'
- }
-};
-Object.keys(assets).forEach(function (key) {
- var asset = assets[key];
- if (asset.type === 'shape') {} else if (asset.type === 'image') {}
-});
-// Music and Sounds
-/****
-* Game Configuration
-****/
-// Sound configuration
-var GAME_SOUND_VOLUMES = {
- bgm1: 0.02,
- breeze1: 0.02,
- cricket1: 0.02,
- frog1: 0.02,
- songbird1: 0.02,
- ufo1: 0.02,
- wings1: 0.02,
- laser1: 0.1,
- laser2: 0.1,
- jetSound: 0.3
-};
-/****
-* Core Game Setup
-****/
-// Initialize game instance
-var gameInstance;
-if (!gameInstance) {
- gameInstance = new LK.Game({
- backgroundColor: 0x000000
- });
-}
-// Layer structure initialization
-var layers = {
- background: new Container(),
- sun: new Container(),
- light1: new Container(),
- jet: new Container(),
- clouds: new Container(),
- ufo: new Container(),
- grassBack: new Container()
-};
-var Background = /*#__PURE__*/function (_Container) {
- function Background() {
- var _this;
- _classCallCheck(this, Background);
- _this = _callSuper(this, Background);
- _this.attachAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- return _this;
- }
- _inherits(Background, _Container);
- return _createClass(Background);
-}(Container); // Branch asset
-var Bird = /*#__PURE__*/function (_Container2) {
- function Bird(type) {
- var _this2;
- _classCallCheck(this, Bird);
- _this2 = _callSuper(this, Bird);
- if (!type) {
- throw new Error('Bird type is required');
- }
- _this2.birdGraphics = _this2.attachAsset("".concat(type, "-right"), {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // The attachAsset method will throw an error if it fails, so we don't need to check again
- createMovementSystem(_this2, _this2.birdGraphics, MOVEMENT_CONFIGS[type]);
- return _this2;
- }
- _inherits(Bird, _Container2);
- return _createClass(Bird, [{
- key: "setChildIndex",
- value: function setChildIndex(index) {
- if (game.children.includes(this)) {
- game.setChildIndex(this, index);
- }
- }
- }, {
- key: "destroy",
- value: function destroy() {
- if (this.birdGraphics) {
- this.birdGraphics.destroy();
- this.birdGraphics = null;
- }
- _superPropGet(Bird, "destroy", this, 3)([]);
- }
- }]);
-}(Container);
-var Bird1 = /*#__PURE__*/function (_Bird) {
- function Bird1() {
- _classCallCheck(this, Bird1);
- return _callSuper(this, Bird1, ['bird1']);
- }
- _inherits(Bird1, _Bird);
- return _createClass(Bird1);
-}(Bird);
-var Bird2 = /*#__PURE__*/function (_Bird2) {
- function Bird2() {
- _classCallCheck(this, Bird2);
- return _callSuper(this, Bird2, ['bird2']);
- }
- _inherits(Bird2, _Bird2);
- return _createClass(Bird2);
-}(Bird); // 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
-/**
-* Configures movement behavior for game entities with tween-based animations
-* @param {Container} entity - Target entity container
-* @param {Graphics} graphics - Visual representation to animate
-* @param {Object} config - Movement configuration:
-* @param {number} [config.baseSpeed=1] - Base movement speed
-* @param {Object} config.textures - Directional sprites {left, right}
-* @param {boolean} [config.useWaveMotion=false] - Enable sine-based path
-* @param {number} [config.waveAmplitude=0] - Vertical deviation magnitude
-* @param {number} [config.waveFrequency=100] - Horizontal wave cycle length
-*/
-// Consolidated movement system with state tracking and error boundaries
-// Unified entity management system with improved cleanup
-var EntityManager = {
- cleanup: function cleanup(entity) {
- if (!entity || entity._cleaned) {
- return;
- }
- entity._cleaned = true;
- // Stop all associated sounds and clear references
- if (entity._sounds instanceof Set) {
- var _iterator = _createForOfIteratorHelper(entity._sounds),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var _sound;
- var soundName = _step.value;
- var sound = LK.getSound(soundName);
- if ((_sound = sound) !== null && _sound !== void 0 && _sound.stop) {
- sound.stop();
- }
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- entity._sounds.clear();
- entity._sounds = null;
- }
- // Clear all timers and references
- if (entity._timers instanceof Set) {
- var _iterator2 = _createForOfIteratorHelper(entity._timers),
- _step2;
- try {
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
- var timer = _step2.value;
- LK.clearTimeout(timer);
- }
- } catch (err) {
- _iterator2.e(err);
- } finally {
- _iterator2.f();
- }
- entity._timers.clear();
- entity._timers = null;
- }
- // Return to pool or remove from parent
- if (entity.type && EntityPool.pools && EntityPool.pools[entity.type]) {
- if (entity.reset) {
- entity.reset();
- }
- EntityPool["return"](entity.type, entity);
- } else if (entity.parent) {
- entity.parent.removeChild(entity);
- }
- // Clear any remaining references
- entity._destroyed = true;
- entity.parent = null;
- // Clear any graphics references
- if (entity.birdGraphics) {
- entity.birdGraphics = null;
- }
- },
- spawn: function spawn(type) {
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- if (!type) {
- throw new Error('Entity type is required');
- }
- var entity = EntityPool.get(type);
- if (!entity) {
- var EntityTypes = {
- bird1: Bird1,
- bird2: Bird2,
- laser: function laser(config) {
- return new Laser(config.startX, config.startY, config.targetX, config.targetY);
- }
- };
- var EntityConstructor = EntityTypes[type];
- if (!EntityConstructor) {
- throw new Error("Unknown entity type: ".concat(type));
- }
- entity = typeof EntityConstructor === 'function' ? EntityConstructor.length ? EntityConstructor(config) : new EntityConstructor() : null;
- if (!entity) {
- throw new Error("Failed to create entity of type: ".concat(type));
- }
- }
- entity.type = type;
- entity._sounds = new Set();
- entity._timers = new Set();
- entity._cleaned = false;
- entity._destroyed = false;
- return entity;
- }
-};
-var EntityPool = {
- pools: {},
- get: function get(type) {
- if (this.pools[type] && this.pools[type].length > 0) {
- return this.pools[type].pop();
- }
- return null;
- },
- "return": function _return(type, entity) {
- if (!this.pools[type]) {
- this.pools[type] = [];
- }
- this.pools[type].push(entity);
- }
-};
-function createMovementSystem(entity, entityGraphics, config) {
- try {
- var _settings$sounds;
- if (!entity || !entityGraphics) {
- console.error('Entity and entityGraphics are required for movement system');
- return null;
- }
- // Initialize entity management systems
- if (!entity._timers) {
- entity._timers = new Set();
- }
- if (!entity._sounds) {
- entity._sounds = new Set();
- }
- var soundManager = window.soundManager || null;
- var defaults = {
- baseSpeed: 1,
- speedVariation: 0,
- horizontalMovement: false,
- useWaveMotion: false,
- waveAmplitude: 0,
- waveFrequency: 100,
- screenBounds: {
- width: 2048,
- height: 2732
- },
- respawnPosition: 'top',
- textures: {
- left: null,
- right: null
- },
- sounds: {
- move: null,
- destroy: null
- },
- scoreValue: 0,
- entityType: null,
- onDestroy: null,
- onUpdate: null,
- handleScreenWrap: false
- };
- var settings = Object.assign({}, defaults, config || {});
- entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation;
- entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1;
- entity.lastX = entity.x || 0;
- entity.lastY = entity.y || 0;
- entity.scoreValue = settings.scoreValue;
- // Initialize movement sound
- if ((_settings$sounds = settings.sounds) !== null && _settings$sounds !== void 0 && _settings$sounds.move && soundManager) {
- var moveSound = soundManager.play(settings.sounds.move, {
- loop: true
- });
- if (moveSound) {
- entity._sounds.add(settings.sounds.move);
- }
- }
- entity.update = function () {
- try {
- var _settings$textures, _settings$textures2;
- if (settings.entityType === 'laser') {
- if (!this.vx || !this.vy) {
- return;
- }
- this.x += this.vx;
- this.y += this.vy;
- if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) {
- EntityManager.cleanup(this);
- }
- } else if (settings.horizontalMovement) {
- var _settings$onUpdate;
- this.x += this.speed * this.direction;
- if (settings.useWaveMotion && settings.baseY !== undefined) {
- this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude;
- }
- if (settings.handleScreenWrap) {
- if (this.x > settings.screenBounds.width + this.width / 2) {
- this.x = -this.width / 2;
- } else if (this.x < -this.width / 2) {
- this.x = settings.screenBounds.width + this.width / 2;
- }
- }
- (_settings$onUpdate = settings.onUpdate) === null || _settings$onUpdate === void 0 || _settings$onUpdate.call(settings, this);
- } else {
- this.y += this.speed;
- if (settings.useWaveMotion) {
- this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude;
- }
- }
- if (entityGraphics && (_settings$textures = settings.textures) !== null && _settings$textures !== void 0 && _settings$textures.left && (_settings$textures2 = settings.textures) !== null && _settings$textures2 !== void 0 && _settings$textures2.right) {
- try {
- var rightAsset = LK.getAsset(settings.textures.right, {});
- var leftAsset = LK.getAsset(settings.textures.left, {});
- if (rightAsset !== null && rightAsset !== void 0 && rightAsset.texture && leftAsset !== null && leftAsset !== void 0 && leftAsset.texture) {
- entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture;
- }
- } catch (error) {
- console.error('Error updating entity texture:', error);
- }
- }
- if (settings.horizontalMovement) {
- if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- var _settings$onDestroy;
- EntityManager.cleanup(this);
- (_settings$onDestroy = settings.onDestroy) === null || _settings$onDestroy === void 0 || _settings$onDestroy.call(settings, this);
- }
- } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) {
- switch (settings.respawnPosition) {
- case 'random':
- this.y = Math.random() * settings.screenBounds.height;
- this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width;
- break;
- case 'side':
- this.y = Math.random() * settings.screenBounds.height;
- this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width;
- break;
- default:
- this.y = -this.height;
- this.x = Math.random() * settings.screenBounds.width;
- }
- }
- this.lastX = this.x;
- this.lastY = this.y;
- } catch (error) {
- console.error('Error in entity update:', error);
- EntityManager.cleanup(this);
- }
- }.bind(entity);
- if (typeof entity.destroy !== 'function') {
- entity.destroy = function () {
- var _settings$sounds2;
- if (this._destroyed) {
- return;
- }
- this._destroyed = true;
- EntityManager.cleanup(this);
- if ((_settings$sounds2 = settings.sounds) !== null && _settings$sounds2 !== void 0 && _settings$sounds2.destroy && soundManager) {
- soundManager.stop(settings.sounds.destroy);
- }
- }.bind(entity);
- }
- return entity;
- } catch (error) {
- console.error('Error in createMovementSystem:', error);
- return null;
- }
-}
-// Cat class to manage cat behavior
-var Cat = /*#__PURE__*/function (_Container3) {
- function Cat() {
- var _this3;
- _classCallCheck(this, Cat);
- _this3 = _callSuper(this, Cat);
- try {
- _this3.catGraphics = _this3.attachAsset('cat', {
- anchorX: 0.5,
- anchorY: 1
- });
- } catch (error) {
- console.error('Error creating cat:', error);
- }
- return _this3;
- }
- _inherits(Cat, _Container3);
- return _createClass(Cat, [{
- key: "update",
- value: function update() {
- try {
- // Add any specific update logic for the cat here
- } catch (error) {
- console.error('Error in cat update:', error);
- }
- }
- }]);
-}(Container);
-var CloudMovement = {
- init: function init(cloud) {
- if (!cloud) {
- throw new Error('Cloud entity is required');
- }
- cloud._movement = {
- speed: Math.random() * 0.5 + 0.2,
- direction: Math.random() < 0.5 ? -1 : 1,
- bounds: {
- left: -cloud.width,
- right: game.width + cloud.width
- }
- };
- this.update(cloud);
- },
- update: function update(cloud) {
- if (!cloud || !cloud._movement) {
- return;
- }
- cloud.x += cloud._movement.speed * cloud._movement.direction;
- // Handle bounds checking and wrapping
- if (cloud.x < cloud._movement.bounds.left) {
- cloud.x = cloud._movement.bounds.right;
- } else if (cloud.x > cloud._movement.bounds.right) {
- cloud.x = cloud._movement.bounds.left;
- }
- },
- cleanup: function cleanup(cloud) {
- if (!cloud) {
- return;
- }
- delete cloud._movement;
- }
-};
-var Cloud = /*#__PURE__*/function (_Container4) {
- function Cloud() {
- var _this4;
- _classCallCheck(this, Cloud);
- _this4 = _callSuper(this, Cloud);
- _this4.cloudGraphics = _this4.attachAsset('cloud', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- createMovementSystem(_this4, _this4.cloudGraphics, {
- speed: Math.random() * 0.5 + 0.2,
- direction: Math.random() < 0.5 ? -1 : 1,
- boundaryCheck: true,
- boundaryWidth: 2048
- });
- return _this4;
- }
- _inherits(Cloud, _Container4);
- return _createClass(Cloud, [{
- key: "update",
- value: function update() {
- this.updateMovement();
- }
- }, {
- key: "destroy",
- value: function destroy() {
- EntityManager.cleanup(this);
- _superPropGet(Cloud, "destroy", this, 3)([]);
- }
- }]);
-}(Container); // Game instance already initialized above
-// Layer structure initialization with proper cleanup handling
-var initializeLayers = function initializeLayers() {
- game.layers = {
- background: new Container(),
- sun: new Container(),
- light1: new Container(),
- jetLeft: new Container(),
- jetRight: new Container(),
- clouds: new Container(),
- ufo: new Container(),
- grassBack: new Container(),
- bird1: new Container(),
- tree: new Container(),
- stack1: new Container(),
- bird2: new Container(),
- mirror: new Container(),
- grassFront: new Container(),
- cat: new Container(),
- laser: new Container(),
- reticle: new Container(),
- enemies: new Container(),
- birds: new Container()
- };
- // Add cleanup methods to each layer
- Object.values(game.layers).forEach(function (layer) {
- layer.cleanup = function () {
- while (this.children.length > 0) {
- var child = this.children[0];
- if (typeof child.destroy === 'function') {
- child.destroy();
- }
- }
- };
- });
-};
-// Factory functions for specific pulse effects
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- return new Pulse(lightGraphics, {
- scaleMax: 1.6,
- duration: 1500
- });
-};
-var SunPulse = function SunPulse(sunGraphics) {
- return new Pulse(sunGraphics, {
- scaleMax: 1.1,
- duration: 1000
- });
-};
-// Removed redundant startPulsating function as it's now handled by Pulse class
-// Sound system is already initialized above
-SoundManager = {
- playEffect: function playEffect(soundName) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- try {
- var sound = this._sounds.get(soundName) || LK.getSound(soundName);
- if (!sound) {
- console.warn("Sound '".concat(soundName, "' not found"));
- return;
- }
- var _options$volume = options.volume,
- volume = _options$volume === void 0 ? this._volumes[soundName] || 1 : _options$volume,
- _options$loops = options.loops,
- loops = _options$loops === void 0 ? false : _options$loops;
- sound.play({
- volume: volume,
- loops: loops
- });
- return sound;
- } catch (error) {
- console.error("Error playing sound effect '".concat(soundName, "':"), error);
- }
- },
- playMusic: function playMusic() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- try {
- var _options$volume2 = options.volume,
- volume = _options$volume2 === void 0 ? this._volumes[this.effects.bgm] || 1 : _options$volume2,
- _options$fade = options.fade,
- fade = _options$fade === void 0 ? true : _options$fade;
- return LK.playMusic(this.effects.bgm, {
- loop: false,
- volume: volume,
- fade: fade ? {
- start: 0,
- end: 1,
- duration: 4000
- } : undefined
- });
- } catch (error) {
- console.error('Error playing background music:', error);
- }
- },
- stopSoundFunc: function stopSoundFunc(soundName) {
- try {
- var sound = this._sounds.get(soundName) || LK.getSound(soundName);
- if (sound !== null && sound !== void 0 && sound.stop) {
- sound.stop();
- }
- } catch (error) {
- console.error("Error stopping sound '".concat(soundName, "':"), error);
- }
- },
- pauseSound: function pauseSound(soundName) {
- try {
- var sound = this._sounds.get(soundName) || LK.getSound(soundName);
- if (sound !== null && sound !== void 0 && sound.pause) {
- sound.pause();
- }
- } catch (error) {
- console.error("Error pausing sound '".concat(soundName, "':"), error);
- }
- },
- setVolume: function setVolume(soundName, volume) {
- try {
- var sound = this._sounds.get(soundName);
- if (sound) {
- sound.volume = volume;
- this._volumes[soundName] = volume;
- }
- } catch (error) {
- console.error("Error setting volume for '".concat(soundName, "':"), error);
- }
- }
-};
-// Initialize sound system
-SoundManager.init();
-// Sound effect wrapper classes using the unified system
-var UFOSound = function UFOSound() {
- this.play = function () {
- return SoundManager.playEffect(SoundManager.effects.ufo);
- };
-};
-var LaserSound = function LaserSound() {
- this.play = function () {
- return SoundManager.playEffect(SoundManager.effects.laser);
- };
-};
-var BackgroundMusic = function BackgroundMusic() {
- this.play = function () {
- return SoundManager.playMusic();
- };
-};
-// Unified movement system for all entities
-// Unified movement system with improved cleanup and state management
-// Note: This is the main implementation of createMovementSystem used throughout the code
-/**
-* Unified movement system for all moving entities
-* @param {Object} entity - The entity to apply movement to
-* @param {Object} entityGraphics - The graphics object for the entity
-* @param {Object} config - Configuration options for movement
-*/
-// Removed duplicate createMovementSystem function as it's already defined above
-/**
-* Bird1 movement configuration
-*/
-/**
-* Bird2 movement configuration
-*/
-/**
-* UFO movement configuration
-*/
-// Entity movement configurations
-var MOVEMENT_CONFIGS = {
- bird1: {
- baseSpeed: 1,
- speedVariation: 0.5,
- useWaveMotion: true,
- waveAmplitude: 4.5,
- waveFrequency: 120,
- horizontalMovement: false,
- textures: {
- left: 'bird1-left',
- right: 'bird1-right'
- },
- respawnPosition: 'top',
- sounds: {
- move: 'wings1',
- destroy: null
- },
- scoreValue: 5
- },
- bird2: {
- baseSpeed: 1.5,
- 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
- },
- ufo: {
- baseSpeed: 3,
- speedVariation: 1,
- useWaveMotion: true,
- waveAmplitude: 50,
- waveFrequency: 100,
- horizontalMovement: true,
- baseY: function baseY() {
- return Math.random() * 300 + 100;
- },
- textures: null,
- sounds: {
- move: 'ufo1',
- destroy: null
- },
- scoreValue: 20
- }
-};
-function BirdMovement(bird, birdGraphics, birdType) {
- var config = Object.assign({}, MOVEMENT_CONFIGS[birdType], {
- entityType: birdType,
- onDestroy: function onDestroy(entity) {
- var index = birds.indexOf(entity);
- if (index > -1) {
- birds.splice(index, 1);
- LK.setTimeout(function () {
- if (birdType === 'bird1') {
- spawnBird1();
- } else {
- spawnBird2();
- }
- }, Math.random() * 2000 + 1000);
- }
- }
- });
- createMovementSystem(bird, birdGraphics, config);
-}
-function UFOMovement(ufo, ufoGraphics) {
- var config = Object.assign({}, MOVEMENT_CONFIGS.ufo, {
- baseY: MOVEMENT_CONFIGS.ufo.baseY(),
- entityType: 'ufo',
- onDestroy: function onDestroy(entity) {
- if (entity.sounds && entity.sounds.move) {
- LK.getSound(entity.sounds.move).stop();
- }
- entity.destroy();
- ufo = null;
- handleUFOReappearance();
- },
- handleLaserCollision: function handleLaserCollision(laser) {
- var angle = Math.atan2(laser.vy, laser.vx) + Math.PI;
- laser.vx = Math.cos(angle) * laser.speed;
- laser.vy = Math.sin(angle) * laser.speed;
- return true;
- }
- });
- createMovementSystem(ufo, ufoGraphics, config);
-}
-/**
-* Jet movement configuration
-*/
-/**
-* 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;
- // Initializes entity movement parameters 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
+// Function to create a pulsating effect
+// Bird2Effects class to handle effects and animations for Bird2
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
- try {
- // 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)
- });
- }
- } catch (error) {
- console.error('Error in Bird2Effects:', error);
- }
+ // Add any specific effects or animations for Bird2 here
};
};
-// BirdMovement is already defined with MOVEMENT_CONFIGS above
-// 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;
+// 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
};
- self.resetScore = function () {
- self.score = 0;
- };
- self.getScore = function () {
- return self.score;
- };
};
-// Game input handlers with proper cleanup
-var LaserSystem = /*#__PURE__*/function () {
- function LaserSystem() {
- _classCallCheck(this, LaserSystem);
- this.activeLasers = new Set();
- this._cleanupQueue = new Set();
- }
- return _createClass(LaserSystem, [{
- key: "addLaser",
- value: function addLaser(laser) {
- if (!laser) {
- return;
+function startPulsating(target) {
+ function pulsate() {
+ tween(target, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 444,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(target, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 444,
+ easing: tween.easeInOut,
+ onFinish: pulsate
+ });
}
- this.activeLasers.add(laser);
- }
- }, {
- key: "queueForCleanup",
- value: function queueForCleanup(laser) {
- if (!laser) {
- return;
- }
- this._cleanupQueue.add(laser);
- }
- }, {
- key: "update",
- value: function update() {
- // Handle cleanup queue
- if (this._cleanupQueue.size > 0) {
- var _iterator3 = _createForOfIteratorHelper(this._cleanupQueue),
- _step3;
- try {
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
- var laser = _step3.value;
- this.activeLasers["delete"](laser);
- EntityManager.cleanup(laser);
- }
- } catch (err) {
- _iterator3.e(err);
- } finally {
- _iterator3.f();
- }
- this._cleanupQueue.clear();
- }
- // Update active lasers
- var _iterator4 = _createForOfIteratorHelper(this.activeLasers),
- _step4;
- try {
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
- var laser = _step4.value;
- if (!laser || laser._destroyed) {
- this.queueForCleanup(laser);
- continue;
- }
- if (laser.update) {
- laser.update();
- }
- }
- } catch (err) {
- _iterator4.e(err);
- } finally {
- _iterator4.f();
- }
- }
- }, {
- key: "clear",
- value: function clear() {
- var _iterator5 = _createForOfIteratorHelper(this.activeLasers),
- _step5;
- try {
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
- var laser = _step5.value;
- EntityManager.cleanup(laser);
- }
- } catch (err) {
- _iterator5.e(err);
- } finally {
- _iterator5.f();
- }
- this.activeLasers.clear();
- this._cleanupQueue.clear();
- }
- }]);
-}(); // Initialize laser system
-var laserSystem = new LaserSystem();
-// game.down is already defined above with proper laser system integration
-game.move = function (x, y, obj) {
- try {
- if (!game.reticle) {
- game.reticle = new Reticle();
- game.layers.reticle.addChild(game.reticle);
- }
- var eventX = obj && obj.event ? obj.event.x : x;
- var eventY = obj && obj.event ? obj.event.y : y;
- if (game.reticle) {
- game.reticle.x = eventX;
- game.reticle.y = eventY;
- }
- } catch (error) {
- console.error('Error in game.move:', error);
+ });
}
-};
-// Initialize sun and light1 (already added to layers)
-var sun = game.layers.sun.getChildAt(0);
-var light1 = game.layers.light1.getChildAt(0);
-// Add score display if not already present
-if (!game.scoreDisplay) {
- game.scoreDisplay = game.addChild(new Mirror());
- game.scoreDisplay.x = 1700;
- game.scoreDisplay.y = 300;
+ pulsate();
}
-// Function to add a UFO to the game
-// Initialize game state
-var GameState = {
- clouds: [],
- birds: [],
- ufo: null,
- score: 0,
- cat: null,
- scoreDisplay: null
-};
+// Define layers
+var LAYER_BACKGROUND = 0;
+var LAYER_CLOUDS = 1;
+var LAYER_BIRDS = 2;
+var LAYER_UFO = 3;
+var LAYER_GRASS = 4;
+var LAYER_CAT = 5;
+var LAYER_RETICLE = 6;
+var LAYER_LASER = 7;
+var LAYER_SCORE = 8;
+// Function to set layer index
+function setLayerIndex(object, layer) {
+ game.setChildIndex(object, layer);
+}
+// Initialize game objects with layers
+var background = LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+background.x = 2048 / 2;
+background.y = 2732 / 2 - 200;
+game.addChild(background);
+setLayerIndex(background, LAYER_BACKGROUND);
+// Add a sun to the game in the top left corner
+var sun = game.addChild(new Sun());
+sun.x = 480;
+sun.y = 590;
+setLayerIndex(sun, LAYER_CLOUDS);
// Initialize clouds array
-//GameState.clouds = [];
-//GameState.birds = [];
-//GameState.score = 0;
+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
- GameState.clouds.push(cloud);
- game.layers.clouds.addChild(cloud);
- // No need to add cloud directly to game since it's already in the clouds layer
+ cloud.y = Math.random() * (2732 / 2);
+ clouds.push(cloud);
+ game.addChild(cloud);
+ setLayerIndex(cloud, LAYER_CLOUDS);
}
// Initialize birds
-function spawnBird1() {
- var bird = EntityManager.spawn('bird1');
- if (bird) {
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- game.layers.birds.addChild(bird);
- GameState.birds.push(bird);
- }
-}
-function spawnBird2() {
- var bird = EntityManager.spawn('bird2');
- if (bird) {
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- game.layers.birds.addChild(bird);
- GameState.birds.push(bird);
- }
-}
-// Initial bird spawns
spawnBird1();
spawnBird2();
-spawnBird2();
-// Start UFO 3 seconds after game loads
-var ufoTimer = LK.setTimeout(function () {
- GameState.ufo = new UFO();
- game.layers.enemies.addChild(GameState.ufo);
-}, 3000);
-// Function to handle UFO reappearance logic
-function handleUFOReappearance() {
- if (!ufo) {
- LK.setTimeout(function () {
- ufo = addUFO();
- }, Math.random() * 10000 + 20000);
- }
+// Function to spawn a Bird2 and set its layer
+function spawnBird2() {
+ var bird = new Bird2();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ bird.speed = 1 + Math.random() * 0.6;
+ bird.lastIntersecting = false;
+ bird.type = 'Bird2';
+ bird.color = 0x746130;
+ LK.setTimeout(function () {
+ game.addChild(bird);
+ setLayerIndex(bird, LAYER_BIRDS);
+ birds.push(bird);
+ }, 2000);
}
-// Function to handle jet reappearance logic
-var jetTimer;
-function handleJetReappearance() {
- try {
- 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;
- }
- }, Math.random() * 5000 + 5000);
- } catch (error) {
- console.error('Error in handleJetReappearance:', error);
- }
+// Function to spawn a bird and set its layer
+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';
+ bird.color = 0x746130;
+ LK.setTimeout(function () {
+ game.addChild(bird);
+ setLayerIndex(bird, LAYER_BIRDS);
+ birds.push(bird);
+ }, 2000);
}
-// Initialize a timer to add a Jet at a random time between 5 and 10 seconds
-// 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);
- }
-}
-function gameTick() {
- try {
- updateClouds();
- updateEnemies();
- updateLasers();
- checkInteractions();
- requestAnimationFrame(gameTick);
- } catch (error) {
- console.error('Error in game tick:', error);
- requestAnimationFrame(gameTick);
- }
-}
-function updateClouds() {
- // Update existing clouds
- for (var i = 0; i < GameState.clouds.length; i++) {
- GameState.clouds[i].update();
- }
- // Ensure minimum cloud count
- while (GameState.clouds.length < 3) {
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2);
- GameState.clouds.push(cloud);
- game.layers.clouds.addChild(cloud);
- }
-}
-function updateEnemies() {
- var enemies = game.layers.enemies.children;
- var screenWidth = 2048;
- var screenHeight = 2732;
- enemies.forEach(function (enemy) {
- if (!enemy || !enemy.update) {
- return;
+// Ensure there are always 3 birds on screen
+game.update = function () {
+ // Update each bird
+ birds.forEach(function (bird) {
+ bird.update();
+ // Check if the bird has moved off-screen
+ if (bird.lastY <= 2732 && bird.y > 2732) {
+ bird.y = -bird.height; // Respawn the bird at the top
+ bird.x = Math.random() * 2048; // Randomize the x position
+ bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
}
- enemy.update();
- if (enemy instanceof Bird1 || enemy instanceof Bird2) {
- handleBirdCollisions(enemy, enemies);
- handleBirdRespawn(enemy, screenWidth, screenHeight);
- }
});
-}
-function handleBirdCollisions(bird, enemies) {
- if (!bird.lastIntersecting) {
- enemies.forEach(function (otherEnemy) {
- if (bird === otherEnemy || !(otherEnemy instanceof Bird1 || otherEnemy instanceof Bird2)) {
- return;
- }
- if (bird.intersects(otherEnemy)) {
- var dx = bird.x - otherEnemy.x;
- var dy = bird.y - otherEnemy.y;
- var distance = Math.sqrt(dx * dx + dy * dy) || 1;
- var bounceFactor = 5;
- bird.x += dx / distance * bounceFactor;
- bird.y += dy / distance * bounceFactor;
- otherEnemy.x -= dx / distance * bounceFactor;
- otherEnemy.y -= dy / distance * bounceFactor;
- bird.lastIntersecting = true;
- otherEnemy.lastIntersecting = true;
- }
+};
+// Add a tree to the game
+var tree = game.addChild(new Tree());
+tree.x = 2048 / 2 + 500; // Move the tree 500px to the right
+tree.y = 2765; // Position the tree on the grass
+var treeChildIndex = Math.min(7, game.children.length - 1);
+game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered after Bird1
+var score = 0;
+// Add the grass floor to the game
+var grass = new Grass();
+grass.x = 1020;
+grass.y = 2735;
+game.addChild(grass);
+setLayerIndex(grass, LAYER_GRASS);
+var grass2 = new Grass2();
+grass2.x = 1020;
+grass2.y = 2735; // Position grass2 at the bottom
+game.addChild(grass2);
+var grass2ChildIndex = game.getChildIndex(tree) + 1;
+game.setChildIndex(grass2, grass2ChildIndex); // Set grass2 to be rendered after the tree
+var scoreDisplay = new ScoreDisplay();
+scoreDisplay.x = 2048 / 2 + 520;
+scoreDisplay.y = 2732 - 185;
+game.addChild(scoreDisplay);
+setLayerIndex(scoreDisplay, LAYER_SCORE);
+// Function to handle bgm1 end event
+function onBgm1End() {
+ // Set a timer to replay bgm1 after 50-80 seconds
+ var bgmTimer = LK.setTimeout(function () {
+ LK.playMusic('bgm1', {
+ loop: true,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: onBgm1End
});
- }
- bird.lastIntersecting = enemies.some(function (otherEnemy) {
- return bird !== otherEnemy && bird.intersects(otherEnemy);
- });
+ }, Math.random() * 30000 + 50000);
}
-function handleBirdRespawn(bird, screenWidth, screenHeight) {
- if (bird.lastY <= screenHeight && bird.y > screenHeight) {
- bird.y = -bird.height;
- bird.x = Math.random() * screenWidth;
- bird.speed = 1 + Math.random() * 0.6;
- }
-}
-function updateLasers() {
- if (!game.layers.laser) {
- return;
- }
- game.layers.laser.children.forEach(function (laser) {
- if (laser && typeof laser.update === 'function') {
- laser.update();
- }
- });
-}
-// Start the game loop
-requestAnimationFrame(gameTick);
-// Note: Tree, stack1, grassBack, 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
-// SoundManager is already defined earlier in the code
-// This is a helper function that uses the SoundManager
-function playSoundEffect(soundName) {
- var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'play';
- var volume = arguments.length > 2 ? arguments[2] : undefined;
- var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
- var effectVolume = volume || GAME_SOUND_VOLUMES[soundName] || 1;
- if (action === 'play') {
- SoundManager.play(soundName, {
- volume: effectVolume,
- loops: loops
- });
- } else if (action === 'stop') {
- SoundManager.stop(soundName);
- }
-}
-// Initialize sound system
-SoundManager.init();
-// Initialize cat instance
-GameState.cat = new Cat();
-GameState.cat.x = 2048 / 2;
-GameState.cat.y = 2732 - 100;
-game.layers.cat.addChild(GameState.cat);
-var AudioSystem = {
- _initialized: false,
- _bgmPlaying: false,
- init: function init() {
- var _this5 = this;
- return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) {
- switch (_context.prev = _context.next) {
- case 0:
- if (!_this5._initialized) {
- _context.next = 5;
- break;
- }
- return _context.abrupt("return");
- case 5:
- _context.prev = 6;
- _context.next = 10;
- return Promise.all([_this5._initBackgroundMusic(), _this5._initAmbientSounds()]);
- case 10:
- _this5._initialized = true;
- _context.next = 18;
- break;
- case 14:
- _context.prev = 14;
- _context.t0 = _context["catch"](6);
- console.error('Failed to initialize audio system:', _context.t0);
- case 18:
- case "end":
- return _context.stop();
- }
- }
- }, _callee, null, [[6, 14]]);
- }))();
+;
+// Add the cat to the game
+var cat = game.addChild(new Cat());
+cat.x = 200; // Position the cat to the far left
+cat.y = 2732; // Position the cat at the bottom of the screen
+var catChildIndex = Math.min(10, game.children.length - 1);
+game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass
+// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
+LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.02,
+ // Set to the lowest volume
+ duration: 4000
},
- _initBackgroundMusic: function _initBackgroundMusic() {
- var _this6 = this;
- return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
- var bgm;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) {
- switch (_context2.prev = _context2.next) {
- case 0:
- bgm = LK.getSound('bgm1');
- if (bgm) {
- _context2.next = 7;
- break;
- }
- return _context2.abrupt("return");
- case 7:
- bgm.volume = GAME_SOUND_VOLUMES.bgm1 || 0.1;
- bgm.loop = true;
- // Start background music
- _this6._bgmPlaying = true;
- _context2.next = 16;
- return bgm.play();
- case 16:
- case "end":
- return _context2.stop();
- }
- }
- }, _callee2);
- }))();
- },
- _initAmbientSounds: function _initAmbientSounds() {
- return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
- var ambientSounds, _i, _ambientSounds, soundName, sound;
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) {
- switch (_context3.prev = _context3.next) {
- case 0:
- ambientSounds = ['breeze1', 'cricket1', 'frog1', 'songbird1'];
- _i = 0, _ambientSounds = ambientSounds;
- case 5:
- if (!(_i < _ambientSounds.length)) {
- _context3.next = 25;
- break;
- }
- soundName = _ambientSounds[_i];
- sound = LK.getSound(soundName);
- if (sound) {
- _context3.next = 15;
- break;
- }
- return _context3.abrupt("continue", 22);
- case 15:
- sound.volume = GAME_SOUND_VOLUMES[soundName] || 0.1;
- sound.loop = true;
- _context3.next = 22;
- return sound.play();
- case 22:
- _i++;
- _context3.next = 5;
- break;
- case 25:
- case "end":
- return _context3.stop();
- }
- }
- }, _callee3);
- }))();
- },
- toggleBackgroundMusic: function toggleBackgroundMusic() {
- var bgm = LK.getSound('bgm1');
- if (!bgm) {
- return;
- }
- if (this._bgmPlaying) {
- bgm.stop();
- } else {
- bgm.play();
- }
- this._bgmPlaying = !this._bgmPlaying;
- }
-};
-// Initialize audio system
-AudioSystem.init();
-/**
-* Check for interactions between game entities
-*/
-var CollisionSystem = {
- handleLaserCollision: function handleLaserCollision(laser, enemy) {
- if (!(laser !== null && laser !== void 0 && laser.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || !laser.intersects(enemy)) {
- return false;
- }
- try {
- var destroyed = enemy.handleLaserCollision ? enemy.handleLaserCollision(laser) : function () {
- EntityManager.cleanup(enemy);
- EntityManager.cleanup(laser);
- return true;
- }();
- if (destroyed) {
- var _enemy$getScoreValue, _GameState$scoreDispl, _GameState$scoreDispl2;
- var points = ((_enemy$getScoreValue = enemy.getScoreValue) === null || _enemy$getScoreValue === void 0 ? void 0 : _enemy$getScoreValue.call(enemy)) || enemy.scoreValue || 5;
- GameState.score += points;
- (_GameState$scoreDispl = GameState.scoreDisplay) === null || _GameState$scoreDispl === void 0 || (_GameState$scoreDispl2 = _GameState$scoreDispl.updateScore) === null || _GameState$scoreDispl2 === void 0 || _GameState$scoreDispl2.call(_GameState$scoreDispl, GameState.score);
- return true;
- }
- } catch (error) {
- console.error('Error handling laser collision:', error);
- }
- return false;
- },
- handleUFOCollision: function handleUFOCollision(ufo, enemy) {
- if (!(ufo !== null && ufo !== void 0 && ufo.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || enemy === ufo || !ufo.intersects(enemy)) {
- return;
- }
- try {
- EntityManager.cleanup(enemy);
- SoundManager.play('electro');
- } catch (error) {
- console.error('Error handling UFO collision:', error);
- }
- },
- checkCollisions: function checkCollisions() {
- try {
- var _game$layers$enemies, _game$layers$laser;
- var enemies = ((_game$layers$enemies = game.layers.enemies) === null || _game$layers$enemies === void 0 ? void 0 : _game$layers$enemies.children) || [];
- var lasers = ((_game$layers$laser = game.layers.laser) === null || _game$layers$laser === void 0 ? void 0 : _game$layers$laser.children) || [];
- // Process laser collisions
- var _iterator6 = _createForOfIteratorHelper(lasers),
- _step6;
- try {
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
- var laser = _step6.value;
- if (!laser || laser._destroyed) {
- continue;
- }
- var _iterator8 = _createForOfIteratorHelper(enemies),
- _step8;
- try {
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
- var enemy = _step8.value;
- if (!enemy || enemy._destroyed) {
- continue;
- }
- if (this.handleLaserCollision(laser, enemy)) {
- break;
- }
- }
- } catch (err) {
- _iterator8.e(err);
- } finally {
- _iterator8.f();
- }
- }
- // Process UFO collisions
- } catch (err) {
- _iterator6.e(err);
- } finally {
- _iterator6.f();
- }
- var ufo = enemies.find(function (child) {
- return child instanceof UFO && !child._destroyed;
+ onEnd: function onEnd() {
+ // Set a timer to replay bgm1 every 20-50 seconds
+ LK.setTimeout(function () {
+ LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.5,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: onEnd // Set the onEnd function to replay bgm1
});
- if (ufo) {
- var _iterator7 = _createForOfIteratorHelper(enemies),
- _step7;
- try {
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
- var enemy = _step7.value;
- if (!enemy || enemy._destroyed || enemy === ufo) {
- continue;
- }
- this.handleUFOCollision(ufo, enemy);
- }
- } catch (err) {
- _iterator7.e(err);
- } finally {
- _iterator7.f();
- }
- }
- } catch (error) {
- console.error('Error in checkCollisions:', error);
- }
+ }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
}
-};
-function checkInteractions() {
- CollisionSystem.checkCollisions();
-}
-/*****
-* 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) {
- try {
- if (!obj || !params) {
- console.error('Invalid parameters for updateMovement');
- return;
+});
+// 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
}
- // 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 || 1) * (params.direction || 1);
- if (params.boundaryCheck) {
- handleScreenBoundaries(obj, params.boundaryWidth);
- }
- // Store last position for next update
- obj.lastX = obj.x;
- obj.lastY = obj.y;
- } catch (error) {
- console.error('Error in updateMovement:', error);
- }
-}
-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) {
- return;
- }
- if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) {
- if (Array.isArray(sounds)) {
- sounds.forEach(function (sound) {
- return SoundManager.stop(sound);
- });
- }
- if (typeof obj.destroy === 'function') {
- 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']);
-};
\ No newline at end of file
+ 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);
+});
\ 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