User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var _GameObjectMovement = _defineProperty2({' Line Number: 92
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var _GameObjectMovement = _defineProperty2({' Line Number: 92
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var _GameObjectMovement = _defineProperty2({' Line Number: 92
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1107
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addToLayer')' in or related to this line: 'game.layerManager.addToLayer(sun, LAYERS.SUN);' Line Number: 1715
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addToLayer')' in or related to this line: 'game.layerManager.addToLayer(sun, LAYERS.SUN);' Line Number: 1715
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addToLayer')' in or related to this line: 'game.layerManager.addToLayer(sun, LAYERS.SUN);' Line Number: 1715
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addToLayer')' in or related to this line: 'game.layerManager.addToLayer(sun, LAYERS.SUN);' Line Number: 1715
User prompt
Please fix the bug: 'screenWidth is not defined' in or related to this line: 'grassFront.x = screenWidth / 2;' Line Number: 1168
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'MovementConfigs')' in or related to this line: 'GameObjectMovement.MovementConfigs = {' Line Number: 58
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var configs = GameObjectMovement.MovementConfigs || {};' Line Number: 1041
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Initialize Game ****/ // Initialize game var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var _GameObjectMovement; GameObjectMovement.MovementConfigs = { bird1: { speed: 2, speedRange: 1, arcEnabled: true, arcAmplitude: 50, arcFrequency: 100, canFlip: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.5, arcEnabled: true, arcAmplitude: 60, arcFrequency: 120, canFlip: true, moveSound: 'wings1' }, cloud1: { speed: 0.5, speedRange: 0.2, arcEnabled: false, canFlip: false }, cloud2: { speed: 0.6, speedRange: 0.3, arcEnabled: false, canFlip: false }, jet1: { speed: 5, speedRange: 2, arcEnabled: false, canFlip: true, moveSound: 'jet1' }, ufo1: { speed: 3, speedRange: 1, arcEnabled: true, arcAmplitude: 30, arcFrequency: 80, canFlip: true, moveSound: 'ufo1' }, ufo2: { speed: 3.5, speedRange: 1.5, arcEnabled: true, arcAmplitude: 40, arcFrequency: 90, canFlip: true, moveSound: 'ufo1' } }; var _excluded = ["interval"]; 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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) { return; } f = !1; } else { for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) { return; } } finally { if (o) { throw n; } } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) { return r; } } 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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) { return e; } if (void 0 !== e) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) { return Array.from(r); } } function _arrayWithoutHoles(r) { if (Array.isArray(r)) { return _arrayLikeToArray(r); } } function _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 _objectWithoutProperties(e, t) { if (null == e) { return {}; } var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) { o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) { return {}; } var t = {}; for (var n in r) { if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) { continue; } t[n] = r[n]; } } return t; } 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 _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 _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, 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 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, UI: 18 }; function AABBIntersect(obj1, obj2) { if (!(obj1 !== null && obj1 !== void 0 && obj1.x) || !(obj2 !== null && obj2 !== void 0 && obj2.x) || !(obj1 !== null && obj1 !== void 0 && obj1.y) || !(obj2 !== null && obj2 !== void 0 && obj2.y) || !obj1.active || !obj2.active) { return false; } var getDimensions = function getDimensions(obj) { var _obj$graphics, _obj$graphics2; var width = obj.width || ((_obj$graphics = obj.graphics) === null || _obj$graphics === void 0 ? void 0 : _obj$graphics.width) || 0; var height = obj.height || ((_obj$graphics2 = obj.graphics) === null || _obj$graphics2 === void 0 ? void 0 : _obj$graphics2.height) || 0; return { width: width, height: height }; }; var dim1 = getDimensions(obj1); var dim2 = getDimensions(obj2); var bounds1 = { left: obj1.x - dim1.width / 2, right: obj1.x + dim1.width / 2, top: obj1.y - dim1.height / 2, bottom: obj1.y + dim1.height / 2 }; var bounds2 = { left: obj2.x - dim2.width / 2, right: obj2.x + dim2.width / 2, top: obj2.y - dim2.height / 2, bottom: obj2.y + dim2.height / 2 }; return bounds1.right > bounds2.left && bounds1.left < bounds2.right && bounds1.bottom > bounds2.top && bounds1.top < bounds2.bottom; } var SoundManager = /*#__PURE__*/function () { function SoundManager() { _classCallCheck(this, SoundManager); this.soundConfig = this._initSoundConfig(); this.soundResources = { timers: new Map(), callbacks: new Map(), intervals: new Map() }; this.masterVolume = 1.0; } return _createClass(SoundManager, [{ key: "_validateVolume", value: function _validateVolume(volume) { var validatedVolume = Number(volume); return !isNaN(validatedVolume) && validatedVolume >= 0 && validatedVolume <= 1 ? validatedVolume : SoundManager.DEFAULT_VOLUME; } }, { key: "_initSoundConfig", value: function _initSoundConfig() { var baseConfig = { volume: SoundManager.DEFAULT_VOLUME }; var configs = _defineProperty(_defineProperty(_defineProperty({}, SoundManager.SOUND_TYPES.AMBIENT, _objectSpread(_objectSpread({}, baseConfig), SoundManager.DEFAULT_DELAY)), SoundManager.SOUND_TYPES.BACKGROUND, _objectSpread(_objectSpread({}, baseConfig), {}, { isMusic: true, loop: true })), SoundManager.SOUND_TYPES.EFFECT, _objectSpread({}, baseConfig)); return _defineProperty(_defineProperty(_defineProperty({}, SoundManager.SOUND_TYPES.AMBIENT, { sounds: ['songbird1', 'cricket1', 'breeze1', 'frog1', 'chitter'].map(function (id) { return _objectSpread({ id: id }, configs[SoundManager.SOUND_TYPES.AMBIENT]); }) }), SoundManager.SOUND_TYPES.BACKGROUND, { sounds: [_objectSpread({ id: 'bgm1' }, configs[SoundManager.SOUND_TYPES.BACKGROUND])] }), SoundManager.SOUND_TYPES.EFFECT, _objectSpread({ sounds: { ufo1: 'ufo1', ufo2: 'ufo1', laser: 'laser1', jet: 'jet1', jet2: 'jet2', dead1: 'dead1', dead2: 'dead2', dead3: 'dead3', wings: 'wings1' } }, configs[SoundManager.SOUND_TYPES.EFFECT])); } }, { key: "_cleanupSound", value: function _cleanupSound(soundId) { var _callback$onStop; if (!soundId) { return; } var sound = LK.getSound(soundId); if (sound !== null && sound !== void 0 && sound.playing) { sound.stop(); } if (LK.isMusicPlaying(soundId)) { LK.stopMusic(soundId); } var resources = this.soundResources; [resources.timers, resources.intervals].forEach(function (collection) { var timerId = collection.get(soundId); if (timerId) { collection === resources.timers ? LK.clearTimeout(timerId) : LK.clearInterval(timerId); collection["delete"](soundId); } }); var callback = resources.callbacks.get(soundId); callback === null || callback === void 0 || (_callback$onStop = callback.onStop) === null || _callback$onStop === void 0 || _callback$onStop.call(callback); resources.callbacks["delete"](soundId); } }, { key: "_handleAutoRestart", value: function _handleAutoRestart(soundId, _ref2) { var _this = this; var interval = _ref2.interval, options = _objectWithoutProperties(_ref2, _excluded); var _ref3 = interval || {}, min = _ref3.min, max = _ref3.max; if (!min || !max || max <= min) { return; } var delay = Math.random() * (max - min) + min; this.soundResources.timers.set(soundId, LK.setTimeout(function () { return _this._playSound(soundId, options); }, delay)); } }, { key: "_playSound", value: function _playSound(soundId, options) { if (!soundId) { return null; } var volume = this._validateVolume(options.volume); var sound = LK.getSound(soundId); if (!sound) { this.soundResources.callbacks["delete"](soundId); return null; } try { options.isMusic ? LK.playMusic(soundId, { volume: volume }) : Object.assign(sound, { volume: volume, loop: options.loop || false }).play(); options.autoRestart && this._handleAutoRestart(soundId, options); return sound; } catch (e) { this.soundResources.callbacks["delete"](soundId); return null; } } }, { key: "playSound", value: function playSound(soundId) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (!soundId) { return null; } var existingCallback = this.soundResources.callbacks.get(soundId); if (existingCallback !== null && existingCallback !== void 0 && existingCallback.isPlaying) { return null; } this.stopSound(soundId); var mergedOptions = _objectSpread({ volume: SoundManager.DEFAULT_VOLUME, loop: false, isMusic: false, isPlaying: true }, options); this.soundResources.callbacks.set(soundId, mergedOptions); var sound = this._playSound(soundId, mergedOptions); if (!sound) { mergedOptions.isPlaying = false; } return sound; } }, { key: "playEffectSound", value: function playEffectSound(effectType) { var _this$soundConfig$Sou; if (!effectType || !((_this$soundConfig$Sou = this.soundConfig[SoundManager.SOUND_TYPES.EFFECT]) !== null && _this$soundConfig$Sou !== void 0 && _this$soundConfig$Sou.sounds[effectType])) { return null; } return this.playSound(this.soundConfig[SoundManager.SOUND_TYPES.EFFECT].sounds[effectType], { volume: this.soundConfig[SoundManager.SOUND_TYPES.EFFECT].volume }); } }, { key: "stopSound", value: function stopSound(soundId) { return soundId ? (this._cleanupSound(soundId), true) : false; } }, { key: "setMasterVolume", value: function setMasterVolume(volume) { var newVolume = this._validateVolume(volume); return newVolume !== undefined && (this.masterVolume = newVolume, true); } }, { key: "playAmbientSounds", value: function playAmbientSounds() { var _this2 = this; this.soundConfig[SoundManager.SOUND_TYPES.AMBIENT].sounds.forEach(function (sound) { return _this2.playSound(sound.id, { volume: sound.volume, autoRestart: true, interval: { min: sound.min, max: sound.max } }); }); } }, { key: "playBackgroundMusic", value: function playBackgroundMusic() { var _this3 = this; this.soundConfig[SoundManager.SOUND_TYPES.BACKGROUND].sounds.forEach(function (sound) { return _this3.playSound(sound.id, { volume: sound.volume, isMusic: true, loop: true }); }); } }, { key: "stopAllSounds", value: function stopAllSounds() { var _this4 = this; var allSoundIds = new Set([].concat(_toConsumableArray(this.soundResources.timers.keys()), _toConsumableArray(this.soundResources.callbacks.keys()), _toConsumableArray(this.soundResources.intervals.keys()), _toConsumableArray(this.soundConfig[SoundManager.SOUND_TYPES.AMBIENT].sounds.map(function (s) { return s.id; })), _toConsumableArray(this.soundConfig[SoundManager.SOUND_TYPES.BACKGROUND].sounds.map(function (s) { return s.id; })), _toConsumableArray(Object.values(this.soundConfig[SoundManager.SOUND_TYPES.EFFECT].sounds)))); allSoundIds.forEach(function (id) { return _this4._cleanupSound(id); }); this.soundResources.timers.clear(); this.soundResources.callbacks.clear(); this.soundResources.intervals.clear(); return true; } }]); }(); _defineProperty(SoundManager, "DEFAULT_VOLUME", 0.1); _defineProperty(SoundManager, "DEFAULT_DELAY", { min: 20000, max: 30000 }); _defineProperty(SoundManager, "SOUND_TYPES", { AMBIENT: 'ambient', BACKGROUND: 'background', EFFECT: 'effect' }); var Container = /*#__PURE__*/function () { function Container() { _classCallCheck(this, Container); this.children = []; } return _createClass(Container, [{ key: "attachAsset", value: function attachAsset(assetName, options) { if (!assetName) { return null; } var sprite = LK.getAsset(assetName, {}); if (!sprite) { return null; } if (options) { Object.assign(sprite, options); } return this.addChild(sprite); } }, { key: "addChild", value: function addChild(child) { if (!child || this.children.includes(child)) { return child; } this.children.push(child); return child; } }, { key: "destroy", value: function destroy() { if (!this.children) { return; } var processedChildren = new Set(); this.children.forEach(function (child) { if (child && child.destroy && !processedChildren.has(child)) { processedChildren.add(child); child.destroy(); } }); this.children = []; } }]); }(); var EntityManager = /*#__PURE__*/function () { function EntityManager() { _classCallCheck(this, EntityManager); this.entities = []; this.scheduledRemovals = []; } return _createClass(EntityManager, [{ key: "add", value: function add(entity) { if (!entity || this.entities.includes(entity)) { return; } this.entities.push(entity); this._updateSpawnCount(entity, 1); } }, { key: "remove", value: function remove(entity) { var _game$layerManager; if (!entity) { return; } this._cleanupEntityResources(entity); this._updateTracking(entity); this.entities = this.entities.filter(function (e) { return e !== entity; }); (_game$layerManager = game.layerManager) === null || _game$layerManager === void 0 || _game$layerManager.removeFromAllLayers(entity); } }, { key: "_cleanupEntityResources", value: function _cleanupEntityResources(entity) { var _entity$movement; if (!(entity !== null && entity !== void 0 && (_entity$movement = entity.movement) !== null && _entity$movement !== void 0 && _entity$movement.options)) { return; } if (entity.movement.options.moveSound) { var _game$soundManager; (_game$soundManager = game.soundManager) === null || _game$soundManager === void 0 || _game$soundManager.stopSound(entity.movement.options.moveSound); } if ((entity === null || entity === void 0 ? void 0 : entity.type) === 'bird') { var _game$soundManager2; (_game$soundManager2 = game.soundManager) === null || _game$soundManager2 === void 0 || _game$soundManager2.playEffectSound('wings'); } if (entity !== null && entity !== void 0 && entity.destroy) { entity.destroy(); } } }, { key: "_updateTracking", value: function _updateTracking(entity) { this._updateSpawnCount(entity, -1); } }, { key: "_updateSpawnCount", value: function _updateSpawnCount(entity, delta) { var _game$spawnManager; if (entity !== null && entity !== void 0 && entity.type && (_game$spawnManager = game.spawnManager) !== null && _game$spawnManager !== void 0 && _game$spawnManager.objectCounts) { var currentCount = game.spawnManager.objectCounts[entity.type] || 0; game.spawnManager.objectCounts[entity.type] = Math.max(0, currentCount + delta); } } }, { key: "update", value: function update(deltaTime) { var _this5 = this; this.entities.forEach(function (entity, i) { var _entity$update; if (!entity || entity.destroyed || entity.markedForRemoval) { _this5._scheduleForRemoval(entity, i); return; } (_entity$update = entity.update) === null || _entity$update === void 0 || _entity$update.call(entity, deltaTime); }); this._processScheduledRemovals(); } }, { key: "_scheduleForRemoval", value: function _scheduleForRemoval(entity, index) { if (!entity || this.scheduledRemovals.includes(index)) { return; } this._cleanupEntityResources(entity); this._updateTracking(entity); this.scheduledRemovals.push(index); } }, { key: "_processScheduledRemovals", value: function _processScheduledRemovals() { var _this6 = this; if (!this.scheduledRemovals) { this.scheduledRemovals = []; } this.scheduledRemovals.sort(function (a, b) { return b - a; }).forEach(function (index) { return _this6.entities.splice(index, 1); }); this.scheduledRemovals = []; } }, { key: "getEntitiesByType", value: function getEntitiesByType(type) { return type ? this.entities.filter(function (entity) { return (entity === null || entity === void 0 ? void 0 : entity.constructor) === type && !entity.destroyed; }) : []; } }, { key: "clear", value: function clear() { var _this7 = this; this.entities.forEach(function (entity) { _this7._cleanupEntityResources(entity); _this7._updateTracking(entity); LK.removeFromAllLayers(entity); }); this.entities = []; if (!game.spawnManager) { return; } var timers = game.spawnManager.spawnTimers || {}; Object.values(timers).forEach(LK.clearTimeout); game.spawnManager.spawnTimers = {}; game.spawnManager.objectCounts = Object.fromEntries(Object.keys(LAYERS).filter(function (key) { return typeof LAYERS[key] === 'number'; }).map(function (key) { return [key.toLowerCase(), 0]; })); } }, { key: "destroy", value: function destroy() { this.clear(); this.entities = null; } }]); }(); var GameObject = /*#__PURE__*/function (_Container) { function GameObject(assetName) { var _this8; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, GameObject); _this8 = _callSuper(this, GameObject); _this8.graphics = _this8.attachAsset(assetName, {}); return _this8; } _inherits(GameObject, _Container); return _createClass(GameObject, [{ key: "destroy", value: function destroy() { var _this$movement; if ((_this$movement = this.movement) !== null && _this$movement !== void 0 && _this$movement.cleanup) { this.movement.cleanup(); } _superPropGet(GameObject, "destroy", this, 3)([]); } }, { key: "_updateArcOffset", value: function _updateArcOffset(deltaTime) { if (!this.currentState || !this.options) { return; } if (!this.currentState.arcOffset || !this.options.arcEnabled || !this.options.arcAmplitude) { return; } this.currentState.arcOffset += deltaTime * (Math.PI * 2) / (this.options.arcFrequency || 100); } }, { key: "_calculateMovement", value: function _calculateMovement() { var _this$options, _this$options2, _this$options3; if (!this.currentState || !this.object || !this.graphics) { return { x: 0, y: 0 }; } if (!this.currentState.speed || !this.currentState.direction) { return { x: 0, y: 0 }; } var bounds = GameObjectMovement.CommonConfig.screenDimensions; var width = this.graphics.width || 0; var height = this.graphics.height || 0; // Calculate base movement var movement = { x: this.currentState.speed * this.currentState.direction, y: 0 }; // Apply arc movement if enabled if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.arcEnabled && (_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.arcAmplitude && this.currentState.arcOffset) { movement.y = Math.sin(this.currentState.arcOffset) * this.options.arcAmplitude; // Prevent object from moving outside vertical bounds var nextY = this.object.y + movement.y; if (nextY - height / 2 < 0) { movement.y = -this.object.y + height / 2; } else if (nextY + height / 2 > bounds.height) { movement.y = bounds.height - this.object.y - height / 2; } } // Prevent horizontal out-of-bounds for non-destroying objects if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.destroyOutOfBounds)) { var nextX = this.object.x + movement.x; if (nextX - width / 2 < 0) { movement.x = -this.object.x + width / 2; this.currentState.direction *= -1; } else if (nextX + width / 2 > bounds.width) { movement.x = bounds.width - this.object.x - width / 2; this.currentState.direction *= -1; } } return movement; } }, { key: "_applyMovement", value: function _applyMovement(movement) { var _this$options4; if (!movement || !this.object || !this.object.x || !this.object.y) { return; } var _movement$x = movement.x, x = _movement$x === void 0 ? 0 : _movement$x, _movement$y = movement.y, y = _movement$y === void 0 ? 0 : _movement$y; if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.isVertical) { this.object.y = this.object.y + x; this.object.x = this.object.x + y; } else { this.object.x = this.object.x + x; this.object.y = this.object.y + y; } } }, { key: "_checkBoundaries", value: function _checkBoundaries() { var _this$options5; if (!this.object || !this.graphics) { return; } var bounds = GameObjectMovement.CommonConfig.screenDimensions; var width = this.graphics.width || 0; var height = this.graphics.height || 0; // Check if object should be destroyed when out of bounds if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.destroyOutOfBounds) { var buffer = Math.max(width, height); if (this.object.x < -buffer || this.object.x > bounds.width + buffer || this.object.y < -buffer || this.object.y > bounds.height + buffer) { var _this$object$destroy, _this$object; (_this$object$destroy = (_this$object = this.object).destroy) === null || _this$object$destroy === void 0 || _this$object$destroy.call(_this$object); } } else { // Keep object within screen bounds this.object.x = Math.max(width / 2, Math.min(this.object.x, bounds.width - width / 2)); this.object.y = Math.max(height / 2, Math.min(this.object.y, bounds.height - height / 2)); } } }, { key: "_handleSoundTriggers", value: function _handleSoundTriggers() { var _this$options6, _this$currentState, _this$object2, _this$object3; if (!((_this$options6 = this.options) !== null && _this$options6 !== void 0 && _this$options6.moveSound) || (_this$currentState = this.currentState) !== null && _this$currentState !== void 0 && _this$currentState.soundPlayed) { return; } var bounds = this.options.soundTriggerBounds || GameObjectMovement.CommonConfig.soundTriggerBounds; if (((_this$object2 = this.object) === null || _this$object2 === void 0 ? void 0 : _this$object2.x) > bounds.min && ((_this$object3 = this.object) === null || _this$object3 === void 0 ? void 0 : _this$object3.x) < bounds.max) { var _game$soundManager3; (_game$soundManager3 = game.soundManager) === null || _game$soundManager3 === void 0 || _game$soundManager3.playEffectSound(this.options.moveSound); this.currentState.soundPlayed = true; } } }, { key: "_updateGraphics", value: function _updateGraphics() { var _this$options7, _this$currentState2, _this$object4; if (!((_this$options7 = this.options) !== null && _this$options7 !== void 0 && _this$options7.canFlip) || !this.graphics || !((_this$currentState2 = this.currentState) !== null && _this$currentState2 !== void 0 && _this$currentState2.direction) || !((_this$object4 = this.object) !== null && _this$object4 !== void 0 && _this$object4.x)) { return; } var isVertical = this.options.isVertical; if (isVertical && this.currentState.lastX !== undefined) { this.graphics.flipX = this.object.x < this.currentState.lastX; } else { this.graphics.flipX = this.currentState.direction < 0; } } }]); }(Container); var Background = /*#__PURE__*/function (_GameObject) { function Background() { _classCallCheck(this, Background); return _callSuper(this, Background, ['background']); } _inherits(Background, _GameObject); return _createClass(Background); }(GameObject); var Bird = /*#__PURE__*/function (_GameObject2) { function Bird(type) { var _this9; _classCallCheck(this, Bird); var validType = ['bird1', 'bird2'].includes(type) ? type : 'bird1'; _this9 = _callSuper(this, Bird, [validType]); _this9.type = validType; var config = GameObjectMovement.MovementConfigs[validType]; _this9.movement = config ? new GameObjectMovement(_this9, _this9.graphics, config) : null; _this9.soundPlayed = false; return _this9; } _inherits(Bird, _GameObject2); return _createClass(Bird, [{ key: "update", value: function update(deltaTime) { if (!this.active || !this.movement) { return; } _superPropGet(Bird, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }, { key: "destroy", value: function destroy() { var _game$soundManager4; this.movement = null; _superPropGet(Bird, "destroy", this, 3)([]); (_game$soundManager4 = game.soundManager) === null || _game$soundManager4 === void 0 || _game$soundManager4.playEffectSound('wings'); } }]); }(GameObject); var Cat = /*#__PURE__*/function (_GameObject3) { function Cat() { var _this10; _classCallCheck(this, Cat); _this10 = _callSuper(this, Cat, ['cat', { anchorX: 0.5, anchorY: 1 }]); _this10.type = 'cat'; return _this10; } _inherits(Cat, _GameObject3); return _createClass(Cat); }(GameObject); var ENTITY_TYPES = { CLOUD: ['cloud1', 'cloud2'], GRASS: ['grass-front', 'grass-back'] }; var EnvironmentEntity = /*#__PURE__*/function (_GameObject4) { function EnvironmentEntity(type) { var _this11; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, EnvironmentEntity); var defaultOptions = { anchorX: 0.5, anchorY: 0.5, alpha: type.startsWith('cloud') ? 0.8 : 1.0 }; _this11 = _callSuper(this, EnvironmentEntity, [type, _objectSpread(_objectSpread({}, defaultOptions), options)]); _this11.type = type; if (type && typeof type === 'string') { var configs = GameObjectMovement.MovementConfigs || {}; GameObjectMovement.MovementConfigs = GameObjectMovement.MovementConfigs || {}; var config = configs[type]; if (config) { _this11.movement = new GameObjectMovement(_this11, _this11.graphics, config); } } return _this11; } _inherits(EnvironmentEntity, _GameObject4); return _createClass(EnvironmentEntity, [{ key: "update", value: function update(deltaTime) { if (!this.active) { return; } if (this.movement && this.graphics) { this.movement.update(deltaTime); this._updateGraphics(); } } }, { key: "destroy", value: function destroy() { var _this$movement2, _this$graphics; this.active = false; if ((_this$movement2 = this.movement) !== null && _this$movement2 !== void 0 && _this$movement2.cleanup) { this.movement.cleanup(); this.movement = null; } if ((_this$graphics = this.graphics) !== null && _this$graphics !== void 0 && _this$graphics.destroy) { this.graphics.destroy(); this.graphics = null; } _superPropGet(EnvironmentEntity, "destroy", this, 3)([]); } }]); }(GameObject); var Cloud = /*#__PURE__*/function (_EnvironmentEntity) { function Cloud() { var _this12; _classCallCheck(this, Cloud); var cloudType = ENTITY_TYPES.CLOUD[Math.floor(Math.random() * ENTITY_TYPES.CLOUD.length)]; _this12 = _callSuper(this, Cloud, [cloudType]); _this12.type = cloudType; return _this12; } _inherits(Cloud, _EnvironmentEntity); return _createClass(Cloud, [{ key: "update", value: function update(deltaTime) { if (!this.active) { return; } _superPropGet(Cloud, "update", this, 3)([deltaTime]); } }]); }(EnvironmentEntity); var GrassLayer = /*#__PURE__*/function (_EnvironmentEntity2) { function GrassLayer(type) { _classCallCheck(this, GrassLayer); if (!ENTITY_TYPES.GRASS.includes(type)) { throw new Error("Invalid grass type: ".concat(type)); } return _callSuper(this, GrassLayer, [type]); } _inherits(GrassLayer, _EnvironmentEntity2); return _createClass(GrassLayer); }(EnvironmentEntity); var grassFront = new GrassLayer('grass-front'); grassFront.x = screenWidth / 2; grassFront.y = screenHeight - grassFront.height / 2; var grassBack = new GrassLayer('grass-back'); grassBack.x = LK.width / 2; grassBack.y = LK.height - 150; var Jet1 = /*#__PURE__*/function (_GameObject5) { function Jet1() { var _this13; _classCallCheck(this, Jet1); _this13 = _callSuper(this, Jet1, ['jet1']); _this13.type = 'jet1'; _this13.movement = new GameObjectMovement(_this13, _this13.graphics, GameObjectMovement.MovementConfigs[_this13.type]); _this13.soundPlayed = false; return _this13; } _inherits(Jet1, _GameObject5); return _createClass(Jet1, [{ key: "update", value: function update(deltaTime) { if (!this.active) { return; } _superPropGet(Jet1, "update", this, 3)([deltaTime]); if (!this.soundPlayed && this.isOnScreen()) { var _game$soundManager5; (_game$soundManager5 = game.soundManager) === null || _game$soundManager5 === void 0 || _game$soundManager5.playEffectSound('jet1'); this.soundPlayed = true; } } }, { key: "isOnScreen", value: function isOnScreen() { return this.x >= -this.width / 2 && this.x <= LK.width + this.width / 2; } }, { key: "destroy", value: function destroy() { if (this.soundPlayed) { var _game$soundManager6; (_game$soundManager6 = game.soundManager) === null || _game$soundManager6 === void 0 || _game$soundManager6.stopSound('jet1'); } _superPropGet(Jet1, "destroy", this, 3)([]); } }]); }(GameObject); var GameUtils = /*#__PURE__*/function () { function GameUtils() { _classCallCheck(this, GameUtils); } return _createClass(GameUtils, null, [{ key: "validateVolume", value: function validateVolume(volume) { if (!volume) { return null; } var parsed = typeof volume === 'string' ? parseFloat(volume) : volume; if (typeof parsed !== 'number' || isNaN(parsed)) { return null; } return Math.max(0, Math.min(1, parsed)); } }]); }(); var Laser = /*#__PURE__*/function (_Container2) { function Laser(startX, startY, targetX, targetY) { var _this14; _classCallCheck(this, Laser); _this14 = _callSuper(this, Laser); _this14.laserGraphics = _this14.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; _this14.vx = dx / distance * speed; _this14.vy = dy / distance * speed; _this14.x = startX; _this14.y = startY; _this14.lastIntersecting = false; _this14.active = true; LK.getSound('laser1').play(); return _this14; } _inherits(Laser, _Container2); return _createClass(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; } this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > 2048 || this.y < 0 || this.y > 2732) { this.destroy(); } } }]); }(Container); var PulseEffect = /*#__PURE__*/function () { function PulseEffect(graphics) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, PulseEffect); this.graphics = graphics; this.options = { minScale: options.minScale || 0.95, maxScale: options.maxScale || 1.05, duration: options.duration || 1000, easing: options.easing || 'easeInOutQuad' }; this.active = false; } return _createClass(PulseEffect, [{ key: "startPulsating", value: function startPulsating() { if (this.active) { return; } this.active = true; this._pulse(); } }, { key: "stopPulsating", value: function stopPulsating() { this.active = false; if (this.graphics) { this.graphics.scale = 1; } } }, { key: "_pulse", value: function _pulse() { var _this15 = this; if (!this.active || !this.graphics) { return; } var _this$options8 = this.options, minScale = _this$options8.minScale, maxScale = _this$options8.maxScale, duration = _this$options8.duration, easing = _this$options8.easing; tween.to(this.graphics, { scale: maxScale }, duration / 2, { ease: easing }).then(function () { return tween.to(_this15.graphics, { scale: minScale }, duration / 2, { ease: easing }); }).then(function () { return _this15._pulse(); }); } }], [{ key: "createPulse", value: function createPulse(type, graphics) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; switch (type) { case 'sun': return new ScalePulse(graphics, _objectSpread({ minScale: 0.95, maxScale: 1.05, speed: 0.02, interval: 40 }, options)); case 'light': return new BrightnessPulse(graphics, _objectSpread({ minBrightness: 0.9, maxBrightness: 1.1, speed: 0.05, interval: 40 }, options)); default: return new ScalePulse(graphics, options); } } }]); }(); var Light = /*#__PURE__*/function (_GameObject6) { function Light() { _classCallCheck(this, Light); return _callSuper(this, Light, ['light1', { anchorX: 0.5, anchorY: 0.5, brightness: 1.5 }]); } _inherits(Light, _GameObject6); return _createClass(Light); }(GameObject); var Sun = /*#__PURE__*/function (_GameObject7) { function Sun() { _classCallCheck(this, Sun); return _callSuper(this, Sun, ['sun', { anchorX: 0.5, anchorY: 0.5, brightness: 1.5 }]); } _inherits(Sun, _GameObject7); return _createClass(Sun); }(GameObject); var UFO = /*#__PURE__*/function (_GameObject8) { function UFO(type) { var _this16; _classCallCheck(this, UFO); if (!type || !['ufo1', 'ufo2'].includes(type)) { type = 'ufo1'; } var asset = LK.getAsset(type, {}); if (!asset) { type = 'ufo1'; } _this16 = _callSuper(this, UFO, [type]); _this16.type = type; _this16.movement = new GameObjectMovement(_this16, _this16.graphics, GameObjectMovement.MovementConfigs[type]); _this16.soundPlayed = false; return _this16; } _inherits(UFO, _GameObject8); return _createClass(UFO, [{ key: "update", value: function update(deltaTime) { if (!this.active || !this.movement) { return; } _superPropGet(UFO, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } if (!this.soundPlayed && this.isOnScreen()) { var _game$soundManager7; (_game$soundManager7 = game.soundManager) === null || _game$soundManager7 === void 0 || _game$soundManager7.playEffectSound('ufo1'); this.soundPlayed = true; } } }, { key: "isOnScreen", value: function isOnScreen() { return this.x >= -this.width / 2 && this.x <= LK.width + this.width / 2; } }, { key: "destroy", value: function destroy() { if (this.soundPlayed) { var _game$soundManager8; (_game$soundManager8 = game.soundManager) === null || _game$soundManager8 === void 0 || _game$soundManager8.stopSound(this.options.sound); } this.movement = null; _superPropGet(UFO, "destroy", this, 3)([]); } }]); }(GameObject); var GameInitializer = /*#__PURE__*/function () { function GameInitializer() { _classCallCheck(this, GameInitializer); this.game = null; this.initialized = false; } return _createClass(GameInitializer, [{ key: "initialize", value: function initialize(gameInstance) { if (this.initialized) { return; } this.game = gameInstance; // Initialize core systems this._initializeManagers(); this._setupGameState(); this._loadResources(); this.initialized = true; } }, { key: "_initializeManagers", value: function _initializeManagers() { // Initialize sound manager if not already present if (!this.game.soundManager) { this.game.soundManager = new SoundManager(); } // Initialize entity manager if not already present if (!this.game.entityManager) { this.game.entityManager = new EntityManager(); } // Initialize layer manager if not already present if (!this.game.layerManager) { this.game.layerManager = new LayerManager(); } } }, { key: "_setupGameState", value: function _setupGameState() { if (!this.game.state) { this.game.state = new GameState(); } this.game.state.reset(); } }, { key: "_loadResources", value: function _loadResources() { // Placeholder for resource loading logic // This would typically load textures, sounds, etc. } }]); }(); var GameState = /*#__PURE__*/function () { function GameState() { _classCallCheck(this, GameState); this.score = 0; this.isGameOver = false; this.isPaused = false; this.currentLevel = 1; } return _createClass(GameState, [{ key: "reset", value: function reset() { this.score = 0; this.isGameOver = false; this.isPaused = false; this.currentLevel = 1; } }]); }(); var BasePulse = /*#__PURE__*/function () { function BasePulse(graphics) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, BasePulse); if (!graphics || _typeof(graphics) !== 'object') { throw new Error('Graphics must be a valid object'); } if (typeof graphics.scale === 'undefined' && (typeof graphics.scaleX === 'undefined' || typeof graphics.scaleY === 'undefined') && typeof graphics.brightness === 'undefined') { throw new Error('Graphics object must have either scale, scaleX/scaleY, or brightness property'); } this.graphics = graphics; this.pulseTimer = null; this.options = Object.assign({ min: 1.0, max: 1.2, speed: 0.01, interval: 50 }, options); } return _createClass(BasePulse, [{ key: "startPulsating", value: function startPulsating() { var self = this; var value = this.options.min; var direction = 1; if (this.pulseTimer) { LK.clearInterval(this.pulseTimer); } this.pulseTimer = LK.setInterval(function () { value += direction * self.options.speed; if (value >= self.options.max) { direction = -1; value = self.options.max; } else if (value <= self.options.min) { direction = 1; value = self.options.min; } self.updateGraphics(value); }, this.options.interval); } }, { key: "stopPulsating", value: function stopPulsating() { if (this.pulseTimer) { LK.clearInterval(this.pulseTimer); } this.resetGraphics(); } }, { key: "updateGraphics", value: function updateGraphics(value) { if (!this.graphics) { return; } if (typeof this.graphics.scale !== 'undefined') { this.graphics.scale = value; } else if (typeof this.graphics.scaleX !== 'undefined' && typeof this.graphics.scaleY !== 'undefined') { this.graphics.scaleX = value; this.graphics.scaleY = value; } } }, { key: "resetGraphics", value: function resetGraphics() { if (!this.graphics) { return; } if (typeof this.graphics.scale !== 'undefined') { this.graphics.scale = this.options.min; } else if (typeof this.graphics.scaleX !== 'undefined' && typeof this.graphics.scaleY !== 'undefined') { this.graphics.scaleX = this.options.min; this.graphics.scaleY = this.options.min; } } }]); }(); var ScalePulse = /*#__PURE__*/function (_BasePulse) { function ScalePulse(graphics) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, ScalePulse); return _callSuper(this, ScalePulse, [graphics, Object.assign({}, options, { min: options.minScale || 1.0, max: options.maxScale || 1.2 })]); } _inherits(ScalePulse, _BasePulse); return _createClass(ScalePulse, [{ key: "updateGraphics", value: function updateGraphics(scale) { if (!this.graphics) { return; } if (typeof this.graphics.scale !== 'undefined') { this.graphics.scale = scale; } else if (typeof this.graphics.scaleX !== 'undefined' && typeof this.graphics.scaleY !== 'undefined') { this.graphics.scaleX = scale; this.graphics.scaleY = scale; } } }, { key: "resetGraphics", value: function resetGraphics() { this.updateGraphics(this.options.min); } }]); }(BasePulse); var BrightnessPulse = /*#__PURE__*/function (_BasePulse2) { function BrightnessPulse(graphics) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, BrightnessPulse); return _callSuper(this, BrightnessPulse, [graphics, Object.assign({}, options, { min: options.minBrightness || 1.0, max: options.maxBrightness || 2.0, speed: 0.05 })]); } _inherits(BrightnessPulse, _BasePulse2); return _createClass(BrightnessPulse, [{ key: "updateGraphics", value: function updateGraphics(brightness) { if (!this.graphics || typeof this.graphics.brightness === 'undefined') { return; } this.graphics.brightness = brightness; } }, { key: "resetGraphics", value: function resetGraphics() { this.updateGraphics(this.options.min); } }]); }(BasePulse); var ReticlePulse = /*#__PURE__*/function (_ScalePulse) { function ReticlePulse(reticleGraphics) { _classCallCheck(this, ReticlePulse); return _callSuper(this, ReticlePulse, [reticleGraphics, { minScale: 1.0, maxScale: 1.2, speed: 0.01, interval: 50 }]); } _inherits(ReticlePulse, _ScalePulse); return _createClass(ReticlePulse); }(ScalePulse); var BirdEffects = /*#__PURE__*/function () { function BirdEffects(bird) { _classCallCheck(this, BirdEffects); if (!bird || !bird.graphics) { return; } this.bird = bird; this.originalAlpha = bird.graphics.alpha || 1.0; this.active = false; this.pulseTimer = null; } return _createClass(BirdEffects, [{ key: "startEffects", value: function startEffects() { if (!this.bird || !this.bird.graphics || this.active) { return; } this.active = true; this.bird.graphics.alpha = 0.8; } }, { key: "stopEffects", value: function stopEffects() { if (this.pulseTimer) { LK.clearInterval(this.pulseTimer); this.pulseTimer = null; } if (this.bird && this.bird.graphics) { this.bird.graphics.alpha = this.originalAlpha; this.bird.graphics.scale = 1; this.bird.graphics.scaleX = 1; this.bird.graphics.scaleY = 1; this.bird.graphics.brightness = 1; } this.active = false; this.bird = null; this.originalAlpha = null; } }]); }(); var Reticle = /*#__PURE__*/function (_GameObject9) { function Reticle() { var _this18; _classCallCheck(this, Reticle); _this18 = _callSuper(this, Reticle, ['reticle1']); _this18.pulse = new ReticlePulse(_this18.graphics); _this18.pulse.startPulsating(); return _this18; } _inherits(Reticle, _GameObject9); return _createClass(Reticle); }(GameObject); game.move = function (x, y) { if (!game.reticle && typeof Reticle !== 'undefined') { game.reticle = new Reticle(); game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); } if (game.reticle) { game.reticle.x = x; game.reticle.y = y; } }; var scoreDisplay = game.mirror; var sun = new Sun(); sun.x = 480; sun.y = 680; game.layerManager.addToLayer(sun, LAYERS.SUN); var light1 = new Light(); light1.x = 510; light1.y = 1500; game.layerManager.addToLayer(light1, LAYERS.LIGHT1); light1.visible = true; var score = 0; game.scoreManager = new ScoreManager(); // Initial interval for UFO appearances between 10 to 20 seconds // Helper functions for game update function updateEntityPositions() { game.entityManager.update(); // Handle off-screen birds game.children.forEach(function (entity) { 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(LAYERS.LASER) || []; var enemies = CollisionManager.getActiveEnemies([LAYERS.BIRD1, LAYERS.BIRD2, LAYERS.UFO1, LAYERS.UFO2]); if (!projectiles.length || !enemies.length) { return; } var gridSize = 200; var grid = new Map(); var processedCollisions = new Set(); var simultaneousCollisions = new Map(); enemies.forEach(function (enemy) { if (!(enemy !== null && enemy !== void 0 && enemy.active) || typeof enemy.x !== 'number' || typeof enemy.y !== 'number') { return; } var gridX = Math.floor(enemy.x / gridSize); var gridY = Math.floor(enemy.y / gridSize); var key = "".concat(gridX, ",").concat(gridY); if (!grid.has(key)) { grid.set(key, new Set()); } grid.get(key).add(enemy); var adjacentCells = [[-1, -1], [0, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [0, 1], [1, 1]]; adjacentCells.forEach(function (_ref4) { var _ref5 = _slicedToArray(_ref4, 2), dx = _ref5[0], dy = _ref5[1]; var adjKey = "".concat(gridX + dx, ",").concat(gridY + dy); if (!grid.has(adjKey)) { grid.set(adjKey, new Set()); } grid.get(adjKey).add(enemy); }); }); projectiles.forEach(function (laser) { if (!(laser !== null && laser !== void 0 && laser.active) || typeof laser.x !== 'number' || typeof laser.y !== 'number') { return; } var gridX = Math.floor(laser.x / gridSize); var gridY = Math.floor(laser.y / gridSize); var key = "".concat(gridX, ",").concat(gridY); var cellTargets = grid.get(key); if (!(cellTargets !== null && cellTargets !== void 0 && cellTargets.size)) { return; } var closestTarget = CollisionManager.findClosestTarget(laser, Array.from(cellTargets), processedCollisions); if (closestTarget) { processedCollisions.add(closestTarget); if (!simultaneousCollisions.has(laser)) { simultaneousCollisions.set(laser, []); } simultaneousCollisions.get(laser).push(closestTarget); } }); simultaneousCollisions.forEach(function (targets, laser) { targets.forEach(function (target) { if (target !== null && target !== void 0 && target.active && laser !== null && laser !== void 0 && laser.active) { handleCollisionPoints(laser, target); } }); }); return true; } var CollisionManager = /*#__PURE__*/function () { function CollisionManager() { _classCallCheck(this, CollisionManager); this.quadrantMap = new Map(); this.cellSize = 100; } return _createClass(CollisionManager, [{ key: "getActiveEnemies", value: function getActiveEnemies() { if (!this.quadrantMap) { return []; } var enemies = []; var _iterator = _createForOfIteratorHelper(this.quadrantMap.values()), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var quadrant = _step.value; if (Array.isArray(quadrant)) { enemies.push.apply(enemies, _toConsumableArray(quadrant.filter(function (enemy) { return enemy && enemy.active; }))); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return enemies; } }, { key: "createQuadrantMap", value: function createQuadrantMap(enemies) { var _this19 = this; if (!Array.isArray(enemies)) { return; } this.quadrantMap.clear(); enemies.forEach(function (enemy) { if (!enemy || typeof enemy.x !== 'number' || typeof enemy.y !== 'number') { return; } var key = "".concat(Math.floor(enemy.x / _this19.cellSize), ",").concat(Math.floor(enemy.y / _this19.cellSize)); if (!_this19.quadrantMap.has(key)) { _this19.quadrantMap.set(key, []); } _this19.quadrantMap.get(key).push(enemy); }); } }], [{ key: "findClosestTarget", value: function findClosestTarget(laser, targets, processedCollisions) { var potentialHits = targets.filter(function (target) { return target && target.active && target.x !== undefined && target.y !== undefined && !processedCollisions.has(target) && AABBIntersect(laser, target); }); if (potentialHits.length > 0) { potentialHits.sort(function (a, b) { var distA = Math.pow(laser.x - a.x, 2) + Math.pow(laser.y - a.y, 2); var distB = Math.pow(laser.x - b.x, 2) + Math.pow(laser.y - b.y, 2); return distA - distB; }); return potentialHits[0]; } return null; } }]); }(); var ScoreManager = /*#__PURE__*/function () { function ScoreManager() { _classCallCheck(this, ScoreManager); this.score = 0; this.highScore = Number(storage.get('highScore')) || 0; this.mirror = null; this.initialized = false; } return _createClass(ScoreManager, [{ key: "updateScore", value: function updateScore(points) { if (!this.initialized || typeof points !== 'number') { return; } this.score += points; if (this.score > this.highScore) { this.highScore = this.score; storage.set('highScore', this.highScore); } if (this.mirror && typeof this.mirror.text !== 'undefined') { this.mirror.text = "Score: ".concat(this.score, "\nHigh Score: ").concat(this.highScore); } } }, { key: "reset", value: function reset() { this.updateScore(0); } }, { key: "cleanup", value: function cleanup() { this.score = 0; this.mirror = null; } }]); }(); var GameObjectMovement = /*#__PURE__*/function () { function GameObjectMovement(object, graphics) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; _classCallCheck(this, GameObjectMovement); this.object = object; this.graphics = graphics; var typeConfig = object.type ? GameObjectMovement.MovementConfigs[object.type] : null; var mergedOptions = this.validateMovementConfig(_objectSpread(_objectSpread({}, typeConfig), options)); this.options = mergedOptions; this.currentState = { speed: mergedOptions.speed + Math.random() * (mergedOptions.speedRange || 0), direction: Math.random() < 0.5 ? 1 : -1, arcOffset: Math.random() * Math.PI * 2, lastX: object.x, lastY: object.y, soundPlayed: false }; this.soundTimer = null; this.soundInstance = null; if (this.options.moveSound && game.soundManager) { this.cleanupSound(); this.initializeSound(); } if (typeConfig) { this.maxCount = typeConfig.maxCount; this.respawnTime = typeConfig.respawnTime; this.exclusiveWith = typeConfig.exclusiveWith; } } return _createClass(GameObjectMovement, [{ key: "update", value: function update(deltaTime) { if (!this.object || !this.graphics || !this.currentState) { return; } this._updateArcOffset(deltaTime); var movement = this._calculateMovement(); this._applyMovement(movement); this._checkBoundaries(); this._handleSoundTriggers(); this._updateGraphics(); } }, { key: "validateMovementConfig", value: function validateMovementConfig() { var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var validatedConfig = _objectSpread({}, GameObjectMovement.DefaultMovementConfig); validatedConfig.speed = Math.max(0, Number(config.speed) || validatedConfig.speed); validatedConfig.speedRange = Math.max(0, Number(config.speedRange) || validatedConfig.speedRange); validatedConfig.arcEnabled = Boolean(config.arcEnabled); if (validatedConfig.arcEnabled) { validatedConfig.arcAmplitude = Math.max(0, Number(config.arcAmplitude) || validatedConfig.arcAmplitude); validatedConfig.arcFrequency = Math.max(1, Number(config.arcFrequency) || validatedConfig.arcFrequency); } validatedConfig.canFlip = Boolean(config.canFlip); validatedConfig.moveSound = typeof config.moveSound === 'string' ? config.moveSound : validatedConfig.moveSound; return validatedConfig; } }, { key: "cleanupSound", value: function cleanupSound() { if (this.soundTimer) { var _game$soundManager9; (_game$soundManager9 = game.soundManager) === null || _game$soundManager9 === void 0 || _game$soundManager9.stopSound(this.options.moveSound); LK.clearTimeout(this.soundTimer); this.soundTimer = null; } if (this.currentState) { this.currentState.soundPlayed = false; } } }, { key: "initializeSound", value: function initializeSound() { var _this$options9, _this17 = this; if (!((_this$options9 = this.options) !== null && _this$options9 !== void 0 && _this$options9.moveSound) || !game.soundManager) { return; } this.cleanupSound(); if (this.currentState) { this.currentState.soundPlayed = false; } if (this.soundInstance) { game.soundManager.stopSound(this.soundInstance); this.soundInstance = null; } this.soundInstance = game.soundManager.playSound(this.options.moveSound, { volume: 0.1, interval: { min: 20000, max: 30000 }, onPlay: function onPlay() { return _this17.currentState && (_this17.currentState.soundPlayed = true); }, onStop: function onStop() { if (_this17.currentState) { _this17.currentState.soundPlayed = false; } _this17.soundTimer = null; _this17.soundInstance = null; } }); } }]); }(); var GameObjectMovement = /*#__PURE__*/function () { function GameObjectMovement(object, graphics) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; _classCallCheck(this, GameObjectMovement); this.object = object; this.graphics = graphics; var typeConfig = object.type ? GameObjectMovement.MovementConfigs[object.type] : null; var mergedOptions = this.validateMovementConfig(_objectSpread(_objectSpread({}, typeConfig), options)); this.options = mergedOptions; this.currentState = { speed: mergedOptions.speed + Math.random() * (mergedOptions.speedRange || 0), direction: Math.random() < 0.5 ? 1 : -1, arcOffset: Math.random() * Math.PI * 2, lastX: object.x, lastY: object.y, soundPlayed: false }; this.soundTimer = null; this.soundInstance = null; if (this.options.moveSound && game.soundManager) { this.cleanupSound(); this.initializeSound(); } if (typeConfig) { this.maxCount = typeConfig.maxCount; this.respawnTime = typeConfig.respawnTime; this.exclusiveWith = typeConfig.exclusiveWith; } } _createClass(GameObjectMovement, [{ key: "update", value: function update(deltaTime) { if (!this.object || !this.graphics || !this.currentState) { return; } this._updateArcOffset(deltaTime); var movement = this._calculateMovement(); this._applyMovement(movement); this._checkBoundaries(); this._handleSoundTriggers(); this._updateGraphics(); } }, { key: "validateMovementConfig", value: function validateMovementConfig() { var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var validatedConfig = _objectSpread({}, GameObjectMovement.DefaultMovementConfig); validatedConfig.speed = Math.max(0, Number(config.speed) || validatedConfig.speed); validatedConfig.speedRange = Math.max(0, Number(config.speedRange) || validatedConfig.speedRange); validatedConfig.arcEnabled = Boolean(config.arcEnabled); if (validatedConfig.arcEnabled) { validatedConfig.arcAmplitude = Math.max(0, Number(config.arcAmplitude) || validatedConfig.arcAmplitude); validatedConfig.arcFrequency = Math.max(1, Number(config.arcFrequency) || validatedConfig.arcFrequency); } validatedConfig.canFlip = Boolean(config.canFlip); validatedConfig.moveSound = typeof config.moveSound === 'string' ? config.moveSound : validatedConfig.moveSound; return validatedConfig; } }, { key: "cleanupSound", value: function cleanupSound() { if (this.soundTimer) { var _game$soundManager9; (_game$soundManager9 = game.soundManager) === null || _game$soundManager9 === void 0 || _game$soundManager9.stopSound(this.options.moveSound); LK.clearTimeout(this.soundTimer); this.soundTimer = null; } if (this.currentState) { this.currentState.soundPlayed = false; } } }, { key: "initializeSound", value: function initializeSound() { var _this$options9, _this17 = this; if (!((_this$options9 = this.options) !== null && _this$options9 !== void 0 && _this$options9.moveSound) || !game.soundManager) { return; } this.cleanupSound(); if (this.currentState) { this.currentState.soundPlayed = false; } if (this.soundInstance) { game.soundManager.stopSound(this.soundInstance); this.soundInstance = null; } this.soundInstance = game.soundManager.playSound(this.options.moveSound, { volume: 0.1, interval: { min: 20000, max: 30000 }, onPlay: function onPlay() { return _this17.currentState && (_this17.currentState.soundPlayed = true); }, onStop: function onStop() { if (_this17.currentState) { _this17.currentState.soundPlayed = false; } _this17.soundTimer = null; _this17.soundInstance = null; } }); } }]); return GameObjectMovement; }(); GameObjectMovement.MovementConfigs = { bird1: { speed: 2, speedRange: 1, arcEnabled: true, arcAmplitude: 50, arcFrequency: 100, canFlip: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.5, arcEnabled: true, arcAmplitude: 60, arcFrequency: 120, canFlip: true, moveSound: 'wings1' }, cloud1: { speed: 0.5, speedRange: 0.2, arcEnabled: false, canFlip: false }, cloud2: { speed: 0.6, speedRange: 0.3, arcEnabled: false, canFlip: false }, jet1: { speed: 5, speedRange: 2, arcEnabled: false, canFlip: true, moveSound: 'jet1' }, ufo1: { speed: 3, speedRange: 1, arcEnabled: true, arcAmplitude: 30, arcFrequency: 80, canFlip: true, moveSound: 'ufo1' }, ufo2: { speed: 3.5, speedRange: 1.5, arcEnabled: true, arcAmplitude: 40, arcFrequency: 90, canFlip: true, moveSound: 'ufo1' } }; GameObjectMovement.DefaultMovementConfig = { speed: 1, speedRange: 0.5, arcEnabled: false, arcAmplitude: 0, arcFrequency: 100, canFlip: false, moveSound: null };
===================================================================
--- original.js
+++ change.js
@@ -15,8 +15,65 @@
/****
* Game Code
****/
var _GameObjectMovement;
+GameObjectMovement.MovementConfigs = {
+ bird1: {
+ speed: 2,
+ speedRange: 1,
+ arcEnabled: true,
+ arcAmplitude: 50,
+ arcFrequency: 100,
+ canFlip: true,
+ moveSound: 'wings1'
+ },
+ bird2: {
+ speed: 2.5,
+ speedRange: 1.5,
+ arcEnabled: true,
+ arcAmplitude: 60,
+ arcFrequency: 120,
+ canFlip: true,
+ moveSound: 'wings1'
+ },
+ cloud1: {
+ speed: 0.5,
+ speedRange: 0.2,
+ arcEnabled: false,
+ canFlip: false
+ },
+ cloud2: {
+ speed: 0.6,
+ speedRange: 0.3,
+ arcEnabled: false,
+ canFlip: false
+ },
+ jet1: {
+ speed: 5,
+ speedRange: 2,
+ arcEnabled: false,
+ canFlip: true,
+ moveSound: 'jet1'
+ },
+ ufo1: {
+ speed: 3,
+ speedRange: 1,
+ arcEnabled: true,
+ arcAmplitude: 30,
+ arcFrequency: 80,
+ canFlip: true,
+ moveSound: 'ufo1'
+ },
+ ufo2: {
+ speed: 3.5,
+ speedRange: 1.5,
+ arcEnabled: true,
+ arcAmplitude: 40,
+ arcFrequency: 90,
+ canFlip: true,
+ moveSound: 'ufo1'
+ }
+};
var _excluded = ["interval"];
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
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
wings1
Sound effect
ufo1
Sound effect
cricket1
Sound effect
frog1
Sound effect
bgm1
Music
breeze1
Sound effect
songbird1
Sound effect
laser1
Sound effect
teslacoil
Sound effect
chitter
Sound effect
laser2
Sound effect
dead1
Sound effect
electro
Sound effect