User prompt
upgrade buttons are not upgrading
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'cost')' in or related to this line: 'if (self.points >= upgrade.cost) {' Line Number: 308
User prompt
upgrade button text is missing
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'cost')' in or related to this line: 'if (self.points >= upgrade.cost) {' Line Number: 285
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'cost')' in or related to this line: 'if (self.points >= upgrade.cost) {' Line Number: 285
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'cost')' in or related to this line: 'if (self.points >= upgrade.cost) {' Line Number: 262
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'cost')' in or related to this line: 'label = 'Income +20%\nCost: ' + Math.floor(upgrade.cost);' Line Number: 583
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.upgrades = self.upgrades;' Line Number: 270 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
move floaty text down 60px
User prompt
move the floaty text down 30px
User prompt
move score image text up 100px
User prompt
increase the height of the scroll image (scoreimg) and move its text up 50px
User prompt
move scoreimge down 100px
User prompt
move the scroll down 50px
User prompt
for the score display brlow, make the scroll object stretch down 100px more
User prompt
move the powerup buttons to the top right.
User prompt
make the score image at the bottom of the screen taller, extending down
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.buttonText.setText(label);' Line Number: 536 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
ensure this game follows idle/hypercasual game logic. add and remove logic as needed to meet tha game style.
User prompt
continue
User prompt
ensure this game follows idle/hypercasual game logic. add and remove logic as needed to meet tha game style. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'The supplied index is out of bounds' in or related to this line: 'game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered at index 7 or the last valid index' Line Number: 729
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 160 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
birds spawn non-stop, crashng the game
User prompt
Compilation error[L1402]: Uncaught ReferenceError: Reticle is not defined
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Background = Container.expand(function () { var self = Container.call(this); var backgroundGraphics = self.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(backgroundGraphics); game.layerManager.addToLayer(self, LAYERS.BACKGROUND); }); var Bird = Container.expand(function (type) { var self = Container.call(this); var birdGraphics = self.attachAsset(type === 'bird1' ? 'bird1' : 'bird2', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(birdGraphics); self.update = function () { self.y += self.speed; self.lastY = self.y; }; return self; }); var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 1 }); self.x = 230; self.y = 2732; self.shootingInterval = 1000; // Time between shots in milliseconds self.lastShotTime = 0; self.shoot = function (target) { var laser = new Laser(self.x - 140, self.y - 440, target.x, target.y); game.addChild(laser); game.layerManager.addToLayer(laser, LAYERS.LASER); }; var findClosestTarget = function findClosestTarget(catX, catY) { var closestTarget = null; var closestDistance = 1000; // Set a reasonable range game.children.forEach(function (child) { if (child instanceof Bird && (child.type === 'bird1' || child.type === 'bird2') || child instanceof UFO) { var distance = Math.sqrt(Math.pow(child.x - catX, 2) + Math.pow(child.y - catY, 2)); if (distance < closestDistance) { closestDistance = distance; closestTarget = child; } } }); return closestTarget; }; self.update = function () { if (LK.ticks - self.lastShotTime >= self.shootingInterval) { self.lastShotTime = LK.ticks; self.shoot(findClosestTarget(self.x, self.y)); } }; }); var Cloud = Container.expand(function () { var self = Container.call(this); var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)]; var cloudGraphics = self.attachAsset(cloudType, { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }); var layerIndex = cloudType === 'cloud1' ? LAYERS.CLOUD1 : LAYERS.CLOUD2; game.layerManager.addToLayer(self, layerIndex); self.movement = new CloudMovement(self, cloudGraphics); // Override destroy method to remove from layer tracking var originalDestroy = self.destroy; self.destroy = function () { // Remove from layer tracking before destroying if (game.layerManager) { game.layerManager.removeFromTracking(self); } // Call the original destroy method originalDestroy.call(self); }; self.update = function () { self.movement.update(); }; return self; }); var GrassBack = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1 }); self.update = function () { self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; self.addChild(grassGraphics); // Add grass graphics to the container // Set the layer index for grass-back game.layerManager.addToLayer(self, LAYERS.GRASS_BACK); }); 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 () { self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50% self.lastX = self.x; // Update lastX after movement }; // Set the layer index for grass-front game.layerManager.addToLayer(self, LAYERS.GRASS_FRONT); }); var Laser = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var laserGraphics = self.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 // Increase brightness by 200% }); // Play the laser1 sound when the laser is created LK.getSound('laser1').play(); // Calculate direction and speed var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 30; // Reduce speed of the laser self.vx = dx / distance * speed; self.vy = dy / distance * speed; // Set initial position self.x = startX; self.y = startY; // Override destroy method to remove from layer tracking var originalDestroy = self.destroy; self.destroy = function () { // Remove from layer tracking before destroying if (game.layerManager) { game.layerManager.removeFromTracking(self); } // Call the original destroy method originalDestroy.call(self); }; self.update = function () { game.children.forEach(function (child) { if ((child instanceof Bird1 || child instanceof Bird2) && self.intersects(child)) { child.destroy(); self.destroy(); } }); self.x += self.vx; self.y += self.vy; if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; // Set the layer index for laser game.layerManager.addToLayer(self, LAYERS.LASER); }); var Light1 = Container.expand(function () { var self = Container.call(this); var lightGraphics = self.attachAsset('light1', { anchorX: 0.5, anchorY: 0.5, alpha: 1.0 }); self.x = 450; self.y = 450; self.update = function () { self.x += Math.sin(LK.ticks / 90) * 0.1; }; self.pulse = new Light1Pulse(lightGraphics); self.pulse.startPulsating(); game.layerManager.addToLayer(self, LAYERS.LIGHT1); }); var Mirror = Container.expand(function () { var self = Container.call(this); var mirrorGraphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(mirrorGraphics); // Set the layer index for mirror game.layerManager.addToLayer(self, LAYERS.MIRROR); // Score display functionality var scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = 260; scoreText.x = -155; scoreText.rotation = (-83 + 2) * (Math.PI / 180); self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; return self; }); var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(reticleGraphics); // Set the layer index for reticle game.layerManager.addToLayer(self, LAYERS.RETICLE); return self; }); var Reticle1 = Container.expand(function () { var self = Container.call(this); var reticle1Graphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(reticle1Graphics); // Set the layer index for reticle game.layerManager.addToLayer(self, LAYERS.RETICLE); }); 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 }; // Set the layer index for stack game.layerManager.addToLayer(self, LAYERS.STACK); }); var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); self.pulse = new SunPulse(sunGraphics); self.pulse.startPulsating(); // Set the layer index for sun game.layerManager.addToLayer(self, LAYERS.SUN); }); var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree1', { 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 }; // Set the layer index for tree game.layerManager.addToLayer(self, LAYERS.TREE); }); var Tree2 = Container.expand(function () { var self = Container.call(this); var tree2Graphics = self.attachAsset('tree2', { anchorX: 0.5, anchorY: 1 }); self.addChild(tree2Graphics); // Set the layer index for tree2 game.layerManager.addToLayer(self, LAYERS.TREE); }); var UFO = Container.expand(function (type) { var self = Container.call(this); var ufoGraphics = self.attachAsset(type === 'ufo1' ? 'ufo1' : 'ufo2', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new UFOMovement(self, ufoGraphics); // Override destroy method to remove from layer tracking var originalDestroy = self.destroy; self.destroy = function () { // Remove from layer tracking before destroying if (game.layerManager) { game.layerManager.removeFromTracking(self); } // Call the original destroy method originalDestroy.call(self); }; // Set the layer index for ufo game.layerManager.addToLayer(self, type === 'ufo1' ? LAYERS.UFO1 : LAYERS.UFO2); }); /**** * Initialize Game ****/ // Initialize clouds array var game = new LK.Game({ // No title, no description backgroundColor: 0x87CEEB // Sky blue }); /**** * Game Code ****/ // Define CLOUD_TYPES array to fix 'CLOUD_TYPES is not defined' error // CloudMovement class to handle cloud movement and fade effects var UFOMovement = function UFOMovement(ufo, ufoGraphics) { this.ufo = ufo; this.ufoGraphics = ufoGraphics; this.speed = Math.random() * 2 + 1; // Random speed between 1 and 3 this.direction = Math.random() < 0.5 ? 1 : -1; // Random initial direction this.update = function () { this.ufo.x += this.speed * this.direction; // Check for screen boundaries and reverse direction if needed if (this.ufo.x > 2048 + this.ufo.width / 2 || this.ufo.x < -this.ufo.width / 2) { this.direction *= -1; } }.bind(this); }; var CLOUD_TYPES = ['cloud1', 'cloud2']; var CloudMovement = function CloudMovement(cloud, cloudGraphics) { this.cloud = cloud; this.cloudGraphics = cloudGraphics; this.speed = Math.random() * 0.55 + 0.25; this.direction = Math.random() < 0.5 ? 1 : -1; this.update = function () { this.cloud.x += this.speed * this.direction; var screenWidth = 2048; var halfWidth = this.cloud.width / 2; if (this.cloud.x > screenWidth + halfWidth) { this.cloud.x = -halfWidth; } else if (this.cloud.x < -halfWidth) { this.cloud.x = screenWidth + halfWidth; } }.bind(this); }; 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); } /**** * Layer Constants ****/ var LAYERS = { BACKGROUND: 0, SUN: 1, LIGHT1: 2, UFO2: 3, CLOUD1: 4, JET1: 5, CLOUD2: 6, UFO1: 7, BIRD1: 8, GRASS_BACK: 9, TREE: 10, STACK: 11, BIRD2: 12, MIRROR: 13, GRASS_FRONT: 14, CAT: 15, LASER: 16, RETICLE: 17 }; /**** * Layer Management System ****/ var LayerManager = /*#__PURE__*/function () { function LayerManager(gameInstance) { _classCallCheck(this, LayerManager); this.game = gameInstance; this.layerMap = {}; } return _createClass(LayerManager, [{ key: "setLayerIndex", value: function setLayerIndex(object, layerId) { if (!object || !this.game.children.includes(object)) { return; } // Ensure the layer ID is valid and within bounds layerId = Math.max(0, Math.min(layerId, this.game.children.length)); // Set the child index if (layerId < this.game.children.length) { this.game.setChildIndex(object, layerId); } // Update the layer map this.layerMap[object.id] = layerId; } }, { key: "getObjectsInLayer", value: function getObjectsInLayer(layerId) { var objects = []; for (var id in this.layerMap) { if (this.layerMap[id] === layerId) { // Find the object in the game's children for (var i = 0; i < this.game.children.length; i++) { var child = this.game.children[i]; if (child.id === id) { objects.push(child); break; } } } } return objects; } /** * Add an object to a specific layer * @param {Object} object - The game object to add * @param {Number} layerId - The layer ID */ }, { key: "addToLayer", value: function addToLayer(object, layerId) { if (!object || !object.id) { return; } // Add the object if it's not already a child if (!this.game.children.includes(object)) { this.game.addChild(object); } // Set the child index to match the LAYERS order this.game.setChildIndex(object, layerId); // Update the layer map this.layerMap[object.id] = layerId; } /** * Get the layer of an object * @param {Object} object - The game object * @return {Number} The layer ID or -1 if not found */ }, { key: "getObjectLayer", value: function getObjectLayer(object) { if (!object || !object.id) { return -1; } return this.layerMap[object.id] !== undefined ? this.layerMap[object.id] : -1; } /** * Remove an object from layer tracking * @param {Object} object - The game object to remove */ }, { key: "removeFromTracking", value: function removeFromTracking(object) { if (!object || !object.id) { return; } delete this.layerMap[object.id]; } /** * Bring an object to the front of its layer * @param {Object} object - The game object */ }, { key: "bringToFrontOfLayer", value: function bringToFrontOfLayer(object) { if (!object || !object.id) { return; } var layerId = this.getObjectLayer(object); if (layerId === -1) { return; } // Find the highest index within this layer var highestIndex = layerId; for (var id in this.layerMap) { if (this.layerMap[id] === layerId) { // Find the object in the game's children for (var i = 0; i < this.game.children.length; i++) { var child = this.game.children[i]; if (child.id === id && i > highestIndex) { highestIndex = i; } } } } // Set the object to the highest index within its layer this.game.setChildIndex(object, highestIndex); } /** * Send an object to the back of its layer * @param {Object} object - The game object */ }, { key: "sendToBackOfLayer", value: function sendToBackOfLayer(object) { if (!object || !object.id) { return; } var layerId = this.getObjectLayer(object); if (layerId === -1) { return; } // Find the lowest index within this layer var lowestIndex = layerId; for (var id in this.layerMap) { if (this.layerMap[id] === layerId) { // Find the object in the game's children for (var i = 0; i < this.game.children.length; i++) { var child = this.game.children[i]; if (child.id === id && i < lowestIndex) { lowestIndex = i; } } } } // Set the object to the lowest index within its layer this.game.setChildIndex(object, lowestIndex); } /** * Helper function to add multiple objects to a layer at once * @param {Array} objects - Array of game objects * @param {Number} layerId - The layer ID */ }, { key: "addMultipleToLayer", value: function addMultipleToLayer(objects, layerId) { var _this2 = this; if (!Array.isArray(objects)) { return; } objects.forEach(function (object) { return _this2.addToLayer(object, layerId); }); } }]); }(); game.layerManager = new LayerManager(game); // Using UFO sound ID as placeholder function flipImageVerticallyBasedOnDirection(graphics, lastX, currentX) { if (graphics) { if (lastX < currentX && graphics.scaleX < 0) { graphics.scaleX *= -1; // Flip horizontally to face right } else if (lastX > currentX && graphics.scaleX > 0) { graphics.scaleX *= -1; // Flip horizontally to face left } } } function flipImageBasedOnDirection(graphics, lastX, currentX) { if (graphics) { if (lastX < currentX) { graphics.scaleY = Math.abs(graphics.scaleY); // Face right when moving right by ensuring scaleY is positive } else if (lastX > currentX) { graphics.scaleY = -Math.abs(graphics.scaleY); // Face left when moving left by ensuring scaleY is negative } } } // SunPulse class to handle the pulsating effect for Sun function AABBIntersect(obj1, obj2) { if (obj1 && obj2) { return obj1.x < obj2.x + obj2.width && obj1.x + obj1.width > obj2.x && obj1.y < obj2.y + obj2.height && obj1.y + obj1.height > obj2.y; } return false; } // Using existing CLOUD_TYPES definition var SunPulse = function SunPulse(sunGraphics) { this.sunGraphics = sunGraphics; this.startPulsating = function () { function pulsate() { tween(this.sunGraphics, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function () { tween(this.sunGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; // Light1Pulse class to handle the pulsating effect for Light1 var Light1Pulse = function Light1Pulse(lightGraphics) { this.lightGraphics = lightGraphics; this.startPulsating = function () { function pulsate() { tween(this.lightGraphics, { scaleX: 1.6, scaleY: 1.6 }, { duration: 1000, easing: tween.easeInOut, onFinish: function () { tween(this.lightGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1500, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; function startPulsating(target) { var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888; function pulsate() { tween(target, { scaleX: 1.2, scaleY: 1.2 }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: duration, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); } // UFOMovement class to handle UFO movement var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () {}; }; // 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 }; }; // Add background to the BACKGROUND layer var background = new Background(); background.x = 2048 / 2; background.y = 2732 / 2 - 140; game.addChild(background); game.layerManager.addToLayer(background, LAYERS.BACKGROUND); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { var self = this; var currentScore = 0; var highScore = storage.highScore; self.addScore = function (points) { if (typeof points !== 'number' || points < 0) { return currentScore; } currentScore += Math.floor(points); if (currentScore > highScore) { highScore = currentScore; storage.highScore = highScore; } return currentScore; }; self.resetScore = function () { currentScore = 0; return currentScore; }; self.getScore = function () { return currentScore; }; self.getHighScore = function () { return highScore; }; }; var birds = []; // Add a sun to the game in the top left corner var sun = new Sun(); sun.x = 480; sun.y = 680; game.layerManager.addToLayer(sun, LAYERS.SUN); var light1 = new Light1(); light1.x = 510; light1.y = 1500; game.layerManager.addToLayer(light1, LAYERS.LIGHT1); light1.visible = true; // Function to add a UFO to the game function addUFO() { var ufo = new UFO('ufo1'); game.addChild(ufo); ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; ufo.y = Math.random() * (2732 / 2 - ufo.height); ufo.customUpdate = function () { if (!ufo.soundPlayed && ufo.x > 0 && ufo.x < 2048) { if (currentAmbientSound) { currentAmbientSound.stop(); } LK.getSound('ufo1').play(); ufo.soundPlayed = true; } ufo.update(); }; return ufo; } // Initialize clouds array var clouds = []; // Using existing CLOUD_TYPES definition function initializeClouds() { function ensureCloudCount() { // Remove off-screen clouds clouds = clouds.filter(function (cloud) { if (cloud.x < -cloud.width || cloud.x > 2048 + cloud.width) { cloud.destroy(); return false; } return true; }); // Add new clouds if needed, maintaining 3-5 clouds while (clouds.length < 5) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); game.addChild(cloud); game.layerManager.addToLayer(cloud, clouds.length < 3 ? LAYERS.CLOUD1 : LAYERS.CLOUD2); clouds.push(cloud); } } // Initial cloud setup ensureCloudCount(); // Check cloud count every second LK.setInterval(ensureCloudCount, 1000); } // Call initializeClouds after game initialization initializeClouds(); var bird1; // Define bird1 variable in the global scope var bird; // Define bird variable in the global scope // Initialize birds and score var birds = []; var score = 0; var scoreDisplay = new Mirror(); scoreDisplay.x = 2048 / 2 + 400; scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; game.addChild(scoreDisplay); // Initialize ambient sounds timer with 20-30 second intervals function initializeAmbientSounds() { function playAmbientSounds() { if (currentAmbientSound) { currentAmbientSound.stop(); } if (Array.isArray(sounds) && sounds.length > 0) { var soundId = sounds[Math.floor(Math.random() * sounds.length)]; } else { console.error("Sounds array is not defined or empty."); return; } var sound = LK.getSound(soundId); sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000); // 20-30 seconds } playAmbientSounds(); } // Initialize background music timer with 20-30 second intervals function initializeBGM() { function playBGM() { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: VOLUME_BGM1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(playBGM, Math.random() * 30000 + 20000); // 20-50 seconds } }); } playBGM(); } // Start the game initializeBGM(); initializeAmbientSounds(); spawnBird1(); spawnBird2(); // Initialize variables for UFOs and laser var ufo1, ufo2, laser; var score = 0; // Initialize timers for UFOs with 20-30 second respawn function initializeUFOTimers() { // UFO1 Timer // UFO1 Timer function spawnUFO1() { if (!game.children.some(function (c) { return c instanceof UFO && c.type === 'ufo1'; })) { var ufo1 = new UFO('ufo1'); game.addChild(ufo1); game.layerManager.addToLayer(ufo1, LAYERS.UFO1); } LK.setTimeout(spawnUFO1, Math.random() * 10000 + 20000); } // Initialize UFO1 spawn timer immediately spawnUFO1(); // UFO2 Timer function spawnUFO2() { if (!game.children.some(function (c) { return c instanceof UFO; })) { ufo2 = new UFO('ufo2'); game.addChild(ufo2); ufo2.x = Math.random() < 0.5 ? 2048 + ufo2.width / 2 : -ufo2.width / 2; ufo2.y = Math.random() * (2732 / 2 - ufo2.height); } LK.setTimeout(spawnUFO2, Math.random() * 10000 + 20000); } spawnUFO2(); } initializeUFOTimers(); var originalUpdate = game.update; game.update = function () { // Call the original update function first originalUpdate.call(this); // Update clouds for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } // 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 } }); // Ensure correct number of birds with sound effects var bird1Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).length; var bird2Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).length; // Maintain exactly 1 Bird1 if (bird1Count < 1) { var newBird1 = new Bird('bird1'); newBird1.x = Math.random() * 2048; newBird1.y = -newBird1.height; newBird1.speed = Math.random() * 1.6 + 1; newBird1.lastIntersecting = false; newBird1.type = 'bird1'; newBird1.color = 0x746130; game.addChild(newBird1); game.layerManager.addToLayer(newBird1, LAYERS.BIRD1); birds.push(newBird1); LK.getSound('bird1').play(); } else if (bird1Count > 1) { var extraBird1s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).slice(1); extraBird1s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Maintain exactly 3 Bird2s if (bird2Count < 3) { for (var i = 0; i < 3 - bird2Count; i++) { var newBird2 = new Bird('bird2'); newBird2.x = Math.random() < 0.5 ? 0 : 2048; newBird2.y = Math.random() * (2732 / 2); newBird2.speed = 1 + Math.random() * 0.6; newBird2.lastIntersecting = false; newBird2.type = 'bird2'; newBird2.color = 0xFFFFFF; game.addChild(newBird2); game.layerManager.addToLayer(newBird2, LAYERS.BIRD2); birds.push(newBird2); LK.getSound('bird2').play(); } } else if (bird2Count > 3) { var extraBird2s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).slice(3); extraBird2s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Update UFOs, jets, and check for collisions game.children.forEach(function (entity) { if (entity instanceof UFO) { if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } if (typeof entity.update === 'function') { entity.update(); } } }); // Update each laser and check collisions game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird && bird.type === 'bird1') { score += 5; LK.getSound('dead1').play(); } else if (bird instanceof Bird && bird.type === 'bird2') { score += 1; LK.getSound('dead2').play(); } scoreDisplay.updateScore(score.toString()); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); LK.getSound('laser1').play(); } }); // Check for intersections with UFOs game.children.forEach(function (entity) { if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) { score += 25; scoreDisplay.updateScore(score.toString()); entity.destroy(); child.destroy(); LK.getSound('dead3').play(); LK.getSound('laser2').play(); } }); // Update lastIntersecting state child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || game.children.some(function (entity) { return entity instanceof UFO && child.intersects(entity); }); } }); // If there's no UFO, try to spawn one ufo = addUFO(); }; function spawnBird1() { if (!birds.some(function (b) { return b instanceof Bird && b.type === 'bird1'; })) { var bird1 = new Bird('bird1'); bird1.x = Math.random() * 2048; bird1.y = -bird1.height; bird1.speed = Math.random() * 1.6 + 1; bird1.lastIntersecting = false; bird1.type = 'bird1'; bird1.color = 0x746130; game.addChild(bird1); if (game.children.includes(bird1)) { game.layerManager.addToLayer(bird1, LAYERS.BIRD1); birds.push(bird1); } } LK.setTimeout(spawnBird1, Math.random() * 10000 + 20000); } function spawnBird2() { var bird2Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).length; if (bird2Count < 3) { var bird = new Bird('bird2'); bird.y = Math.random() * (2732 / 2); bird.x = Math.random() < 0.5 ? 0 : 2048; bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'bird2'; bird.color = 0xFFFFFF; game.addChild(bird); if (game.children.includes(bird)) { game.layerManager.addToLayer(bird, LAYERS.BIRD2); birds.push(bird); } } LK.setTimeout(spawnBird2, Math.random() * 10000 + 20000); } // Update the main game update function to include bird updates var originalUpdate = game.update; game.update = function () { // Call the original update function first originalUpdate.call(this); // 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 } }); // Ensure correct number of birds var bird1Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).length; var bird2Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).length; // Maintain exactly 1 Bird1 if (bird1Count < 1) { var newBird1 = new Bird('bird1'); newBird1.x = Math.random() * 2048; newBird1.y = Math.random() * (2732 / 2); game.addChild(newBird1); game.layerManager.addToLayer(newBird1, LAYERS.BIRD1); birds.push(newBird1); } else if (bird1Count > 1) { var extraBird1s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).slice(1); extraBird1s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Maintain exactly 3 Bird2s if (bird2Count < 3) { for (var i = 0; i < 3 - bird2Count; i++) { var newBird2 = new Bird('bird2'); newBird2.x = Math.random() * 2048; newBird2.y = Math.random() * (2732 / 2); game.addChild(newBird2); game.layerManager.addToLayer(newBird2, LAYERS.BIRD2); birds.push(newBird2); } } else if (bird2Count > 3) { var extraBird2s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).slice(3); extraBird2s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Update UFOs, jets, and check for collisions game.children.forEach(function (entity) { if (entity instanceof UFO) { if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } entity.update(); } }); // Update each laser and check collisions game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird && bird.type === 'bird1') { score += 5; LK.getSound('dead1').play(); } else if (bird instanceof Bird && bird.type === 'bird2') { score += 1; LK.getSound('dead2').play(); } scoreDisplay.updateScore(score.toString()); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); LK.getSound('laser1').play(); } }); // Check for intersections with UFOs game.children.forEach(function (entity) { if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) { score += 25; scoreDisplay.updateScore(score.toString()); entity.destroy(); child.destroy(); LK.getSound('dead3').play(); LK.getSound('laser2').play(); } }); // Update lastIntersecting state child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || game.children.some(function (entity) { return entity instanceof UFO && child.intersects(entity); }); } }); }; // 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 // Add tree to the proper layer if (game.children.includes(tree)) { game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer } var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Add stack1 to the proper layer if (game.children.includes(stack1)) { game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer } // 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); // Add grassBack to the proper layer if (game.children.includes(grassBack)) { game.layerManager.addToLayer(grassBack, LAYERS.GRASS_BACK); // Use layer manager to set grass-back layer } var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px game.addChild(grassFront); // Add grassFront to the proper layer if (game.children.includes(grassFront)) { game.layerManager.addToLayer(grassFront, LAYERS.GRASS_FRONT); // Use layer manager to set grass-front layer } var scoreDisplay = new Mirror(); scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px game.addChild(scoreDisplay); var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px game.addChild(mirror); // Add mirror to the proper layer if (game.children.includes(mirror)) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer } // 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 // Add cat to the proper layer if (game.children.includes(cat)) { game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer } // Play bgm1 once on load and set a timer to replay it every 20-30 seconds LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: onEnd }); }, Math.random() * 10000 + 20000); } }); // 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; // Sound volumes configuration // Initialize random timers for each sound to play between 20-30 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); } sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000); }, Math.random() * 10000 + 20000); }); var bird2; // Define bird2 variable in the global scope // UFOMovement class to handle UFO movement var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music // LaserSound class to manage laser sound effects var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () {}; }; // Removed invalid CSS assignment to game.style.css // 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 }; }; // Add background to the BACKGROUND layer var background = new Background(); background.x = 2048 / 2; background.y = 2732 / 2 - 140; game.layerManager.addToLayer(background, LAYERS.BACKGROUND); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { var self = this; var currentScore = 0; var highScore = storage.highScore || 0; self.addScore = function (points) { if (typeof points !== 'number' || points < 0) { return currentScore; } currentScore += Math.floor(points); if (currentScore > highScore) { highScore = currentScore; storage.highScore = highScore; } return currentScore; }; self.resetScore = function () { currentScore = 0; return currentScore; }; self.getScore = function () { return currentScore; }; self.getHighScore = function () { return highScore; }; }; // Game Over Function function gameOver() { // Stop the game ticker game.ticker.stop(); // Display Game Over message with score var gameOverText = new Text("Game Over\nScore: " + score, { fontFamily: 'Arial', fontSize: 64, fill: 'white', align: 'center' }); gameOverText.anchor.set(0.5); gameOverText.x = game.screen.width / 2; gameOverText.y = game.screen.height / 2; game.stage.addChild(gameOverText); // Make the game over text interactive (clickable) gameOverText.interactive = true; gameOverText.buttonMode = true; gameOverText.on('pointerdown', restartGame); console.log("Game Over. Final Score: " + 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.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); // Use layer manager to set reticle layer } } 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.layerManager.addToLayer(laser, LAYERS.LASER); // Use layer manager to set laser layer } }; 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 = new Sun(); sun.x = 480; sun.y = 680; game.layerManager.addToLayer(sun, LAYERS.SUN); var light1 = new Light1(); light1.x = 510; light1.y = 1500; game.layerManager.addToLayer(light1, LAYERS.LIGHT1); light1.visible = true; // Function to add a UFO to the game // Using existing CLOUD_TYPES definition // initializeClouds already called earlier var bird1; // Define bird1 variable in the global scope var bird; // Define bird variable in the global scope 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 clouds for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } if (ufo) { ufo.customUpdate(); // Cache game children to avoid repeated property access var gameChildren = game.children; // Update lasers and check collisions gameChildren.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds and UFO var hasIntersection = birds.some(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { score += bird instanceof Bird1 ? 5 : bird instanceof Bird2 ? 1 : 0; scoreDisplay.updateScore(score); LK.getSound('dead1').play(); bird.destroy(); birds.splice(birds.indexOf(bird), 1); child.destroy(); return true; } return child.intersects(bird); }); if (!hasIntersection && ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) { score += 25; scoreDisplay.updateScore(score); LK.getSound('dead3').play(); child.destroy(); } child.lastIntersecting = hasIntersection || ufo && child.intersects(ufo); } }); // Check for intersections between UFO and birds var ufoIntersection = birds.some(function (bird) { if (!ufo.lastIntersecting && ufo.intersects(bird)) { bird.destroy(); birds.splice(birds.indexOf(bird), 1); LK.getSound('dead2').play(); return true; } return ufo.intersects(bird); }); ufo.lastIntersecting = ufoIntersection; // Check if UFO is out of bounds if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) { ufo.destroy(); ufo = null; ufoTimer = LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 20000 + 30000); } ufo.lastX = ufo.x; } ; // Additional game element updates (cat, grass, etc.) var originalUpdate = game.update; game.update = function () { // Call the original update function first originalUpdate.call(this); // 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 } }); // Ensure correct number of birds var bird1Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).length; var bird2Count = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).length; // Maintain exactly 1 Bird1 if (bird1Count < 1) { var newBird1 = new Bird('bird1'); newBird1.x = Math.random() * 2048; newBird1.y = Math.random() * (2732 / 2); game.addChild(newBird1); game.layerManager.addToLayer(newBird1, LAYERS.BIRD1); birds.push(newBird1); } else if (bird1Count > 1) { var extraBird1s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird1'; }).slice(1); extraBird1s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Maintain exactly 3 Bird2s if (bird2Count < 3) { for (var i = 0; i < 3 - bird2Count; i++) { var newBird2 = new Bird('bird2'); newBird2.x = Math.random() * 2048; newBird2.y = Math.random() * (2732 / 2); game.addChild(newBird2); game.layerManager.addToLayer(newBird2, LAYERS.BIRD2); birds.push(newBird2); } } else if (bird2Count > 3) { var extraBird2s = birds.filter(function (b) { return b instanceof Bird && b.type === 'bird2'; }).slice(3); extraBird2s.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } // Update UFOs, jets, and check for collisions game.children.forEach(function (entity) { if (entity instanceof UFO) { if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } if (typeof entity.update === 'function') { entity.update(); } } }); // Update each laser and check collisions game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird && bird.type === 'bird1') { score += 5; LK.getSound('dead1').play(); } else if (bird instanceof Bird && bird.type === 'bird2') { score += 1; LK.getSound('dead2').play(); } scoreDisplay.updateScore(score.toString()); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); LK.getSound('laser1').play(); } }); // Check for intersections with UFOs game.children.forEach(function (entity) { if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) { score += 25; scoreDisplay.updateScore(score.toString()); entity.destroy(); child.destroy(); LK.getSound('dead3').play(); LK.getSound('laser2').play(); } }); // Update lastIntersecting state child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || game.children.some(function (entity) { return entity instanceof UFO && child.intersects(entity); }); } }); // 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 // Add tree to the proper layer if (game.children.includes(tree)) { game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer } var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Add stack1 to the proper layer if (game.children.includes(stack1)) { game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer } // 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); // Add grassBack to the proper layer if (game.children.includes(grassBack)) { game.layerManager.addToLayer(grassBack, LAYERS.GRASS_BACK); // Use layer manager to set grass-back layer } var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px game.addChild(grassFront); // Add grassFront to the proper layer if (game.children.includes(grassFront)) { game.layerManager.addToLayer(grassFront, LAYERS.GRASS_FRONT); // Use layer manager to set grass-front layer } // Add cat and score display to the game, ensuring they are added only once if (!game.cat) { game.cat = game.addChild(new Cat()); } game.cat.x = 230; game.cat.y = 2732; scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px game.addChild(scoreDisplay); var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px game.addChild(mirror); mirror.visible = true; game.layerManager.addToLayer(game.cat, LAYERS.CAT); // Add mirror to the proper layer using the layer manager // Add mirror to the proper layer if (game.children.includes(mirror)) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer } // Function to handle bgm1 end event function onBgm1End() {} // 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 20-30 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); } sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000); }, Math.random() * 10000 + 20000); }); }; };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(backgroundGraphics);
game.layerManager.addToLayer(self, LAYERS.BACKGROUND);
});
var Bird = Container.expand(function (type) {
var self = Container.call(this);
var birdGraphics = self.attachAsset(type === 'bird1' ? 'bird1' : 'bird2', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(birdGraphics);
self.update = function () {
self.y += self.speed;
self.lastY = self.y;
};
return self;
});
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 1
});
self.x = 230;
self.y = 2732;
self.shootingInterval = 1000; // Time between shots in milliseconds
self.lastShotTime = 0;
self.shoot = function (target) {
var laser = new Laser(self.x - 140, self.y - 440, target.x, target.y);
game.addChild(laser);
game.layerManager.addToLayer(laser, LAYERS.LASER);
};
var findClosestTarget = function findClosestTarget(catX, catY) {
var closestTarget = null;
var closestDistance = 1000; // Set a reasonable range
game.children.forEach(function (child) {
if (child instanceof Bird && (child.type === 'bird1' || child.type === 'bird2') || child instanceof UFO) {
var distance = Math.sqrt(Math.pow(child.x - catX, 2) + Math.pow(child.y - catY, 2));
if (distance < closestDistance) {
closestDistance = distance;
closestTarget = child;
}
}
});
return closestTarget;
};
self.update = function () {
if (LK.ticks - self.lastShotTime >= self.shootingInterval) {
self.lastShotTime = LK.ticks;
self.shoot(findClosestTarget(self.x, self.y));
}
};
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)];
var cloudGraphics = self.attachAsset(cloudType, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
var layerIndex = cloudType === 'cloud1' ? LAYERS.CLOUD1 : LAYERS.CLOUD2;
game.layerManager.addToLayer(self, layerIndex);
self.movement = new CloudMovement(self, cloudGraphics);
// Override destroy method to remove from layer tracking
var originalDestroy = self.destroy;
self.destroy = function () {
// Remove from layer tracking before destroying
if (game.layerManager) {
game.layerManager.removeFromTracking(self);
}
// Call the original destroy method
originalDestroy.call(self);
};
self.update = function () {
self.movement.update();
};
return self;
});
var GrassBack = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass-back', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
};
self.addChild(grassGraphics); // Add grass graphics to the container
// Set the layer index for grass-back
game.layerManager.addToLayer(self, LAYERS.GRASS_BACK);
});
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 () {
self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
self.lastX = self.x; // Update lastX after movement
};
// Set the layer index for grass-front
game.layerManager.addToLayer(self, LAYERS.GRASS_FRONT);
});
var Laser = Container.expand(function (startX, startY, targetX, targetY) {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
brightness: 2.0 // Increase brightness by 200%
});
// Play the laser1 sound when the laser is created
LK.getSound('laser1').play();
// Calculate direction and speed
var dx = targetX - startX;
var dy = targetY - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 30; // Reduce speed of the laser
self.vx = dx / distance * speed;
self.vy = dy / distance * speed;
// Set initial position
self.x = startX;
self.y = startY;
// Override destroy method to remove from layer tracking
var originalDestroy = self.destroy;
self.destroy = function () {
// Remove from layer tracking before destroying
if (game.layerManager) {
game.layerManager.removeFromTracking(self);
}
// Call the original destroy method
originalDestroy.call(self);
};
self.update = function () {
game.children.forEach(function (child) {
if ((child instanceof Bird1 || child instanceof Bird2) && self.intersects(child)) {
child.destroy();
self.destroy();
}
});
self.x += self.vx;
self.y += self.vy;
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
};
// Set the layer index for laser
game.layerManager.addToLayer(self, LAYERS.LASER);
});
var Light1 = Container.expand(function () {
var self = Container.call(this);
var lightGraphics = self.attachAsset('light1', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1.0
});
self.x = 450;
self.y = 450;
self.update = function () {
self.x += Math.sin(LK.ticks / 90) * 0.1;
};
self.pulse = new Light1Pulse(lightGraphics);
self.pulse.startPulsating();
game.layerManager.addToLayer(self, LAYERS.LIGHT1);
});
var Mirror = Container.expand(function () {
var self = Container.call(this);
var mirrorGraphics = self.attachAsset('mirror1', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(mirrorGraphics);
// Set the layer index for mirror
game.layerManager.addToLayer(self, LAYERS.MIRROR);
// Score display functionality
var scoreText = new Text2('0', {
size: 175,
fill: 0x800080,
font: "Courier New, Courier, monospace",
stroke: 0x00FF00,
strokeThickness: 15,
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreText.y = 260;
scoreText.x = -155;
scoreText.rotation = (-83 + 2) * (Math.PI / 180);
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
return self;
});
var Reticle = Container.expand(function () {
var self = Container.call(this);
var reticleGraphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(reticleGraphics);
// Set the layer index for reticle
game.layerManager.addToLayer(self, LAYERS.RETICLE);
return self;
});
var Reticle1 = Container.expand(function () {
var self = Container.call(this);
var reticle1Graphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(reticle1Graphics);
// Set the layer index for reticle
game.layerManager.addToLayer(self, LAYERS.RETICLE);
});
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
};
// Set the layer index for stack
game.layerManager.addToLayer(self, LAYERS.STACK);
});
var Sun = Container.expand(function () {
var self = Container.call(this);
var sunGraphics = self.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5
});
self.pulse = new SunPulse(sunGraphics);
self.pulse.startPulsating();
// Set the layer index for sun
game.layerManager.addToLayer(self, LAYERS.SUN);
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree1', {
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
};
// Set the layer index for tree
game.layerManager.addToLayer(self, LAYERS.TREE);
});
var Tree2 = Container.expand(function () {
var self = Container.call(this);
var tree2Graphics = self.attachAsset('tree2', {
anchorX: 0.5,
anchorY: 1
});
self.addChild(tree2Graphics);
// Set the layer index for tree2
game.layerManager.addToLayer(self, LAYERS.TREE);
});
var UFO = Container.expand(function (type) {
var self = Container.call(this);
var ufoGraphics = self.attachAsset(type === 'ufo1' ? 'ufo1' : 'ufo2', {
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new UFOMovement(self, ufoGraphics);
// Override destroy method to remove from layer tracking
var originalDestroy = self.destroy;
self.destroy = function () {
// Remove from layer tracking before destroying
if (game.layerManager) {
game.layerManager.removeFromTracking(self);
}
// Call the original destroy method
originalDestroy.call(self);
};
// Set the layer index for ufo
game.layerManager.addToLayer(self, type === 'ufo1' ? LAYERS.UFO1 : LAYERS.UFO2);
});
/****
* Initialize Game
****/
// Initialize clouds array
var game = new LK.Game({
// No title, no description
backgroundColor: 0x87CEEB // Sky blue
});
/****
* Game Code
****/
// Define CLOUD_TYPES array to fix 'CLOUD_TYPES is not defined' error
// CloudMovement class to handle cloud movement and fade effects
var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
this.ufo = ufo;
this.ufoGraphics = ufoGraphics;
this.speed = Math.random() * 2 + 1; // Random speed between 1 and 3
this.direction = Math.random() < 0.5 ? 1 : -1; // Random initial direction
this.update = function () {
this.ufo.x += this.speed * this.direction;
// Check for screen boundaries and reverse direction if needed
if (this.ufo.x > 2048 + this.ufo.width / 2 || this.ufo.x < -this.ufo.width / 2) {
this.direction *= -1;
}
}.bind(this);
};
var CLOUD_TYPES = ['cloud1', 'cloud2'];
var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
this.cloud = cloud;
this.cloudGraphics = cloudGraphics;
this.speed = Math.random() * 0.55 + 0.25;
this.direction = Math.random() < 0.5 ? 1 : -1;
this.update = function () {
this.cloud.x += this.speed * this.direction;
var screenWidth = 2048;
var halfWidth = this.cloud.width / 2;
if (this.cloud.x > screenWidth + halfWidth) {
this.cloud.x = -halfWidth;
} else if (this.cloud.x < -halfWidth) {
this.cloud.x = screenWidth + halfWidth;
}
}.bind(this);
};
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);
}
/****
* Layer Constants
****/
var LAYERS = {
BACKGROUND: 0,
SUN: 1,
LIGHT1: 2,
UFO2: 3,
CLOUD1: 4,
JET1: 5,
CLOUD2: 6,
UFO1: 7,
BIRD1: 8,
GRASS_BACK: 9,
TREE: 10,
STACK: 11,
BIRD2: 12,
MIRROR: 13,
GRASS_FRONT: 14,
CAT: 15,
LASER: 16,
RETICLE: 17
};
/****
* Layer Management System
****/
var LayerManager = /*#__PURE__*/function () {
function LayerManager(gameInstance) {
_classCallCheck(this, LayerManager);
this.game = gameInstance;
this.layerMap = {};
}
return _createClass(LayerManager, [{
key: "setLayerIndex",
value: function setLayerIndex(object, layerId) {
if (!object || !this.game.children.includes(object)) {
return;
}
// Ensure the layer ID is valid and within bounds
layerId = Math.max(0, Math.min(layerId, this.game.children.length));
// Set the child index
if (layerId < this.game.children.length) {
this.game.setChildIndex(object, layerId);
}
// Update the layer map
this.layerMap[object.id] = layerId;
}
}, {
key: "getObjectsInLayer",
value: function getObjectsInLayer(layerId) {
var objects = [];
for (var id in this.layerMap) {
if (this.layerMap[id] === layerId) {
// Find the object in the game's children
for (var i = 0; i < this.game.children.length; i++) {
var child = this.game.children[i];
if (child.id === id) {
objects.push(child);
break;
}
}
}
}
return objects;
}
/**
* Add an object to a specific layer
* @param {Object} object - The game object to add
* @param {Number} layerId - The layer ID
*/
}, {
key: "addToLayer",
value: function addToLayer(object, layerId) {
if (!object || !object.id) {
return;
}
// Add the object if it's not already a child
if (!this.game.children.includes(object)) {
this.game.addChild(object);
}
// Set the child index to match the LAYERS order
this.game.setChildIndex(object, layerId);
// Update the layer map
this.layerMap[object.id] = layerId;
}
/**
* Get the layer of an object
* @param {Object} object - The game object
* @return {Number} The layer ID or -1 if not found
*/
}, {
key: "getObjectLayer",
value: function getObjectLayer(object) {
if (!object || !object.id) {
return -1;
}
return this.layerMap[object.id] !== undefined ? this.layerMap[object.id] : -1;
}
/**
* Remove an object from layer tracking
* @param {Object} object - The game object to remove
*/
}, {
key: "removeFromTracking",
value: function removeFromTracking(object) {
if (!object || !object.id) {
return;
}
delete this.layerMap[object.id];
}
/**
* Bring an object to the front of its layer
* @param {Object} object - The game object
*/
}, {
key: "bringToFrontOfLayer",
value: function bringToFrontOfLayer(object) {
if (!object || !object.id) {
return;
}
var layerId = this.getObjectLayer(object);
if (layerId === -1) {
return;
}
// Find the highest index within this layer
var highestIndex = layerId;
for (var id in this.layerMap) {
if (this.layerMap[id] === layerId) {
// Find the object in the game's children
for (var i = 0; i < this.game.children.length; i++) {
var child = this.game.children[i];
if (child.id === id && i > highestIndex) {
highestIndex = i;
}
}
}
}
// Set the object to the highest index within its layer
this.game.setChildIndex(object, highestIndex);
}
/**
* Send an object to the back of its layer
* @param {Object} object - The game object
*/
}, {
key: "sendToBackOfLayer",
value: function sendToBackOfLayer(object) {
if (!object || !object.id) {
return;
}
var layerId = this.getObjectLayer(object);
if (layerId === -1) {
return;
}
// Find the lowest index within this layer
var lowestIndex = layerId;
for (var id in this.layerMap) {
if (this.layerMap[id] === layerId) {
// Find the object in the game's children
for (var i = 0; i < this.game.children.length; i++) {
var child = this.game.children[i];
if (child.id === id && i < lowestIndex) {
lowestIndex = i;
}
}
}
}
// Set the object to the lowest index within its layer
this.game.setChildIndex(object, lowestIndex);
}
/**
* Helper function to add multiple objects to a layer at once
* @param {Array} objects - Array of game objects
* @param {Number} layerId - The layer ID
*/
}, {
key: "addMultipleToLayer",
value: function addMultipleToLayer(objects, layerId) {
var _this2 = this;
if (!Array.isArray(objects)) {
return;
}
objects.forEach(function (object) {
return _this2.addToLayer(object, layerId);
});
}
}]);
}();
game.layerManager = new LayerManager(game);
// Using UFO sound ID as placeholder
function flipImageVerticallyBasedOnDirection(graphics, lastX, currentX) {
if (graphics) {
if (lastX < currentX && graphics.scaleX < 0) {
graphics.scaleX *= -1; // Flip horizontally to face right
} else if (lastX > currentX && graphics.scaleX > 0) {
graphics.scaleX *= -1; // Flip horizontally to face left
}
}
}
function flipImageBasedOnDirection(graphics, lastX, currentX) {
if (graphics) {
if (lastX < currentX) {
graphics.scaleY = Math.abs(graphics.scaleY); // Face right when moving right by ensuring scaleY is positive
} else if (lastX > currentX) {
graphics.scaleY = -Math.abs(graphics.scaleY); // Face left when moving left by ensuring scaleY is negative
}
}
}
// SunPulse class to handle the pulsating effect for Sun
function AABBIntersect(obj1, obj2) {
if (obj1 && obj2) {
return obj1.x < obj2.x + obj2.width && obj1.x + obj1.width > obj2.x && obj1.y < obj2.y + obj2.height && obj1.y + obj1.height > obj2.y;
}
return false;
}
// Using existing CLOUD_TYPES definition
var SunPulse = function SunPulse(sunGraphics) {
this.sunGraphics = sunGraphics;
this.startPulsating = function () {
function pulsate() {
tween(this.sunGraphics, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function () {
tween(this.sunGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: pulsate.bind(this)
});
}.bind(this)
});
}
pulsate.call(this);
};
};
// Light1Pulse class to handle the pulsating effect for Light1
var Light1Pulse = function Light1Pulse(lightGraphics) {
this.lightGraphics = lightGraphics;
this.startPulsating = function () {
function pulsate() {
tween(this.lightGraphics, {
scaleX: 1.6,
scaleY: 1.6
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function () {
tween(this.lightGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: pulsate.bind(this)
});
}.bind(this)
});
}
pulsate.call(this);
};
};
function startPulsating(target) {
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
function pulsate() {
tween(target, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: pulsate
});
}
});
}
pulsate();
}
// UFOMovement class to handle UFO movement
var UFOSound = function UFOSound() {
this.play = function () {
LK.getSound('ufo1').play();
};
};
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {};
};
// 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
};
};
// Add background to the BACKGROUND layer
var background = new Background();
background.x = 2048 / 2;
background.y = 2732 / 2 - 140;
game.addChild(background);
game.layerManager.addToLayer(background, LAYERS.BACKGROUND);
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
var self = this;
var currentScore = 0;
var highScore = storage.highScore;
self.addScore = function (points) {
if (typeof points !== 'number' || points < 0) {
return currentScore;
}
currentScore += Math.floor(points);
if (currentScore > highScore) {
highScore = currentScore;
storage.highScore = highScore;
}
return currentScore;
};
self.resetScore = function () {
currentScore = 0;
return currentScore;
};
self.getScore = function () {
return currentScore;
};
self.getHighScore = function () {
return highScore;
};
};
var birds = [];
// Add a sun to the game in the top left corner
var sun = new Sun();
sun.x = 480;
sun.y = 680;
game.layerManager.addToLayer(sun, LAYERS.SUN);
var light1 = new Light1();
light1.x = 510;
light1.y = 1500;
game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
light1.visible = true;
// Function to add a UFO to the game
function addUFO() {
var ufo = new UFO('ufo1');
game.addChild(ufo);
ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2;
ufo.y = Math.random() * (2732 / 2 - ufo.height);
ufo.customUpdate = function () {
if (!ufo.soundPlayed && ufo.x > 0 && ufo.x < 2048) {
if (currentAmbientSound) {
currentAmbientSound.stop();
}
LK.getSound('ufo1').play();
ufo.soundPlayed = true;
}
ufo.update();
};
return ufo;
}
// Initialize clouds array
var clouds = [];
// Using existing CLOUD_TYPES definition
function initializeClouds() {
function ensureCloudCount() {
// Remove off-screen clouds
clouds = clouds.filter(function (cloud) {
if (cloud.x < -cloud.width || cloud.x > 2048 + cloud.width) {
cloud.destroy();
return false;
}
return true;
});
// Add new clouds if needed, maintaining 3-5 clouds
while (clouds.length < 5) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * (2732 / 2);
game.addChild(cloud);
game.layerManager.addToLayer(cloud, clouds.length < 3 ? LAYERS.CLOUD1 : LAYERS.CLOUD2);
clouds.push(cloud);
}
}
// Initial cloud setup
ensureCloudCount();
// Check cloud count every second
LK.setInterval(ensureCloudCount, 1000);
}
// Call initializeClouds after game initialization
initializeClouds();
var bird1; // Define bird1 variable in the global scope
var bird; // Define bird variable in the global scope
// Initialize birds and score
var birds = [];
var score = 0;
var scoreDisplay = new Mirror();
scoreDisplay.x = 2048 / 2 + 400;
scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50;
game.addChild(scoreDisplay);
// Initialize ambient sounds timer with 20-30 second intervals
function initializeAmbientSounds() {
function playAmbientSounds() {
if (currentAmbientSound) {
currentAmbientSound.stop();
}
if (Array.isArray(sounds) && sounds.length > 0) {
var soundId = sounds[Math.floor(Math.random() * sounds.length)];
} else {
console.error("Sounds array is not defined or empty.");
return;
}
var sound = LK.getSound(soundId);
sound.play();
currentAmbientSound = sound;
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000);
LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000); // 20-30 seconds
}
playAmbientSounds();
}
// Initialize background music timer with 20-30 second intervals
function initializeBGM() {
function playBGM() {
LK.playMusic('bgm1', {
loop: false,
fade: {
start: 0,
end: VOLUME_BGM1,
duration: 4000
},
onEnd: function onEnd() {
LK.setTimeout(playBGM, Math.random() * 30000 + 20000); // 20-50 seconds
}
});
}
playBGM();
}
// Start the game
initializeBGM();
initializeAmbientSounds();
spawnBird1();
spawnBird2();
// Initialize variables for UFOs and laser
var ufo1, ufo2, laser;
var score = 0;
// Initialize timers for UFOs with 20-30 second respawn
function initializeUFOTimers() {
// UFO1 Timer
// UFO1 Timer
function spawnUFO1() {
if (!game.children.some(function (c) {
return c instanceof UFO && c.type === 'ufo1';
})) {
var ufo1 = new UFO('ufo1');
game.addChild(ufo1);
game.layerManager.addToLayer(ufo1, LAYERS.UFO1);
}
LK.setTimeout(spawnUFO1, Math.random() * 10000 + 20000);
}
// Initialize UFO1 spawn timer immediately
spawnUFO1();
// UFO2 Timer
function spawnUFO2() {
if (!game.children.some(function (c) {
return c instanceof UFO;
})) {
ufo2 = new UFO('ufo2');
game.addChild(ufo2);
ufo2.x = Math.random() < 0.5 ? 2048 + ufo2.width / 2 : -ufo2.width / 2;
ufo2.y = Math.random() * (2732 / 2 - ufo2.height);
}
LK.setTimeout(spawnUFO2, Math.random() * 10000 + 20000);
}
spawnUFO2();
}
initializeUFOTimers();
var originalUpdate = game.update;
game.update = function () {
// Call the original update function first
originalUpdate.call(this);
// Update clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
// 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
}
});
// Ensure correct number of birds with sound effects
var bird1Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).length;
var bird2Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).length;
// Maintain exactly 1 Bird1
if (bird1Count < 1) {
var newBird1 = new Bird('bird1');
newBird1.x = Math.random() * 2048;
newBird1.y = -newBird1.height;
newBird1.speed = Math.random() * 1.6 + 1;
newBird1.lastIntersecting = false;
newBird1.type = 'bird1';
newBird1.color = 0x746130;
game.addChild(newBird1);
game.layerManager.addToLayer(newBird1, LAYERS.BIRD1);
birds.push(newBird1);
LK.getSound('bird1').play();
} else if (bird1Count > 1) {
var extraBird1s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).slice(1);
extraBird1s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Maintain exactly 3 Bird2s
if (bird2Count < 3) {
for (var i = 0; i < 3 - bird2Count; i++) {
var newBird2 = new Bird('bird2');
newBird2.x = Math.random() < 0.5 ? 0 : 2048;
newBird2.y = Math.random() * (2732 / 2);
newBird2.speed = 1 + Math.random() * 0.6;
newBird2.lastIntersecting = false;
newBird2.type = 'bird2';
newBird2.color = 0xFFFFFF;
game.addChild(newBird2);
game.layerManager.addToLayer(newBird2, LAYERS.BIRD2);
birds.push(newBird2);
LK.getSound('bird2').play();
}
} else if (bird2Count > 3) {
var extraBird2s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).slice(3);
extraBird2s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Update UFOs, jets, and check for collisions
game.children.forEach(function (entity) {
if (entity instanceof UFO) {
if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
LK.getSound('ufo1').play();
entity.soundPlayed = true;
}
if (typeof entity.update === 'function') {
entity.update();
}
}
});
// Update each laser and check collisions
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds
birds.forEach(function (bird) {
if (!child.lastIntersecting && AABBIntersect(child, bird)) {
if (bird instanceof Bird && bird.type === 'bird1') {
score += 5;
LK.getSound('dead1').play();
} else if (bird instanceof Bird && bird.type === 'bird2') {
score += 1;
LK.getSound('dead2').play();
}
scoreDisplay.updateScore(score.toString()); // Update the score display
bird.destroy(); // Remove the bird when hit by a laser
birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
child.destroy();
LK.getSound('laser1').play();
}
});
// Check for intersections with UFOs
game.children.forEach(function (entity) {
if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) {
score += 25;
scoreDisplay.updateScore(score.toString());
entity.destroy();
child.destroy();
LK.getSound('dead3').play();
LK.getSound('laser2').play();
}
});
// Update lastIntersecting state
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
}) || game.children.some(function (entity) {
return entity instanceof UFO && child.intersects(entity);
});
}
});
// If there's no UFO, try to spawn one
ufo = addUFO();
};
function spawnBird1() {
if (!birds.some(function (b) {
return b instanceof Bird && b.type === 'bird1';
})) {
var bird1 = new Bird('bird1');
bird1.x = Math.random() * 2048;
bird1.y = -bird1.height;
bird1.speed = Math.random() * 1.6 + 1;
bird1.lastIntersecting = false;
bird1.type = 'bird1';
bird1.color = 0x746130;
game.addChild(bird1);
if (game.children.includes(bird1)) {
game.layerManager.addToLayer(bird1, LAYERS.BIRD1);
birds.push(bird1);
}
}
LK.setTimeout(spawnBird1, Math.random() * 10000 + 20000);
}
function spawnBird2() {
var bird2Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).length;
if (bird2Count < 3) {
var bird = new Bird('bird2');
bird.y = Math.random() * (2732 / 2);
bird.x = Math.random() < 0.5 ? 0 : 2048;
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'bird2';
bird.color = 0xFFFFFF;
game.addChild(bird);
if (game.children.includes(bird)) {
game.layerManager.addToLayer(bird, LAYERS.BIRD2);
birds.push(bird);
}
}
LK.setTimeout(spawnBird2, Math.random() * 10000 + 20000);
}
// Update the main game update function to include bird updates
var originalUpdate = game.update;
game.update = function () {
// Call the original update function first
originalUpdate.call(this);
// 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
}
});
// Ensure correct number of birds
var bird1Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).length;
var bird2Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).length;
// Maintain exactly 1 Bird1
if (bird1Count < 1) {
var newBird1 = new Bird('bird1');
newBird1.x = Math.random() * 2048;
newBird1.y = Math.random() * (2732 / 2);
game.addChild(newBird1);
game.layerManager.addToLayer(newBird1, LAYERS.BIRD1);
birds.push(newBird1);
} else if (bird1Count > 1) {
var extraBird1s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).slice(1);
extraBird1s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Maintain exactly 3 Bird2s
if (bird2Count < 3) {
for (var i = 0; i < 3 - bird2Count; i++) {
var newBird2 = new Bird('bird2');
newBird2.x = Math.random() * 2048;
newBird2.y = Math.random() * (2732 / 2);
game.addChild(newBird2);
game.layerManager.addToLayer(newBird2, LAYERS.BIRD2);
birds.push(newBird2);
}
} else if (bird2Count > 3) {
var extraBird2s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).slice(3);
extraBird2s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Update UFOs, jets, and check for collisions
game.children.forEach(function (entity) {
if (entity instanceof UFO) {
if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
LK.getSound('ufo1').play();
entity.soundPlayed = true;
}
entity.update();
}
});
// Update each laser and check collisions
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds
birds.forEach(function (bird) {
if (!child.lastIntersecting && AABBIntersect(child, bird)) {
if (bird instanceof Bird && bird.type === 'bird1') {
score += 5;
LK.getSound('dead1').play();
} else if (bird instanceof Bird && bird.type === 'bird2') {
score += 1;
LK.getSound('dead2').play();
}
scoreDisplay.updateScore(score.toString()); // Update the score display
bird.destroy(); // Remove the bird when hit by a laser
birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
child.destroy();
LK.getSound('laser1').play();
}
});
// Check for intersections with UFOs
game.children.forEach(function (entity) {
if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) {
score += 25;
scoreDisplay.updateScore(score.toString());
entity.destroy();
child.destroy();
LK.getSound('dead3').play();
LK.getSound('laser2').play();
}
});
// Update lastIntersecting state
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
}) || game.children.some(function (entity) {
return entity instanceof UFO && child.intersects(entity);
});
}
});
};
// 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
// Add tree to the proper layer
if (game.children.includes(tree)) {
game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer
}
var score = 0;
// Add stack1 image to the game
var stack1 = game.addChild(new Stack1());
stack1.x = 1700; // Move 700px to the right
stack1.y = 2250; // Move down by 800px
// Add stack1 to the proper layer
if (game.children.includes(stack1)) {
game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer
}
// 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);
// Add grassBack to the proper layer
if (game.children.includes(grassBack)) {
game.layerManager.addToLayer(grassBack, LAYERS.GRASS_BACK); // Use layer manager to set grass-back layer
}
var grassFront = new GrassFront();
grassFront.x = 1020;
grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
game.addChild(grassFront);
// Add grassFront to the proper layer
if (game.children.includes(grassFront)) {
game.layerManager.addToLayer(grassFront, LAYERS.GRASS_FRONT); // Use layer manager to set grass-front layer
}
var scoreDisplay = new Mirror();
scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px
game.addChild(scoreDisplay);
var mirror = new Mirror();
mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
game.addChild(mirror);
// Add mirror to the proper layer
if (game.children.includes(mirror)) {
game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer
}
// 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
// Add cat to the proper layer
if (game.children.includes(cat)) {
game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer
}
// Play bgm1 once on load and set a timer to replay it every 20-30 seconds
LK.playMusic('bgm1', {
loop: false,
fade: {
start: 0,
end: 0.1,
duration: 4000
},
onEnd: function onEnd() {
LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: false,
fade: {
start: 0,
end: 0.1,
duration: 4000
},
onEnd: onEnd
});
}, Math.random() * 10000 + 20000);
}
});
// 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;
// Sound volumes configuration
// Initialize random timers for each sound to play between 20-30 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
currentAmbientSound.stop();
}
sound.play();
currentAmbientSound = sound;
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000);
ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000);
}, Math.random() * 10000 + 20000);
});
var bird2; // Define bird2 variable in the global scope
// UFOMovement class to handle UFO movement
var UFOSound = function UFOSound() {
this.play = function () {
LK.getSound('ufo1').play();
};
};
// BackgroundMusic class to manage background music
// LaserSound class to manage laser sound effects
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {};
};
// Removed invalid CSS assignment to game.style.css
// 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
};
};
// Add background to the BACKGROUND layer
var background = new Background();
background.x = 2048 / 2;
background.y = 2732 / 2 - 140;
game.layerManager.addToLayer(background, LAYERS.BACKGROUND);
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
var self = this;
var currentScore = 0;
var highScore = storage.highScore || 0;
self.addScore = function (points) {
if (typeof points !== 'number' || points < 0) {
return currentScore;
}
currentScore += Math.floor(points);
if (currentScore > highScore) {
highScore = currentScore;
storage.highScore = highScore;
}
return currentScore;
};
self.resetScore = function () {
currentScore = 0;
return currentScore;
};
self.getScore = function () {
return currentScore;
};
self.getHighScore = function () {
return highScore;
};
};
// Game Over Function
function gameOver() {
// Stop the game ticker
game.ticker.stop();
// Display Game Over message with score
var gameOverText = new Text("Game Over\nScore: " + score, {
fontFamily: 'Arial',
fontSize: 64,
fill: 'white',
align: 'center'
});
gameOverText.anchor.set(0.5);
gameOverText.x = game.screen.width / 2;
gameOverText.y = game.screen.height / 2;
game.stage.addChild(gameOverText);
// Make the game over text interactive (clickable)
gameOverText.interactive = true;
gameOverText.buttonMode = true;
gameOverText.on('pointerdown', restartGame);
console.log("Game Over. Final Score: " + 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.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); // Use layer manager to set reticle layer
}
}
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.layerManager.addToLayer(laser, LAYERS.LASER); // Use layer manager to set laser layer
}
};
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 = new Sun();
sun.x = 480;
sun.y = 680;
game.layerManager.addToLayer(sun, LAYERS.SUN);
var light1 = new Light1();
light1.x = 510;
light1.y = 1500;
game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
light1.visible = true;
// Function to add a UFO to the game
// Using existing CLOUD_TYPES definition
// initializeClouds already called earlier
var bird1; // Define bird1 variable in the global scope
var bird; // Define bird variable in the global scope
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 clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
if (ufo) {
ufo.customUpdate();
// Cache game children to avoid repeated property access
var gameChildren = game.children;
// Update lasers and check collisions
gameChildren.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds and UFO
var hasIntersection = birds.some(function (bird) {
if (!child.lastIntersecting && AABBIntersect(child, bird)) {
score += bird instanceof Bird1 ? 5 : bird instanceof Bird2 ? 1 : 0;
scoreDisplay.updateScore(score);
LK.getSound('dead1').play();
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
child.destroy();
return true;
}
return child.intersects(bird);
});
if (!hasIntersection && ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
score += 25;
scoreDisplay.updateScore(score);
LK.getSound('dead3').play();
child.destroy();
}
child.lastIntersecting = hasIntersection || ufo && child.intersects(ufo);
}
});
// Check for intersections between UFO and birds
var ufoIntersection = birds.some(function (bird) {
if (!ufo.lastIntersecting && ufo.intersects(bird)) {
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
LK.getSound('dead2').play();
return true;
}
return ufo.intersects(bird);
});
ufo.lastIntersecting = ufoIntersection;
// Check if UFO is out of bounds
if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
ufo.destroy();
ufo = null;
ufoTimer = LK.setTimeout(function () {
ufo = addUFO();
}, Math.random() * 20000 + 30000);
}
ufo.lastX = ufo.x;
}
;
// Additional game element updates (cat, grass, etc.)
var originalUpdate = game.update;
game.update = function () {
// Call the original update function first
originalUpdate.call(this);
// 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
}
});
// Ensure correct number of birds
var bird1Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).length;
var bird2Count = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).length;
// Maintain exactly 1 Bird1
if (bird1Count < 1) {
var newBird1 = new Bird('bird1');
newBird1.x = Math.random() * 2048;
newBird1.y = Math.random() * (2732 / 2);
game.addChild(newBird1);
game.layerManager.addToLayer(newBird1, LAYERS.BIRD1);
birds.push(newBird1);
} else if (bird1Count > 1) {
var extraBird1s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird1';
}).slice(1);
extraBird1s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Maintain exactly 3 Bird2s
if (bird2Count < 3) {
for (var i = 0; i < 3 - bird2Count; i++) {
var newBird2 = new Bird('bird2');
newBird2.x = Math.random() * 2048;
newBird2.y = Math.random() * (2732 / 2);
game.addChild(newBird2);
game.layerManager.addToLayer(newBird2, LAYERS.BIRD2);
birds.push(newBird2);
}
} else if (bird2Count > 3) {
var extraBird2s = birds.filter(function (b) {
return b instanceof Bird && b.type === 'bird2';
}).slice(3);
extraBird2s.forEach(function (b) {
b.destroy();
birds.splice(birds.indexOf(b), 1);
});
}
// Update UFOs, jets, and check for collisions
game.children.forEach(function (entity) {
if (entity instanceof UFO) {
if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
LK.getSound('ufo1').play();
entity.soundPlayed = true;
}
if (typeof entity.update === 'function') {
entity.update();
}
}
});
// Update each laser and check collisions
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds
birds.forEach(function (bird) {
if (!child.lastIntersecting && AABBIntersect(child, bird)) {
if (bird instanceof Bird && bird.type === 'bird1') {
score += 5;
LK.getSound('dead1').play();
} else if (bird instanceof Bird && bird.type === 'bird2') {
score += 1;
LK.getSound('dead2').play();
}
scoreDisplay.updateScore(score.toString()); // Update the score display
bird.destroy(); // Remove the bird when hit by a laser
birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
child.destroy();
LK.getSound('laser1').play();
}
});
// Check for intersections with UFOs
game.children.forEach(function (entity) {
if (entity instanceof UFO && !child.lastIntersecting && AABBIntersect(child, entity)) {
score += 25;
scoreDisplay.updateScore(score.toString());
entity.destroy();
child.destroy();
LK.getSound('dead3').play();
LK.getSound('laser2').play();
}
});
// Update lastIntersecting state
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
}) || game.children.some(function (entity) {
return entity instanceof UFO && child.intersects(entity);
});
}
});
// 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
// Add tree to the proper layer
if (game.children.includes(tree)) {
game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer
}
var score = 0;
// Add stack1 image to the game
var stack1 = game.addChild(new Stack1());
stack1.x = 1700; // Move 700px to the right
stack1.y = 2250; // Move down by 800px
// Add stack1 to the proper layer
if (game.children.includes(stack1)) {
game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer
}
// 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);
// Add grassBack to the proper layer
if (game.children.includes(grassBack)) {
game.layerManager.addToLayer(grassBack, LAYERS.GRASS_BACK); // Use layer manager to set grass-back layer
}
var grassFront = new GrassFront();
grassFront.x = 1020;
grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
game.addChild(grassFront);
// Add grassFront to the proper layer
if (game.children.includes(grassFront)) {
game.layerManager.addToLayer(grassFront, LAYERS.GRASS_FRONT); // Use layer manager to set grass-front layer
}
// Add cat and score display to the game, ensuring they are added only once
if (!game.cat) {
game.cat = game.addChild(new Cat());
}
game.cat.x = 230;
game.cat.y = 2732;
scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px
game.addChild(scoreDisplay);
var mirror = new Mirror();
mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
game.addChild(mirror);
mirror.visible = true;
game.layerManager.addToLayer(game.cat, LAYERS.CAT);
// Add mirror to the proper layer using the layer manager
// Add mirror to the proper layer
if (game.children.includes(mirror)) {
game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer
}
// Function to handle bgm1 end event
function onBgm1End() {}
// 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 20-30 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
currentAmbientSound.stop();
}
sound.play();
currentAmbientSound = sound;
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000);
ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000);
}, Math.random() * 10000 + 20000);
});
};
};
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