Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 48
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 168
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Level: 1 (x1.0)", {' Line Number: 148
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 140
Code edit (1 edits merged)
Please save this source code
User prompt
make label text black
User prompt
move all objects to the top right of the screen
User prompt
make the game play itself until a player clicks a start button
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 34
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 119
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 102
Code edit (1 edits merged)
Please save this source code
User prompt
change all label text colors to white
User prompt
remove unused objects
User prompt
apply images to all image obects
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var laserGraphics = new Graphics();' Line Number: 273
Code edit (1 edits merged)
Please save this source code
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
1. **Global Scope Initialization**: Ensure that all important variables, instances, arrays, and variables are initialized in the global scope of `gamecode.js`. This includes arrays for game objects like `cats`, `kittens`, `birds`, `ufos`, `clouds`, `powerUps`, and `sparkles`.
2. **Asset Classes**: Differentiate between asset classes for different behaviors, such as 'HeroBullets' and 'EnemyBullets', and ensure distinct assets are assigned to these classes.
3. **Event Listeners**: Ensure event listeners are correctly using the `obj.event` for the event object, and not assuming any standard libraries are included.
4. **Touchscreen Compatibility**: Ensure the game is touchscreen-compatible and does not rely on keyboard inputs or controls.
5. **Asset Retrieval**: Use `LK.getAsset('
User prompt
continue developing hte app
User prompt
ensure the game is initialized correctly
User prompt
continue
/**** * 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('bird', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1 + Math.random() * 0.6; self.lastY = self.y; self.update = function () { self.y += self.speed; self.lastY = self.y; }; }); // Bird2 class to represent the second kind of bird var Bird2 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5, tint: 0x88CCFF // Light blue tint to differentiate }); self.speed = 0.8 + Math.random() * 0.5; self.lastY = self.y; self.update = function () { self.y += self.speed; self.lastY = self.y; }; }); // Add Bird3 class for variety var Bird3 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5, tint: 0xFFCC88 // Orange tint to differentiate }); self.speed = 1.2 + Math.random() * 0.7; self.lastY = self.y; self.update = function () { self.y += self.speed; self.lastY = self.y; }; }); // 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.level = 1; self.attackRate = 2; // attacks per second self.attackRange = 300; self.lastAttackTime = 0; self.update = function () { // Check for nearby birds to attack var currentTime = LK.ticks / 60; if (currentTime - self.lastAttackTime > 1 / self.attackRate) { for (var i = 0; i < birds.length; i++) { var bird = birds[i]; var dx = bird.x - self.x; var dy = bird.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < self.attackRange) { // Create laser from cat to bird var laser = new Laser(self.x, self.y - 100, bird.x, bird.y); game.addChild(laser); self.lastAttackTime = currentTime; break; } } } }; }); // Cloud class to represent cloud behavior var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 // Set default opacity to 80% }); self.movement = new CloudMovement(self, cloudGraphics); }); // CloudMovement class to handle cloud movement and fade effects var CloudMovement = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 // Set default opacity to 80% }); self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8 self.hasAccelerated = false; // Track if the cloud has already accelerated self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left self.lastX = self.x; // Track last X position for future checks self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections self.update = function () { self.x += self.speed * self.direction; // If the cloud moves off-screen, reposition it to the opposite side if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) { self.x = -self.width / 2; } else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.x = 2048 + self.width / 2; } // Check for overlap with other clouds for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== self && self.intersects(clouds[i])) { if (!self.hasAccelerated) { self.speed *= 1.5; // Increase speed by 50% self.hasAccelerated = true; // Mark as accelerated } break; } else if (self.hasAccelerated && !self.intersects(clouds[i])) { self.speed /= 1.5; // Reset speed to original self.hasAccelerated = false; // Reset acceleration state } } // Check if the cloud intersects with the sun if (!self.lastIntersecting && self.intersects(sun)) { self.speed *= 2; // Double the speed when touching the sun tween(cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } else if (self.lastIntersecting && !self.intersects(sun)) { self.speed /= 2; // Reset speed to original when not touching the sun tween(cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } self.lastIntersecting = self.intersects(sun); self.lastX = self.x; // Update lastX after movement }; }); // GrassBack class to represent the grass image var GrassBack = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; self.addChild(grassGraphics); // Add grass graphics to the container self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; }); // GrassFront class to represent the second grass image var GrassFront = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass-front', { anchorX: 0.5, anchorY: 1 }); self.lastX = self.x; // Initialize lastX for tracking changes on X self.addChild(grass2Graphics); // Add grass2 graphics to the container self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50% self.lastX = self.x; // Update lastX after movement }; }); // Jet class to represent a jet flying across the screen var Jet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet', { anchorX: 0.5, anchorY: 0.5 }); // Add a label to the jet var jetLabel = new Text2('Jet', { size: 50, fill: 0xFFFFFF }); jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet jetLabel.y = -60; // Position the label above the jet self.addChild(jetLabel); // Add a label to the jet var jetLabel = new Text2('Jet', { size: 50, fill: 0xFFFFFF }); jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet jetLabel.y = -60; // Position the label above the jet self.addChild(jetLabel); self.speed = 10; // Set the speed of the jet 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; // If the jet 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; } 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, endX, endY) { var self = Container.call(this); self.startX = startX; self.startY = startY; self.endX = endX; self.endY = endY; // Calculate angle and distance var dx = endX - startX; var dy = endY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx); // Create laser graphics var laserGraphics = new Graphics(); laserGraphics.lineStyle(2, 0xFF0000, 1); laserGraphics.moveTo(0, 0); laserGraphics.lineTo(distance, 0); laserGraphics.rotation = angle; self.addChild(laserGraphics); self.x = startX; self.y = startY; // Play laser sound LK.getSound('laser1').play(); self.lastIntersecting = false; self.lifespan = 30; // frames self.update = function () { self.lifespan--; if (self.lifespan <= 0) { self.destroy(); } }; }); // Light1 class to represent a light object var Light1 = Container.expand(function () { var self = Container.call(this); var lightGraphics = self.attachAsset('light1', { anchorX: 0.5, anchorY: 0.5 }); self.x = 450, self.y = 450; // Add a label to the light1 object var lightLabel = new Text2('Light1', { size: 50, fill: 0xFFFFFF }); lightLabel.anchor.set(0.5, 0.5); // Center the label on the light lightLabel.y = -60; // Position the label above the light self.addChild(lightLabel); self.update = function () { // Add any specific update logic for the light here }; }); // Mirror class to manage score display var Mirror = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 14 // Rotate image right 15 degrees }); var scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = 50; // 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 x = 100; y = 100; self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // Reticle class to manage reticle behavior var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Add any specific update logic for the reticle here }; // Start the pulsating effect for the reticle startPulsating(self); }); // Stack1 class to represent the stack1 image var Stack1 = Container.expand(function () { var self = Container.call(this); var stackGraphics = self.attachAsset('stack1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / -12 }); self.update = function () { // Add any specific update logic for stack1 here }; }); // ScoreManager class to manage score logic // Sun class to represent a sun in the top right corner var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); startPulsating(sunGraphics); // Start the pulsating effect on the sun graphics }); // Function to create a pulsating effect // Tree class to represent a tree with a 9:16 aspect ratio var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, antialias: true, // Apply antialias effect stroke: 0x000000, // Add a black stroke strokeThickness: 15 // Set stroke thickness to 15px }); self.update = function () { // Add any specific update logic for the tree here }; }); // UFO class to represent a UFO var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction self.lastX = self.x; self.customUpdate = function () { self.x += self.speed * self.direction; // Check if UFO has moved off-screen 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; LK.getSound('ufo1').stop(); } self.lastX = self.x; }; }); /**** * Initialize Game ****/ // UFOMovement class to handle UFO movement /**** * Assets LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'}) ****/ // Initialize clouds array var game = new LK.Game({ // No title, no description backgroundColor: 0x000000 // Black }); /**** * Game Code ****/ // JetMovement class to handle jet movement var JetMovement = function JetMovement(jet, jetGraphics) { this.jet = jet; this.jetGraphics = jetGraphics; this.jet.speed = Math.max(1.6, 3.2) * 2; // Set the jet speed to 200% faster than the fastest object (Bird2 or UFO) this.jet.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.jet.lastX = this.jet.x; // Track last X position for future checks this.jet.update = function () { this.x += this.speed * this.direction; // If the jet moves off-screen, reposition it to the opposite side if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) { this.x = -this.width / 2; } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) { this.x = 2048 + this.width / 2; } this.lastX = this.x; // Update lastX after movement }; }; var bird2; // Define bird2 variable in the global scope // Bird2Effects class to handle effects and animations for Bird2 // Function to create a pulsating effect function startPulsating(target) { var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888; function pulsate() { tween(target, { scaleX: 1.1, scaleY: 1.1 }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: duration, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); } // UFOSound class to manage UFO sound effects // UFOMovement class to handle UFO movement var UFOMovement = function UFOMovement(ufo, ufoGraphics) { this.ufo = ufo; this.ufoGraphics = ufoGraphics; this.ufo.speed = 3.2; // Decrease speed by 20% this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.ufo.lastX = this.ufo.x; // Track last X position for future checks this.ufo.update = function () { this.x += this.speed * this.direction; this.y = 100 + Math.sin(this.x / 50) * 250; // Extend the wave pattern to be longer and wider // Stop playing ufo1 sound after UFO leaves the screen if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { this.destroy(); ufo = null; LK.getSound('ufo1').stop(); } this.lastX = this.x; // Update lastX after movement }; }; var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; var Bird1Movement = function Bird1Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = -this.height; this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048; } if (this.birdGraphics) { if (this.lastX <= this.x) { this.birdGraphics.texture = LK.getAsset('bird1-right', {}).texture; } else if (this.lastX > this.x) { this.birdGraphics.texture = LK.getAsset('bird1-left', {}).texture; } this.lastX = this.x; // Update lastX after movement } this.lastY = this.y; // Update lastY after movement }; }; var Bird2Movement = function Bird2Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% if (this.birdGraphics) { if (this.lastX <= this.x) { this.birdGraphics.texture = LK.getAsset('bird2-right', {}).texture; } else if (this.lastX > this.x) { this.birdGraphics.texture = LK.getAsset('bird2-left', {}).texture; } this.lastX = this.x; // Update lastX after movement } // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = Math.random() * 2732; // Random initial y position within the screen height this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } this.lastY = this.y; // Update lastY after movement }; }; var CloudMovement = function CloudMovement(cloud, cloudGraphics) { this.cloud = cloud; this.cloudGraphics = cloudGraphics; this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8 this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.cloud.lastX = this.cloud.x; // Track last X position for future checks this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections this.cloud.update = function () { this.x += this.speed * this.direction; // If the cloud moves off-screen, reposition it to the opposite side if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) { this.x = -this.width / 2; } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) { this.x = 2048 + this.width / 2; } // Check for overlap with other clouds for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== this && this.intersects(clouds[i])) { if (!this.hasAccelerated) { this.speed *= 1.5; // Increase speed by 50% this.hasAccelerated = true; // Mark as accelerated } break; } else if (this.hasAccelerated && !this.intersects(clouds[i])) { this.speed /= 1.5; // Reset speed to original this.hasAccelerated = false; // Reset acceleration state } } // Check if the cloud intersects with the sun if (!this.lastIntersecting && this.intersects(sun)) { this.speed *= 2; // Double the speed when touching the sun if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } } else if (this.lastIntersecting && !this.intersects(sun)) { this.speed /= 2; // Reset speed to original when not touching the sun if (this.cloudGraphics) { tween(this.cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } } this.lastIntersecting = this.intersects(sun); this.lastX = this.x; // Update lastX after movement }; }; var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird2 here }; }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2 - 100; game.addChild(background); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { var self = this; self.score = 0; self.addScore = function (points) { self.score += points; return self.score; }; self.resetScore = function () { self.score = 0; }; self.getScore = function () { return self.score; }; }; var ScoreManager = function ScoreManager() { var self = this; self.score = 0; self.addScore = function (points) { self.score += points; return self.score; }; self.resetScore = function () { self.score = 0; }; self.getScore = function () { return self.score; }; }; var birds = []; game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.addChild(new Reticle()); if (game.children.includes(game.reticle)) { game.setChildIndex(game.reticle, 7); // Set reticle to be rendered after the tree } } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point game.addChild(laser); if (game.children.includes(laser) && game.children.includes(game.reticle)) { game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle } }; var VOLUME_BGM1 = 0.02; var VOLUME_BREEZE1 = 0.02; var VOLUME_CRICKET1 = 0.02; var VOLUME_FROG1 = 0.02; var VOLUME_SONGBIRD1 = 0.02; var VOLUME_UFO1 = 0.02; var VOLUME_WINGS1 = 0.02; game.move = function (x, y, obj) { if (!game.reticle) { game.reticle = game.addChild(new Reticle()); } if (obj.event) { var x = obj.event.x; var y = obj.event.y; } game.reticle.x = x; game.reticle.y = y; }; // Add a sun to the game in the top left corner var sun = game.addChild(new Sun()); sun.x = 480; sun.y = 680; // Ensure sun is added to the game before setting its index if (game.children.includes(sun)) { game.setChildIndex(sun, 1); // Set sun to be rendered after the background } var light1 = game.addChild(new Light1()); light1.x = 530; // Move light1 right by 50px light1.y = 1490; // Move light1 down by 210px // Ensure light1 is added to the game before setting its index if (game.children.includes(light1)) { game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun } // Function to add a UFO to the game function addUFO() { var ufo = new UFO(); game.addChild(ufo); // Ensure UFO is added to the game before setting its index if (game.children.includes(ufo) && game.children.includes(clouds[0])) { game.setChildIndex(ufo, game.getChildIndex(clouds[0]) + 1); // Set UFO to be rendered after the first cloud } ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen ufo.y = Math.random() * (2732 / 2 - ufo.height); // Random initial y position within the top half of the screen ufo.customUpdate = function () { ufo.update(); }; // Removed ufo sound playing at startup return ufo; } // Initialize clouds array var clouds = []; for (var i = 0; i < 4; i++) { // Add 3 clouds for variety var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen clouds.push(cloud); game.addChild(cloud); // Ensure cloud is added to the game before setting its index if (game.children.includes(cloud)) { game.setChildIndex(cloud, 2); // Set clouds to be rendered after the sun } } var bird1; // Define bird1 variable in the global scope // Initialize birds spawnBird1(); spawnBird2(); spawnBird2(); // Initialize a timer to add a UFO at a random time between 20 and 30 seconds var ufo; // Define the ufo variable in the global scope var laser; // Define the laser variable in the global scope var ufoTimer = LK.setTimeout(function () { addUFO(); // Reset the timer for the UFO to reappear between 10-20 seconds ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000); }, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds game.update = function () { // Update each bird birds.forEach(function (bird, index) { bird.update(); // Check if the bird has moved off-screen if (bird.lastY <= 2732 && bird.y > 2732) { bird.destroy(); birds.splice(index, 1); spawnBird(); } }); // Update clouds clouds.forEach(function (cloud) { cloud.update(); }); // Update UFO if present if (ufo) { ufo.customUpdate(); } // Spawn UFO randomly if (!ufo && Math.random() < 0.001) { spawnUFO(); } // Ensure there are always 3 birds while (birds.length < 3) { spawnBird(); } }; // Helper function to spawn birds function spawnBird() { var birdType = Math.random(); var bird; if (birdType < 0.6) { bird = new Bird1(); } else if (birdType < 0.9) { bird = new Bird2(); } else { bird = new Bird3(); } bird.x = Math.random() * 2048; bird.y = -bird.height; game.addChild(bird); birds.push(bird); } // Helper function to spawn UFO function spawnUFO() { ufo = new UFO(); ufo.x = ufo.direction > 0 ? -ufo.width / 2 : 2048 + ufo.width / 2; ufo.y = Math.random() * 1000 + 200; game.addChild(ufo); LK.getSound('ufo1').play(); } // Function to spawn a third kind of bird function spawnBird1() { var bird1 = new Bird1(); bird1.x = Math.random() * 2048; bird1.y = -bird1.height; bird1.speed = 1 + Math.random() * 0.6; bird1.lastIntersecting = false; bird1.type = 'bird1'; // Specific property for Bird1 bird1.color = 0x746130; // Specific color for Bird1 LK.setTimeout(function () { game.addChild(bird1); // Ensure bird1 is added to the game before setting its index if (game.children.includes(bird1)) { if (game.children.includes(bird1) && game.children.includes(tree)) { game.setChildIndex(bird1, game.getChildIndex(tree)); // Set Bird1 to be rendered before tree } } birds.push(bird1); }, 2000); } function spawnBird2() { var bird = new Bird2(); bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'bird2'; // Specific property for Bird2 bird.color = 0xFFFFFF; // Specific color for Bird2 LK.setTimeout(function () { game.addChild(bird); // Ensure bird is added to the game before setting its index if (game.children.includes(bird)) { game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1 } 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 + 600; // Move the tree 500px to the right tree.y = 2500; // Position the tree on the grass // Ensure tree is added to the game before setting its index if (game.children.includes(tree) && game.children.includes(bird1)) { game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1 } var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1650; // Move 500px to the right stack1.y = 2300; // Move down by 800px // Ensure stack1 is added to the game before setting its index if (game.children.includes(stack1) && game.children.includes(tree)) { game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree } // Add the grass floor to the game var grassBack = new GrassBack(); grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom game.addChild(grassBack); // Ensure grassBack is added to the game before setting its index if (game.children.includes(grassBack)) { game.setChildIndex(grassBack, 5); // Set grassBack to be rendered after Bird3 } var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px game.addChild(grassFront); // Ensure grassFront is added to the game before setting its index if (game.children.includes(grassFront) && game.children.includes(bird2)) { game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2 } var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; // Move the score display 400px to the right mirror.y = 2732 - 185 - 80 - 390; // Move the score display up by an additional 80px game.addChild(mirror); // Ensure mirror is added to the game before setting its index if (game.children.includes(mirror) && game.children.includes(stack1)) { game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1 } // Ensure laser is added to the game before setting mirror's index if (game.children.includes(laser) && game.children.includes(mirror)) { game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser } // 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 = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Ensure cat is added to the game before setting its index if (game.children.includes(cat)) { game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value } // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: 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
@@ -1,1371 +1,955 @@
/****
-* Initialize Game
+* Plugins
****/
-var game = new LK.Game({
- // No title, no description
- // Always backgroundColor is black
- backgroundColor: 0x000000
-});
+var tween = LK.import("@upit/tween.v1");
/****
-* Game Code
+* Classes
****/
-/**
-* Cat Defender - Idle Game
-*
-* A game where cats automatically defend against incoming birds and UFOs.
-* Features idle point accumulation, upgrades, and progressive difficulty.
-*/
-// --- Global Variables ---
-function _toConsumableArray(r) {
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
-}
-function _nonIterableSpread() {
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
-}
-function _iterableToArray(r) {
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
- return Array.from(r);
- }
-}
-function _arrayWithoutHoles(r) {
- if (Array.isArray(r)) {
- return _arrayLikeToArray(r);
- }
-}
-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 _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;
+// 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('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 1 + Math.random() * 0.6;
+ self.lastY = self.y;
+ self.update = function () {
+ self.y += self.speed;
+ self.lastY = self.y;
+ };
+});
+// Bird2 class to represent the second kind of bird
+var Bird2 = Container.expand(function () {
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0x88CCFF // Light blue tint to differentiate
+ });
+ self.speed = 0.8 + Math.random() * 0.5;
+ self.lastY = self.y;
+ self.update = function () {
+ self.y += self.speed;
+ self.lastY = self.y;
+ };
+});
+// Add Bird3 class for variety
+var Bird3 = Container.expand(function () {
+ var self = Container.call(this);
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFCC88 // Orange tint to differentiate
+ });
+ self.speed = 1.2 + Math.random() * 0.7;
+ self.lastY = self.y;
+ self.update = function () {
+ self.y += self.speed;
+ self.lastY = self.y;
+ };
+});
+// 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.level = 1;
+ self.attackRate = 2; // attacks per second
+ self.attackRange = 300;
+ self.lastAttackTime = 0;
+ self.update = function () {
+ // Check for nearby birds to attack
+ var currentTime = LK.ticks / 60;
+ if (currentTime - self.lastAttackTime > 1 / self.attackRate) {
+ for (var i = 0; i < birds.length; i++) {
+ var bird = birds[i];
+ var dx = bird.x - self.x;
+ var dy = bird.y - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < self.attackRange) {
+ // Create laser from cat to bird
+ var laser = new Laser(self.x, self.y - 100, bird.x, bird.y);
+ game.addChild(laser);
+ self.lastAttackTime = currentTime;
+ break;
}
}
}
};
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
+});
+// Cloud class to represent cloud behavior
+var Cloud = Container.expand(function () {
+ var self = Container.call(this);
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.8 // Set default opacity to 80%
+ });
+ self.movement = new CloudMovement(self, cloudGraphics);
+});
+// CloudMovement class to handle cloud movement and fade effects
+var CloudMovement = Container.expand(function () {
+ var self = Container.call(this);
+ var cloudGraphics = self.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.8 // Set default opacity to 80%
+ });
+ self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
+ self.hasAccelerated = false; // Track if the cloud has already accelerated
+ self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ self.lastX = self.x; // Track last X position for future checks
+ self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
+ self.update = function () {
+ self.x += self.speed * self.direction;
+ // If the cloud moves off-screen, reposition it to the opposite side
+ if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
+ self.x = -self.width / 2;
+ } else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
+ self.x = 2048 + self.width / 2;
}
- 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 _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);
-}
-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 _classCallCheck(a, n) {
- if (!(a instanceof n)) {
- throw new TypeError("Cannot call a class as a function");
- }
-}
-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);
-}
-var cats = [];
-var kittens = [];
-var birds = [];
-var ufos = [];
-var clouds = [];
-var powerUps = [];
-var sparkles = [];
-// Game State Variables
-var score = 0;
-var level = 1;
-var multiplier = 1.0; // Starts at 1.0, increases by 0.1 per level
-var idlePoints = 0;
-var enemiesDefeated = 0;
-var lastUpdateTime = Date.now();
-var idlePointsLastCalculated = Date.now();
-// Game Constants
-var CANVAS_WIDTH = 2048;
-var CANVAS_HEIGHT = 2732;
-var ENEMIES_PER_LEVEL = 10;
-var BASE_IDLE_POINTS_RATE = 0.5; // Points per cat per second
-var BIRD_POINTS = 10;
-var UFO_POINTS = 20;
-var BIRD_SPAWN_INTERVAL = 2000; // ms
-var UFO_SPAWN_INTERVAL = 15000; // ms
-var MAX_BIRDS = 10;
-var MAX_UFOS = 3;
-var CLOUD_SPAWN_INTERVAL = 5000; // ms
-var MAX_CLOUDS = 8;
-// Timers
-var birdSpawnTimer = 0;
-var ufoSpawnTimer = 0;
-var cloudSpawnTimer = 0;
-// --- Utility Functions ---
-function distance(x1, y1, x2, y2) {
- var dx = x1 - x2;
- var dy = y1 - y2;
- return Math.sqrt(dx * dx + dy * dy);
-}
-// --- Game Classes ---
-/**
-* Base class for game entities
-*/
-var GameObject = /*#__PURE__*/function () {
- function GameObject(x, y, width, height, assetId) {
- _classCallCheck(this, GameObject);
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- this.assetId = assetId;
- this.active = true;
- }
- return _createClass(GameObject, [{
- key: "update",
- value: function update(deltaTime) {
- // Override in subclasses
- }
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
- }
- // Draw the sprite
- LK.drawImage(this.assetId, this.x, this.y, this.width, this.height);
- }
- }, {
- key: "isColliding",
- value: function isColliding(other) {
- return this.x < other.x + other.width && this.x + this.width > other.x && this.y < other.y + other.height && this.y + this.height > other.y;
- }
- }]);
-}();
-/**
-* Base class for defenders (Cats and Kittens)
-*/
-var Defender = /*#__PURE__*/function (_GameObject) {
- function Defender(x, y, width, height, assetId, attackRange, attackCooldown, attackDamage, moveSpeed) {
- var _this;
- _classCallCheck(this, Defender);
- _this = _callSuper(this, Defender, [x, y, width, height, assetId]);
- _this.attackRange = attackRange;
- _this.attackCooldown = attackCooldown;
- _this.attackDamage = attackDamage;
- _this.moveSpeed = moveSpeed;
- _this.attackTimer = 0;
- _this.target = null;
- return _this;
- }
- _inherits(Defender, _GameObject);
- return _createClass(Defender, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Handle attack cooldown
- if (this.attackTimer > 0) {
- this.attackTimer -= deltaTime;
- }
- // Find target if none exists
- if (!this.target || !this.target.active) {
- this.findTarget();
- }
- // Move towards target or attack
- if (this.target) {
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, this.target.x + this.target.width / 2, this.target.y + this.target.height / 2);
- if (dist <= this.attackRange) {
- this.attack();
- } else {
- this.moveTowardsTarget(deltaTime);
+ // 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
}
}
- }, {
- key: "findTarget",
- value: function findTarget() {
- // Find closest enemy
- var closestDist = Infinity;
- var closest = null;
- // Check birds first
- var _iterator = _createForOfIteratorHelper(birds),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var bird = _step.value;
- if (!bird.active) {
- continue;
- }
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, bird.x + bird.width / 2, bird.y + bird.height / 2);
- if (dist < closestDist) {
- closestDist = dist;
- closest = bird;
- }
- }
- // Check UFOs if no birds found or if this is a kitten (kittens prefer UFOs)
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- if ((!closest || this instanceof LittleCat) && ufos.length > 0) {
- var _iterator2 = _createForOfIteratorHelper(ufos),
- _step2;
- try {
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
- var ufo = _step2.value;
- if (!ufo.active) {
- continue;
- }
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, ufo.x + ufo.width / 2, ufo.y + ufo.height / 2);
- if (dist < closestDist) {
- closestDist = dist;
- closest = ufo;
- }
- }
- } catch (err) {
- _iterator2.e(err);
- } finally {
- _iterator2.f();
- }
- }
- this.target = closest;
+ // 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
+ });
}
- }, {
- key: "moveTowardsTarget",
- value: function moveTowardsTarget(deltaTime) {
- if (!this.target) {
- return;
- }
- var targetX = this.target.x + this.target.width / 2;
- var targetY = this.target.y + this.target.height / 2;
- var dx = targetX - (this.x + this.width / 2);
- var dy = targetY - (this.y + this.height / 2);
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist > 0) {
- var moveX = dx / dist * this.moveSpeed * deltaTime;
- var moveY = dy / dist * this.moveSpeed * deltaTime;
- this.x += moveX;
- this.y += moveY;
- }
+ self.lastIntersecting = self.intersects(sun);
+ self.lastX = self.x; // Update lastX after movement
+ };
+});
+// GrassBack class to represent the grass image
+var GrassBack = Container.expand(function () {
+ var self = Container.call(this);
+ var grassGraphics = self.attachAsset('grass-back', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.update = function () {
+ // Add any specific update logic for the grass here
+ // Example: Slightly move the grass to simulate wind effect
+ self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
+ };
+ self.addChild(grassGraphics); // Add grass graphics to the container
+ self.update = function () {
+ // Add any specific update logic for the grass here
+ // Example: Slightly move the grass to simulate wind effect
+ self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
+ };
+});
+// GrassFront class to represent the second grass image
+var GrassFront = Container.expand(function () {
+ var self = Container.call(this);
+ var grass2Graphics = self.attachAsset('grass-front', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.lastX = self.x; // Initialize lastX for tracking changes on X
+ self.addChild(grass2Graphics); // Add grass2 graphics to the container
+ self.update = function () {
+ // Add any specific update logic for the grass here
+ // Example: Slightly move the grass to simulate wind effect
+ self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
+ self.lastX = self.x; // Update lastX after movement
+ };
+});
+// Jet class to represent a jet flying across the screen
+var Jet = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add a label to the jet
+ var jetLabel = new Text2('Jet', {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
+ jetLabel.y = -60; // Position the label above the jet
+ self.addChild(jetLabel);
+ // Add a label to the jet
+ var jetLabel = new Text2('Jet', {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
+ jetLabel.y = -60; // Position the label above the jet
+ self.addChild(jetLabel);
+ self.speed = 10; // Set the speed of the jet
+ 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;
+ // If the jet 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;
}
- }, {
- key: "attack",
- value: function attack() {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- this.target.takeDamage(this.attackDamage);
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
+ 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, endX, endY) {
+ var self = Container.call(this);
+ self.startX = startX;
+ self.startY = startY;
+ self.endX = endX;
+ self.endY = endY;
+ // Calculate angle and distance
+ var dx = endX - startX;
+ var dy = endY - startY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var angle = Math.atan2(dy, dx);
+ // Create laser graphics
+ var laserGraphics = new Graphics();
+ laserGraphics.lineStyle(2, 0xFF0000, 1);
+ laserGraphics.moveTo(0, 0);
+ laserGraphics.lineTo(distance, 0);
+ laserGraphics.rotation = angle;
+ self.addChild(laserGraphics);
+ self.x = startX;
+ self.y = startY;
+ // Play laser sound
+ LK.getSound('laser1').play();
+ self.lastIntersecting = false;
+ self.lifespan = 30; // frames
+ self.update = function () {
+ self.lifespan--;
+ if (self.lifespan <= 0) {
+ self.destroy();
}
- }]);
-}(GameObject);
-/**
-* Cat Class - Standard defender
-*/
-var Cat = /*#__PURE__*/function (_Defender) {
- function Cat(x, y) {
- _classCallCheck(this, Cat);
- return _callSuper(this, Cat, [x, y, 64, 64, 'cat', 100, 1.0, 2, 2]);
- }
- _inherits(Cat, _Defender);
- return _createClass(Cat);
-}(Defender);
-/**
-* Kitten Class - Faster but weaker defender
-*/
-var LittleCat = /*#__PURE__*/function (_Defender2) {
- function LittleCat(x, y) {
- _classCallCheck(this, LittleCat);
- return _callSuper(this, LittleCat, [x, y, 48, 48, 'kitten', 60, 0.5, 1, 3]);
- }
- _inherits(LittleCat, _Defender2);
- return _createClass(LittleCat);
-}(Defender);
-/**
-* Enemy base class
-*/
-var Enemy = /*#__PURE__*/function (_GameObject2) {
- function Enemy(x, y, width, height, assetId, health, speed, pointValue) {
- var _this2;
- _classCallCheck(this, Enemy);
- _this2 = _callSuper(this, Enemy, [x, y, width, height, assetId]);
- _this2.health = health;
- _this2.maxHealth = health;
- _this2.speed = speed;
- _this2.pointValue = pointValue;
- _this2.targetX = CANVAS_WIDTH / 2;
- _this2.targetY = CANVAS_HEIGHT / 2;
- return _this2;
- }
- _inherits(Enemy, _GameObject2);
- return _createClass(Enemy, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Move towards center
- var dx = this.targetX - (this.x + this.width / 2);
- var dy = this.targetY - (this.y + this.height / 2);
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist > 10) {
- // Not too close to center
- var moveX = dx / dist * this.speed * deltaTime;
- var moveY = dy / dist * this.speed * deltaTime;
- this.x += moveX;
- this.y += moveY;
- } else {
- // Reached center, remove
- this.active = false;
- }
+ };
+});
+// Light1 class to represent a light object
+var Light1 = Container.expand(function () {
+ var self = Container.call(this);
+ var lightGraphics = self.attachAsset('light1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.x = 450, self.y = 450;
+ // Add a label to the light1 object
+ var lightLabel = new Text2('Light1', {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ lightLabel.anchor.set(0.5, 0.5); // Center the label on the light
+ lightLabel.y = -60; // Position the label above the light
+ self.addChild(lightLabel);
+ self.update = function () {
+ // Add any specific update logic for the light here
+ };
+});
+// Mirror class to manage score display
+var Mirror = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreGraphics = self.attachAsset('mirror1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / 14 // Rotate image right 15 degrees
+ });
+ var scoreText = new Text2('0', {
+ size: 175,
+ fill: 0x800080,
+ font: "Courier New, Courier, monospace",
+ // Segmented clock style font
+ stroke: 0x00FF00,
+ strokeThickness: 15,
+ dropShadow: true,
+ dropShadowColor: 0x000000,
+ dropShadowBlur: 5,
+ dropShadowAngle: Math.PI / 6,
+ dropShadowDistance: 6
+ });
+ scoreText.y = 50; // 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
+ x = 100;
+ y = 100;
+ self.addChild(scoreText);
+ self.updateScore = function (newScore) {
+ scoreText.setText(newScore);
+ };
+});
+// Reticle class to manage reticle behavior
+var Reticle = Container.expand(function () {
+ var self = Container.call(this);
+ var reticleGraphics = self.attachAsset('reticle1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Add any specific update logic for the reticle here
+ };
+ // Start the pulsating effect for the reticle
+ startPulsating(self);
+});
+// Stack1 class to represent the stack1 image
+var Stack1 = Container.expand(function () {
+ var self = Container.call(this);
+ var stackGraphics = self.attachAsset('stack1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / -12
+ });
+ self.update = function () {
+ // Add any specific update logic for stack1 here
+ };
+});
+// ScoreManager class to manage score logic
+// Sun class to represent a sun in the top right corner
+var Sun = Container.expand(function () {
+ var self = Container.call(this);
+ var sunGraphics = self.attachAsset('sun', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ startPulsating(sunGraphics); // Start the pulsating effect on the sun graphics
+});
+// Function to create a pulsating effect
+// Tree class to represent a tree with a 9:16 aspect ratio
+var Tree = Container.expand(function () {
+ var self = Container.call(this);
+ var treeGraphics = self.attachAsset('tree', {
+ anchorX: 0.5,
+ anchorY: 1,
+ antialias: true,
+ // Apply antialias effect
+ stroke: 0x000000,
+ // Add a black stroke
+ strokeThickness: 15 // Set stroke thickness to 15px
+ });
+ self.update = function () {
+ // Add any specific update logic for the tree here
+ };
+});
+// UFO class to represent a UFO
+var UFO = Container.expand(function () {
+ var self = Container.call(this);
+ var ufoGraphics = self.attachAsset('ufo', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction
+ self.lastX = self.x;
+ self.customUpdate = function () {
+ self.x += self.speed * self.direction;
+ // Check if UFO has moved off-screen
+ 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;
+ LK.getSound('ufo1').stop();
}
- }, {
- key: "takeDamage",
- value: function takeDamage(amount) {
- this.health -= amount;
- if (this.health <= 0) {
- this.defeat();
- }
+ self.lastX = self.x;
+ };
+});
+
+/****
+* Initialize Game
+****/
+// UFOMovement class to handle UFO movement
+/****
+* Assets
+LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
+****/
+// Initialize clouds array
+var game = new LK.Game({
+ // No title, no description
+ backgroundColor: 0x000000 // Black
+});
+
+/****
+* Game Code
+****/
+// JetMovement class to handle jet movement
+var JetMovement = function JetMovement(jet, jetGraphics) {
+ this.jet = jet;
+ this.jetGraphics = jetGraphics;
+ this.jet.speed = Math.max(1.6, 3.2) * 2; // Set the jet speed to 200% faster than the fastest object (Bird2 or UFO)
+ this.jet.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ this.jet.lastX = this.jet.x; // Track last X position for future checks
+ this.jet.update = function () {
+ this.x += this.speed * this.direction;
+ // If the jet moves off-screen, reposition it to the opposite side
+ if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
+ this.x = -this.width / 2;
+ } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ this.x = 2048 + this.width / 2;
}
- }, {
- key: "defeat",
- value: function defeat() {
- this.active = false;
- // Add points
- var pointsEarned = this.pointValue * multiplier;
- score += pointsEarned;
- enemiesDefeated++;
- // Check for level up
- if (enemiesDefeated >= ENEMIES_PER_LEVEL) {
- levelUp();
+ this.lastX = this.x; // Update lastX after movement
+ };
+};
+var bird2; // Define bird2 variable in the global scope
+// Bird2Effects class to handle effects and animations for Bird2
+// Function to create a pulsating effect
+function startPulsating(target) {
+ var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
+ function pulsate() {
+ tween(target, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: duration,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(target, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: duration,
+ easing: tween.easeInOut,
+ onFinish: pulsate
+ });
}
- // Create sparkles
- for (var i = 0; i < 5; i++) {
- createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'defeat');
- }
- // Chance to spawn power-up
- if (Math.random() < 0.2) {
- // 20% chance
- spawnPowerUp(this.x, this.y);
- }
- }
- }, {
- key: "render",
- value: function render() {
- _superPropGet(Enemy, "render", this, 3)([]);
- // Draw health bar
- var healthPercent = this.health / this.maxHealth;
- var barWidth = this.width * 0.8;
- var barHeight = 5;
- var barX = this.x + (this.width - barWidth) / 2;
- var barY = this.y - 10;
- // Background
- LK.setFillStyle('rgba(0,0,0,0.5)');
- LK.fillRect(barX, barY, barWidth, barHeight);
- // Health
- LK.setFillStyle('rgba(255,50,50,0.8)');
- LK.fillRect(barX, barY, barWidth * healthPercent, barHeight);
- }
- }]);
-}(GameObject);
-/**
-* Bird Class - Standard enemy
-*/
-var Bird = /*#__PURE__*/function (_Enemy) {
- function Bird() {
- _classCallCheck(this, Bird);
- // Random position at edge of screen
- var side = Math.floor(Math.random() * 4);
- var x, y;
- switch (side) {
- case 0:
- // Top
- x = Math.random() * CANVAS_WIDTH;
- y = -50;
- break;
- case 1:
- // Right
- x = CANVAS_WIDTH + 50;
- y = Math.random() * CANVAS_HEIGHT;
- break;
- case 2:
- // Bottom
- x = Math.random() * CANVAS_WIDTH;
- y = CANVAS_HEIGHT + 50;
- break;
- case 3:
- // Left
- x = -50;
- y = Math.random() * CANVAS_HEIGHT;
- break;
- }
- return _callSuper(this, Bird, [x, y, 32, 32, 'birdImage', 3, 50, BIRD_POINTS]);
+ });
}
- _inherits(Bird, _Enemy);
- return _createClass(Bird);
-}(Enemy);
-/**
-* UFO Class - Rare, stronger enemy
-*/
-var UFO = /*#__PURE__*/function (_Enemy2) {
- function UFO() {
- _classCallCheck(this, UFO);
- // Random position at edge of screen
- var side = Math.floor(Math.random() * 4);
- var x, y;
- switch (side) {
- case 0:
- // Top
- x = Math.random() * CANVAS_WIDTH;
- y = -50;
- break;
- case 1:
- // Right
- x = CANVAS_WIDTH + 50;
- y = Math.random() * CANVAS_HEIGHT;
- break;
- case 2:
- // Bottom
- x = Math.random() * CANVAS_WIDTH;
- y = CANVAS_HEIGHT + 50;
- break;
- case 3:
- // Left
- x = -50;
- y = Math.random() * CANVAS_HEIGHT;
- break;
+ pulsate();
+}
+// UFOSound class to manage UFO sound effects
+// UFOMovement class to handle UFO movement
+var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
+ this.ufo = ufo;
+ this.ufoGraphics = ufoGraphics;
+ this.ufo.speed = 3.2; // Decrease speed by 20%
+ this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ this.ufo.lastX = this.ufo.x; // Track last X position for future checks
+ this.ufo.update = function () {
+ this.x += this.speed * this.direction;
+ this.y = 100 + Math.sin(this.x / 50) * 250; // Extend the wave pattern to be longer and wider
+ // Stop playing ufo1 sound after UFO leaves the screen
+ if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ this.destroy();
+ ufo = null;
+ LK.getSound('ufo1').stop();
}
- return _callSuper(this, UFO, [x, y, 64, 32, 'ufoImage', 10, 30, UFO_POINTS]);
- }
- _inherits(UFO, _Enemy2);
- return _createClass(UFO);
-}(Enemy);
-/**
-* PowerUp Class - Temporary boosts for defenders
-*/
-var PowerUp = /*#__PURE__*/function (_GameObject3) {
- function PowerUp(x, y) {
- var _this3;
- _classCallCheck(this, PowerUp);
- _this3 = _callSuper(this, PowerUp, [x, y, 30, 30, 'powerupImage']);
- // Update last known positions
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- // Decrease lifespan
- this.lastX = this.x;
- this.lastY = this.y;
- // Decrease lifespan
- _this3.effects = {
- damage: {
- color: '#ff5555',
- duration: 10,
- multiplier: 2
+ this.lastX = this.x; // Update lastX after movement
+ };
+};
+var UFOSound = function UFOSound() {
+ this.play = function () {
+ LK.getSound('ufo1').play();
+ };
+};
+// BackgroundMusic class to manage background music
+var BackgroundMusic = function BackgroundMusic() {
+ this.play = function () {
+ LK.playMusic('bgm1', {
+ loop: true,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
},
- speed: {
- color: '#55ff55',
- duration: 15,
- multiplier: 1.5
- },
- range: {
- color: '#5555ff',
- duration: 12,
- multiplier: 1.5
- },
- multi: {
- color: '#ffaa55',
- duration: 8,
- multiplier: 1
- },
- chain: {
- color: '#55ffff',
- duration: 10,
- multiplier: 1
- },
- shield: {
- color: '#aaaaff',
- duration: 20,
- multiplier: 1
- },
- heal: {
- color: '#ff55ff',
- duration: 0,
- multiplier: 1
- },
- time: {
- color: '#ffff55',
- duration: 5,
- multiplier: 0.5
- }
- };
- // Select random type
- var types = Object.keys(_this3.effects);
- _this3.type = types[Math.floor(Math.random() * types.length)];
- // Set duration
- _this3.duration = 10; // seconds
- _this3.lifespan = 10; // seconds before disappearing if not collected
- return _this3;
- }
- _inherits(PowerUp, _GameObject3);
- return _createClass(PowerUp, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Decrease lifespan
- this.lifespan -= deltaTime;
- if (this.lifespan <= 0) {
- this.active = false;
- return;
- }
- // Check for collision with defenders
- for (var _i = 0, _cats = cats; _i < _cats.length; _i++) {
- var cat = _cats[_i];
- if (this.isColliding(cat)) {
- this.applyEffect(cat);
- this.active = false;
- return;
- }
- }
- for (var _i2 = 0, _kittens = kittens; _i2 < _kittens.length; _i2++) {
- var kitten = _kittens[_i2];
- if (this.isColliding(kitten)) {
- this.applyEffect(kitten);
- this.active = false;
- return;
- }
- }
- // Floating animation
- this.y += Math.sin(Date.now() / 200) * 0.5;
+ onEnd: onBgm1End
+ });
+ };
+};
+// LaserSound class to manage laser sound effects
+var LaserSound = function LaserSound() {
+ this.play = function () {
+ LK.getSound('laser1').play();
+ };
+};
+var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
+ this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X
+ this.bird.update = function () {
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ // Check if the bird has moved off-screen
+ if (this.lastY <= 2732 && this.y > 2732) {
+ this.y = -this.height;
+ this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
}
- }, {
- key: "applyEffect",
- value: function applyEffect(defender) {
- var _this4 = this;
- // Apply effect based on type
- switch (this.type) {
- case 'damage':
- defender.attackDamage *= this.effects.damage.multiplier;
- setTimeout(function () {
- defender.attackDamage /= _this4.effects.damage.multiplier;
- }, this.effects.damage.duration * 1000);
- break;
- case 'speed':
- defender.moveSpeed *= this.effects.speed.multiplier;
- setTimeout(function () {
- defender.moveSpeed /= _this4.effects.speed.multiplier;
- }, this.effects.speed.duration * 1000);
- break;
- case 'range':
- defender.attackRange *= this.effects.range.multiplier;
- setTimeout(function () {
- defender.attackRange /= _this4.effects.range.multiplier;
- }, this.effects.range.duration * 1000);
- break;
- case 'multi':
- // Create temporary multi-attack effect
- var originalAttack = defender.attack;
- defender.attack = function () {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- this.target.takeDamage(this.attackDamage);
- // Attack additional enemies
- var count = 0;
- for (var _i3 = 0, _arr = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i3 < _arr.length; _i3++) {
- var enemy = _arr[_i3];
- if (enemy !== this.target && enemy.active && count < 2) {
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
- if (dist <= this.attackRange * 1.5) {
- enemy.takeDamage(this.attackDamage / 2);
- count++;
- // Create attack effect
- createSparkle(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, 'attack');
- }
- }
- }
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
- };
- setTimeout(function () {
- defender.attack = originalAttack;
- }, this.effects.multi.duration * 1000);
- break;
- case 'chain':
- // Create chain attack effect
- var chainAttack = defender.attack;
- defender.attack = function () {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- // Initial attack
- this.target.takeDamage(this.attackDamage);
- // Chain to nearby enemies
- var lastEnemy = this.target;
- var chainCount = 0;
- for (var _i4 = 0, _arr2 = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i4 < _arr2.length; _i4++) {
- var enemy = _arr2[_i4];
- if (enemy !== lastEnemy && enemy.active && chainCount < 3) {
- var dist = distance(lastEnemy.x + lastEnemy.width / 2, lastEnemy.y + lastEnemy.height / 2, enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
- if (dist <= 100) {
- enemy.takeDamage(this.attackDamage * 0.7);
- chainCount++;
- lastEnemy = enemy;
- // Create chain effect
- createSparkle(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, 'chain');
- }
- }
- }
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
- };
- setTimeout(function () {
- defender.attack = chainAttack;
- }, this.effects.chain.duration * 1000);
- break;
- case 'shield':
- // Create shield effect
- defender.shielded = true;
- setTimeout(function () {
- defender.shielded = false;
- }, this.effects.shield.duration * 1000);
- break;
- case 'heal':
- // Heal all defenders
- for (var _i5 = 0, _cats2 = cats; _i5 < _cats2.length; _i5++) {
- var cat = _cats2[_i5];
- } // Cats don't have health in this game, but could add temporary invincibility
- for (var _i6 = 0, _kittens2 = kittens; _i6 < _kittens2.length; _i6++) {
- var kitten = _kittens2[_i6];
- } // Kittens don't have health in this game, but could add temporary invincibility
- break;
- case 'time':
- // Slow down all enemies
- var _iterator3 = _createForOfIteratorHelper(birds),
- _step3;
- try {
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
- var bird = _step3.value;
- if (bird.active) {
- bird.speed *= this.effects.time.multiplier;
- }
- }
- } catch (err) {
- _iterator3.e(err);
- } finally {
- _iterator3.f();
- }
- var _iterator4 = _createForOfIteratorHelper(ufos),
- _step4;
- try {
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
- var ufo = _step4.value;
- if (ufo.active) {
- ufo.speed *= this.effects.time.multiplier;
- }
- }
- } catch (err) {
- _iterator4.e(err);
- } finally {
- _iterator4.f();
- }
- setTimeout(function () {
- var _iterator5 = _createForOfIteratorHelper(birds),
- _step5;
- try {
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
- var bird = _step5.value;
- if (bird.active) {
- bird.speed /= _this4.effects.time.multiplier;
- }
- }
- } catch (err) {
- _iterator5.e(err);
- } finally {
- _iterator5.f();
- }
- var _iterator6 = _createForOfIteratorHelper(ufos),
- _step6;
- try {
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
- var ufo = _step6.value;
- if (ufo.active) {
- ufo.speed /= _this4.effects.time.multiplier;
- }
- }
- } catch (err) {
- _iterator6.e(err);
- } finally {
- _iterator6.f();
- }
- }, this.effects.time.duration * 1000);
- break;
+ if (this.birdGraphics) {
+ if (this.lastX <= this.x) {
+ this.birdGraphics.texture = LK.getAsset('bird1-right', {}).texture;
+ } else if (this.lastX > this.x) {
+ this.birdGraphics.texture = LK.getAsset('bird1-left', {}).texture;
}
- // Create collection effect
- for (var i = 0; i < 10; i++) {
- createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'powerup');
- }
+ this.lastX = this.x; // Update lastX after movement
}
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
+ this.lastY = this.y; // Update lastY after movement
+ };
+};
+var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
+ this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X
+ this.bird.update = function () {
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ if (this.birdGraphics) {
+ if (this.lastX <= this.x) {
+ this.birdGraphics.texture = LK.getAsset('bird2-right', {}).texture;
+ } else if (this.lastX > this.x) {
+ this.birdGraphics.texture = LK.getAsset('bird2-left', {}).texture;
}
- // Draw power-up background
- LK.setFillStyle(this.effects[this.type].color);
- LK.fillRect(this.x, this.y, this.width, this.height);
- // Draw icon
- this.drawPowerUpIcon();
- // Pulsing effect based on remaining lifespan
- if (this.lifespan < 3) {
- var alpha = 0.5 + 0.5 * Math.sin(Date.now() / 100);
- LK.setFillStyle("rgba(255,255,255,".concat(alpha, ")"));
- LK.fillRect(this.x, this.y, this.width, this.height);
- }
+ this.lastX = this.x; // Update lastX after movement
}
- // Helper method to convert hex color to RGB format
- }, {
- key: "hexToRgb",
- value: function hexToRgb(hex) {
- // Remove # if present
- hex = hex.replace('#', '');
- // Parse the hex values
- var r = parseInt(hex.substring(0, 2), 16);
- var g = parseInt(hex.substring(2, 4), 16);
- var b = parseInt(hex.substring(4, 6), 16);
- return "".concat(r, ",").concat(g, ",").concat(b);
+ // Check if the bird has moved off-screen
+ if (this.lastY <= 2732 && this.y > 2732) {
+ this.y = Math.random() * 2732; // Random initial y position within the screen height
+ this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
}
- // Draw an icon representing the power-up type
- }, {
- key: "drawPowerUpIcon",
- value: function drawPowerUpIcon() {
- var centerX = this.x + this.width / 2;
- var centerY = this.y + this.height / 2;
- var iconSize = this.width / 6;
- LK.setFillStyle('white');
- switch (this.type) {
- case 'damage':
- // Draw a plus symbol
- LK.fillRect(centerX - iconSize, centerY - iconSize / 3, iconSize * 2, iconSize * 2 / 3);
- LK.fillRect(centerX - iconSize / 3, centerY - iconSize, iconSize * 2 / 3, iconSize * 2);
- break;
- case 'speed':
- // Draw a lightning bolt
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX - iconSize, centerY - iconSize);
- LK.lineTo(centerX + iconSize / 2, centerY);
- LK.lineTo(centerX - iconSize / 2, centerY);
- LK.lineTo(centerX + iconSize, centerY + iconSize);
- LK.stroke();
- break;
- case 'range':
- // Draw a circle
- LK.drawCircle(centerX, centerY, iconSize);
- LK.setFillStyle(this.effects[this.type].color);
- LK.drawCircle(centerX, centerY, iconSize / 2);
- break;
- case 'multi':
- // Draw multiple dots
- for (var i = 0; i < 3; i++) {
- var angle = i / 3 * Math.PI * 2;
- LK.drawCircle(centerX + Math.cos(angle) * iconSize, centerY + Math.sin(angle) * iconSize, iconSize / 2);
- }
- break;
- case 'chain':
- // Draw connected dots
- var points = [{
- x: centerX - iconSize,
- y: centerY - iconSize
- }, {
- x: centerX,
- y: centerY
- }, {
- x: centerX + iconSize,
- y: centerY + iconSize
- }];
- // Draw lines connecting points
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(points[0].x, points[0].y);
- LK.lineTo(points[1].x, points[1].y);
- LK.lineTo(points[2].x, points[2].y);
- LK.stroke();
- // Draw points
- for (var _i7 = 0, _points = points; _i7 < _points.length; _i7++) {
- var point = _points[_i7];
- LK.drawCircle(point.x, point.y, iconSize / 3);
- }
- break;
- case 'shield':
- // Draw shield shape
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX, centerY - iconSize);
- LK.lineTo(centerX + iconSize, centerY - iconSize / 2);
- LK.lineTo(centerX + iconSize, centerY + iconSize / 2);
- LK.lineTo(centerX, centerY + iconSize);
- LK.lineTo(centerX - iconSize, centerY + iconSize / 2);
- LK.lineTo(centerX - iconSize, centerY - iconSize / 2);
- LK.lineTo(centerX, centerY - iconSize);
- LK.stroke();
- break;
- case 'heal':
- // Draw plus symbol
- LK.fillRect(centerX - iconSize, centerY - iconSize / 4, iconSize * 2, iconSize / 2);
- LK.fillRect(centerX - iconSize / 4, centerY - iconSize, iconSize / 2, iconSize * 2);
- break;
- case 'time':
- // Draw clock symbol
- LK.drawCircle(centerX, centerY, iconSize);
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX, centerY);
- LK.lineTo(centerX, centerY - iconSize * 0.7);
- LK.moveTo(centerX, centerY);
- LK.lineTo(centerX + iconSize * 0.5, centerY);
- LK.stroke();
- break;
- }
+ this.lastY = this.y; // Update lastY after movement
+ };
+};
+var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
+ this.cloud = cloud;
+ this.cloudGraphics = cloudGraphics;
+ this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
+ this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated
+ this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ this.cloud.lastX = this.cloud.x; // Track last X position for future checks
+ this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
+ this.cloud.update = function () {
+ this.x += this.speed * this.direction;
+ // If the cloud moves off-screen, reposition it to the opposite side
+ if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
+ this.x = -this.width / 2;
+ } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ this.x = 2048 + this.width / 2;
}
- }]);
-}(GameObject);
-/**
-* Sparkle Class - Visual effects
-*/
-var Sparkle = /*#__PURE__*/function (_GameObject4) {
- function Sparkle(x, y, type) {
- var _this5;
- _classCallCheck(this, Sparkle);
- _this5 = _callSuper(this, Sparkle, [x, y, 10, 10, 'sparkleImage']);
- _this5.type = type || 'defeat'; // defeat, attack, powerup
- _this5.lifespan = 0.5; // seconds
- _this5.velocity = {
- x: (Math.random() - 0.5) * 100,
- y: (Math.random() - 0.5) * 100
- };
- // Update last known positions
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- // Update position
- this.lastX = this.x;
- this.lastY = this.y;
- // Update position
- switch (_this5.type) {
- case 'defeat':
- _this5.color = "rgba(255,255,".concat(Math.floor(Math.random() * 100) + 155, ",0.8)");
+ // Check for overlap with other clouds
+ for (var i = 0; i < clouds.length; i++) {
+ if (clouds[i] !== this && this.intersects(clouds[i])) {
+ if (!this.hasAccelerated) {
+ this.speed *= 1.5; // Increase speed by 50%
+ this.hasAccelerated = true; // Mark as accelerated
+ }
break;
- case 'attack':
- _this5.color = "rgba(255,".concat(Math.floor(Math.random() * 100) + 100, ",100,0.8)");
- break;
- case 'powerup':
- _this5.color = "rgba(".concat(Math.floor(Math.random() * 155) + 100, ",").concat(Math.floor(Math.random() * 155) + 100, ",255,0.8)");
- break;
- case 'chain':
- _this5.color = "rgba(100,255,".concat(Math.floor(Math.random() * 155) + 100, ",0.8)");
- break;
- default:
- _this5.color = "rgba(255,255,255,0.8)";
+ } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
+ this.speed /= 1.5; // Reset speed to original
+ this.hasAccelerated = false; // Reset acceleration state
+ }
}
- return _this5;
- }
- _inherits(Sparkle, _GameObject4);
- return _createClass(Sparkle, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
+ // Check if the cloud intersects with the sun
+ if (!this.lastIntersecting && this.intersects(sun)) {
+ this.speed *= 2; // Double the speed when touching the sun
+ if (this.cloudGraphics) {
+ tween(this.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
}
- // Update position
- this.x += this.velocity.x * deltaTime;
- this.y += this.velocity.y * deltaTime;
- // Decrease lifespan
- this.lifespan -= deltaTime;
- if (this.lifespan <= 0) {
- this.active = false;
+ } else if (this.lastIntersecting && !this.intersects(sun)) {
+ this.speed /= 2; // Reset speed to original when not touching the sun
+ if (this.cloudGraphics) {
+ tween(this.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
}
}
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
- }
- // Draw sparkle
- var alpha = this.lifespan * 2; // Fade out
- LK.setFillStyle(this.color.replace('0.8', alpha));
- LK.fillRect(this.x, this.y, this.width, this.height);
+ this.lastIntersecting = this.intersects(sun);
+ this.lastX = this.x; // Update lastX after movement
+ };
+};
+var Bird2Effects = function Bird2Effects(bird) {
+ this.bird = bird;
+ this.applyEffects = function () {
+ // Add any specific effects or animations for Bird2 here
+ };
+};
+// Bird1Effects class to handle effects and animations for Bird1
+var Bird1Effects = function Bird1Effects(bird) {
+ this.bird = bird;
+ this.applyEffects = function () {
+ // Add any specific effects or animations for Bird1 here
+ };
+};
+var background = LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+background.x = 2048 / 2;
+background.y = 2732 / 2 - 100;
+game.addChild(background);
+// ScoreManager class to manage score logic
+var ScoreManager = function ScoreManager() {
+ var self = this;
+ self.score = 0;
+ self.addScore = function (points) {
+ self.score += points;
+ return self.score;
+ };
+ self.resetScore = function () {
+ self.score = 0;
+ };
+ self.getScore = function () {
+ return self.score;
+ };
+};
+var ScoreManager = function ScoreManager() {
+ var self = this;
+ self.score = 0;
+ self.addScore = function (points) {
+ self.score += points;
+ return self.score;
+ };
+ self.resetScore = function () {
+ self.score = 0;
+ };
+ self.getScore = function () {
+ return self.score;
+ };
+};
+var birds = [];
+game.down = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = game.addChild(new Reticle());
+ if (game.children.includes(game.reticle)) {
+ game.setChildIndex(game.reticle, 7); // Set reticle to be rendered after the tree
}
- }]);
-}(GameObject); // --- Cloud Class ---
-var Cloud = /*#__PURE__*/function (_GameObject5) {
- function Cloud() {
- var _this6;
- _classCallCheck(this, Cloud);
- var size = 32 + Math.floor(Math.random() * 96); // Random size between 32x32 and 128x128
- var y = Math.random() * (CANVAS_HEIGHT - size);
- _this6 = _callSuper(this, Cloud, [CANVAS_WIDTH + size, y, size, size, 'cloudImage']);
- _this6.speed = 10 + Math.random() * 20; // Random speed
- _this6.parallaxLayer = Math.random(); // Random depth effect
- return _this6;
}
- _inherits(Cloud, _GameObject5);
- return _createClass(Cloud, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Move cloud from right to left
- this.x -= this.speed * this.parallaxLayer * deltaTime;
- // Remove if off screen
- if (this.x + this.width < 0) {
- this.active = false;
- }
- }
- }]);
-}(GameObject); // --- Game Functions ---
-// Create a sparkle effect
-function createSparkle(x, y, type) {
- var sparkle = new Sparkle(x, y, type);
- sparkle.width *= 1.5; // Adjusted size
- sparkle.height *= 1.5; // Adjusted size
- sparkles.push(sparkle);
- return sparkle;
+ game.reticle.x = x;
+ game.reticle.y = y;
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
+ game.addChild(laser);
+ if (game.children.includes(laser) && game.children.includes(game.reticle)) {
+ game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle
+ }
+};
+var VOLUME_BGM1 = 0.02;
+var VOLUME_BREEZE1 = 0.02;
+var VOLUME_CRICKET1 = 0.02;
+var VOLUME_FROG1 = 0.02;
+var VOLUME_SONGBIRD1 = 0.02;
+var VOLUME_UFO1 = 0.02;
+var VOLUME_WINGS1 = 0.02;
+game.move = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = game.addChild(new Reticle());
+ }
+ if (obj.event) {
+ var x = obj.event.x;
+ var y = obj.event.y;
+ }
+ game.reticle.x = x;
+ game.reticle.y = y;
+};
+// Add a sun to the game in the top left corner
+var sun = game.addChild(new Sun());
+sun.x = 480;
+sun.y = 680;
+// Ensure sun is added to the game before setting its index
+if (game.children.includes(sun)) {
+ game.setChildIndex(sun, 1); // Set sun to be rendered after the background
}
-// Spawn a power-up
-function spawnPowerUp(x, y) {
- var powerUp = new PowerUp(x, y);
- powerUp.width *= 1.2; // Adjusted size
- powerUp.height *= 1.2; // Adjusted size
- powerUps.push(powerUp);
- return powerUp;
+var light1 = game.addChild(new Light1());
+light1.x = 530; // Move light1 right by 50px
+light1.y = 1490; // Move light1 down by 210px
+// Ensure light1 is added to the game before setting its index
+if (game.children.includes(light1)) {
+ game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun
}
-// Level up function
-function levelUp() {
- level++;
- multiplier = 1 + (level - 1) * 0.1; // Increase multiplier by 0.1 per level
- enemiesDefeated = 0;
- // Create level up effect
- for (var i = 0; i < 20; i++) {
- createSparkle(CANVAS_WIDTH / 2 + (Math.random() - 0.5) * 200, CANVAS_HEIGHT / 2 + (Math.random() - 0.5) * 200, 'levelup');
+// Function to add a UFO to the game
+function addUFO() {
+ var ufo = new UFO();
+ game.addChild(ufo);
+ // Ensure UFO is added to the game before setting its index
+ if (game.children.includes(ufo) && game.children.includes(clouds[0])) {
+ game.setChildIndex(ufo, game.getChildIndex(clouds[0]) + 1); // Set UFO to be rendered after the first cloud
}
+ ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen
+ ufo.y = Math.random() * (2732 / 2 - ufo.height); // Random initial y position within the top half of the screen
+ ufo.customUpdate = function () {
+ ufo.update();
+ };
+ // Removed ufo sound playing at startup
+ return ufo;
}
-// --- Main Game Functions ---
-// Initialize game
-function initialize() {
- // Add cat image
- var catImage = LK.getAsset('cat', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleY: 400 / 64,
- scaleX: 400 / 64,
- x: CANVAS_WIDTH / 2,
- y: CANVAS_HEIGHT / 2
+// Initialize clouds array
+var clouds = [];
+for (var i = 0; i < 4; i++) {
+ // Add 3 clouds for variety
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
+ clouds.push(cloud);
+ game.addChild(cloud);
+ // Ensure cloud is added to the game before setting its index
+ if (game.children.includes(cloud)) {
+ game.setChildIndex(cloud, 2); // Set clouds to be rendered after the sun
+ }
+}
+var bird1; // Define bird1 variable in the global scope
+// Initialize birds
+spawnBird1();
+spawnBird2();
+spawnBird2();
+// Initialize a timer to add a UFO at a random time between 20 and 30 seconds
+var ufo; // Define the ufo variable in the global scope
+var laser; // Define the laser variable in the global scope
+var ufoTimer = LK.setTimeout(function () {
+ addUFO();
+ // Reset the timer for the UFO to reappear between 10-20 seconds
+ ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000);
+}, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds
+game.update = function () {
+ // Update each bird
+ birds.forEach(function (bird, index) {
+ bird.update();
+ // Check if the bird has moved off-screen
+ if (bird.lastY <= 2732 && bird.y > 2732) {
+ bird.destroy();
+ birds.splice(index, 1);
+ spawnBird();
+ }
});
- game.addChild(catImage);
- // Add cloud image
- var cloudImage = LK.getAsset('cloudImage', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleY: 400 / 100,
- scaleX: 400 / 100,
- x: CANVAS_WIDTH * 0.5,
- y: CANVAS_HEIGHT * 0.2
+ // Update clouds
+ clouds.forEach(function (cloud) {
+ cloud.update();
});
- game.addChild(cloudImage);
- // Add power-up image
- var powerupImage = LK.getAsset('powerupImage', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleY: 400 / 30,
- scaleX: 400 / 30,
- x: CANVAS_WIDTH * 0.3,
- y: CANVAS_HEIGHT * 0.3
- });
- game.addChild(powerupImage);
- // Add sparkle image
- var sparkleImage = LK.getAsset('sparkleImage', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleY: 400 / 10,
- scaleX: 400 / 10,
- x: CANVAS_WIDTH * 0.7,
- y: CANVAS_HEIGHT * 0.7
- });
- game.addChild(sparkleImage);
- // Create initial cat
- var initialCat = new Cat(CANVAS_WIDTH * 0.1, CANVAS_HEIGHT * 0.1); // Adjusted position
- cats.push(initialCat);
- // Initialize timers
- lastUpdateTime = Date.now();
- idlePointsLastCalculated = Date.now();
- // Create initial clouds
- for (var i = 0; i < 5; i++) {
- var cloud = new Cloud();
- cloud.x = Math.random() * CANVAS_WIDTH; // Position randomly across screen
- cloud.y = Math.random() * (CANVAS_HEIGHT - cloud.height); // Adjusted position
- cloud.width *= 1.5; // Adjusted size
- cloud.height *= 1.5; // Adjusted size
- clouds.push(cloud);
+ // Update UFO if present
+ if (ufo) {
+ ufo.customUpdate();
}
-}
-// Update game state
-function update(deltaTime) {
- // Update last known positions
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- this.lastX = this.x;
- this.lastY = this.y;
- // Move cloud from right to left
- this.lastX = this.x;
- this.lastY = this.y;
- // Move towards center
- this.lastX = this.x;
- this.lastY = this.y;
- // Handle attack cooldown
- this.lastX = this.x;
- this.lastY = this.y;
- // Override in subclasses
- this.lastX = this.x;
- this.lastY = this.y;
- // Move cloud from right to left
- this.lastX = this.x;
- this.lastY = this.y;
- // Move towards center
- this.lastX = this.x;
- this.lastY = this.y;
- // Handle attack cooldown
- this.lastX = this.x;
- this.lastY = this.y;
- // Override in subclasses
- var currentTime = Date.now();
- deltaTime = (currentTime - lastUpdateTime) / 1000; // Convert to seconds
- lastUpdateTime = currentTime;
- // Calculate idle points
- calculateIdlePoints();
- // Spawn enemies based on timers
- birdSpawnTimer += deltaTime * 1000;
- if (birdSpawnTimer >= BIRD_SPAWN_INTERVAL / (1 + (level - 1) * 0.1) && birds.length < MAX_BIRDS) {
- birds.push(new Bird());
- birdSpawnTimer = 0;
+ // Spawn UFO randomly
+ if (!ufo && Math.random() < 0.001) {
+ spawnUFO();
}
- ufoSpawnTimer += deltaTime * 1000;
- if (ufoSpawnTimer >= UFO_SPAWN_INTERVAL && ufos.length < MAX_UFOS && level % 5 === 0) {
- ufos.push(new UFO());
- ufoSpawnTimer = 0;
+ // Ensure there are always 3 birds
+ while (birds.length < 3) {
+ spawnBird();
}
- // Spawn clouds
- cloudSpawnTimer += deltaTime * 1000;
- if (cloudSpawnTimer >= CLOUD_SPAWN_INTERVAL && clouds.length < MAX_CLOUDS) {
- spawnCloud();
- cloudSpawnTimer = 0;
+};
+// Helper function to spawn birds
+function spawnBird() {
+ var birdType = Math.random();
+ var bird;
+ if (birdType < 0.6) {
+ bird = new Bird1();
+ } else if (birdType < 0.9) {
+ bird = new Bird2();
+ } else {
+ bird = new Bird3();
}
- // Update all game objects
- updateGameObjects(cats, deltaTime);
- updateGameObjects(kittens, deltaTime);
- updateGameObjects(birds, deltaTime);
- updateGameObjects(ufos, deltaTime);
- updateGameObjects(powerUps, deltaTime);
- updateGameObjects(sparkles, deltaTime);
- updateGameObjects(clouds, deltaTime);
- // Clean up inactive objects
- cleanupInactiveObjects();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ game.addChild(bird);
+ birds.push(bird);
}
-// Update array of game objects
-function updateGameObjects(objects, deltaTime) {
- for (var i = 0; i < objects.length; i++) {
- if (objects[i].active) {
- objects[i].update(deltaTime);
+// Helper function to spawn UFO
+function spawnUFO() {
+ ufo = new UFO();
+ ufo.x = ufo.direction > 0 ? -ufo.width / 2 : 2048 + ufo.width / 2;
+ ufo.y = Math.random() * 1000 + 200;
+ game.addChild(ufo);
+ LK.getSound('ufo1').play();
+}
+// Function to spawn a third kind of bird
+function spawnBird1() {
+ var bird1 = new Bird1();
+ bird1.x = Math.random() * 2048;
+ bird1.y = -bird1.height;
+ bird1.speed = 1 + Math.random() * 0.6;
+ bird1.lastIntersecting = false;
+ bird1.type = 'bird1'; // Specific property for Bird1
+ bird1.color = 0x746130; // Specific color for Bird1
+ LK.setTimeout(function () {
+ game.addChild(bird1);
+ // Ensure bird1 is added to the game before setting its index
+ if (game.children.includes(bird1)) {
+ if (game.children.includes(bird1) && game.children.includes(tree)) {
+ game.setChildIndex(bird1, game.getChildIndex(tree)); // Set Bird1 to be rendered before tree
+ }
}
- }
+ birds.push(bird1);
+ }, 2000);
}
-// Clean up inactive objects
-function cleanupInactiveObjects() {
- birds = birds.filter(function (obj) {
- return obj.active;
+function spawnBird2() {
+ var bird = new Bird2();
+ bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half
+ bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ bird.speed = 1 + Math.random() * 0.6;
+ bird.lastIntersecting = false;
+ bird.type = 'bird2'; // Specific property for Bird2
+ bird.color = 0xFFFFFF; // Specific color for Bird2
+ LK.setTimeout(function () {
+ game.addChild(bird);
+ // Ensure bird is added to the game before setting its index
+ if (game.children.includes(bird)) {
+ game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1
+ }
+ 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
+ }
});
- ufos = ufos.filter(function (obj) {
- return obj.active;
- });
- powerUps = powerUps.filter(function (obj) {
- return obj.active;
- });
- sparkles = sparkles.filter(function (obj) {
- return obj.active;
- });
- clouds = clouds.filter(function (obj) {
- return obj.active;
- });
+};
+// Add a tree to the game
+var tree = game.addChild(new Tree());
+tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
+tree.y = 2500; // Position the tree on the grass
+// Ensure tree is added to the game before setting its index
+if (game.children.includes(tree) && game.children.includes(bird1)) {
+ game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
}
-// Render game
-function render() {
- // Clear canvas
- LK.clear();
- // Render clouds (background)
- renderGameObjects(clouds);
- // Render game objects
- renderGameObjects(cats);
- renderGameObjects(kittens);
- renderGameObjects(birds);
- renderGameObjects(ufos);
- renderGameObjects(powerUps);
- renderGameObjects(sparkles);
- // Render UI
- renderUI();
+var score = 0;
+// Add stack1 image to the game
+var stack1 = game.addChild(new Stack1());
+stack1.x = 1650; // Move 500px to the right
+stack1.y = 2300; // Move down by 800px
+// Ensure stack1 is added to the game before setting its index
+if (game.children.includes(stack1) && game.children.includes(tree)) {
+ game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
}
-// Render array of game objects
-function renderGameObjects(objects) {
- for (var i = 0; i < objects.length; i++) {
- if (objects[i].active) {
- objects[i].render();
- }
- }
+// Add the grass floor to the game
+var grassBack = new GrassBack();
+grassBack.x = 1020;
+grassBack.y = 2735; // Position grassBack at the bottom
+game.addChild(grassBack);
+// Ensure grassBack is added to the game before setting its index
+if (game.children.includes(grassBack)) {
+ game.setChildIndex(grassBack, 5); // Set grassBack to be rendered after Bird3
}
-// Render UI elements
-function renderUI() {
- // Score display
- LK.setFillStyle('white');
- LK.setFont('400px Arial');
- LK.fillText("Score: ".concat(Math.floor(score)), CANVAS_WIDTH / 2, 400, 'center');
- // Level and multiplier
- LK.setFont('18px Arial');
- LK.fillText("Level: ".concat(level), CANVAS_WIDTH - 100, 50, 'right');
- LK.fillText("Multiplier: ".concat(multiplier.toFixed(1), "x"), CANVAS_WIDTH / 2, 80, 'center');
- // Enemies defeated counter
- LK.fillText("Enemies: ".concat(enemiesDefeated, "/").concat(ENEMIES_PER_LEVEL), 100, 50, 'left');
- // Idle points counter
- LK.fillText("Idle Points: ".concat(Math.floor(idlePoints)), CANVAS_WIDTH - 100, CANVAS_HEIGHT - 50, 'right');
+var grassFront = new GrassFront();
+grassFront.x = 1020;
+grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
+game.addChild(grassFront);
+// Ensure grassFront is added to the game before setting its index
+if (game.children.includes(grassFront) && game.children.includes(bird2)) {
+ game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
}
-// Handle input events
-function handleInput(obj) {
- var x = obj.event.x;
- var y = obj.event.y;
- // Check if clicked on a power-up
- var _iterator7 = _createForOfIteratorHelper(powerUps),
- _step7;
- try {
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
- var powerUp = _step7.value;
- if (powerUp.active && x >= powerUp.x && x <= powerUp.x + powerUp.width && y >= powerUp.y && y <= powerUp.y + powerUp.height) {
- // Collect power-up
- powerUp.active = false;
- // Apply to nearest defender
- var closestDist = Infinity;
- var closest = null;
- var _iterator8 = _createForOfIteratorHelper(cats),
- _step8;
- try {
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
- var cat = _step8.value;
- var dist = distance(powerUp.x, powerUp.y, cat.x, cat.y);
- if (dist < closestDist) {
- closestDist = dist;
- closest = cat;
- }
- }
- } catch (err) {
- _iterator8.e(err);
- } finally {
- _iterator8.f();
- }
- var _iterator9 = _createForOfIteratorHelper(kittens),
- _step9;
- try {
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
- var kitten = _step9.value;
- var dist = distance(powerUp.x, powerUp.y, kitten.x, kitten.y);
- if (dist < closestDist) {
- closestDist = dist;
- closest = kitten;
- }
- }
- } catch (err) {
- _iterator9.e(err);
- } finally {
- _iterator9.f();
- }
- if (closest) {
- powerUp.applyEffect(closest);
- }
- return;
- }
- }
- // Place a new cat at the clicked position
- } catch (err) {
- _iterator7.e(err);
- } finally {
- _iterator7.f();
- }
- if (idlePoints >= 50) {
- idlePoints -= 50;
- cats.push(new Cat(x, y));
- }
+var mirror = new Mirror();
+mirror.x = 2048 / 2 + 400; // Move the score display 400px to the right
+mirror.y = 2732 - 185 - 80 - 390; // Move the score display up by an additional 80px
+game.addChild(mirror);
+// Ensure mirror is added to the game before setting its index
+if (game.children.includes(mirror) && game.children.includes(stack1)) {
+ game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
}
-// Main game loop
-function gameLoop() {
- update(1 / 60); // 60 FPS
- render();
+// Ensure laser is added to the game before setting mirror's index
+if (game.children.includes(laser) && game.children.includes(mirror)) {
+ game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
}
-// Start the game
-initialize();
-LK.on('pointerdown', handleInput);
-multiplier = 1.0 + (level - 1) * 0.1;
\ No newline at end of file
+// 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 = 230; // Move the cat 20px to the left
+cat.y = 2732; // Position the cat at the bottom of the screen
+// Ensure cat is added to the game before setting its index
+if (game.children.includes(cat)) {
+ game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+}
+// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
+LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.02,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ // Set a timer to replay bgm1 every 20-50 seconds
+ LK.setTimeout(function () {
+ LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.5,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: 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);
+});
\ 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