Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'entityManager is not defined' in or related to this line: 'entityManager.add(bird1);' Line Number: 2521
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1400
User prompt
Please fix the bug: 'EntityManager is not defined' in or related to this line: 'var entityManager = new EntityManager();' Line Number: 1241
User prompt
Please fix the bug: 'entityManager is not defined' in or related to this line: 'entityManager.add(bird1);' Line Number: 2579
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1396
User prompt
Please fix the bug: 'entityManager is not defined' in or related to this line: 'entityManager.add(bird1);' Line Number: 2578
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird2 is not defined' in or related to this line: 'spawnBird2();' Line Number: 1339
User prompt
Please fix the bug: 'Timeout.tick error: spawnBird1 is not defined' in or related to this line: 'spawnBird1();' Line Number: 1319
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)];' Line Number: 115
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: entity.update is not a function' in or related to this line: 'entity.update();' Line Number: 2222
User prompt
Please fix the bug: 'TypeError: entity.update is not a function' in or related to this line: 'entity.update();' Line Number: 2222
User prompt
Please fix the bug: 'TypeError: entity.update is not a function' in or related to this line: 'entity.update();' Line Number: 2222
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * 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 Bird1 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird1', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new Bird1Movement(self, birdGraphics); game.layerManager.addToLayer(self, LAYERS.BIRD1); }); var Bird2 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird2', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new Bird2Movement(self, birdGraphics); game.layerManager.addToLayer(self, LAYERS.BIRD2); }); var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 1 }); self.update = function () {}; game.layerManager.addToLayer(self, LAYERS.CAT); }); 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); 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 Jet1 = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet1', { anchorX: 0.5, anchorY: 0.5, flipX: 1 }); game.layerManager.addToLayer(self, LAYERS.JET1); self.speed = 10; self.direction = Math.random() < 0.5 ? 1 : -1; self.lastX = self.x; self.soundPlayed = false; self.x = Math.random() < 0.5 ? 2048 + self.width / 2 : -self.width / 2; self.update = function () { flipImageVerticallyBasedOnDirection(jetGraphics, self.lastX, self.x); self.x += self.speed * self.direction; if (!self.soundPlayed && self.x > 0 && self.x < 2048) { LK.getSound('jet1').play(); self.soundPlayed = true; } if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) { self.destroy(); game.jet = null; var respawnTime = Math.random() * 10000 + 10000; game.jetSpawnTimer = LK.setTimeout(function () { var jet = new Jet1(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2); game.addChild(jet); game.jet = jet; game.jetSpawnTimer = null; }, respawnTime); } self.lastX = self.x; }; }); var Laser = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var laserGraphics = self.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 // Increase brightness by 200% }); // Play the laser1 sound when the laser is created LK.getSound('laser1').play(); // Calculate direction and speed var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; // Speed of the laser increased by 200% self.vx = dx / distance * speed; self.vy = dy / distance * speed; // Set initial position self.x = startX; self.y = startY; 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.update = function () { if (!self.pulse) { self.pulse = new ReticlePulse(reticleGraphics); self.pulse.startPulsating(); } }; game.layerManager.addToLayer(self, LAYERS.RETICLE); }); 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 () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new UFOMovement(self, ufoGraphics); game.layerManager.addToLayer(self, LAYERS.UFO2); }); var UFO1 = Container.expand(function () { var self = Container.call(this); var ufo1Graphics = self.attachAsset('ufo1', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new UFOMovement(self, ufo1Graphics); // Set the layer index for ufo1 game.layerManager.addToLayer(self, LAYERS.UFO1); }); var UFO2 = Container.expand(function () { var self = Container.call(this); var ufo2Graphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); self.movement = new UFOMovement(self, ufo2Graphics); game.layerManager.addToLayer(self, LAYERS.UFO2); }); /**** * Initialize Game ****/ // Initialize clouds array var game = new LK.Game({ // No title, no description backgroundColor: 0x87CEEB // Sky blue }); /**** * Game Code ****/ // CloudMovement class to handle cloud movement and fade effects 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); } 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); }; /**** * 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; } var CLOUD_TYPES = ['cloud1', 'cloud2']; 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); }; }; var bird2; // Define bird2 variable in the global scope 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 UFOMovement = function UFOMovement(ufo, ufoGraphics) { this.ufo = ufo; this.ufoGraphics = ufoGraphics; this.ufo.speed = 3.2; this.ufo.direction = Math.random() < 0.5 ? 1 : -1; this.ufo.lastX = this.ufo.x; this.ufo.soundPlayed = false; this.ufo.update = function () { var currentX = this.x; var screenWidth = 2048; var halfWidth = this.width / 2; var tickCos = Math.cos(LK.ticks / 60); var tickSin = Math.sin(LK.ticks / 120); this.x += this.speed * tickCos; this.y = 100 + tickSin * 250; if (this.x > 0 && this.x < screenWidth && !this.soundPlayed) { LK.getSound('ufo1').play(); this.soundPlayed = true; } if (this.x < 0 || this.x > screenWidth) { this.soundPlayed = false; } if (currentX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || currentX >= -halfWidth && this.x < -halfWidth) { LK.getSound('ufo1').stop(); this.destroy(); ufo = null; } this.lastX = this.x; }; }; var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; var Bird1Movement = function Bird1Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = storage.bird1_lastY || this.bird.y; this.bird.lastX = storage.bird1_lastX || this.bird.x; this.bird.update = function () { var currentX = this.x; var currentY = this.y; var screenWidth = 2048; var screenHeight = 2732; this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; if (currentY > screenHeight + this.height) { this.y = -this.height; var rand = Math.random(); this.x = rand < 0.33 ? rand * screenWidth : rand < 0.5 ? 0 : screenWidth; } this.rotation = Math.atan2(this.y - currentY, this.x - currentX) * 0.1; var isIntersectingCloud = false; for (var i = 0; i < clouds.length; i++) { if (this.intersects(clouds[i])) { isIntersectingCloud = true; break; } } if (isIntersectingCloud && !this.lastIntersecting) { this.speed *= 0.8; LK.getSound('wings1').play(); } this.lastIntersecting = isIntersectingCloud; if (Math.abs(this.lastX - currentX) > 1 || Math.abs(this.lastY - currentY) > 1) { this.lastX = currentX; this.lastY = currentY; storage.bird1_lastX = currentX; storage.bird1_lastY = currentY; } flipImageVerticallyBasedOnDirection(birdGraphics, currentX, this.x); }; }; var Bird2Movement = function Bird2Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = Math.random() * 2732; // Random initial y position within the screen height this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } this.lastX = this.x; // Track position for next update this.lastY = this.y; // Update lastY after movement storage.bird2_lastX = this.lastX; // Store lastX using storage plugin storage.bird2_lastY = this.lastY; // Store lastY using storage plugin }; }; var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () {}; }; var ReticlePulse = function ReticlePulse(reticleGraphics) { this.reticleGraphics = reticleGraphics; this.startPulsating = function () { function pulsate() { tween(this.reticleGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.easeInOut, onFinish: function () { tween(this.reticleGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; // 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 || 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; }; }; 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 } }; 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 function addUFO() { var ufo = new UFO1(); game.addChild(ufo); game.layerManager.addToLayer(ufo, LAYERS.UFO1); 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) { LK.getSound('ufo1').play(); ufo.soundPlayed = true; } ufo.update(); }; return ufo; } // Initialize clouds array var clouds = []; var CLOUD_TYPES = ['cloud1', 'cloud2']; 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 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; // Initialize ambient sounds timer function initializeAmbientSounds() { function playAmbientSounds() { LK.getSound('songbird1').play(); LK.getSound('cricket1').play(); LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000); } playAmbientSounds(); } // Initialize background music timer function initializeBGM() { function playBGM() { LK.playMusic('bgm1'); LK.setTimeout(playBGM, Math.random() * 10000 + 20000); } playBGM(); } // Start the game spawnBird1(); spawnBird2(); initializeAmbientSounds(); initializeBGM(); // 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 function spawnUFO1() { if (!game.children.some(function (c) { return c instanceof UFO1; })) { ufo1 = addUFO(); } LK.setTimeout(spawnUFO1, Math.random() * 10000 + 20000); } spawnUFO1(); // UFO2 Timer function spawnUFO2() { if (!game.children.some(function (c) { return c instanceof UFO2; })) { ufo2 = new UFO2(); game.addChild(ufo2); game.layerManager.addToLayer(ufo2, LAYERS.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 } }); // Update UFO and check for collisions if (ufo) { ufo.customUpdate(); // Update each laser game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds and UFO birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird1) { score += 5; } else if (bird instanceof Bird2 || bird instanceof Bird3) { score += 1; } scoreDisplay.updateScore(score); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }); }); if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) { score += 25; scoreDisplay.updateScore(score); child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || ufo && child.intersects(ufo); } }); } else { // If there's no UFO, try to spawn one ufo = addUFO(); } }; function spawnBird1() { if (!birds.some(function (b) { return b instanceof Bird1; })) { var bird1 = new 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); game.layerManager.addToLayer(bird1, LAYERS.BIRD1); birds.push(bird1); LK.setTimeout(function () { if (!birds.some(function (b) { return b instanceof Bird1; })) { spawnBird1(); } }, Math.random() * 10000 + 20000); } } function spawnBird2() { if (birds.filter(function (b) { return b instanceof Bird2; }).length < 3) { var bird = new Bird2(); bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'bird2'; // Specific property for Bird2 bird.color = 0xFFFFFF; // Specific color for Bird2 LK.setTimeout(function () { game.addChild(bird); // Ensure bird is added to the game before setting its index if (game.children.includes(bird)) { game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1 } birds.push(bird); }, 2000); } } // 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 } }); // Update UFO and check for collisions if (ufo) { ufo.customUpdate(); // Update each laser game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds and UFO birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird1) { score += 5; } else if (bird instanceof Bird2 || bird instanceof Bird3) { score += 1; } scoreDisplay.updateScore(score); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }); }); if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) { score += 25; scoreDisplay.updateScore(score); child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || ufo && child.intersects(ufo); } }); } }; // Add a tree to the game var tree = game.addChild(new Tree()); tree.x = 2048 / 2 + 600; // Move the tree 500px to the right tree.y = 2500; // Position the tree on the grass // Ensure tree is added to the game before setting its index if (game.children.includes(tree) && game.children.includes(bird1)) { game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1 } var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Ensure stack1 is added to the game before setting its index if (game.children.includes(stack1) && game.children.includes(tree)) { game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree } // Add the grass floor to the game var grassBack = new GrassBack(); grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom game.addChild(grassBack); // Ensure grassBack is added to the game before setting its index if (game.children.includes(grassBack)) { // Make sure we don't set an index that's out of bounds var safeIndex = Math.min(5, game.children.length - 1); game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely } var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px game.addChild(grassFront); // Ensure grassFront is added to the game before setting its index if (game.children.includes(grassFront) && game.children.includes(bird2)) { game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2 } var 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); // Ensure mirror is added to the game before setting its index if (game.children.includes(mirror) && game.children.includes(stack1)) { game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1 } // Ensure laser is added to the game before setting mirror's index if (game.children.includes(laser) && game.children.includes(mirror)) { game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser } // Function to handle bgm1 end event function onBgm1End() { // Set a timer to replay bgm1 after 50-80 seconds var bgmTimer = LK.setTimeout(function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Ensure cat is added to the game before setting its index if (game.children.includes(cat)) { game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value } // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: onEnd // Set the onEnd function to replay bgm1 }); }, Math.random() * 10000 + 20000); // Random time between 20-30 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; // Sound volumes configuration // Initialize random timers for each sound to play between 30-50 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); // Stop the currently playing ambient sound } sound.play(); currentAmbientSound = sound; // Set the current ambient sound // Set a timeout to reset the current ambient sound after it finishes playing LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); // Convert duration from seconds to milliseconds // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000); }, Math.random() * 20000 + 30000); }); // Using UFO sound ID as placeholder var CLOUD_TYPES = ['cloud1', 'cloud2']; 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); }; }; var bird2; // Define bird2 variable in the global scope // UFOMovement class to handle UFO movement var UFOMovement = function UFOMovement(ufo, ufoGraphics) { this.ufo = ufo; this.ufoGraphics = ufoGraphics; this.ufo.speed = 3.2; // Decrease speed by 20% this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left this.ufo.lastX = this.ufo.x; // Track last X position for future checks this.ufo.update = function () { var _this5 = this; // Cache current position and dimensions var currentX = this.x; var screenWidth = 2048; var halfWidth = this.width / 2; // Update position based on pattern this.x += this.speed * Math.cos(LK.ticks / 60); this.y = 100 + Math.sin(LK.ticks / 120) * 250; // Optimize movement pattern var distanceFromCenter = Math.abs(this.x - screenWidth / 2); if (distanceFromCenter > screenWidth / 3) { this.speed *= -0.95; // Smooth direction change } // Cache intersection checks var isIntersectingCloud = clouds.some(function (cloud) { return _this5.intersects(cloud); }); if (isIntersectingCloud && !this.lastIntersecting) { this.speed *= 1.2; LK.getSound('ufo1').play(); } this.lastIntersecting = isIntersectingCloud; // Stop playing ufo1 sound after UFO leaves the screen if (this.lastX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || this.lastX >= -halfWidth && this.x < -halfWidth) { this.destroy(); ufo = null; LK.getSound('ufo1').stop(); } this.lastX = this.x; // Update lastX after movement }; }; var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; var Bird1Movement = function Bird1Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = this.bird.y; this.bird.lastX = this.bird.x; this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; this.lastY = this.y; this.lastX = this.x; }.bind(this.bird); }; var Bird2Movement = function Bird2Movement(bird, birdGraphics) { this.bird = bird; this.birdGraphics = birdGraphics; this.bird.speed = Math.random() * 1.6 + 1; this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X this.bird.update = function () { this.y += this.speed; this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis // Check if the bird has moved off-screen if (this.lastY <= 2732 && this.y > 2732) { this.y = Math.random() * 2732; // Random initial y position within the screen height this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } this.lastX = this.x; // Track position for next update this.lastY = this.y; // Update lastY after movement storage.bird2_lastX = this.lastX; // Store lastX using storage plugin storage.bird2_lastY = this.lastY; // Store lastY using storage plugin }; }; var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () {}; }; var ReticlePulse = function ReticlePulse(reticleGraphics) { this.reticleGraphics = reticleGraphics; this.startPulsating = function () { function pulsate() { tween(this.reticleGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 1000, easing: tween.easeInOut, onFinish: function () { tween(this.reticleGraphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; // 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; }; }; 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 // Initialize clouds array var clouds = []; // Initialize cloud types var CLOUD_TYPES = ['cloud1', 'cloud2']; // Add initial clouds // Call initializeClouds after game initialization initializeClouds(); 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(); } // Add a jet to the game if it doesn't exist and no jet spawn timer is active if (!game.jet && !game.jetSpawnTimer) { var jet = new Jet1(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2); game.addChild(jet); game.jet = jet; game.layerManager.addToLayer(jet, LAYERS.JET1); LK.getSound('jet1').play(); } // Update jet if (game.jet) { game.jet.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); scoreDisplay.updateScore(score); 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; } }; // Function to spawn a third kind of bird // 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 } }); // Update UFO and check for collisions if (ufo) { ufo.customUpdate(); // Update each laser game.children.forEach(function (child) { if (child instanceof Laser) { child.update(); // Check for intersections with birds and UFO birds.forEach(function (bird) { if (!child.lastIntersecting && AABBIntersect(child, bird)) { if (bird instanceof Bird1) { score += 5; } else if (bird instanceof Bird2 || bird instanceof Bird3) { score += 1; } scoreDisplay.updateScore(score); // Update the score display bird.destroy(); // Remove the bird when hit by a laser birds.splice(birds.indexOf(bird), 1); // Remove bird from the array child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }); }); if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) { score += 25; scoreDisplay.updateScore(score); child.destroy(); } child.lastIntersecting = birds.some(function (bird) { return child.intersects(bird); }) || ufo && child.intersects(ufo); } }); } }; // Add a tree to the game var tree = game.addChild(new Tree()); tree.x = 2048 / 2 + 600; // Move the tree 500px to the right tree.y = 2500; // Position the tree on the grass // Ensure tree is added to the game before setting its index if (game.children.includes(tree) && game.children.includes(bird1)) { game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1 } var score = 0; // Add stack1 image to the game var stack1 = game.addChild(new Stack1()); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Ensure stack1 is added to the game before setting its index if (game.children.includes(stack1) && game.children.includes(tree)) { game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree } // Add the grass floor to the game var grassBack = new GrassBack(); grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom game.addChild(grassBack); // Ensure grassBack is added to the game before setting its index if (game.children.includes(grassBack)) { // Make sure we don't set an index that's out of bounds var safeIndex = Math.min(5, game.children.length - 1); game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely } var grassFront = new GrassFront(); grassFront.x = 1020; grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px game.addChild(grassFront); // Ensure grassFront is added to the game before setting its index if (game.children.includes(grassFront) && game.children.includes(bird2)) { game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2 } var 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); // Mirror doesn't need a specific layer as it's positioned using setChildIndex // Ensure mirror is added to the game before setting its index if (game.children.includes(mirror) && game.children.includes(stack1)) { game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1 } // Ensure laser is added to the game before setting mirror's index if (game.children.includes(laser) && game.children.includes(mirror)) { game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser } // Function to handle bgm1 end event ; // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Ensure cat is added to the game before setting its index if (game.children.includes(cat)) { game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value } // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: onEnd // Set the onEnd function to replay bgm1 }); }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Initialize random timers for each sound to play between 30-50 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); // Stop the currently playing ambient sound } sound.play(); currentAmbientSound = sound; // Set the current ambient sound // Set a timeout to reset the current ambient sound after it finishes playing LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); // Convert duration from seconds to milliseconds // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000); }, Math.random() * 20000 + 30000); });
===================================================================
--- original.js
+++ change.js
@@ -22,21 +22,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new Bird1Movement(self, birdGraphics);
- // 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();
- };
game.layerManager.addToLayer(self, LAYERS.BIRD1);
});
var Bird2 = Container.expand(function () {
var self = Container.call(this);
@@ -44,21 +31,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new Bird2Movement(self, birdGraphics);
- // 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();
- };
game.layerManager.addToLayer(self, LAYERS.BIRD2);
});
var Cat = Container.expand(function () {
var self = Container.call(this);
@@ -68,9 +42,8 @@
});
self.update = function () {};
game.layerManager.addToLayer(self, LAYERS.CAT);
});
-// Define cloud types at the beginning
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, {
@@ -80,23 +53,8 @@
});
var layerIndex = cloudType === 'cloud1' ? LAYERS.CLOUD1 : LAYERS.CLOUD2;
game.layerManager.addToLayer(self, layerIndex);
self.movement = new CloudMovement(self, cloudGraphics);
- self.cloudType = cloudType;
- // Override destroy method to remove from layer tracking and update counts
- var originalDestroy = self.destroy;
- self.destroy = function () {
- // Remove from layer tracking before destroying
- if (game.layerManager) {
- game.layerManager.removeFromTracking(self);
- }
- // Update spawn manager counts
- if (spawnManager) {
- spawnManager.objectCounts[self.cloudType === 'cloud1' ? 'cloud1' : 'cloud2']--;
- }
- // Call the original destroy method
- originalDestroy.call(self);
- };
self.update = function () {
self.movement.update();
};
return self;
@@ -141,18 +99,8 @@
self.direction = Math.random() < 0.5 ? 1 : -1;
self.lastX = self.x;
self.soundPlayed = false;
self.x = Math.random() < 0.5 ? 2048 + self.width / 2 : -self.width / 2;
- // 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 () {
flipImageVerticallyBasedOnDirection(jetGraphics, self.lastX, self.x);
self.x += self.speed * self.direction;
if (!self.soundPlayed && self.x > 0 && self.x < 2048) {
@@ -161,15 +109,14 @@
}
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.destroy();
game.jet = null;
- var respawnTime = Math.random() * 10000 + 20000;
+ var respawnTime = Math.random() * 10000 + 10000;
game.jetSpawnTimer = LK.setTimeout(function () {
var jet = new Jet1();
jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
jet.y = Math.random() * (2732 / 2);
game.addChild(jet);
- game.layerManager.addToLayer(jet, LAYERS.JET1);
game.jet = jet;
game.jetSpawnTimer = null;
}, respawnTime);
}
@@ -180,86 +127,36 @@
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
- brightness: 2.0
+ brightness: 2.0 // Increase brightness by 200%
});
+ // Play the laser1 sound when the laser is created
LK.getSound('laser1').play();
+ // Calculate direction and speed
var dx = targetX - startX;
var dy = targetY - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
- var speed = 60;
+ var speed = 60; // Speed of the laser increased by 200%
self.vx = dx / distance * speed;
self.vy = dy / distance * speed;
+ // Set initial position
self.x = startX;
self.y = startY;
- self.lastIntersecting = false;
- var originalDestroy = self.destroy;
- self.destroy = function () {
- if (game.layerManager) {
- game.layerManager.removeFromTracking(self);
- }
- originalDestroy.call(self);
- };
self.update = function () {
game.children.forEach(function (child) {
- if (!self.lastIntersecting && (child instanceof Bird1 || child instanceof Bird2 || child instanceof UFO1 || child instanceof UFO2) && self.intersects(child)) {
- var points = 0;
- var soundEffect = '';
- if (child instanceof Bird1) {
- points = 100;
- soundEffect = 'dead2';
- if (spawnManager) {
- spawnManager.objectCounts.bird1--;
- }
- } else if (child instanceof Bird2) {
- points = 50;
- soundEffect = 'dead2';
- if (spawnManager) {
- spawnManager.objectCounts.bird2--;
- }
- } else if (child instanceof UFO1) {
- points = 250;
- soundEffect = 'dead3';
- if (spawnManager) {
- spawnManager.objectCounts.ufo1--;
- }
- } else if (child instanceof UFO2) {
- points = 250;
- soundEffect = 'dead3';
- if (spawnManager) {
- spawnManager.objectCounts.ufo2--;
- }
- }
- if (points > 0) {
- // Update the global score
- game.score = (game.score || 0) + points;
- // Update score display
- if (scoreDisplay && scoreDisplay.updateScore) {
- scoreDisplay.updateScore(game.score);
- }
- if (mirror && mirror.updateScore) {
- mirror.updateScore(game.score);
- }
- // Play sound effect and destroy objects
- LK.getSound(soundEffect).play();
- child.destroy();
- self.destroy();
- return;
- }
+ if ((child instanceof Bird1 || child instanceof Bird2) && self.intersects(child)) {
+ child.destroy();
+ self.destroy();
}
});
self.x += self.vx;
self.y += self.vy;
- // Update intersection state
- self.lastIntersecting = game.children.some(function (target) {
- return (target instanceof Bird1 || target instanceof Bird2 || target instanceof UFO1 || target instanceof UFO2) && self.intersects(target);
- });
- // Destroy if out of bounds
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);
@@ -298,11 +195,11 @@
dropShadowBlur: 5,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
- scoreText.y = 260 + 50; // Move down 50px
+ scoreText.y = 260;
scoreText.x = -155;
- scoreText.rotation = (-83 - 3) * (Math.PI / 180); // Rotate left by 3 degrees
+ scoreText.rotation = (-83 + 2) * (Math.PI / 180);
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
@@ -361,12 +258,12 @@
var treeGraphics = self.attachAsset('tree1', {
anchorX: 0.5,
anchorY: 1,
antialias: true,
- // Apply antialias effect
+ // Apply antialias effect
stroke: 0x000000,
- // Add a black stroke
- strokeThickness: 15 // Set stroke thickness to 15px
+ // Add a black stroke
+ strokeThickness: 15 // Set stroke thickness to 15px
});
self.update = function () {
// Add any specific update logic for the tree here
};
@@ -398,18 +295,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new UFOMovement(self, ufo1Graphics);
- // 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 ufo1
game.layerManager.addToLayer(self, LAYERS.UFO1);
});
var UFO2 = Container.expand(function () {
@@ -418,18 +305,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new UFOMovement(self, ufo2Graphics);
- // 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);
- };
game.layerManager.addToLayer(self, LAYERS.UFO2);
});
/****
@@ -443,213 +320,25 @@
/****
* Game Code
****/
-// Define cloud types at the beginning
// CloudMovement class to handle cloud movement and fade effects
-var EntityManager = function EntityManager() {
- this.entities = [];
- this.add = function (entity) {
- this.entities.push(entity);
- game.addChild(entity);
- };
- this.remove = function (entity) {
- var index = this.entities.indexOf(entity);
- if (index > -1) {
- this.entities.splice(index, 1);
- entity.destroy();
- }
- };
- this.update = function () {
- this.entities.forEach(function (entity) {
- if (entity.update) {
- entity.update();
- }
- });
- };
- this.getAllOfType = function (type) {
- return this.entities.filter(function (entity) {
- return entity instanceof type;
- });
- };
- this.clear = function () {
- this.entities.forEach(function (entity) {
- entity.destroy();
- });
- this.entities = [];
- };
-};
-var entityManager = new EntityManager();
-function _typeof2(o) {
- "@babel/helpers - typeof";
- return _typeof2 = "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;
- }, _typeof2(o);
-}
-function _createForOfIteratorHelper(r, e) {
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (!t) {
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
- t && (r = t);
- var _n = 0,
- F = function F() {};
- return {
- s: F,
- n: function n() {
- return _n >= r.length ? {
- done: !0
- } : {
- done: !1,
- value: r[_n++]
- };
- },
- e: function e(r) {
- throw r;
- },
- f: F
- };
- }
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
- var o,
- a = !0,
- u = !1;
- return {
- s: function s() {
- t = t.call(r);
- },
- n: function n() {
- var r = t.next();
- return a = r.done, r;
- },
- e: function e(r) {
- u = !0, o = r;
- },
- f: function f() {
- try {
- a || null == t["return"] || t["return"]();
- } finally {
- if (u) {
- throw o;
- }
- }
- }
- };
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
-function _classCallCheck2(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, _toPropertyKey2(o.key), o);
- }
-}
-function _createClass2(e, r, t) {
- return r && __defineProperties(e.prototype, r), t && __defineProperties(e, t), Object.defineProperty(e, "prototype", {
- writable: !1
- }), e;
-}
-function _toPropertyKey2(t) {
- var i = _toPrimitive2(t, "string");
- return "symbol" == _typeof2(i) ? i : i + "";
-}
-function _toPrimitive2(t, r) {
- if ("object" != _typeof2(t) || !t) {
- return t;
- }
- var e = t[Symbol.toPrimitive];
- if (void 0 !== e) {
- var i = e.call(t, r || "default");
- if ("object" != _typeof2(i)) {
- return i;
- }
- throw new TypeError("@@toPrimitive must return a primitive value.");
- }
- return ("string" === r ? String : Number)(t);
-}
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-var GameObjectMovement = function GameObjectMovement(object, graphics, options) {
- this.object = object;
- this.graphics = graphics;
- this.options = Object.assign({
- speed: 1,
- speedRange: 0.6,
- arcAmplitude: 6.5,
- arcFrequency: 100,
- isVertical: false,
- canFlip: true,
- moveSound: null,
- respawnTime: {
- min: 20000,
- max: 30000
- }
- }, options);
- this.speed = this.options.speed + Math.random() * this.options.speedRange;
+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.lastX = this.object.x;
- this.lastY = this.object.y;
- this.soundPlayed = false;
this.update = function () {
- var currentX = this.object.x;
- var currentY = this.object.y;
+ this.cloud.x += this.speed * this.direction;
var screenWidth = 2048;
- var screenHeight = 2732;
- var halfWidth = this.object.width / 2;
- if (this.options.isVertical) {
- this.object.y += this.speed;
- this.object.x += Math.sin(this.object.y / this.options.arcFrequency) * this.options.arcAmplitude;
- if (currentY > screenHeight + this.object.height) {
- this.object.y = -this.object.height;
- this.object.x = Math.random() * screenWidth;
- }
- } else {
- this.object.x += this.speed * this.direction;
- if (this.object.x > screenWidth + halfWidth) {
- this.object.x = -halfWidth;
- } else if (this.object.x < -halfWidth) {
- this.object.x = screenWidth + halfWidth;
- }
+ 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;
}
- if (this.options.canFlip) {
- flipImageVerticallyBasedOnDirection(this.graphics, currentX, this.object.x);
- }
- if (this.options.moveSound && !this.soundPlayed && this.object.x > 0 && this.object.x < screenWidth) {
- LK.getSound(this.options.moveSound).play();
- this.soundPlayed = true;
- }
- this.lastX = this.object.x;
- this.lastY = this.object.y;
}.bind(this);
};
-var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
- return new GameObjectMovement(cloud, cloudGraphics, {
- speed: 0.25,
- speedRange: 0.55,
- isVertical: false,
- canFlip: false
- });
-};
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
@@ -690,9 +379,25 @@
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
-/*****
+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);
+};
+/****
* Layer Constants
****/
var LAYERS = {
BACKGROUND: 0,
@@ -713,18 +418,16 @@
CAT: 15,
LASER: 16,
RETICLE: 17
};
-/*****
+/****
* Layer Management System
****/
var LayerManager = /*#__PURE__*/function () {
function LayerManager(gameInstance) {
_classCallCheck(this, LayerManager);
this.game = gameInstance;
this.layerMap = {};
- // Layer order mapping to ensure correct rendering order
- this.layerOrder = [LAYERS.BACKGROUND, LAYERS.SUN, LAYERS.LIGHT1, LAYERS.UFO2, LAYERS.CLOUD1, LAYERS.JET1, LAYERS.CLOUD2, LAYERS.UFO1, LAYERS.BIRD1, LAYERS.GRASS_BACK, LAYERS.TREE, LAYERS.STACK, LAYERS.BIRD2, LAYERS.MIRROR, LAYERS.GRASS_FRONT, LAYERS.CAT, LAYERS.LASER, LAYERS.RETICLE];
}
return _createClass(LayerManager, [{
key: "setLayerIndex",
value: function setLayerIndex(object, layerId) {
@@ -758,12 +461,12 @@
}
return objects;
}
/**
- * Add an object to a specific layer
- * @param {Object} object - The game object to add
- * @param {Number} layerId - The layer ID
- */
+ * 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) {
@@ -778,12 +481,12 @@
// 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
- */
+ * 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) {
@@ -791,11 +494,11 @@
}
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
- */
+ * Remove an object from layer tracking
+ * @param {Object} object - The game object to remove
+ */
}, {
key: "removeFromTracking",
value: function removeFromTracking(object) {
if (!object || !object.id) {
@@ -803,11 +506,11 @@
}
delete this.layerMap[object.id];
}
/**
- * Bring an object to the front of its layer
- * @param {Object} object - The game object
- */
+ * 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) {
@@ -833,11 +536,11 @@
// 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
- */
+ * 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) {
@@ -863,12 +566,12 @@
// 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
- */
+ * 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;
@@ -907,58 +610,83 @@
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 Pulse = function Pulse(graphics, options) {
- this.graphics = graphics;
- this.options = Object.assign({
- minScale: 1.0,
- maxScale: 1.2,
- expandDuration: 1000,
- contractDuration: 1000,
- easing: tween.easeInOut
- }, options);
+var CLOUD_TYPES = ['cloud1', 'cloud2'];
+var SunPulse = function SunPulse(sunGraphics) {
+ this.sunGraphics = sunGraphics;
this.startPulsating = function () {
function pulsate() {
- tween(this.graphics, {
- scaleX: this.options.maxScale,
- scaleY: this.options.maxScale
+ tween(this.sunGraphics, {
+ scaleX: 1.1,
+ scaleY: 1.1
}, {
- duration: this.options.expandDuration,
- easing: this.options.easing,
+ duration: 1000,
+ easing: tween.easeInOut,
onFinish: function () {
- tween(this.graphics, {
- scaleX: this.options.minScale,
- scaleY: this.options.minScale
+ tween(this.sunGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
}, {
- duration: this.options.contractDuration,
- easing: this.options.easing,
+ duration: 1000,
+ easing: tween.easeInOut,
onFinish: pulsate.bind(this)
});
}.bind(this)
});
}
pulsate.call(this);
};
};
-var SunPulse = function SunPulse(sunGraphics) {
- return new Pulse(sunGraphics, {
- maxScale: 1.1
- });
-};
// Light1Pulse class to handle the pulsating effect for Light1
var Light1Pulse = function Light1Pulse(lightGraphics) {
- return new Pulse(lightGraphics, {
- maxScale: 1.6,
- contractDuration: 1500
- });
+ 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);
+ };
};
var bird2; // Define bird2 variable in the global scope
-function startPulsating(target, options) {
- var pulse = new Pulse(target, options);
- pulse.startPulsating();
- return pulse;
+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 UFOMovement = function UFOMovement(ufo, ufoGraphics) {
this.ufo = ufo;
@@ -1015,46 +743,96 @@
LK.getSound('laser1').play();
};
};
var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- return new GameObjectMovement(bird, birdGraphics, {
- speed: 1,
- speedRange: 1.6,
- arcAmplitude: 6.5,
- arcFrequency: 100,
- isVertical: true,
- canFlip: true,
- moveSound: 'wings1'
- });
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = storage.bird1_lastY || this.bird.y;
+ this.bird.lastX = storage.bird1_lastX || this.bird.x;
+ this.bird.update = function () {
+ var currentX = this.x;
+ var currentY = this.y;
+ var screenWidth = 2048;
+ var screenHeight = 2732;
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5;
+ if (currentY > screenHeight + this.height) {
+ this.y = -this.height;
+ var rand = Math.random();
+ this.x = rand < 0.33 ? rand * screenWidth : rand < 0.5 ? 0 : screenWidth;
+ }
+ this.rotation = Math.atan2(this.y - currentY, this.x - currentX) * 0.1;
+ var isIntersectingCloud = false;
+ for (var i = 0; i < clouds.length; i++) {
+ if (this.intersects(clouds[i])) {
+ isIntersectingCloud = true;
+ break;
+ }
+ }
+ if (isIntersectingCloud && !this.lastIntersecting) {
+ this.speed *= 0.8;
+ LK.getSound('wings1').play();
+ }
+ this.lastIntersecting = isIntersectingCloud;
+ if (Math.abs(this.lastX - currentX) > 1 || Math.abs(this.lastY - currentY) > 1) {
+ this.lastX = currentX;
+ this.lastY = currentY;
+ storage.bird1_lastX = currentX;
+ storage.bird1_lastY = currentY;
+ }
+ flipImageVerticallyBasedOnDirection(birdGraphics, currentX, this.x);
+ };
};
var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
- return new GameObjectMovement(bird, birdGraphics, {
- speed: 1,
- speedRange: 1.6,
- arcAmplitude: 6.5,
- arcFrequency: 100,
- isVertical: true,
- canFlip: true,
- moveSound: 'wings1'
- });
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
+ this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
+ this.bird.update = function () {
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
+ // Check if the bird has moved off-screen
+ if (this.lastY <= 2732 && this.y > 2732) {
+ this.y = Math.random() * 2732; // Random initial y position within the screen height
+ this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ }
+ this.lastX = this.x; // Track position for next update
+ this.lastY = this.y; // Update lastY after movement
+ storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
+ storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
+ };
};
-var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- return new GameObjectMovement(ufo, ufoGraphics, {
- speed: 3.2,
- speedRange: 0.8,
- isVertical: false,
- canFlip: true,
- moveSound: 'ufo1'
- });
-};
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {};
};
var ReticlePulse = function ReticlePulse(reticleGraphics) {
- return new Pulse(reticleGraphics, {
- maxScale: 1.2
- });
+ this.reticleGraphics = reticleGraphics;
+ this.startPulsating = function () {
+ function pulsate() {
+ tween(this.reticleGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function () {
+ tween(this.reticleGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: pulsate.bind(this)
+ });
+ }.bind(this)
+ });
+ }
+ pulsate.call(this);
+ };
};
// Bird1Effects class to handle effects and animations for Bird1
var Bird1Effects = function Bird1Effects(bird) {
this.bird = bird;
@@ -1096,28 +874,20 @@
};
};
var birds = [];
game.down = function (x, y, obj) {
- if (obj && obj.event) {
- x = obj.event.x;
- y = obj.event.y;
- }
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
if (game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE);
+ game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); // Use layer manager to set reticle layer
}
}
game.reticle.x = x;
game.reticle.y = y;
- if (typeof x === 'undefined' || typeof y === 'undefined') {
- console.error('Invalid coordinates for laser');
- return;
- }
- var laser = new Laser(cat.x - 140, cat.y - 440, x, 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);
+ game.layerManager.addToLayer(laser, LAYERS.LASER); // Use layer manager to set laser layer
}
};
game.move = function (x, y, obj) {
if (!game.reticle) {
@@ -1157,8 +927,9 @@
return ufo;
}
// Initialize clouds array
var clouds = [];
+var CLOUD_TYPES = ['cloud1', 'cloud2'];
function initializeClouds() {
function ensureCloudCount() {
// Remove off-screen clouds
clouds = clouds.filter(function (cloud) {
@@ -1167,9 +938,9 @@
return false;
}
return true;
});
- // Add new clouds if needed, maintaining 3-5 clouds
+ // Add new clouds if needed
while (clouds.length < 5) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * (2732 / 2);
@@ -1189,86 +960,117 @@
var bird; // Define bird variable in the global scope
// Initialize birds and score
var birds = [];
var score = 0;
-var mirror = new Mirror();
-mirror.x = 2048 / 2 + 400;
-mirror.y = 2732 - 185 - 80 - 390 + 30 + 50;
-game.addChild(mirror);
-game.mirror = mirror;
-var scoreDisplay = mirror;
-scoreDisplay.x = 2048 / 2 + 400;
-scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50;
-var SoundManager = function SoundManager() {
- this.soundTimers = {};
- this.soundIntervals = {
- ambient: {
- min: 20000,
- max: 30000
- },
- background: {
- min: 20000,
- max: 30000
+// Initialize ambient sounds timer
+function initializeAmbientSounds() {
+ function playAmbientSounds() {
+ LK.getSound('songbird1').play();
+ LK.getSound('cricket1').play();
+ LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000);
+ }
+ playAmbientSounds();
+}
+// Initialize background music timer
+function initializeBGM() {
+ function playBGM() {
+ LK.playMusic('bgm1');
+ LK.setTimeout(playBGM, Math.random() * 10000 + 20000);
+ }
+ playBGM();
+}
+// Start the game
+spawnBird1();
+spawnBird2();
+initializeAmbientSounds();
+initializeBGM();
+// 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
+ function spawnUFO1() {
+ if (!game.children.some(function (c) {
+ return c instanceof UFO1;
+ })) {
+ ufo1 = addUFO();
}
- };
- this.playSound = function (soundId, options) {
- options = Object.assign({
- interval: this.soundIntervals.ambient,
- isMusic: false,
- volume: 0.1
- }, options);
- var playFunction = function () {
- if (options.isMusic) {
- LK.playMusic(soundId, {
- volume: options.volume
+ LK.setTimeout(spawnUFO1, Math.random() * 10000 + 20000);
+ }
+ spawnUFO1();
+ // UFO2 Timer
+ function spawnUFO2() {
+ if (!game.children.some(function (c) {
+ return c instanceof UFO2;
+ })) {
+ ufo2 = new UFO2();
+ game.addChild(ufo2);
+ game.layerManager.addToLayer(ufo2, LAYERS.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
+ }
+ });
+ // Update UFO and check for collisions
+ if (ufo) {
+ ufo.customUpdate();
+ // Update each laser
+ game.children.forEach(function (child) {
+ if (child instanceof Laser) {
+ child.update();
+ // Check for intersections with birds and UFO
+ birds.forEach(function (bird) {
+ if (!child.lastIntersecting && AABBIntersect(child, bird)) {
+ if (bird instanceof Bird1) {
+ score += 5;
+ } else if (bird instanceof Bird2 || bird instanceof Bird3) {
+ score += 1;
+ }
+ scoreDisplay.updateScore(score); // Update the score display
+ bird.destroy(); // Remove the bird when hit by a laser
+ birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
+ child.destroy();
+ }
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ });
});
- } else {
- var sound = LK.getSound(soundId);
- sound.volume = options.volume;
- sound.play();
+ if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
+ score += 25;
+ scoreDisplay.updateScore(score);
+ child.destroy();
+ }
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ }) || ufo && child.intersects(ufo);
}
- var nextInterval = Math.random() * (options.interval.max - options.interval.min) + options.interval.min;
- this.soundTimers[soundId] = LK.setTimeout(playFunction.bind(this), nextInterval);
- }.bind(this);
- playFunction();
- return this.soundTimers[soundId];
- };
- this.initialize = function () {
- // Initialize ambient sounds with 20-30 second intervals
- this.playSound('songbird1', {
- volume: 0.1
});
- this.playSound('cricket1', {
- volume: 0.1
- });
- this.playSound('breeze1', {
- volume: 0.1
- });
- this.playSound('frog1', {
- volume: 0.1
- });
- this.playSound('chitter', {
- volume: 0.1
- });
- // Initialize background music with 20-30 second intervals
- this.playSound('bgm1', {
- isMusic: true,
- volume: 0.1,
- interval: this.soundIntervals.background
- });
- };
- this.stopSound = function (soundId) {
- if (this.soundTimers[soundId]) {
- LK.clearTimeout(this.soundTimers[soundId]);
- delete this.soundTimers[soundId];
- }
- LK.getSound(soundId).stop();
- };
- this.stopAllSounds = function () {
- for (var soundId in this.soundTimers) {
- this.stopSound(soundId);
- }
- };
+ } else {
+ // If there's no UFO, try to spawn one
+ ufo = addUFO();
+ }
};
function spawnBird1() {
if (!birds.some(function (b) {
return b instanceof Bird1;
@@ -1280,1353 +1082,735 @@
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);
-}
-var soundManager = new SoundManager();
-soundManager.initialize();
-// Start the game
-initializeBGM();
-initializeAmbientSounds();
-// Ensure game objects are initialized before spawning birds
-LK.setTimeout(function () {
- spawnBird1();
- spawnBird2();
-});
-var _SpawnManager = function SpawnManager() {
- this.spawnTimers = {};
- this.objectCounts = {
- bird1: 0,
- bird2: 0,
- cloud1: 0,
- cloud2: 0,
- ufo1: 0,
- ufo2: 0,
- jet1: 0
- };
- this.spawnRules = {
- bird1: {
- max: 1,
- layer: LAYERS.BIRD1
- },
- bird2: {
- min: 3,
- max: 3,
- layer: LAYERS.BIRD2
- },
- cloud1: {
- min: 2,
- max: 3,
- layer: LAYERS.CLOUD1
- },
- cloud2: {
- min: 1,
- max: 2,
- layer: LAYERS.CLOUD2
- },
- ufo1: {
- max: 1,
- respawnTime: {
- min: 20000,
- max: 30000
- },
- layer: LAYERS.UFO1
- },
- ufo2: {
- max: 1,
- respawnTime: {
- min: 20000,
- max: 30000
- },
- layer: LAYERS.UFO2
- },
- jet1: {
- max: 1,
- respawnTime: {
- min: 20000,
- max: 30000
- },
- layer: LAYERS.JET1
- }
- };
- this.exclusiveGroups = [['ufo1', 'ufo2']];
- this.spawnObject = function (type, Constructor, options) {
- var rule = this.spawnRules[type];
- var count = this.objectCounts[type];
- if (count >= (rule.max || 1)) {
- return;
- }
- for (var i = 0; i < this.exclusiveGroups.length; i++) {
- var group = this.exclusiveGroups[i];
- if (group.includes(type)) {
- var groupTotal = 0;
- for (var j = 0; j < group.length; j++) {
- groupTotal += this.objectCounts[group[j]];
- }
- if (groupTotal > 0) {
- return;
- }
- }
- }
- var obj = new Constructor();
- if (type === 'bird1' || type === 'bird2') {
- obj.x = Math.random() * 2048;
- obj.y = -obj.height;
- } else {
- obj.x = Math.random() < 0.5 ? 2048 + obj.width / 2 : -obj.width / 2;
- obj.y = Math.random() * (2732 / 2);
- }
- game.addChild(obj);
- game.layerManager.addToLayer(obj, rule.layer);
- this.objectCounts[type]++;
- if (type === 'ufo1' || type === 'ufo2') {
- LK.getSound('ufo1').play();
- obj.soundPlayed = true;
- } else if (type === 'jet1') {
- LK.getSound('jet1').play();
- obj.soundPlayed = true;
- }
- if (rule.respawnTime) {
- this.scheduleRespawn(type, Constructor);
- }
- return obj;
- };
- this.scheduleRespawn = function (type, Constructor) {
- var rule = this.spawnRules[type];
- var respawnTime = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min;
- if (this.spawnTimers[type]) {
- LK.clearTimeout(this.spawnTimers[type]);
- }
- this.spawnTimers[type] = LK.setTimeout(function () {
- if (this.objectCounts[type] > 0) {
- this.objectCounts[type]--;
- }
- var shouldSpawn = true;
- for (var i = 0; i < this.exclusiveGroups.length; i++) {
- var group = this.exclusiveGroups[i];
- if (group.includes(type)) {
- var groupTotal = 0;
- for (var j = 0; j < group.length; j++) {
- groupTotal += this.objectCounts[group[j]];
- }
- }
- }
- if (shouldSpawn) {
- this.spawnObject(type, Constructor);
- }
- }.bind(this), respawnTime);
- };
- this.initialize = function () {
- // Initialize birds - exactly 1 Bird1 and 3 Bird2s
- this.spawnObject('bird1', Bird1);
- for (var i = 0; i < this.spawnRules.bird2.min; i++) {
- this.spawnObject('bird2', Bird2);
- }
- // Initialize clouds - ensure 3-5 total clouds
- var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3; // Random between 3-5
- var cloud1ToSpawn = Math.min(totalCloudsToSpawn, this.spawnRules.cloud1.max);
- var cloud2ToSpawn = totalCloudsToSpawn - cloud1ToSpawn;
- for (var i = 0; i < cloud1ToSpawn; i++) {
- this.spawnObject('cloud1', Cloud);
- }
- for (var i = 0; i < cloud2ToSpawn; i++) {
- this.spawnObject('cloud2', Cloud);
- }
- // Initialize UFOs and Jet with respawn timers
- // Randomly choose between UFO1 and UFO2
- if (Math.random() < 0.5) {
- this.spawnObject('ufo1', UFO1);
- } else {
- this.spawnObject('ufo2', UFO2);
- }
- this.spawnObject('jet1', Jet1);
- // Set up periodic check for object counts
- LK.setInterval(function () {
- // Maintain bird counts - exactly 1 Bird1
- if (this.objectCounts.bird1 < 1) {
- this.spawnObject('bird1', Bird1);
- }
- // Maintain bird counts - exactly 3 Bird2s
- while (this.objectCounts.bird2 < 3) {
- this.spawnObject('bird2', Bird2);
- }
- // Maintain cloud counts - ensure 3-5 total clouds
- var totalClouds = this.objectCounts.cloud1 + this.objectCounts.cloud2;
- if (totalClouds < 3) {
- var cloudsNeeded = 3 - totalClouds;
- for (var i = 0; i < cloudsNeeded; i++) {
- if (Math.random() < 0.5 && this.objectCounts.cloud1 < this.spawnRules.cloud1.max) {
- this.spawnObject('cloud1', Cloud);
- } else {
- this.spawnObject('cloud2', Cloud);
- }
- }
- } else if (totalClouds > 5) {
- // If there are more than 5 clouds, don't spawn any more until some are removed
- // This is handled automatically when clouds move off-screen
- }
- // Ensure one UFO (either UFO1 or UFO2) is on screen
- if (this.objectCounts.ufo1 + this.objectCounts.ufo2 < 1 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) {
- if (Math.random() < 0.5) {
- this.spawnObject('ufo1', UFO1);
- } else {
- this.spawnObject('ufo2', UFO2);
- }
- }
- // Ensure one Jet1 is on screen
- if (this.objectCounts.jet1 < 1 && !this.spawnTimers.jet1) {
- this.spawnObject('jet1', Jet1);
- }
- }.bind(this), 1000);
- };
- var spawnManager = new _SpawnManager();
- // Initialize the spawn manager
- _SpawnManager.prototype.initialize = function () {
- // Set up initial spawns
- this.spawnObject('bird1', Bird1);
- for (var i = 0; i < 3; i++) {
- this.spawnObject('bird2', Bird2);
- }
- // Set up cloud spawning
- for (var i = 0; i < 3; i++) {
- this.spawnObject('cloud1', Cloud);
- }
- for (var i = 0; i < 2; i++) {
- this.spawnObject('cloud2', Cloud);
- }
- // Schedule UFO and jet spawns
- this.scheduleRespawn('ufo1', UFO1);
- this.scheduleRespawn('jet1', Jet1);
- };
- spawnManager.initialize();
- // Main game update function
- game.update = function () {
- // Update all game objects
- game.children.forEach(function (entity) {
- if (entity.update) {
- entity.update();
- }
- // Handle off-screen objects
- if (entity instanceof Bird1 || entity instanceof Bird2) {
- if (entity.y > 2732) {
- entity.y = -entity.height;
- entity.x = Math.random() * 2048;
- }
- }
- });
- // Update score display
- if (game.mirror && game.mirror.updateScore) {
- game.mirror.updateScore(game.score || 0);
- }
- // Ensure correct number of birds with sound effects
- var bird1Count = birds.filter(function (b) {
- return b instanceof Bird1;
- }).length;
- var bird2Count = birds.filter(function (b) {
- return b instanceof Bird2;
- }).length;
- // Maintain exactly 1 Bird1
- if (bird1Count < 1) {
- var newBird1 = new 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) {
+ game.layerManager.addToLayer(bird1, LAYERS.BIRD1);
+ birds.push(bird1);
+ LK.setTimeout(function () {
+ if (!birds.some(function (b) {
return b instanceof 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 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();
+ })) {
+ spawnBird1();
}
- } else if (bird2Count > 3) {
- var extraBird2s = birds.filter(function (b) {
- return b instanceof 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 UFO1 || entity instanceof UFO2) {
- 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
- game.children.forEach(function (target) {
- if (!child.lastIntersecting && AABBIntersect(child, target)) {
- var points = 0;
- var soundEffect = '';
- if (target instanceof Bird1) {
- points = 100;
- soundEffect = 'dead1';
- spawnManager.objectCounts.bird1--;
- } else if (target instanceof Bird2) {
- points = 50;
- soundEffect = 'dead2';
- spawnManager.objectCounts.bird2--;
- } else if (target instanceof UFO1 || target instanceof UFO2) {
- points = 250;
- soundEffect = 'dead3';
- spawnManager.objectCounts.ufo--;
- }
- if (points > 0) {
- game.score = (game.score || 0) + points;
- if (game.mirror && game.mirror.updateScore) {
- game.mirror.updateScore(game.score);
- }
- LK.getSound(soundEffect).play();
- target.destroy();
- child.destroy();
- }
- }
- });
- // Update lastIntersecting state
- child.lastIntersecting = game.children.some(function (target) {
- return (target instanceof Bird1 || target instanceof Bird2 || target instanceof UFO1 || target instanceof UFO2) && child.intersects(target);
- });
- }
- });
- };
- function spawnBird1() {
- if (!birds.some(function (b) {
- return b instanceof Bird1;
- })) {
- var bird1 = new 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);
+ }, Math.random() * 10000 + 20000);
}
- function spawnBird2() {
- var bird2Count = entityManager.getAllOfType(Bird2).length;
- if (bird2Count < 3) {
- var bird = new 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;
- entityManager.add(bird);
+}
+function spawnBird2() {
+ if (birds.filter(function (b) {
+ return b instanceof Bird2;
+ }).length < 3) {
+ var bird = new Bird2();
+ bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half
+ bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ bird.speed = 1 + Math.random() * 0.6;
+ bird.lastIntersecting = false;
+ bird.type = 'bird2'; // Specific property for Bird2
+ bird.color = 0xFFFFFF; // Specific color for Bird2
+ LK.setTimeout(function () {
+ game.addChild(bird);
+ // Ensure bird is added to the game before setting its index
+ if (game.children.includes(bird)) {
+ game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1
+ }
birds.push(bird);
- }
- LK.setTimeout(spawnBird2, Math.random() * 10000 + 20000);
+ }, 2000);
}
- // Update bird positions and states
- function updateBirds() {
- // 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 Bird1;
- }).length;
- var bird2Count = birds.filter(function (b) {
- return b instanceof Bird2;
- }).length;
- // Maintain exactly 1 Bird1
- if (bird1Count < 1) {
- var newBird1 = new 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 Bird1;
- }).slice(1);
- extraBird1s.forEach(function (b) {
- b.destroy();
- birds.splice(birds.indexOf(b), 1);
- });
+}
+// 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
}
- // Maintain exactly 3 Bird2s
- if (bird2Count < 3) {
- for (var i = 0; i < 3 - bird2Count; i++) {
- var newBird2 = new 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 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 UFO1 || entity instanceof UFO2) {
- if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
- LK.getSound('ufo1').play();
- entity.soundPlayed = true;
- }
- entity.update();
- }
- });
- // Update each laser and check collisions
+ });
+ // Update UFO and check for collisions
+ if (ufo) {
+ ufo.customUpdate();
+ // Update each laser
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
- // Check for intersections with birds
- game.children.forEach(function (target) {
- if (!child.lastIntersecting && AABBIntersect(child, target)) {
- var points = 0;
- var soundEffect = '';
- if (target instanceof Bird1) {
- points = 100;
- soundEffect = 'dead1';
- spawnManager.objectCounts.bird1--;
- } else if (target instanceof Bird2) {
- points = 50;
- soundEffect = 'dead2';
- spawnManager.objectCounts.bird2--;
- } else if (target instanceof UFO1 || target instanceof UFO2) {
- points = 250;
- soundEffect = 'dead3';
- spawnManager.objectCounts.ufo--;
+ // Check for intersections with birds and UFO
+ birds.forEach(function (bird) {
+ if (!child.lastIntersecting && AABBIntersect(child, bird)) {
+ if (bird instanceof Bird1) {
+ score += 5;
+ } else if (bird instanceof Bird2 || bird instanceof Bird3) {
+ score += 1;
}
- if (points > 0) {
- game.score = (game.score || 0) + points;
- if (game.mirror && game.mirror.updateScore) {
- game.mirror.updateScore(game.score);
- }
- LK.getSound(soundEffect).play();
- target.destroy();
- child.destroy();
- }
+ scoreDisplay.updateScore(score); // Update the score display
+ bird.destroy(); // Remove the bird when hit by a laser
+ birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
+ child.destroy();
}
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ });
});
- // Update lastIntersecting state
- child.lastIntersecting = game.children.some(function (target) {
- return (target instanceof Bird1 || target instanceof Bird2 || target instanceof UFO1 || target instanceof UFO2) && child.intersects(target);
- });
+ if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
+ score += 25;
+ scoreDisplay.updateScore(score);
+ child.destroy();
+ }
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ }) || ufo && child.intersects(ufo);
}
});
}
- ;
- // 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 () {
+};
+// Add a tree to the game
+var tree = game.addChild(new Tree());
+tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
+tree.y = 2500; // Position the tree on the grass
+// Ensure tree is added to the game before setting its index
+if (game.children.includes(tree) && game.children.includes(bird1)) {
+ game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
+}
+var score = 0;
+// Add stack1 image to the game
+var stack1 = game.addChild(new Stack1());
+stack1.x = 1700; // Move 700px to the right
+stack1.y = 2250; // Move down by 800px
+// Ensure stack1 is added to the game before setting its index
+if (game.children.includes(stack1) && game.children.includes(tree)) {
+ game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
+}
+// Add the grass floor to the game
+var grassBack = new GrassBack();
+grassBack.x = 1020;
+grassBack.y = 2735; // Position grassBack at the bottom
+game.addChild(grassBack);
+// Ensure grassBack is added to the game before setting its index
+if (game.children.includes(grassBack)) {
+ // Make sure we don't set an index that's out of bounds
+ var safeIndex = Math.min(5, game.children.length - 1);
+ game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely
+}
+var grassFront = new GrassFront();
+grassFront.x = 1020;
+grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
+game.addChild(grassFront);
+// Ensure grassFront is added to the game before setting its index
+if (game.children.includes(grassFront) && game.children.includes(bird2)) {
+ game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
+}
+var 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);
+// Ensure mirror is added to the game before setting its index
+if (game.children.includes(mirror) && game.children.includes(stack1)) {
+ game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
+}
+// Ensure laser is added to the game before setting mirror's index
+if (game.children.includes(laser) && game.children.includes(mirror)) {
+ game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
+}
+// Function to handle bgm1 end event
+function onBgm1End() {
+ // Set a timer to replay bgm1 after 50-80 seconds
+ var bgmTimer = LK.setTimeout(function () {
+ LK.playMusic('bgm1', {
+ loop: true,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: onBgm1End
+ });
+ }, Math.random() * 30000 + 50000);
+}
+;
+// Add the cat to the game
+var cat = game.addChild(new Cat());
+cat.x = 230; // Move the cat 20px to the left
+cat.y = 2732; // Position the cat at the bottom of the screen
+// Ensure cat is added to the game before setting its index
+if (game.children.includes(cat)) {
+ game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+}
+// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
+LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.02,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ // Set a timer to replay bgm1 every 20-50 seconds
+ LK.setTimeout(function () {
LK.playMusic('bgm1', {
- loop: true,
+ loop: false,
+ // Play once
fade: {
start: 0,
- end: 1,
+ end: 0.5,
+ // Set to the lowest volume
duration: 4000
},
- onEnd: onBgm1End
+ onEnd: onEnd // Set the onEnd function to replay bgm1
});
- }, Math.random() * 30000 + 50000);
+ }, Math.random() * 10000 + 20000); // Random time between 20-30 seconds
}
- ;
- // 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 30-50 seconds
+sounds.forEach(function (soundId) {
+ var sound = LK.getSound(soundId);
+ var ambientSoundTimer = LK.setTimeout(function () {
+ if (currentAmbientSound) {
+ currentAmbientSound.stop(); // Stop the currently playing ambient sound
}
- });
- // 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);
- });
- // Using UFO sound ID as placeholder
- // Using existing CLOUD_TYPES definition
- var Pulse = function Pulse(graphics, options) {
- this.graphics = graphics;
- this.options = Object.assign({
- minScale: 1.0,
- maxScale: 1.2,
- expandDuration: 1000,
- contractDuration: 1000,
- easing: tween.easeInOut
- }, options);
- this.startPulsating = function () {
- function pulsate() {
- tween(this.graphics, {
- scaleX: this.options.maxScale,
- scaleY: this.options.maxScale
- }, {
- duration: this.options.expandDuration,
- easing: this.options.easing,
- onFinish: function () {
- tween(this.graphics, {
- scaleX: this.options.minScale,
- scaleY: this.options.minScale
- }, {
- duration: this.options.contractDuration,
- easing: this.options.easing,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
- }
- pulsate.call(this);
- };
+ sound.play();
+ currentAmbientSound = sound; // Set the current ambient sound
+ // Set a timeout to reset the current ambient sound after it finishes playing
+ LK.setTimeout(function () {
+ currentAmbientSound = null;
+ }, sound.duration * 1000); // Convert duration from seconds to milliseconds
+ // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
+ ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
+ }, Math.random() * 20000 + 30000);
+});
+// Using UFO sound ID as placeholder
+var CLOUD_TYPES = ['cloud1', 'cloud2'];
+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);
};
- var SunPulse = function SunPulse(sunGraphics) {
- return new Pulse(sunGraphics, {
- maxScale: 1.1
- });
- };
- // Light1Pulse class to handle the pulsating effect for Light1
- var Light1Pulse = function Light1Pulse(lightGraphics) {
- return new Pulse(lightGraphics, {
- maxScale: 1.6,
- contractDuration: 1500
- });
- };
- var bird2; // Define bird2 variable in the global scope
- // UFOMovement class to handle UFO movement
- var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- this.ufo = ufo;
- this.ufoGraphics = ufoGraphics;
- this.ufo.speed = 3.2; // Decrease speed by 20%
- this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.ufo.lastX = this.ufo.x; // Track last X position for future checks
- this.ufo.update = function () {
- var _this5 = this;
- // Cache current position and dimensions
- var currentX = this.x;
- var screenWidth = 2048;
- var halfWidth = this.width / 2;
- // Update position based on pattern
- this.x += this.speed * Math.cos(LK.ticks / 60);
- this.y = 100 + Math.sin(LK.ticks / 120) * 250;
- // Optimize movement pattern
- var distanceFromCenter = Math.abs(this.x - screenWidth / 2);
- if (distanceFromCenter > screenWidth / 3) {
- this.speed *= -0.95; // Smooth direction change
- }
- // Cache intersection checks
- var isIntersectingCloud = clouds.some(function (cloud) {
- return _this5.intersects(cloud);
+};
+// 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)
});
- if (isIntersectingCloud && !this.lastIntersecting) {
- this.speed *= 1.2;
- LK.getSound('ufo1').play();
- }
- this.lastIntersecting = isIntersectingCloud;
- // Stop playing ufo1 sound after UFO leaves the screen
- if (this.lastX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || this.lastX >= -halfWidth && this.x < -halfWidth) {
- this.destroy();
- ufo = null;
- LK.getSound('ufo1').stop();
- }
- this.lastX = this.x; // Update lastX after movement
- };
+ }
+ pulsate.call(this);
};
- var UFOSound = function UFOSound() {
- this.play = function () {
+};
+var bird2; // Define bird2 variable in the global scope
+// UFOMovement class to handle UFO movement
+var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
+ this.ufo = ufo;
+ this.ufoGraphics = ufoGraphics;
+ this.ufo.speed = 3.2; // Decrease speed by 20%
+ this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
+ this.ufo.lastX = this.ufo.x; // Track last X position for future checks
+ this.ufo.update = function () {
+ var _this5 = this;
+ // Cache current position and dimensions
+ var currentX = this.x;
+ var screenWidth = 2048;
+ var halfWidth = this.width / 2;
+ // Update position based on pattern
+ this.x += this.speed * Math.cos(LK.ticks / 60);
+ this.y = 100 + Math.sin(LK.ticks / 120) * 250;
+ // Optimize movement pattern
+ var distanceFromCenter = Math.abs(this.x - screenWidth / 2);
+ if (distanceFromCenter > screenWidth / 3) {
+ this.speed *= -0.95; // Smooth direction change
+ }
+ // Cache intersection checks
+ var isIntersectingCloud = clouds.some(function (cloud) {
+ return _this5.intersects(cloud);
+ });
+ if (isIntersectingCloud && !this.lastIntersecting) {
+ this.speed *= 1.2;
LK.getSound('ufo1').play();
- };
+ }
+ this.lastIntersecting = isIntersectingCloud;
+ // Stop playing ufo1 sound after UFO leaves the screen
+ if (this.lastX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || this.lastX >= -halfWidth && this.x < -halfWidth) {
+ this.destroy();
+ ufo = null;
+ LK.getSound('ufo1').stop();
+ }
+ this.lastX = this.x; // Update lastX after movement
};
- // BackgroundMusic class to manage background music
- var BackgroundMusic = function BackgroundMusic() {
- this.play = function () {
- LK.playMusic('bgm1', {
- loop: true,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: onBgm1End
- });
- };
+};
+var UFOSound = function UFOSound() {
+ this.play = function () {
+ LK.getSound('ufo1').play();
};
- // LaserSound class to manage laser sound effects
- var LaserSound = function LaserSound() {
- this.play = function () {
- LK.getSound('laser1').play();
- };
- };
- var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = this.bird.y;
- this.bird.lastX = this.bird.x;
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5;
- this.lastY = this.y;
- this.lastX = this.x;
- }.bind(this.bird);
- };
- var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = Math.random() * 2732; // Random initial y position within the screen height
- this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- }
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
- };
- };
- var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {};
- };
- var ReticlePulse = function ReticlePulse(reticleGraphics) {
- return new Pulse(reticleGraphics, {
- maxScale: 1.2
+};
+// BackgroundMusic class to manage background music
+var BackgroundMusic = function BackgroundMusic() {
+ this.play = function () {
+ LK.playMusic('bgm1', {
+ loop: true,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: onBgm1End
});
};
- // 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
- };
+};
+// LaserSound class to manage laser sound effects
+var LaserSound = function LaserSound() {
+ this.play = function () {
+ LK.getSound('laser1').play();
};
- function spawnBird2() {
- var bird2Count = entityManager.getAllOfType(Bird2).length;
- if (bird2Count < 3) {
- var bird = new 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;
- entityManager.add(bird);
- birds.push(bird);
+};
+var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = this.bird.y;
+ this.bird.lastX = this.bird.x;
+ this.bird.update = function () {
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5;
+ this.lastY = this.y;
+ this.lastX = this.x;
+ }.bind(this.bird);
+};
+var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
+ this.bird = bird;
+ this.birdGraphics = birdGraphics;
+ this.bird.speed = Math.random() * 1.6 + 1;
+ this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
+ this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
+ this.bird.update = function () {
+ this.y += this.speed;
+ this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
+ flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
+ // Check if the bird has moved off-screen
+ if (this.lastY <= 2732 && this.y > 2732) {
+ this.y = Math.random() * 2732; // Random initial y position within the screen height
+ this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
}
- LK.setTimeout(spawnBird2, Math.random() * 10000 + 20000);
- }
- // 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);
- // Initialize bird spawning
- spawnBird2();
- // 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;
- };
+ this.lastX = this.x; // Track position for next update
+ this.lastY = this.y; // Update lastY after movement
+ storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
+ storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
};
- var birds = [];
- game.down = function (x, y, obj) {
- if (obj && obj.event) {
- x = obj.event.x;
- y = obj.event.y;
+};
+var Bird2Effects = function Bird2Effects(bird) {
+ this.bird = bird;
+ this.applyEffects = function () {};
+};
+var ReticlePulse = function ReticlePulse(reticleGraphics) {
+ this.reticleGraphics = reticleGraphics;
+ this.startPulsating = function () {
+ function pulsate() {
+ tween(this.reticleGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function () {
+ tween(this.reticleGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: pulsate.bind(this)
+ });
+ }.bind(this)
+ });
}
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE);
- }
- }
- game.reticle.x = x;
- game.reticle.y = y;
- if (typeof x === 'undefined' || typeof y === 'undefined') {
- console.error('Invalid coordinates for laser');
- return;
- }
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(laser, LAYERS.LASER);
- }
+ pulsate.call(this);
};
- 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());
+};
+// 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;
}
- if (obj.event) {
- var x = obj.event.x;
- var y = obj.event.y;
+ currentScore += Math.floor(points);
+ if (currentScore > highScore) {
+ highScore = currentScore;
+ storage.highScore = highScore;
}
- game.reticle.x = x;
- game.reticle.y = y;
+ return currentScore;
};
- // 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();
+ self.resetScore = function () {
+ currentScore = 0;
+ return currentScore;
+ };
+ self.getScore = function () {
+ return currentScore;
+ };
+ self.getHighScore = function () {
+ return highScore;
+ };
+};
+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
}
- // Add a jet to the game if it doesn't exist and no jet spawn timer is active
- if (!game.jet && !game.jetSpawnTimer) {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
- jet.y = Math.random() * (2732 / 2);
- game.addChild(jet);
- game.jet = jet;
- game.layerManager.addToLayer(jet, LAYERS.JET1);
- LK.getSound('jet1').play();
- }
- // Update jet
- if (game.jet) {
- game.jet.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;
+ }
+ 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
+// Initialize clouds array
+var clouds = [];
+// Initialize cloud types
+var CLOUD_TYPES = ['cloud1', 'cloud2'];
+// Add initial clouds
+// Call initializeClouds after game initialization
+initializeClouds();
+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();
+ }
+ // Add a jet to the game if it doesn't exist and no jet spawn timer is active
+ if (!game.jet && !game.jetSpawnTimer) {
+ var jet = new Jet1();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2);
+ game.addChild(jet);
+ game.jet = jet;
+ game.layerManager.addToLayer(jet, LAYERS.JET1);
+ LK.getSound('jet1').play();
+ }
+ // Update jet
+ if (game.jet) {
+ game.jet.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);
- scoreDisplay.updateScore(score);
+ LK.getSound('dead1').play();
+ bird.destroy();
+ birds.splice(birds.indexOf(bird), 1);
child.destroy();
+ return true;
}
- child.lastIntersecting = hasIntersection || ufo && child.intersects(ufo);
+ return child.intersects(bird);
+ });
+ if (!hasIntersection && ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
+ score += 25;
+ scoreDisplay.updateScore(score);
+ scoreDisplay.updateScore(score);
+ child.destroy();
}
- });
- // 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);
+ child.lastIntersecting = hasIntersection || ufo && child.intersects(ufo);
}
- ufo.lastX = ufo.x;
- }
- };
- // Function to spawn a third kind of bird
- // Update bird positions and states
- function updateBirds() {
- // 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
+ });
+ // 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);
});
- // Ensure correct number of birds
- var bird1Count = birds.filter(function (b) {
- return b instanceof Bird1;
- }).length;
- var bird2Count = birds.filter(function (b) {
- return b instanceof Bird2;
- }).length;
- // Maintain exactly 1 Bird1
- if (bird1Count < 1) {
- var newBird1 = new 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 Bird1;
- }).slice(1);
- extraBird1s.forEach(function (b) {
- b.destroy();
- birds.splice(birds.indexOf(b), 1);
- });
+ 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);
}
- // Maintain exactly 3 Bird2s
- if (bird2Count < 3) {
- for (var i = 0; i < 3 - bird2Count; i++) {
- var newBird2 = new 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 Bird2;
- }).slice(3);
- extraBird2s.forEach(function (b) {
- b.destroy();
- birds.splice(birds.indexOf(b), 1);
- });
+ ufo.lastX = ufo.x;
+ }
+};
+// Function to spawn a third kind of bird
+// 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
}
- // Update UFOs, jets, and check for collisions
- game.children.forEach(function (entity) {
- if (entity instanceof UFO1 || entity instanceof UFO2) {
- if (!entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
- LK.getSound('ufo1').play();
- entity.soundPlayed = true;
- }
- entity.update();
- }
- });
- // Update each laser and check collisions
+ });
+ // Update UFO and check for collisions
+ if (ufo) {
+ ufo.customUpdate();
+ // Update each laser
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
- // Check for intersections with birds
- game.children.forEach(function (target) {
- if (!child.lastIntersecting && AABBIntersect(child, target)) {
- var points = 0;
- var soundEffect = '';
- if (target instanceof Bird1) {
- points = 100;
- soundEffect = 'dead1';
- spawnManager.objectCounts.bird1--;
- } else if (target instanceof Bird2) {
- points = 50;
- soundEffect = 'dead2';
- spawnManager.objectCounts.bird2--;
- } else if (target instanceof UFO1 || target instanceof UFO2) {
- points = 250;
- soundEffect = 'dead3';
- spawnManager.objectCounts.ufo--;
+ // Check for intersections with birds and UFO
+ birds.forEach(function (bird) {
+ if (!child.lastIntersecting && AABBIntersect(child, bird)) {
+ if (bird instanceof Bird1) {
+ score += 5;
+ } else if (bird instanceof Bird2 || bird instanceof Bird3) {
+ score += 1;
}
- if (points > 0) {
- game.score = (game.score || 0) + points;
- if (game.mirror && game.mirror.updateScore) {
- game.mirror.updateScore(game.score);
- }
- LK.getSound(soundEffect).play();
- target.destroy();
- child.destroy();
- }
+ scoreDisplay.updateScore(score); // Update the score display
+ bird.destroy(); // Remove the bird when hit by a laser
+ birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
+ child.destroy();
}
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ });
});
- // Update lastIntersecting state
- child.lastIntersecting = game.children.some(function (target) {
- return (target instanceof Bird1 || target instanceof Bird2 || target instanceof UFO1 || target instanceof UFO2) && child.intersects(target);
- });
+ if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
+ score += 25;
+ scoreDisplay.updateScore(score);
+ child.destroy();
+ }
+ child.lastIntersecting = birds.some(function (bird) {
+ return child.intersects(bird);
+ }) || ufo && child.intersects(ufo);
}
});
}
- ;
- // 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 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
- // 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-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);
- });
- var EntityManager = /*#__PURE__*/function () {
- function EntityManager() {
- _classCallCheck2(this, EntityManager);
- this.entities = [];
- }
- return _createClass2(EntityManager, [{
- key: "add",
- value: function add(entity) {
- this.entities.push(entity);
- // Add to the game world (e.g., addChild)
- game.addChild(entity);
- }
- }, {
- key: "remove",
- value: function remove(entity) {
- var index = this.entities.indexOf(entity);
- if (index > -1) {
- this.entities.splice(index, 1);
- // Remove from the game world (e.g., destroy)
- entity.destroy();
- }
- }
- }, {
- key: "update",
- value: function update(deltaTime) {
- var _iterator = _createForOfIteratorHelper(this.entities),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var entity = _step.value;
- entity.update(deltaTime);
- }
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
- }
- }
- }, {
- key: "getAllOfType",
- value: function getAllOfType(type) {
- return this.entities.filter(function (entity) {
- return entity instanceof type;
- });
- }
- }, {
- key: "clear",
- value: function clear() {
- this.entities.forEach(function (entity) {
- return entity.destroy();
- });
- this.entities = [];
- }
- }]);
- }(); // Instantiate the EntityManager
- var entityManager = new EntityManager();
- // Update entities
- // Update entities using the EntityManager
- entityManager.update(deltaTime);
};
-// Add existing entities to the EntityManager
-var bird1 = new 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;
-entityManager.add(bird1);
-var bird2 = new Bird2();
-bird2.y = Math.random() * (2732 / 2);
-bird2.x = Math.random() < 0.5 ? 0 : 2048;
-bird2.speed = 1 + Math.random() * 0.6;
-bird2.lastIntersecting = false;
-bird2.type = 'bird2';
-bird2.color = 0xFFFFFF;
-entityManager.add(bird2);
-var ufo1 = new UFO1();
-ufo1.x = Math.random() < 0.5 ? 2048 + ufo1.width / 2 : -ufo1.width / 2;
-ufo1.y = Math.random() * (2732 / 2 - ufo1.height);
-entityManager.add(ufo1);
-var ufo2 = new UFO2();
-ufo2.x = Math.random() < 0.5 ? 2048 + ufo2.width / 2 : -ufo2.width / 2;
-ufo2.y = Math.random() * (2732 / 2 - ufo2.height);
-entityManager.add(ufo2);
-var jet = new Jet1();
-jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
-jet.y = Math.random() * (2732 / 2);
-entityManager.add(jet);
-if (typeof x !== 'undefined' && typeof y !== 'undefined') {
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
- entityManager.add(laser);
-} else {
- console.error('Invalid coordinates for laser creation');
+// Add a tree to the game
+var tree = game.addChild(new Tree());
+tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
+tree.y = 2500; // Position the tree on the grass
+// Ensure tree is added to the game before setting its index
+if (game.children.includes(tree) && game.children.includes(bird1)) {
+ game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
}
-// Ensure timers for ambient sounds and bgm1 are set to repeat every 20-30 seconds
-function initializeAmbientSounds() {
- function playAmbientSounds() {
- LK.getSound('songbird1').play();
- LK.getSound('cricket1').play();
- LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000); // 20-30 seconds
- }
- playAmbientSounds();
- // Set initial interval
- LK.setInterval(playAmbientSounds, 25000); // Average of 20-30 seconds
+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
+// Ensure stack1 is added to the game before setting its index
+if (game.children.includes(stack1) && game.children.includes(tree)) {
+ game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
}
-function initializeBGM() {
- function playBGM() {
- LK.playMusic('bgm1');
- }
- playBGM();
- // Set regular interval for background music
- LK.setInterval(playBGM, 25000); // Average of 20-30 seconds
+// Add the grass floor to the game
+var grassBack = new GrassBack();
+grassBack.x = 1020;
+grassBack.y = 2735; // Position grassBack at the bottom
+game.addChild(grassBack);
+// Ensure grassBack is added to the game before setting its index
+if (game.children.includes(grassBack)) {
+ // Make sure we don't set an index that's out of bounds
+ var safeIndex = Math.min(5, game.children.length - 1);
+ game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely
}
-// Fix scoring
-var scoreManager = new ScoreManager();
-var score = 0;
-game.down = function (x, y, obj) {
- if (obj && obj.event) {
- x = obj.event.x;
- y = obj.event.y;
+var grassFront = new GrassFront();
+grassFront.x = 1020;
+grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
+game.addChild(grassFront);
+// Ensure grassFront is added to the game before setting its index
+if (game.children.includes(grassFront) && game.children.includes(bird2)) {
+ game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
+}
+var 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);
+// Mirror doesn't need a specific layer as it's positioned using setChildIndex
+// Ensure mirror is added to the game before setting its index
+if (game.children.includes(mirror) && game.children.includes(stack1)) {
+ game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
+}
+// Ensure laser is added to the game before setting mirror's index
+if (game.children.includes(laser) && game.children.includes(mirror)) {
+ game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
+}
+// Function to handle bgm1 end event
+;
+// Add the cat to the game
+var cat = game.addChild(new Cat());
+cat.x = 230; // Move the cat 20px to the left
+cat.y = 2732; // Position the cat at the bottom of the screen
+// Ensure cat is added to the game before setting its index
+if (game.children.includes(cat)) {
+ game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+}
+// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
+LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.02,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ // Set a timer to replay bgm1 every 20-50 seconds
+ LK.setTimeout(function () {
+ LK.playMusic('bgm1', {
+ loop: false,
+ // Play once
+ fade: {
+ start: 0,
+ end: 0.5,
+ // Set to the lowest volume
+ duration: 4000
+ },
+ onEnd: onEnd // Set the onEnd function to replay bgm1
+ });
+ }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
}
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE);
+});
+// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
+var wingsTimer = LK.setTimeout(function () {
+ LK.getSound('wings1').play();
+ wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
+}, Math.random() * 20000 + 10000);
+// Create an array for all sounds except ufo1, including all birdsong sounds
+var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
+var currentAmbientSound = null;
+// Initialize random timers for each sound to play between 30-50 seconds
+sounds.forEach(function (soundId) {
+ var sound = LK.getSound(soundId);
+ var ambientSoundTimer = LK.setTimeout(function () {
+ if (currentAmbientSound) {
+ currentAmbientSound.stop(); // Stop the currently playing ambient sound
}
- }
- game.reticle.x = x;
- game.reticle.y = y;
- if (typeof x === 'undefined' || typeof y === 'undefined') {
- console.error('Invalid coordinates for laser');
- return;
- }
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(laser, LAYERS.LASER);
- }
-};
-// Adjust layer display order
-game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
-game.layerManager.addToLayer(jet, LAYERS.JET1);
-game.layerManager.addToLayer(mirror, LAYERS.MIRROR);
-// Ensure jet1 and ufo1 sounds play when on screen
-Jet1.prototype.update = function () {
- flipImageVerticallyBasedOnDirection(jetGraphics, self.lastX, self.x);
- self.x += self.speed * self.direction;
- if (!self.soundPlayed && self.x > 0 && self.x < 2048) {
- LK.getSound('jet1').play();
- self.soundPlayed = true;
- }
- if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
- self.destroy();
- game.jet = null;
- var respawnTime = Math.random() * 10000 + 20000;
- game.jetSpawnTimer = LK.setTimeout(function () {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
- jet.y = Math.random() * (2732 / 2);
- game.addChild(jet);
- game.layerManager.addToLayer(jet, LAYERS.JET1);
- game.jet = jet;
- game.jetSpawnTimer = null;
- }, respawnTime);
- }
- self.lastX = self.x;
-};
-UFOMovement.prototype.update = function () {
- var currentX = this.x;
- var screenWidth = 2048;
- var halfWidth = this.width / 2;
- var tickCos = Math.cos(LK.ticks / 60);
- var tickSin = Math.sin(LK.ticks / 120);
- this.x += this.speed * tickCos;
- this.y = 100 + tickSin * 250;
- if (this.x > 0 && this.x < screenWidth && !this.soundPlayed) {
- LK.getSound('ufo1').play();
- this.soundPlayed = true;
- }
- if (this.x < 0 || this.x > screenWidth) {
- this.soundPlayed = false;
- }
- if (currentX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || currentX >= -halfWidth && this.x < -halfWidth) {
- LK.getSound('ufo1').stop();
- this.destroy();
- ufo = null;
- }
- this.lastX = this.x;
-};
\ No newline at end of file
+ sound.play();
+ currentAmbientSound = sound; // Set the current ambient sound
+ // Set a timeout to reset the current ambient sound after it finishes playing
+ LK.setTimeout(function () {
+ currentAmbientSound = null;
+ }, sound.duration * 1000); // Convert duration from seconds to milliseconds
+ // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
+ ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
+ }, Math.random() * 20000 + 30000);
+});
\ No newline at end of file
an orange and white cat facing away from the camera. the cat is sitting straight up and looking up, ready to pounce. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
remove black box
fluffy translucent cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bright sun with wincing cartoon face and a black eye. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a goofy ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red gaming reticle. Minimal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sunny day, hilly landscape. there is an alien invasion taking place in the distance. cities burning.
large AUTUMN SHADES tree with sparse bunches of leaves. branches are exposed, but the tree is tough and old.. true-color, realistic, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
glowing orange sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sideway view of a fighter jet. . . In-Game 2d asset. transparent background. horizontal. No shadows.
shiny purple and black attack ufo.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows