User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = storage.jet1_lastX; // Update lastX after movement' Line Number: 187 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 186 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 186 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 186 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' Line Number: 230 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 186 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 186 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x; // Update lastX after movement' Line Number: 184 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 164 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 165
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 165
User prompt
Please fix the bug: 'storage is not defined' in or related to this line: 'this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y' Line Number: 831 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'EntityManager is not a constructor' in or related to this line: 'game.entityManager = new EntityManager();' Line Number: 57
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'add')' in or related to this line: 'game.entityManager.add(grassBack);' Line Number: 816
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);' Line Number: 682
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);' Line Number: 589
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);' Line Number: 589
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 361
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'getImage')' in or related to this line: 'var asset = LK.init.getImage(assetName);' Line Number: 356
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Initialize Game ****/ // BaseEntityManager removed - using EntityManager defined at the beginning of the file // Initialize clouds array var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue }); /**** * Game Code ****/ // Modern ES6 class implementation for game object movement // Unified GameObjectMovement class with improved movement patterns and sound management // Base GameObject class to handle common functionality var _GameObjectMovement = { MovementConfigs: { base: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: false, canFlip: true, moveSound: null, respawnTime: { min: 20000, max: 30000 }, screenWidth: 2048, screenHeight: 2732 }, bird1: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, ufo1: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, ufo2: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, jet1: { speed: 10, speedRange: 0, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: true, moveSound: 'jet1' }, cloud1: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, cloud2: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, 'grass-front': { speed: 0, speedRange: 0, arcAmplitude: 1.2, arcFrequency: 120, isVertical: false, moveSound: null, canFlip: false }, 'grass-back': { speed: 0, speedRange: 0, arcAmplitude: 0.8, arcFrequency: 150, isVertical: false, moveSound: null, canFlip: false } } }; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof2(e) || "function" == typeof e)) { return e; } if (void 0 !== e) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); } function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));) { ; } return t; } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) { throw new TypeError("Super expression must either be null or a function"); } t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _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 _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 SoundManager = /*#__PURE__*/function () { function SoundManager(config) { _classCallCheck2(this, SoundManager); this.config = config || {}; this.soundTimers = {}; this.soundCallbacks = {}; this.soundIntervals = { ambient: { min: 20000, max: 30000 }, background: { min: 20000, max: 30000 }, ufo: { min: 20000, max: 30000 }, jet: { min: 20000, max: 30000 } }; } return _createClass2(SoundManager, [{ key: "initialize", value: function initialize() { var _this = this; var ambientSounds = [{ id: 'songbird1', volume: 0.1, minDelay: 5000, maxDelay: 15000 }, { id: 'cricket1', volume: 0.1, minDelay: 8000, maxDelay: 20000 }, { id: 'breeze1', volume: 0.1, minDelay: 10000, maxDelay: 25000 }, { id: 'frog1', volume: 0.1, minDelay: 12000, maxDelay: 30000 }, { id: 'chitter', volume: 0.1, minDelay: 15000, maxDelay: 35000 }]; ambientSounds.forEach(function (sound) { var initialDelay = Math.random() * (sound.maxDelay - sound.minDelay) + sound.minDelay; LK.setTimeout(function () { _this.playSound(sound.id, { volume: sound.volume, interval: { min: sound.minDelay, max: sound.maxDelay } }); }, initialDelay); }); this.playSound('bgm1', { isMusic: true, volume: 0.1, loop: true, autoRestart: false }); } }, { key: "playSound", value: function playSound(soundId, options) { var _this2 = this; options = Object.assign({ interval: this.soundIntervals.ambient, isMusic: false, volume: 0.1, loop: false, autoRestart: true, onPlay: null, onStop: null }, options); var _playFunction = function playFunction() { if (options.isMusic) { LK.playMusic(soundId, { volume: options.volume }); } else { var sound = LK.getSound(soundId); if (sound) { sound.volume = options.volume; if (options.loop) { sound.loop = true; } sound.play(); if (options.onPlay) { options.onPlay(); } } } if (options.autoRestart) { var nextInterval = Math.random() * (options.interval.max - options.interval.min) + options.interval.min; _this2.soundTimers[soundId] = LK.setTimeout(_playFunction.bind(_this2), nextInterval); } }; this.soundCallbacks[soundId] = options; _playFunction(); return this.soundTimers[soundId]; } }, { key: "stopSound", value: function stopSound(soundId) { if (this.soundTimers[soundId]) { LK.clearTimeout(this.soundTimers[soundId]); delete this.soundTimers[soundId]; } var sound = LK.getSound(soundId); if (sound) { sound.stop(); if (this.soundCallbacks[soundId] && this.soundCallbacks[soundId].onStop) { this.soundCallbacks[soundId].onStop(); } delete this.soundCallbacks[soundId]; } } }, { key: "stopAllSounds", value: function stopAllSounds() { var _this3 = this; Object.keys(this.soundTimers).forEach(function (soundId) { _this3.stopSound(soundId); }); } }]); }(); var Container = /*#__PURE__*/function () { function Container() { _classCallCheck2(this, Container); this.children = []; } return _createClass2(Container, [{ key: "attachAsset", value: function attachAsset(assetName, options) { if (!assetName) { console.error('Asset name is required for attachAsset'); return null; } var asset = LK.getAsset(assetName, {}); if (!asset) { console.error('Failed to load asset:', assetName); return null; } var sprite = LK.getAsset(assetName, {}); if (options) { Object.assign(sprite, options); } this.addChild(sprite); return sprite; } }, { key: "addChild", value: function addChild(child) { if (child && !this.children.includes(child)) { this.children.push(child); } return child; } }, { key: "destroy", value: function destroy() { if (this.children) { this.children.forEach(function (child) { if (child && child.destroy) { child.destroy(); } }); this.children = []; } } }]); }(); var EntityManager = /*#__PURE__*/function () { function EntityManager() { _classCallCheck2(this, EntityManager); this.entities = []; this.pendingRemovals = []; } return _createClass2(EntityManager, [{ key: "add", value: function add(entity) { if (!entity) { return; } if (!this.entities.includes(entity)) { this.entities.push(entity); if (entity.type && game.spawnManager && game.spawnManager.objectCounts) { game.spawnManager.objectCounts[entity.type] = (game.spawnManager.objectCounts[entity.type] || 0) + 1; } } } }, { key: "remove", value: function remove(entity) { if (!entity) { return; } var index = this.entities.indexOf(entity); if (index > -1) { this.entities.splice(index, 1); // First mark as destroyed to prevent re-entry if (entity.destroy && !entity.destroyed) { entity.destroyed = true; entity.destroy(); } // Then update layer tracking if (game.layerManager) { game.layerManager.removeFromTracking(entity); } // Finally update spawn counts if (entity.type && game.spawnManager && game.spawnManager.objectCounts) { var currentCount = game.spawnManager.objectCounts[entity.type] || 0; game.spawnManager.objectCounts[entity.type] = Math.max(0, currentCount - 1); } } } }, { key: "update", value: function update(deltaTime) { var _this4 = this; // Clear pending removals from previous update this.pendingRemovals = []; // Update entities and mark destroyed ones for removal for (var i = this.entities.length - 1; i >= 0; i--) { var entity = this.entities[i]; if (!entity || entity.destroyed) { this.pendingRemovals.push(entity); continue; } if (entity.update) { entity.update(deltaTime); } } // Remove destroyed entities this.pendingRemovals.forEach(function (entity) { return _this4.remove(entity); }); } }, { key: "getAllOfType", value: function getAllOfType(type) { return this.entities.filter(function (entity) { return entity && !entity.destroyed && entity instanceof type; }); } }, { key: "clear", value: function clear() { // Remove all entities properly using the remove method while (this.entities.length > 0) { this.remove(this.entities[0]); } this.pendingRemovals = []; // Clear spawn timers if they exist if (game.spawnManager) { Object.keys(game.spawnManager.spawnTimers || {}).forEach(function (type) { if (game.spawnManager.spawnTimers[type]) { LK.clearTimeout(game.spawnManager.spawnTimers[type]); delete game.spawnManager.spawnTimers[type]; } }); game.spawnManager.spawnTimers = {}; // Reset all object counts game.spawnManager.objectCounts = { bird1: 0, bird2: 0, cloud1: 0, cloud2: 0, ufo1: 0, ufo2: 0, jet1: 0 }; } } }]); }(); var GameObject = /*#__PURE__*/function (_Container) { function GameObject(assetName) { var _this5; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck2(this, GameObject); _this5 = _callSuper(this, GameObject); _this5.graphics = _this5.attachAsset(assetName, {}); return _this5; } // Common destroy method _inherits(GameObject, _Container); return _createClass2(GameObject, [{ key: "destroy", value: function destroy() { if (this.destroyed) { return; } this.destroyed = true; if (game.layerManager) { game.layerManager.removeFromTracking(this); } if (this.movement && this.movement.cleanup) { this.movement.cleanup(); this.movement = null; } if (this.graphics) { this.graphics.destroy(); this.graphics = null; } _superPropGet(GameObject, "destroy", this, 3)([]); } // Common update method }, { key: "update", value: function update() { if (this.movement) { this.movement.update(); } } }]); }(Container); var Background = /*#__PURE__*/function (_GameObject) { function Background() { _classCallCheck2(this, Background); return _callSuper(this, Background, ['background']); } _inherits(Background, _GameObject); return _createClass2(Background); }(GameObject); var Bird1 = /*#__PURE__*/function (_GameObject2) { function Bird1() { var _this6; _classCallCheck2(this, Bird1); _this6 = _callSuper(this, Bird1, ['bird1']); _this6.type = 'bird1'; _this6.movement = new GameObjectMovement(_this6, _this6.graphics, GameObjectMovement.MovementConfigs.bird1); return _this6; } _inherits(Bird1, _GameObject2); return _createClass2(Bird1); }(GameObject); var Bird2 = /*#__PURE__*/function (_GameObject3) { function Bird2() { var _this7; _classCallCheck2(this, Bird2); _this7 = _callSuper(this, Bird2, ['bird2']); _this7.type = 'bird2'; _this7.movement = new GameObjectMovement(_this7, _this7.graphics, GameObjectMovement.MovementConfigs.bird2); return _this7; } _inherits(Bird2, _GameObject3); return _createClass2(Bird2); }(GameObject); var Cat = /*#__PURE__*/function (_GameObject4) { function Cat() { _classCallCheck2(this, Cat); return _callSuper(this, Cat, ['cat', { anchorX: 0.5, anchorY: 1 }]); } _inherits(Cat, _GameObject4); return _createClass2(Cat); }(GameObject); // Define cloud types at the beginning var CLOUD_TYPES = ['cloud1', 'cloud2']; var GrassLayer = /*#__PURE__*/function (_GameObject5) { function GrassLayer(type) { var _this8; _classCallCheck2(this, GrassLayer); _this8 = _callSuper(this, GrassLayer, [type, { anchorX: 0.5, anchorY: 0.5, alpha: 1 }]); _this8.type = type; _this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]); return _this8; } _inherits(GrassLayer, _GameObject5); return _createClass2(GrassLayer, [{ key: "update", value: function update(deltaTime) { _superPropGet(GrassLayer, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }]); }(GameObject); var GRASS_TYPES = ['grass-front', 'grass-back']; // Initialize grass layers var grassFront = new GrassLayer('grass-front'); grassFront.x = LK.width / 2; grassFront.y = LK.height - 100; var grassBack = new GrassLayer('grass-back'); grassBack.x = LK.width / 2; grassBack.y = LK.height - 150; // Add grass layers to the game game.entityManager.add(grassBack); game.entityManager.add(grassFront); var Cloud = /*#__PURE__*/function (_GameObject6) { function Cloud() { var _this9; _classCallCheck2(this, Cloud); var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)]; _this9 = _callSuper(this, Cloud, [cloudType, { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }]); _this9.type = cloudType; _this9.movement = new GameObjectMovement(_this9, _this9.graphics, GameObjectMovement.MovementConfigs[_this9.type]); return _this9; } _inherits(Cloud, _GameObject6); return _createClass2(Cloud, [{ key: "destroy", value: function destroy() { if (spawnManager) { spawnManager.objectCounts[this.type === 'cloud1' ? 'cloud1' : 'cloud2']--; } this.movement = null; _superPropGet(Cloud, "destroy", this, 3)([]); } }]); }(GameObject); // Using GrassLayer class for grass-back implementation var GrassFront = /*#__PURE__*/function (_GameObject7) { function GrassFront() { _classCallCheck2(this, GrassFront); return _callSuper(this, GrassFront, ['grass-front', { anchorX: 0.5, anchorY: 1 }]); } _inherits(GrassFront, _GameObject7); return _createClass2(GrassFront, [{ key: "update", value: function update() { // Swaying effect with bounds checking and smoother movement var maxOffset = 2.0; var offset = Math.sin(LK.ticks / 90) * 0.15; this.x += Math.max(-maxOffset, Math.min(maxOffset, offset)); } }]); }(GameObject); var Jet1 = /*#__PURE__*/function (_GameObject8) { function Jet1() { var _this10; _classCallCheck2(this, Jet1); _this10 = _callSuper(this, Jet1, ['jet1']); _this10.type = 'jet1'; _this10.movement = new GameObjectMovement(_this10, _this10.graphics, GameObjectMovement.MovementConfigs.jet1); _this10.soundPlayed = false; return _this10; } _inherits(Jet1, _GameObject8); return _createClass2(Jet1, [{ key: "update", value: function update() { _superPropGet(Jet1, "update", this, 3)([]); // Play jet1 sound when on screen if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('jet1').play(); this.soundPlayed = true; } } }]); }(GameObject); function respawnJet() { if (game.jet === null) { var jet = new Jet1(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2); addEntityToLayer(jet, LAYERS.JET1); game.jet = jet; } game.jetSpawnTimer = null; } var Laser = /*#__PURE__*/function (_Container2) { function Laser(startX, startY, targetX, targetY) { var _this11; _classCallCheck2(this, Laser); _this11 = _callSuper(this, Laser); _this11.laserGraphics = _this11.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 }); var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; _this11.vx = dx / distance * speed; _this11.vy = dy / distance * speed; _this11.x = startX; _this11.y = startY; _this11.lastIntersecting = false; _this11.active = true; LK.getSound('laser1').play(); return _this11; } _inherits(Laser, _Container2); return _createClass2(Laser, [{ key: "destroy", value: function destroy() { if (game.layerManager) { game.layerManager.removeFromTracking(this); } _superPropGet(Laser, "destroy", this, 3)([]); } }, { key: "update", value: function update() { if (!this.active) { return; } // Move first this.x += this.vx; this.y += this.vy; // Check collisions only with relevant layers var collided = false; var targets = game.layerManager.getAllInteractiveLayers(); for (var i = 0; i < targets.length && !collided; i++) { for (var j = 0; j < targets.length && !collided; j++) { var target = targets[j]; if (!this.lastIntersecting && this.intersects(target)) { var soundEffect = game.layerManager.isInLayer(target, 'ufos') ? 'dead3' : 'dead2'; LK.getSound(soundEffect).play(); // Update score based on target type var scoreValue = 0; if (game.layerManager.isInLayer(target, LAYERS.BIRD1)) { scoreValue = 5; } else if (game.layerManager.isInLayer(target, LAYERS.BIRD2)) { scoreValue = 1; } else if (game.layerManager.isInLayer(target, LAYERS.UFO1) || game.layerManager.isInLayer(target, LAYERS.UFO2)) { scoreValue = 25; } score += scoreValue; if (game.mirror) { game.mirror.updateScore(score); } target.destroy(); collided = true; } } } // Update intersection state this.lastIntersecting = collided; // Destroy if out of bounds if (this.x < 0 || this.x > 2048 || this.y < 0 || this.y > 2732) { this.destroy(); } } }]); }(Container); var Light1 = /*#__PURE__*/function (_GameObject9) { function Light1() { var _this12; _classCallCheck2(this, Light1); _this12 = _callSuper(this, Light1, ['light1', { anchorX: 0.5, anchorY: 0.5, alpha: 1.0 }]); _this12.x = 450; _this12.y = 450; _this12.pulse = new Light1Pulse(_this12.graphics); _this12.pulse.startPulsating(); return _this12; } _inherits(Light1, _GameObject9); return _createClass2(Light1, [{ key: "update", value: function update() { // Swaying effect with bounds checking and smoother movement var maxOffset = 1.5; var offset = Math.sin(LK.ticks / 90) * 0.1; this.x += Math.max(-maxOffset, Math.min(maxOffset, offset)); } }]); }(GameObject); var Mirror = /*#__PURE__*/function (_GameObject10) { function Mirror() { var _this13; _classCallCheck2(this, Mirror); _this13 = _callSuper(this, Mirror, ['mirror1']); _this13.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 }); _this13.scoreText.y = 260 + 50; _this13.scoreText.x = -155; _this13.scoreText.rotation = (-83 - 3) * (Math.PI / 180); addEntityToLayer(_this13.scoreText, LAYERS.UI); return _this13; } _inherits(Mirror, _GameObject10); return _createClass2(Mirror, [{ key: "updateScore", value: function updateScore(newScore) { this.scoreText.setText(newScore); } }]); }(GameObject); var Reticle = /*#__PURE__*/function (_GameObject11) { function Reticle() { _classCallCheck2(this, Reticle); return _callSuper(this, Reticle, ['reticle1']); } _inherits(Reticle, _GameObject11); return _createClass2(Reticle, [{ key: "update", value: function update() { if (!this.pulse) { this.pulse = new ReticlePulse(this.graphics); this.pulse.startPulsating(); } _superPropGet(Reticle, "update", this, 3)([]); } }]); }(GameObject); var Stack1 = /*#__PURE__*/function (_GameObject12) { function Stack1() { _classCallCheck2(this, Stack1); return _callSuper(this, Stack1, ['stack1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / -12 }]); } _inherits(Stack1, _GameObject12); return _createClass2(Stack1); }(GameObject); var Sun = /*#__PURE__*/function (_GameObject13) { function Sun() { var _this14; _classCallCheck2(this, Sun); _this14 = _callSuper(this, Sun, ['sun']); _this14.pulse = new SunPulse(_this14.graphics); _this14.pulse.startPulsating(); return _this14; } _inherits(Sun, _GameObject13); return _createClass2(Sun); }(GameObject); var Tree = /*#__PURE__*/function (_GameObject14) { function Tree() { var _this15; _classCallCheck2(this, Tree); _this15 = _callSuper(this, Tree, ['tree1', { anchorX: 0.5, anchorY: 1, antialias: true, stroke: 0x000000, strokeThickness: 15 }]); _this15.type = 'tree1'; _this15.movement = new GameObjectMovement(_this15, _this15.graphics, GameObjectMovement.MovementConfigs.tree1); return _this15; } _inherits(Tree, _GameObject14); return _createClass2(Tree, [{ key: "update", value: function update(deltaTime) { _superPropGet(Tree, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }, { key: "destroy", value: function destroy() { this.movement = null; _superPropGet(Tree, "destroy", this, 3)([]); } }]); }(GameObject); var Tree2 = /*#__PURE__*/function (_GameObject15) { function Tree2() { var _this16; _classCallCheck2(this, Tree2); _this16 = _callSuper(this, Tree2, ['tree2', { anchorX: 0.5, anchorY: 1 }]); _this16.type = 'tree2'; _this16.movement = new GameObjectMovement(_this16, _this16.graphics, GameObjectMovement.MovementConfigs.tree2); return _this16; } _inherits(Tree2, _GameObject15); return _createClass2(Tree2, [{ key: "update", value: function update(deltaTime) { _superPropGet(Tree2, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }, { key: "destroy", value: function destroy() { this.movement = null; _superPropGet(Tree2, "destroy", this, 3)([]); } }]); }(GameObject); var UFO1 = /*#__PURE__*/function (_GameObject16) { function UFO1() { var _this17; _classCallCheck2(this, UFO1); _this17 = _callSuper(this, UFO1, ['ufo1']); _this17.type = 'ufo1'; _this17.movement = new GameObjectMovement(_this17, _this17.graphics, GameObjectMovement.MovementConfigs.ufo1); _this17.soundPlayed = false; return _this17; } _inherits(UFO1, _GameObject16); return _createClass2(UFO1, [{ key: "update", value: function update() { _superPropGet(UFO1, "update", this, 3)([]); if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('ufo1').play(); this.soundPlayed = true; } } }]); }(GameObject); var UFO2 = /*#__PURE__*/function (_GameObject17) { function UFO2() { var _this18; _classCallCheck2(this, UFO2); _this18 = _callSuper(this, UFO2, ['ufo2']); _this18.type = 'ufo2'; _this18.movement = new GameObjectMovement(_this18, _this18.graphics, GameObjectMovement.MovementConfigs.ufo2); _this18.soundPlayed = false; return _this18; } _inherits(UFO2, _GameObject17); return _createClass2(UFO2, [{ key: "update", value: function update() { _superPropGet(UFO2, "update", this, 3)([]); if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('ufo1').play(); this.soundPlayed = true; } } }]); }(GameObject); var GameObjectMovement = /*#__PURE__*/function () { _defineProperty(GameObjectMovement, "MovementConfigs", { base: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: false, canFlip: true, moveSound: null, respawnTime: { min: 20000, max: 30000 }, screenWidth: 2048, screenHeight: 2732 }, bird1: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, ufo1: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, ufo2: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, jet1: { speed: 10, speedRange: 0, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: true, moveSound: 'jet1' }, cloud1: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, cloud2: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, 'grass-front': { speed: 0, speedRange: 0, arcAmplitude: 1.2, arcFrequency: 120, isVertical: false, moveSound: null, canFlip: false }, 'grass-back': { speed: 0, speedRange: 0, arcAmplitude: 0.8, arcFrequency: 150, isVertical: false, moveSound: null, canFlip: false } }); function GameObjectMovement(object, graphics) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; _classCallCheck2(this, GameObjectMovement); this.object = object; this.graphics = graphics; this.options = _objectSpread(_objectSpread({}, GameObjectMovement.defaultOptions), options); this.speed = this.options.speed + Math.random() * this.options.speedRange; this.direction = Math.random() < 0.5 ? 1 : -1; this.lastX = this.object.x; this.lastY = this.object.y; this.soundPlayed = false; this.soundTimer = null; this.movementOffset = Math.random() * Math.PI * 2; // Random starting phase for smoother movement } return _createClass2(GameObjectMovement, [{ key: "update", value: function update() { if (!this.object || this.object.destroyed) { this.cleanup(); return; } var _this$object = this.object, currentX = _this$object.x, currentY = _this$object.y, width = _this$object.width, height = _this$object.height; var halfWidth = width / 2; var _this$options = this.options, isVertical = _this$options.isVertical, arcFrequency = _this$options.arcFrequency, arcAmplitude = _this$options.arcAmplitude, screenWidth = _this$options.screenWidth, screenHeight = _this$options.screenHeight; if (isVertical) { this.object.y += this.speed; // Enhanced sinusoidal movement with optimized calculations var phaseOffset = currentY / arcFrequency + this.movementOffset; this.object.x += Math.sin(phaseOffset) * arcAmplitude; if (currentY > screenHeight + height) { this.cleanup(); return; } } else { // Optimized horizontal movement with wave pattern this.object.x += this.speed * this.direction; if (arcAmplitude > 0) { var phaseOffset = currentX / arcFrequency + this.movementOffset; this.object.y += Math.sin(phaseOffset) * (arcAmplitude * 0.5); } var isOutOfBounds = currentX <= screenWidth + halfWidth && this.object.x > screenWidth + halfWidth || currentX >= -halfWidth && this.object.x < -halfWidth; if (isOutOfBounds) { this.cleanup(); return; } } if (this.options.canFlip) { flipImageVerticallyBasedOnDirection(this.graphics, currentX, this.object.x); } if (this.options.moveSound && !this.soundPlayed && this.object.x > 0 && this.object.x < this.options.screenWidth) { this.playMovementSound(); } this.lastX = this.object.x; this.lastY = this.object.y; } }, { key: "cleanup", value: function cleanup() { if (!this.object || this.object.destroyed) { return; } var moveSound = this.options.moveSound; var soundManager = game.soundManager, spawnManager = game.spawnManager; // Stop movement sound if active if (moveSound && soundManager) { soundManager.stopSound(moveSound); } // Destroy object and schedule respawn this.object.destroy(); if (spawnManager !== null && spawnManager !== void 0 && spawnManager.scheduleRespawn) { spawnManager.scheduleRespawn(this.object.type, this.object.constructor); } // Clear references this.object = null; this.soundTimer = null; this.soundPlayed = false; } }, { key: "playMovementSound", value: function playMovementSound() { var _this19 = this; var moveSound = this.options.moveSound; if (!moveSound || !game.soundManager) { return; } game.soundManager.playSound(moveSound, { volume: 0.1, interval: { min: 20000, max: 30000 }, onPlay: function onPlay() { _this19.soundPlayed = true; }, onStop: function onStop() { _this19.soundPlayed = false; _this19.soundTimer = null; } }); } }]); }(); _GameObjectMovement = GameObjectMovement; _defineProperty(GameObjectMovement, "MovementConfigs", { base: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: false, canFlip: true, moveSound: null, respawnTime: { min: 20000, max: 30000 }, screenWidth: 2048, screenHeight: 2732 }, bird1: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, ufo1: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, ufo2: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, jet1: { speed: 10, speedRange: 0, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: true, moveSound: 'jet1' }, cloud1: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, cloud2: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, 'grass-front': { speed: 0, speedRange: 0, arcAmplitude: 1.2, arcFrequency: 120, isVertical: false, moveSound: null, canFlip: false }, 'grass-back': { speed: 0, speedRange: 0, arcAmplitude: 0.8, arcFrequency: 150, isVertical: false, moveSound: null, canFlip: false } }); _defineProperty(GameObjectMovement, "defaultOptions", _GameObjectMovement.MovementConfigs.base); ; // Cloud class already defined above function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /***** * Layer Constants ******/ var LAYERS = { BACKGROUND: 0, SUN: 1, LIGHT1: 2, UFO2: 3, CLOUD1: 4, JET1: 5, CLOUD2: 6, UFO1: 7, BIRD1: 8, GRASS_BACK: 9, TREE: 10, STACK: 11, BIRD2: 12, MIRROR: 13, GRASS_FRONT: 14, CAT: 15, LASER: 16, RETICLE: 17 }; // Initialize LayerManager var layerManager = new LayerManager(); game.layerManager = layerManager; // Cloud management is now handled by SpawnManager // Initialize birds array for tracking var birds = []; var score = 0; var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; mirror.y = 2732 - 185 - 80 - 390 + 30 + 50; game.layerManager.addToLayer(mirror, LAYERS.MIRROR); game.mirror = mirror; var scoreDisplay = mirror; var soundManager = new SoundManager(); soundManager.initialize(); // Initialize spawn manager // Ensure all entities use LayerManager consistently function addEntityToLayer(entity, layer) { if (!entity || !layer) { console.error('Invalid entity or layer provided to addEntityToLayer'); return entity; } game.layerManager.addToLayer(entity, layer); if (!game.children.includes(entity)) { game.addChild(entity); } return entity; } var _SpawnManager = function SpawnManager() { this.spawnTimers = {}; this.spawnRules = { bird1: { max: 1, layer: LAYERS.BIRD1, movement: Bird1Movement, scoreValue: 5 }, bird2: { min: 3, max: 3, layer: LAYERS.BIRD2, movement: Bird2Movement, scoreValue: 1 }, cloud1: { min: 1, max: 3, layer: LAYERS.CLOUD1, movement: CloudMovement }, cloud2: { min: 1, max: 3, layer: LAYERS.CLOUD2, movement: CloudMovement }, // Ensure 3-5 total clouds ufo1: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.UFO1, movement: UFOMovement, sound: 'ufo1', scoreValue: 25 }, ufo2: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.UFO2, movement: UFOMovement, sound: 'ufo1', scoreValue: 25 }, jet1: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.JET1, movement: GameObjectMovement, sound: 'jet1' } }; // Initialize sound manager with ambient sounds configuration this.soundManager = new SoundManager({ ambient: { breeze1: { volume: 0.1, interval: { min: 15000, max: 25000 } }, cricket1: { volume: 0.1, interval: { min: 10000, max: 20000 } }, frog1: { volume: 0.1, interval: { min: 20000, max: 30000 } }, songbird1: { volume: 0.1, interval: { min: 15000, max: 25000 } } } }); this.scoreManager = new ScoreManager(); this.exclusiveGroups = [['ufo1', 'ufo2']]; // Correct layer order as per requirements this.layerOrder = game.layerManager.getLayerOrder(); this.spawnObject = function (type, Constructor, options) { var _this20 = this; var rule = this.spawnRules[type]; if (!rule) { return; } var count = this.objectCounts[type] || 0; var maxCount = rule.max || 1; // Early exit conditions if (count >= maxCount) { return; } // Check exclusive groups (UFO1 and UFO2) if (this.exclusiveGroups.some(function (group) { if (group.includes(type)) { return group.some(function (groupType) { return _this20.objectCounts[groupType] > 0; }); } return false; })) { return; } // Handle minimum count requirements if (rule.min && count < rule.min) { while (count < rule.min) { this.createObject(type, Constructor, rule); count++; } return; } // Ensure proper cloud count (3-5 total) if (type === 'cloud1' || type === 'cloud2') { var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds >= 5) { return; } if (totalClouds < 3) { while (totalClouds < 3) { this.createObject(type, Constructor, rule); totalClouds++; } return; } } // Ensure proper bird counts if (type === 'bird1' && count >= 1) { return; } // Max 1 bird1 if (type === 'bird2' && count >= 3) { return; } // Max 3 bird2 // Create object with respawn timer for specific types this.createObject(type, Constructor, rule); if (rule.respawnTime) { var respawnDelay = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min; this.spawnTimers[type] = LK.setTimeout(function () { delete _this20.spawnTimers[type]; _this20.spawnObject(type, Constructor, options); }, respawnDelay); } }; this.createObject = function (type, Constructor, rule) { if (!Constructor || !rule) { return null; } var obj = new Constructor(); obj.type = type; // Initialize position based on object type var screenWidth = 2048; var screenHeight = 2732; var isVerticalMovement = type.startsWith('bird'); obj.x = isVerticalMovement ? Math.random() * screenWidth : Math.random() < 0.5 ? screenWidth + obj.width / 2 : -obj.width / 2; obj.y = isVerticalMovement ? -obj.height : Math.random() * (screenHeight / 2); // Add to appropriate layer using addEntityToLayer addEntityToLayer(obj, rule.layer); // Initialize movement with appropriate options if (rule.movement) { // Get movement configuration based on object type var params = GameObjectMovement.MovementConfigs[type] || GameObjectMovement.MovementConfigs.base; // Create movement options with the selected parameters var movementOptions = _objectSpread(_objectSpread({}, params), {}, { moveSound: rule.sound || params.moveSound, respawnTime: rule.respawnTime }); obj.movement = new rule.movement(obj, obj.children[0], movementOptions); } if (rule.respawnTime) { this.scheduleRespawn(type, Constructor); } return obj; }; this.scheduleRespawn = function (type, Constructor) { if (!type || !Constructor || !this.spawnRules) { return; } var rule = this.spawnRules[type]; if (!rule) { return; } // Ensure respawn timers for ufo1, ufo2, and jet1 are set to 20-30 seconds var respawnTime; if (type === 'ufo1' || type === 'ufo2' || type === 'jet1') { respawnTime = Math.random() * 10000 + 20000; // 20-30 seconds } else if (rule.respawnTime) { respawnTime = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min; } else { respawnTime = Math.random() * 10000 + 5000; // Default 5-15 seconds } // Clear existing timer if present if (this.spawnTimers[type]) { LK.clearTimeout(this.spawnTimers[type]); this.spawnTimers[type] = null; } // Initialize object counts if not present if (!this.objectCounts[type]) { this.objectCounts[type] = 0; } this.spawnTimers[type] = LK.setTimeout(function () { // Cleanup timer reference delete this.spawnTimers[type]; // Update object count if (this.objectCounts[type] > 0) { this.objectCounts[type]--; } var shouldSpawn = true; // Check exclusive groups (e.g., only one UFO type at a time) if (this.exclusiveGroups) { for (var i = 0; i < this.exclusiveGroups.length; i++) { var group = this.exclusiveGroups[i]; if (group && group.includes(type)) { var groupTotal = 0; for (var j = 0; j < group.length; j++) { groupTotal += this.objectCounts[group[j]] || 0; } if (groupTotal > 0) { shouldSpawn = false; break; } } } } if (shouldSpawn) { this.spawnObject(type, Constructor); } else { // Reschedule spawn attempt if blocked by exclusive group this.scheduleRespawn(type, Constructor); } }.bind(this), respawnTime); // Start the game var spawnManager = new _SpawnManager(); spawnManager.initialize(); 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; 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 and layer ordering LK.setInterval(function () { // Update layer ordering game.layerManager.getLayerOrder().forEach(function (layerId, index) { var objects = game.layerManager.getObjectsInLayer(layerId); objects.forEach(function (obj) { game.layerManager.setLayerIndex(obj, index); }); }.bind(this)); // Maintain bird counts if (game.layerManager.getLayerEntityCount(LAYERS.BIRD1) < 1) { this.spawnObject('bird1', Bird1); } while (game.layerManager.getLayerEntityCount(LAYERS.BIRD2) < 3) { this.spawnObject('bird2', Bird2); } // Maintain cloud counts - ensure 3-5 total clouds var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds < 3) { var cloudsNeeded = 3 - totalClouds; for (var i = 0; i < cloudsNeeded; i++) { if (Math.random() < 0.5 && game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) < this.spawnRules.cloud1.max) { this.spawnObject('cloud1', Cloud); } else if (game.layerManager.getLayerEntityCount(LAYERS.CLOUD2) < this.spawnRules.cloud2.max) { 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 (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) { if (Math.random() < 0.5) { this.spawnObject('ufo1', UFO1); } else { this.spawnObject('ufo2', UFO2); } } // Ensure one jet is on screen if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) { this.spawnObject('jet1', Jet1); } }.bind(this), 1000); }.bind(this); }; var spawnManager = new _SpawnManager(); // Initialize the spawn manager _SpawnManager.prototype.initialize = function () { // Initialize sound and score managers this.soundManager.initialize(); // Set up initial spawns with consistent behavior this.spawnObject('bird1', Bird1); for (var i = 0; i < this.spawnRules.bird2.min; i++) { this.spawnObject('bird2', Bird2); } }; // Set up cloud spawning - 3-5 total clouds var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3; 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); } // Schedule initial UFO and Jet spawns if (Math.random() < 0.5) { this.spawnObject('ufo1', UFO1); } else { this.spawnObject('ufo2', UFO2); } this.spawnObject('jet1', Jet1); // Set up periodic checks for maintaining entity counts LK.setInterval(function () { // Maintain bird counts if (this.objectCounts.bird1 < 1) { this.spawnObject('bird1', Bird1); } while (this.objectCounts.bird2 < 3) { this.spawnObject('bird2', Bird2); } // Maintain cloud counts (3-5 total) var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds < 3) { var type = Math.random() < 0.5 ? 'cloud1' : 'cloud2'; this.spawnObject(type, Cloud); } // Ensure one UFO (either UFO1 or UFO2) is scheduled if (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) { var ufoType = Math.random() < 0.5 ? 'ufo1' : 'ufo2'; this.scheduleRespawn(ufoType, ufoType === 'ufo1' ? UFO1 : UFO2); } // Ensure one Jet1 is scheduled if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) { this.scheduleRespawn('jet1', Jet1); } }.bind(this), 1000); }; 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 (game.layerManager.isInLayer(entity, LAYERS.BIRD1) || game.layerManager.isInLayer(entity, LAYERS.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 using SpawnManager spawnManager.spawnObject('bird1', Bird1); spawnManager.spawnObject('bird2', Bird2); // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); }; // Removed redundant checkAndRespawnBirds function as it's handled by SpawnManager // Update bird positions and states function updateGameBirds() { maintainBirdCount(Bird1, 1, LAYERS.BIRD1); maintainBirdCount(Bird2, 3, LAYERS.BIRD2); } function maintainBirdCount(BirdType, targetCount, layerIndex) { var birdCount = game.layerManager.getLayerGroup('birds').length; if (birdCount < targetCount) { for (var i = 0; i < targetCount - birdCount; i++) { var newBird = new BirdType(); newBird.x = Math.random() * 2048; newBird.y = Math.random() * (2732 / 2); newBird.speed = 1 + Math.random() * 0.6; game.layerManager.addToLayer(newBird, layerIndex); birds.push(newBird); } } else if (birdCount > targetCount) { var extraBirds = birds.filter(function (b) { return game.layerManager.isInLayer(b, 'birds'); }).slice(targetCount); extraBirds.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } } // Update existing birds birds.forEach(function (bird) { bird.update(); if (bird.lastY <= 2732 && bird.y > 2732) { bird.y = -bird.height; bird.x = Math.random() * 2048; bird.speed = 1 + Math.random() * 0.6; } }); // Maintain bird counts maintainBirdCount(Bird1, 1, LAYERS.BIRD1); maintainBirdCount(Bird2, 3, LAYERS.BIRD2); // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); // Add a tree to the game var tree = addEntityToLayer(new Tree(), LAYERS.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 = addEntityToLayer(new Stack1(), LAYERS.STACK); 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 } 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 addEntityToLayer(scoreDisplay, LAYERS.UI); 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.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Add mirror to the proper layer if (game.children.includes(mirror)) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer } // Function to handle bgm1 end event function onBgm1End() { // Set a timer to replay bgm1 after 50-80 seconds var bgmTimer = LK.setTimeout(function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = addEntityToLayer(new Cat(), LAYERS.CAT); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Add cat to the proper layer if (game.children.includes(cat)) { game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer } // Play bgm1 once on load and set a timer to replay it every 20-30 seconds LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: onEnd }); }, Math.random() * 10000 + 20000); } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Sound volumes configuration // Initialize random timers for each sound to play between 20-30 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); } sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000); }, Math.random() * 10000 + 20000); }); // 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); }; }; 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(graphics) { ; this.graphics = graphics; this.pulseTimer = null; this.startPulsating = function () { var self = this; var brightness = 1.0; var direction = 1; this.pulseTimer = LK.setInterval(function () { brightness += direction * 0.05; if (brightness >= 2.0) { direction = -1; brightness = 2.0; } else if (brightness <= 1.0) { direction = 1; brightness = 1.0; } self.graphics.brightness = brightness; }, 50); }; this.stopPulsating = function () { if (this.pulseTimer) { LK.clearInterval(this.pulseTimer); } }; }; var bird2; // Define bird2 variable in the global scope // UFOMovement class to handle UFO movement var UFOMovement = function UFOMovement(ufo, ufoGraphics) { return new GameObjectMovement(ufo, ufoGraphics, { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, canFlip: true, moveSound: 'ufo1' }); }; ; 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) { return new GameObjectMovement(bird, birdGraphics, { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, canFlip: true, moveSound: 'wings1' }); }; // Bird2 movement is handled by MovementConfigs.bird2 var Bird2Effects = function Bird2Effects(bird) { ; this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; var ReticlePulse = function ReticlePulse(reticleGraphics) { return new Pulse(reticleGraphics, { minScale: 0.9, maxScale: 1.3, expandDuration: 800, contractDuration: 1200 }); }; // 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 }; }; // Bird2 spawning is now handled by SpawnManager // 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 = /*#__PURE__*/function () { function ScoreManager() { _classCallCheck2(this, ScoreManager); this.currentScore = 0; this.highScore = storage.highScore || 0; this.scoreValues = { bird1: 100, bird2: 50, ufo1: 250, ufo2: 250 }; } return _createClass2(ScoreManager, [{ key: "updateDisplays", value: function updateDisplays() { var _scoreDisplay, _mirror; if ((_scoreDisplay = scoreDisplay) !== null && _scoreDisplay !== void 0 && _scoreDisplay.updateScore) { scoreDisplay.updateScore(this.currentScore); } if ((_mirror = mirror) !== null && _mirror !== void 0 && _mirror.updateScore) { mirror.updateScore(this.currentScore); } } }, { key: "addScore", value: function addScore(objectType) { var points = this.scoreValues[objectType] || 0; if (points > 0) { this.currentScore += points; if (this.currentScore > this.highScore) { this.highScore = this.currentScore; storage.highScore = this.highScore; } this.updateDisplays(); } return this.currentScore; } }, { key: "resetScore", value: function resetScore() { this.currentScore = 0; this.updateDisplays(); return this.currentScore; } }, { key: "getScore", value: function getScore() { return this.currentScore; } }, { key: "getHighScore", value: function getHighScore() { return this.highScore; } }]); }(); ; 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 = addEntityToLayer(new 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); addEntityToLayer(laser, LAYERS.LASER); }; var VOLUME_BGM1 = 0.02; var VOLUME_BREEZE1 = 0.02; var VOLUME_CRICKET1 = 0.02; var VOLUME_FROG1 = 0.02; var VOLUME_SONGBIRD1 = 0.02; var VOLUME_UFO1 = 0.02; var VOLUME_WINGS1 = 0.02; game.move = function (x, y, obj) { if (!game.reticle) { game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE); } if (obj.event) { x = obj.event.x; y = obj.event.y; } game.reticle.x = x; game.reticle.y = y; }; // Add a sun to the game in the top left corner var sun = new Sun(); sun.x = 480; sun.y = 680; game.layerManager.addToLayer(sun, LAYERS.SUN); var light1 = new Light1(); light1.x = 510; light1.y = 1500; game.layerManager.addToLayer(light1, LAYERS.LIGHT1); light1.visible = true; // Function to add a UFO to the game // Using existing CLOUD_TYPES definition // initializeClouds already called earlier var bird1; // Define bird1 variable in the global scope var bird; // Define bird variable in the global scope var ufo; // Define the ufo variable in the global scope var laser; // Define the laser variable in the global scope var ufoTimer = LK.setTimeout(function () { addUFO(); // Reset the timer for the UFO to reappear between 10-20 seconds ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000); }, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds // Helper functions for game update function updateEntityPositions() { game.children.forEach(function (entity) { if (entity.update) { entity.update(); } // Handle off-screen objects if (game.layerManager.isInLayer(entity, 'birds') && entity.y > 2732) { entity.y = -entity.height; entity.x = Math.random() * 2048; } }); } function handleCollisions() { var projectiles = game.layerManager.getLayerEntities('projectiles'); projectiles.forEach(function (laser) { laser.update(); checkLaserCollisions(laser); }); } function checkLaserCollisions(laser) { var enemies = game.layerManager.getLayerEntities('enemies'); enemies.forEach(function (target) { if (!laser.lastIntersecting && AABBIntersect(laser, target)) { handleCollisionPoints(laser, target); } }); laser.lastIntersecting = enemies.some(function (target) { return laser.intersects(target); }); } function handleCollisionPoints(laser, target) { var soundEffect = ''; var targetType = ''; if (target instanceof Bird1) { soundEffect = 'dead1'; targetType = 'bird1'; spawnManager.objectCounts.bird1--; } else if (target instanceof Bird2) { soundEffect = 'dead2'; targetType = 'bird2'; spawnManager.objectCounts.bird2--; } else if (target instanceof UFO1 || target instanceof UFO2) { soundEffect = 'dead3'; targetType = target instanceof UFO1 ? 'ufo1' : 'ufo2'; spawnManager.objectCounts[targetType]--; } if (targetType) { game.scoreManager.addScore(targetType); LK.getSound(soundEffect).play(); target.destroy(); laser.destroy(); } game.update = function () { updateEntityPositions(); handleCollisions(); if (ufo) { ufo.customUpdate(); // 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; } }; // Update existing birds game.children.forEach(function (bird) { if (game.layerManager.isInLayer(bird, 'birds')) { if (bird.y > 2732) { bird.y = -bird.height; bird.x = Math.random() * 2048; } } }); } // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); // Add a tree to the game var tree = addEntityToLayer(new Tree(), LAYERS.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 = addEntityToLayer(new Stack1(), LAYERS.STACK); 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 } 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 addEntityToLayer(scoreDisplay, LAYERS.UI); 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.layerManager.addToLayer(mirror, LAYERS.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 = addEntityToLayer(new Cat(), LAYERS.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); }); // Initialize EntityManager var entityManager = new EntityManager(); // Initial entity spawning will be handled by the managers 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'); } // Ensure timers for ambient sounds and bgm1 are set to repeat every 20-30 seconds function initializeAmbientSounds() { var _playAmbientSounds = 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 } function initializeBGM() { var playBGM = function playBGM() { LK.playMusic('bgm1'); }; playBGM(); // Set regular interval for background music LK.setInterval(playBGM, 25000); // Average of 20-30 seconds } // 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; } if (!game.reticle) { game.reticle = addEntityToLayer(new 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); addEntityToLayer(laser, LAYERS.LASER); }; // Adjust layer display order // Ensure light1 layer is displayed after background if (light1) { game.layerManager.addToLayer(light1, LAYERS.LIGHT1); } // Ensure jet layer is displayed before cloud2 layer if (jet) { game.layerManager.addToLayer(jet, LAYERS.JET1); } // Ensure mirror layer is displayed behind grass-front if (mirror) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); } // Ensure jet1 and ufo1 sounds play when on screen Jet1.prototype.update = function () { // Fix: Use 'this' instead of 'self' since this is a prototype method var jetGraphics = this.children[0]; flipImageVerticallyBasedOnDirection(jetGraphics, this.lastX, this.x); this.x += this.speed * this.direction; // Play jet sound when on screen if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('jet1').play(); this.soundPlayed = true; } // Stop sound and destroy when off screen if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { LK.getSound('jet1').stop(); this.destroy(); game.jet = null; // Use spawn manager to handle respawn if (game.spawnManager) { game.spawnManager.scheduleRespawn('jet1', Jet1); } } this.lastX = this.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(); } this.lastX = this.x; };
===================================================================
--- original.js
+++ change.js
@@ -18,9 +18,102 @@
****/
// Modern ES6 class implementation for game object movement
// Unified GameObjectMovement class with improved movement patterns and sound management
// Base GameObject class to handle common functionality
-var _GameObjectMovement;
+var _GameObjectMovement = {
+ MovementConfigs: {
+ base: {
+ speed: 2,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: false,
+ canFlip: true,
+ moveSound: null,
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ screenWidth: 2048,
+ screenHeight: 2732
+ },
+ bird1: {
+ speed: 2,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: true,
+ moveSound: 'wings1'
+ },
+ bird2: {
+ speed: 2.5,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: true,
+ moveSound: 'wings1'
+ },
+ ufo1: {
+ speed: 3.2,
+ speedRange: 0.8,
+ arcAmplitude: 4.5,
+ arcFrequency: 80,
+ isVertical: false,
+ moveSound: 'ufo1'
+ },
+ ufo2: {
+ speed: 3.2,
+ speedRange: 0.8,
+ arcAmplitude: 4.5,
+ arcFrequency: 80,
+ isVertical: false,
+ moveSound: 'ufo1'
+ },
+ jet1: {
+ speed: 10,
+ speedRange: 0,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: true,
+ moveSound: 'jet1'
+ },
+ cloud1: {
+ speed: 0.25,
+ speedRange: 0.55,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: false
+ },
+ cloud2: {
+ speed: 0.25,
+ speedRange: 0.55,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: false
+ },
+ 'grass-front': {
+ speed: 0,
+ speedRange: 0,
+ arcAmplitude: 1.2,
+ arcFrequency: 120,
+ isVertical: false,
+ moveSound: null,
+ canFlip: false
+ },
+ 'grass-back': {
+ speed: 0,
+ speedRange: 0,
+ arcAmplitude: 0.8,
+ arcFrequency: 150,
+ isVertical: false,
+ moveSound: null,
+ canFlip: false
+ }
+ }
+};
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
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