User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 651
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 651
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: 647
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: 647
Code edit (2 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 config = GameObjectMovement.MovementConfigs[type];' Line Number: 1011
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: 'var config = GameObjectMovement.MovementConfigs[type];' Line Number: 1011
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 651
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: 647
Code edit (1 edits merged)
Please save this source code
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: 235 āŖš” 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: 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' 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 = storage.jet1_lastX || self.x; // Retrieve lastX from storage or initialize' Line Number: 187 āŖš” Consider importing and using the following plugins: @upit/storage.v1
/**** * 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 _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 asset = LK.getAsset(assetName, {}); if (!asset) { return null; } var sprite = new Sprite(asset); if (sprite && 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; 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 movement = { x: this.currentState.speed * this.currentState.direction, y: (_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 ? Math.sin(this.currentState.arcOffset) * this.options.arcAmplitude : 0 }; if (this.object.y + movement.y < 0 || this.object.y + movement.y > bounds.height) { movement.y = 0; } return movement; } }, { key: "_applyMovement", value: function _applyMovement(movement) { var _this$options3; 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$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.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() { if (!this.object || !this.graphics) { return; } var bounds = GameObjectMovement.CommonConfig.screenDimensions; var width = this.graphics.width || 0; var height = this.graphics.height || 0; if (this.object.x < -width || this.object.x > bounds.width + width || this.object.y < -height || this.object.y > bounds.height + height) { 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); } } }, { key: "_handleSoundTriggers", value: function _handleSoundTriggers() { var _this$options4, _this$currentState, _this$object2, _this$object3; if (!((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.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$options5, _this$currentState2, _this$object4; if (!((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.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; var config = GameObjectMovement.MovementConfigs[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$options6 = this.options, minScale = _this$options6.minScale, maxScale = _this$options6.maxScale, duration = _this$options6.duration, easing = _this$options6.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 UFO = /*#__PURE__*/function (_GameObject7) { function UFO(type) { var _this16; _classCallCheck(this, UFO); if (!type || !['ufo1', 'ufo2'].includes(type)) { type = 'ufo1'; } var asset = LK.init.getImage(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, _GameObject7); 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 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(config) { if (!config) { return {}; } return { speed: config.speed || 1, speedRange: config.speedRange || 0, arcEnabled: config.arcEnabled || false, arcAmplitude: config.arcAmplitude || 0, arcFrequency: config.arcFrequency || 0, canFlip: config.canFlip || false, moveSound: config.moveSound || null }; } }, { 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$options7, _this17 = this; if (!((_this$options7 = this.options) !== null && _this$options7 !== void 0 && _this$options7.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; } }); } }]); }(); _defineProperty(GameObjectMovement, "CommonConfig", { screenDimensions: { width: 2048, height: 2732 }, respawnTime: { min: 20000, max: 30000 }, soundTriggerBounds: { min: -100, max: 2148 } }); _defineProperty(GameObjectMovement, "MovementConfigs", { bird1: { speed: 3, speedRange: 1, arcEnabled: true, arcAmplitude: 50, arcFrequency: 200, canFlip: true, moveSound: 'wings1' }, bird2: { speed: 2, speedRange: 0.5, arcEnabled: true, arcAmplitude: 30, arcFrequency: 150, canFlip: true, moveSound: 'wings1' }, cloud1: { speed: 0.5, speedRange: 0.2 }, cloud2: { speed: 0.3, speedRange: 0.1 }, ufo1: { speed: 2, speedRange: 0.5, arcEnabled: true, arcAmplitude: 20, arcFrequency: 300, canFlip: true, moveSound: 'ufo1' }, ufo2: { speed: 1.5, speedRange: 0.3, arcEnabled: true, arcAmplitude: 15, arcFrequency: 250, canFlip: true, moveSound: 'ufo1' }, jet1: { speed: 8, speedRange: 1, canFlip: true, moveSound: 'jet1' } }); 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 (_GameObject8) { 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, _GameObject8); 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; } }]); }();
===================================================================
--- original.js
+++ change.js
@@ -4,2003 +4,1923 @@
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
-* Classes
+* Initialize Game
****/
-// Background class to represent the background image
-var Background = Container.expand(function () {
- var self = Container.call(this);
- var backgroundGraphics = self.attachAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(backgroundGraphics);
+// Initialize game
+var game = new LK.Game({
+ backgroundColor: 0x87CEEB
});
-// Branch asset
-// Bird1 class to represent the first kind of bird
-var Bird1 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new Bird1Movement(self, birdGraphics);
-});
-// Bird2 class to represent the second kind of bird
-var Bird2 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new Bird2Movement(self, birdGraphics);
-});
-// Cat class to manage cat behavior
-var Cat = Container.expand(function () {
- var self = Container.call(this);
- var catGraphics = self.attachAsset('cat', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.update = function () {
- // Add any specific update logic for the cat here
- };
-});
-// Cloud class to represent cloud behavior
-var Cloud = Container.expand(function () {
- var self = Container.call(this);
- var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)];
- var cloudGraphics = self.attachAsset(cloudType, {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8 // Set default opacity to 80%
- });
- self.movement = new CloudMovement(self, cloudGraphics);
-});
-// CloudMovement class to handle cloud movement and fade effects
-var CloudMovement = Container.expand(function () {
- var self = Container.call(this);
- var cloudGraphics = self.attachAsset('cloud1', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8 // Set default opacity to 80%
- });
- self.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
- self.hasAccelerated = false; // Track if the cloud has already accelerated
- self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- self.lastX = self.x; // Track last X position for future checks
- self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
- self.update = function () {
- flipImageVerticallyBasedOnDirection(cloudGraphics, self.lastX, self.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- self.x += self.speed * self.direction;
- // If the cloud moves off-screen, reposition it to the opposite side
- if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
- self.x = -self.width / 2;
- } else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
- self.x = 2048 + self.width / 2;
+
+/****
+* Game Code
+****/
+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
+ };
}
- // Check for overlap with other clouds
- for (var i = 0; i < clouds.length; i++) {
- if (clouds[i] !== self && self.intersects(clouds[i])) {
- if (!self.hasAccelerated) {
- self.speed *= 1.5; // Increase speed by 50%
- self.hasAccelerated = true; // Mark as accelerated
+ 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;
}
- break;
- } else if (self.hasAccelerated && !self.intersects(clouds[i])) {
- self.speed /= 1.5; // Reset speed to original
- self.hasAccelerated = false; // Reset acceleration state
}
}
- // Check if the cloud intersects with the sun
- if (!self.lastIntersecting && self.intersects(sun)) {
- self.speed *= 2; // Double the speed when touching the sun
- tween(cloudGraphics, {
- alpha: 0.5
- }, {
- duration: 3000,
- easing: tween.linear
- });
- } else if (self.lastIntersecting && !self.intersects(sun)) {
- self.speed /= 2; // Reset speed to original when not touching the sun
- tween(cloudGraphics, {
- alpha: 1.0
- }, {
- duration: 3000,
- easing: tween.linear
- });
- }
- self.lastIntersecting = self.intersects(sun);
- storage.cloud_lastX = self.x; // Store lastX using storage plugin
- self.lastX = storage.cloud_lastX || self.x; // Update lastX after movement
};
-});
-// GrassBack class to represent the grass image
-var GrassBack = Container.expand(function () {
- var self = Container.call(this);
- var grassGraphics = self.attachAsset('grass-back', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.update = function () {
- // Add any specific update logic for the grass here
- // Example: Slightly move the grass to simulate wind effect
- self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
- };
- self.addChild(grassGraphics); // Add grass graphics to the container
-});
-// GrassFront class to represent the second grass image
-var GrassFront = Container.expand(function () {
- var self = Container.call(this);
- var grass2Graphics = self.attachAsset('grass-front', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- self.addChild(grass2Graphics); // Add grass2 graphics to the container
- self.update = function () {
- // Add any specific update logic for the grass here
- // Example: Slightly move the grass to simulate wind effect
- self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
- self.lastX = self.x; // Update lastX after movement
- };
-});
-// Jet1 class to represent a jet flying across the screen
-var Jet1 = Container.expand(function () {
- var self = Container.call(this);
- var jetGraphics = self.attachAsset('jet1', {
- anchorX: 0.5,
- anchorY: 0.5,
- flipX: 1 // Apply the same directional image flipping logic as bird1 and bird2
- });
- // Add a label to the jet
- var jetLabel = new Text2('Jet', {
- size: 50,
- fill: 0xFFFFFF
- });
- jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
- jetLabel.y = -60; // Position the label above the jet
- self.addChild(jetLabel);
- self.speed = 10; // Set the speed of the jet
- self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- self.lastX = self.x; // Track last X position for future checks
- self.x = Math.random() < 0.5 ? 2048 + self.width / 2 : -self.width / 2; // Start from either the far right or left edge of the screen
- self.update = function () {
- flipImageVerticallyBasedOnDirection(jetGraphics, self.lastX, self.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- self.x += self.speed * self.direction;
- // If the jet moves off-screen, destroy it and set it to null
- if (!game.jetSoundPlayed) {
- LK.getSound('jet1').play(); // Play jet1 sound when the jet is on screen
- game.jetSoundPlayed = true; // Ensure it only plays once
- }
- if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
- self.destroy();
- game.jet = null;
- game.jetSoundPlayed = false; // Reset the flag when the jet is removed
- // Set a timer to respawn the jet between 10-20 seconds
- var respawnTime = Math.random() * 10000 + 10000; // Random time between 10-20 seconds
- game.jetSpawnTimer = LK.setTimeout(function () {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; // Start from either the far right or left edge of the screen
- jet.y = Math.random() * (2732 / 2); // Random initial y position in the top half of the screen
- game.addChild(jet);
- game.jet = jet;
- if (!game.jetSoundPlayed) {
- LK.getSound('jetSound').play(); // Play jet sound when it appears
- game.jetSoundPlayed = true; // Ensure it only plays once
+}
+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;
}
- game.jetSpawnTimer = null; // Clear the timer reference
- }, respawnTime);
+ 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;
+ }
+ }
}
- storage.jet1_lastX = self.x; // Store lastX using storage plugin
- self.lastX = storage.jet1_lastX || self.x; // Update lastX after movement
- };
-});
-// Laser class to represent a laser shot from the cat
-var Laser = Container.expand(function (startX, startY, targetX, targetY) {
- var self = Container.call(this);
- var laserGraphics = self.attachAsset('laser2', {
- anchorX: 0.5,
- anchorY: 0.5,
- brightness: 2.0 // Increase brightness by 200%
- });
- // Play the laser1 sound when the laser is created
- LK.getSound('laser1').play();
- // Calculate direction and speed
- var dx = targetX - startX;
- var dy = targetY - startY;
- var distance = Math.sqrt(dx * dx + dy * dy);
- var speed = 60; // Speed of the laser increased by 200%
- self.vx = dx / distance * speed;
- self.vy = dy / distance * speed;
- // Set initial position
- self.x = startX;
- self.y = startY;
- // Update function to move the laser
- self.update = function () {
- game.children.forEach(function (child) {
- if (AABBIntersect(child, bird)) {
- // Debug visualization: Draw a rectangle around the intersecting objects
- var debugGraphics = new Graphics();
- debugGraphics.lineStyle(2, 0xFF0000, 1);
- debugGraphics.drawRect(bird.x, bird.y, bird.width, bird.height);
- game.addChild(debugGraphics);
- LK.setTimeout(function () {
- game.removeChild(debugGraphics);
- }, 100); // Remove debug visualization after 100ms
+ 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;
}
- }); // Close the loop for iterating over game children
- self.x += self.vx;
- self.y += self.vy;
- // Remove laser if it goes off-screen
- if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
- self.destroy();
+ t[n] = r[n];
}
- };
-});
-// Light1 class to represent a light object
-var Light1 = Container.expand(function () {
- var self = Container.call(this);
- var lightGraphics = self.attachAsset('light1', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.2 // Set transparency to 20%
- });
- self.x = 450, self.y = 450;
- self.update = function () {
- // Add any specific update logic for the light here
- };
- self.pulse = new Light1Pulse(lightGraphics);
- self.pulse.startPulsating();
-});
-// Mirror class to manage score display
-var Mirror = Container.expand(function () {
- var self = Container.call(this);
- var scoreGraphics = self.attachAsset('mirror1', {
- anchorX: 0.5,
- anchorY: 0.5,
- rotation: Math.PI / 36 // Rotate image left 5 degrees
- });
- var scoreText = new Text2('0', {
- size: 175,
- fill: 0x800080,
- font: "Courier New, Courier, monospace",
- // Segmented clock style font
- stroke: 0x00FF00,
- strokeThickness: 15,
- dropShadow: true,
- dropShadowColor: 0x000000,
- dropShadowBlur: 5,
- dropShadowAngle: Math.PI / 6,
- dropShadowDistance: 6
- });
- scoreText.y = 160; // Move score text down by 110px
- scoreText.x = -155; // Move score text left by 10px
- scoreText.rotation = -65 * (Math.PI / 180); // Rotate score text left by 65 degrees
- x = 100;
- y = 100;
- self.addChild(scoreText);
- self.updateScore = function (newScore) {
- scoreText.setText(newScore);
- };
-});
-// Mirror1 class to represent the mirror image
-var Mirror1 = Container.expand(function () {
- var self = Container.call(this);
- var mirror1Graphics = self.attachAsset('mirror1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(mirror1Graphics);
-});
-// Reticle class to manage reticle behavior
-var Reticle = Container.expand(function () {
- var self = Container.call(this);
- var reticleGraphics = self.attachAsset('reticle1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Add any specific update logic for the reticle here
- };
- // Start the pulsating effect for the reticle
- startPulsating(self);
-});
-// Reticle1 class to represent the reticle image
-var Reticle1 = Container.expand(function () {
- var self = Container.call(this);
- var reticle1Graphics = self.attachAsset('reticle1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(reticle1Graphics);
-});
-// Stack1 class to represent the stack1 image
-var Stack1 = Container.expand(function () {
- var self = Container.call(this);
- var stackGraphics = self.attachAsset('stack1', {
- anchorX: 0.5,
- anchorY: 0.5,
- rotation: Math.PI / -12
- });
- self.update = function () {
- // Add any specific update logic for stack1 here
- };
-});
-// ScoreManager class to manage score logic
-// Sun class to represent a sun in the top right corner
-var Sun = Container.expand(function () {
- var self = Container.call(this);
- var sunGraphics = self.attachAsset('sun', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.pulse = new SunPulse(sunGraphics);
- self.pulse.startPulsating();
-});
-// Function to create a pulsating effect
-// Tree class to represent a tree with a 9:16 aspect ratio
-var Tree = Container.expand(function () {
- var self = Container.call(this);
- var treeGraphics = self.attachAsset('tree1', {
- anchorX: 0.5,
- anchorY: 1,
- antialias: true,
- // Apply antialias effect
- stroke: 0x000000,
- // Add a black stroke
- strokeThickness: 15 // Set stroke thickness to 15px
- });
- self.update = function () {
- // Add any specific update logic for the tree here
- };
-});
-// Tree2 class to represent the second type of tree
-var Tree2 = Container.expand(function () {
- var self = Container.call(this);
- var tree2Graphics = self.attachAsset('tree2', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.addChild(tree2Graphics);
-});
-// UFO class to represent a UFO
-var UFO = Container.expand(function () {
- var self = Container.call(this);
- var ufoGraphics = self.attachAsset('ufo1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new UFOMovement(self, ufoGraphics);
-});
-// UFO2 class to represent the second type of UFO
-var UFO2 = Container.expand(function () {
- var self = Container.call(this);
- var ufo2Graphics = self.attachAsset('ufo2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new UFOMovement(self, ufo2Graphics);
-});
-
-/****
-* Initialize Game
-****/
-// UFOMovement class to handle UFO movement
-/****
-* Assets
-LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
-****/
-// Initialize clouds array
-var game = new LK.Game({
- // No title, no description
- backgroundColor: 0x87CEEB // Sky blue
-});
-
-/****
-* Game Code
-****/
-// Initialize the layer manager
-/****
-* Layer Constants
-****/
+ }
+ 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,
- EFFECTS: 1,
- SUN: 2,
- JET: 3,
- CLOUDS: 4,
- UFO: 5,
- BIRDS: 6,
- GRASS_BACK: 7,
- TREE: 8,
- STACK: 9,
- GRASS_FRONT: 10,
- CAT: 11,
- RETICLE: 12,
- LASER: 13,
- MIRROR: 14,
- UI: 15
+ 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
};
-/****
-* Layer Management System
-****/
-var LayerManager = function LayerManager(gameInstance) {
- var self = this;
- self.game = gameInstance;
- self.layerMap = {}; // Maps objects to their layers
- /**
- * Add an object to a specific layer
- * @param {Object} object - The game object to add
- * @param {Number} layerId - The layer ID to add the object to
- */
- self.addToLayer = function (object, layerId) {
- if (!object) {
- return;
- }
- // Add to game if not already added
- if (!self.game.children.includes(object)) {
- self.game.addChild(object);
- }
- // Set the object's index based on the layer
- self.setLayerIndex(object, layerId);
- // Store the layer information for this object
- self.layerMap[object.id] = layerId;
- return object;
+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
+ };
};
- /**
- * Set the layer index for an object
- * @param {Object} object - The game object
- * @param {Number} layerId - The layer ID
- */
- self.setLayerIndex = function (object, layerId) {
- if (!object || !self.game.children.includes(object)) {
- return;
- }
- // Ensure the layer ID is valid
- layerId = Math.max(0, Math.min(layerId, self.game.children.length - 1));
- // Set the child index
- self.game.setChildIndex(object, layerId);
- // Update the layer map
- self.layerMap[object.id] = layerId;
+ 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
};
- /**
- * Get the current layer of an object
- * @param {Object} object - The game object
- * @returns {Number} The layer ID or -1 if not found
- */
- self.getObjectLayer = function (object) {
- if (!object || !object.id) {
- return -1;
- }
- return self.layerMap[object.id] || -1;
+ 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
};
- /**
- * Move an object to a different layer
- * @param {Object} object - The game object
- * @param {Number} newLayerId - The new layer ID
- */
- self.moveToLayer = function (object, newLayerId) {
- if (!object) {
- return;
+ 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;
}
- self.setLayerIndex(object, newLayerId);
- };
- /**
- * Get all objects in a specific layer
- * @param {Number} layerId - The layer ID
- * @returns {Array} Array of objects in the layer
- */
- self.getObjectsInLayer = function (layerId) {
- var objects = [];
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id) {
- objects.push(child);
- break;
- }
+ }, {
+ 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);
}
- return objects;
- };
- /**
- * Remove an object from layer tracking
- * @param {Object} object - The game object to remove
- */
- self.removeFromTracking = function (object) {
- if (!object || !object.id) {
- return;
+ }, {
+ 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));
}
- delete self.layerMap[object.id];
- };
- /**
- * Bring an object to the front of its layer
- * @param {Object} object - The game object
- */
- self.bringToFrontOfLayer = function (object) {
- if (!object || !object.id) {
- return;
+ }, {
+ 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;
+ }
}
- var layerId = self.getObjectLayer(object);
- if (layerId === -1) {
- return;
+ }, {
+ 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;
}
- // Find the highest index within this layer
- var highestIndex = layerId;
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id && i > highestIndex) {
- highestIndex = i;
- }
- }
+ }, {
+ 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
+ });
}
- // Set the object to the highest index within its layer
- self.game.setChildIndex(object, highestIndex);
- };
- /**
- * Send an object to the back of its layer
- * @param {Object} object - The game object
- */
- self.sendToBackOfLayer = function (object) {
- if (!object || !object.id) {
- return;
+ }, {
+ key: "stopSound",
+ value: function stopSound(soundId) {
+ return soundId ? (this._cleanupSound(soundId), true) : false;
}
- var layerId = self.getObjectLayer(object);
- if (layerId === -1) {
- return;
+ }, {
+ key: "setMasterVolume",
+ value: function setMasterVolume(volume) {
+ var newVolume = this._validateVolume(volume);
+ return newVolume !== undefined && (this.masterVolume = newVolume, true);
}
- // Find the lowest index within this layer
- var lowestIndex = layerId;
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id && i < lowestIndex) {
- lowestIndex = i;
+ }, {
+ 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
}
- }
- }
+ });
+ });
}
- // Set the object to the lowest index within its layer
- self.game.setChildIndex(object, lowestIndex);
- };
- /**
- * Helper function to add multiple objects to a layer at once
- * @param {Array} objects - Array of game objects
- * @param {Number} layerId - The layer ID
- */
- self.addMultipleToLayer = function (objects, layerId) {
- if (!Array.isArray(objects)) {
- return;
+ }, {
+ 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
+ });
+ });
}
- objects.forEach(function (object) {
- self.addToLayer(object, layerId);
- });
- };
-};
-var layerManager = new LayerManager(game);
-// Using UFO sound ID as placeholder
-function flipImageVerticallyBasedOnDirection(graphics, lastX, currentX) {
- if (graphics) {
- if (lastX < currentX && graphics.scaleX < 0) {
- graphics.scaleX *= -1; // Flip horizontally to face right
- } else if (lastX > currentX && graphics.scaleX > 0) {
- graphics.scaleX *= -1; // Flip horizontally to face left
+ }, {
+ 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 = [];
}
-}
-function flipImageBasedOnDirection(graphics, lastX, currentX) {
- if (graphics) {
- if (lastX < currentX) {
- graphics.scaleY = Math.abs(graphics.scaleY); // Face right when moving right by ensuring scaleY is positive
- } else if (lastX > currentX) {
- graphics.scaleY = -Math.abs(graphics.scaleY); // Face left when moving left by ensuring scaleY is negative
+ return _createClass(Container, [{
+ key: "attachAsset",
+ value: function attachAsset(assetName, options) {
+ if (!assetName) {
+ return null;
+ }
+ var asset = LK.getAsset(assetName, {});
+ if (!asset) {
+ return null;
+ }
+ var sprite = new Sprite(asset);
+ if (sprite && 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 = [];
}
-}
-// SunPulse class to handle the pulsating effect for Sun
-function AABBIntersect(obj1, obj2) {
- if (obj1 && obj2) {
- return obj1.x < obj2.x + obj2.width && obj1.x + obj1.width > obj2.x && obj1.y < obj2.y + obj2.height && obj1.y + obj1.height > obj2.y;
- }
- return false;
-}
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-var SunPulse = function SunPulse(sunGraphics) {
- this.sunGraphics = sunGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.sunGraphics, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.sunGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
+ 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);
}
- pulsate.call(this);
- };
-};
-// Light1Pulse class to handle the pulsating effect for Light1
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- this.lightGraphics = lightGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.lightGraphics, {
- scaleX: 1.6,
- scaleY: 1.6
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.lightGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1500,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
+ }, {
+ 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();
}
- pulsate.call(this);
- };
-};
-var bird2; // Define bird2 variable in the global scope
-// Bird2Effects class to handle effects and animations for Bird2
-// Function to create a pulsating effect
-function startPulsating(target) {
- var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
- function pulsate() {
- tween(target, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(target, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: pulsate
- });
+ }, {
+ 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;
}
- pulsate();
-}
-// UFOSound class to manage UFO sound effects
-// UFOMovement class to handle UFO movement
-var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- this.ufo = ufo;
- this.ufoGraphics = ufoGraphics;
- this.ufo.speed = 3.2; // Decrease speed by 20%
- this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.ufo.lastX = this.ufo.x; // Track last X position for future checks
- this.ufo.update = function () {
- this.x += this.speed * this.direction;
- this.y = 100 + Math.sin(this.x / 200) * 250; // Slow down the wave pattern further
- // Stop playing ufo1 sound after UFO leaves the screen
- if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- this.destroy();
- ufo = null;
- LK.getSound('ufo1').stop();
+ _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)([]);
}
- storage.ufo_lastX = this.x; // Store lastX using storage plugin
- this.lastX = storage.ufo_lastX || this.x; // Update lastX after movement
- };
-};
-var UFOSound = function UFOSound() {
- this.play = function () {
- LK.getSound('ufo1').play();
- };
-};
-// BackgroundMusic class to manage background music
-var BackgroundMusic = function BackgroundMusic() {
- this.play = function () {
- LK.playMusic('bgm1', {
- loop: true,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: onBgm1End
- });
- };
-};
-// LaserSound class to manage laser sound effects
-var LaserSound = function LaserSound() {
- this.play = function () {
- LK.getSound('laser1').play();
- };
-};
-var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird1_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird1_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = -this.height;
- this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
+ }, {
+ key: "_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);
}
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird1_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird1_lastY = this.lastY; // Store lastY using storage plugin
- };
-};
-var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = Math.random() * 2732; // Random initial y position within the screen height
- this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ }, {
+ key: "_calculateMovement",
+ value: function _calculateMovement() {
+ var _this$options, _this$options2;
+ 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 movement = {
+ x: this.currentState.speed * this.currentState.direction,
+ y: (_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 ? Math.sin(this.currentState.arcOffset) * this.options.arcAmplitude : 0
+ };
+ if (this.object.y + movement.y < 0 || this.object.y + movement.y > bounds.height) {
+ movement.y = 0;
+ }
+ return movement;
}
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
- };
-};
-var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
- this.cloud = cloud;
- this.cloudGraphics = cloudGraphics;
- this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
- this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated
- this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.cloud.lastX = this.cloud.x; // Track last X position for future checks
- this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
- this.cloud.update = function () {
- flipImageVerticallyBasedOnDirection(this.cloudGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- this.x += this.speed * this.direction;
- // If the cloud moves off-screen, reposition it to the opposite side
- if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
- this.x = -this.width / 2;
- } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- this.x = 2048 + this.width / 2;
+ }, {
+ key: "_applyMovement",
+ value: function _applyMovement(movement) {
+ var _this$options3;
+ 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$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.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;
+ }
}
- // Check for overlap with other clouds
- for (var i = 0; i < clouds.length; i++) {
- if (clouds[i] !== this && this.intersects(clouds[i])) {
- if (!this.hasAccelerated) {
- this.speed *= 1.5; // Increase speed by 50%
- this.hasAccelerated = true; // Mark as accelerated
- }
- break;
- } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
- this.speed /= 1.5; // Reset speed to original
- this.hasAccelerated = false; // Reset acceleration state
+ }, {
+ key: "_checkBoundaries",
+ value: function _checkBoundaries() {
+ if (!this.object || !this.graphics) {
+ return;
}
+ var bounds = GameObjectMovement.CommonConfig.screenDimensions;
+ var width = this.graphics.width || 0;
+ var height = this.graphics.height || 0;
+ if (this.object.x < -width || this.object.x > bounds.width + width || this.object.y < -height || this.object.y > bounds.height + height) {
+ 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);
+ }
}
- // Check if the cloud intersects with the sun
- if (!this.lastIntersecting && this.intersects(sun)) {
- this.speed *= 2; // Double the speed when touching the sun
- if (this.cloudGraphics) {
- tween(this.cloudGraphics, {
- alpha: 0.5
- }, {
- duration: 3000,
- easing: tween.linear
- });
+ }, {
+ key: "_handleSoundTriggers",
+ value: function _handleSoundTriggers() {
+ var _this$options4, _this$currentState, _this$object2, _this$object3;
+ if (!((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.moveSound) || (_this$currentState = this.currentState) !== null && _this$currentState !== void 0 && _this$currentState.soundPlayed) {
+ return;
}
- } else if (this.lastIntersecting && !this.intersects(sun)) {
- this.speed /= 2; // Reset speed to original when not touching the sun
- if (this.cloudGraphics) {
- tween(this.cloudGraphics, {
- alpha: 1.0
- }, {
- duration: 3000,
- easing: tween.linear
- });
+ 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;
}
}
- this.lastIntersecting = this.intersects(sun);
- this.lastX = this.x; // Update lastX after movement
- };
-};
-var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird2 here
- };
-};
-// Bird1Effects class to handle effects and animations for Bird1
-var Bird1Effects = function Bird1Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird1 here
- };
-};
-// Add background to the BACKGROUND layer
-var background = new Background();
-background.x = 2048 / 2;
-background.y = 2732 / 2 - 140;
-layerManager.addToLayer(background, LAYERS.BACKGROUND);
-// ScoreManager class to manage score logic
-var ScoreManager = function ScoreManager() {
- var self = this;
- self.score = 0;
- self.addScore = function (points) {
- self.score += points;
- return self.score;
- };
- self.resetScore = function () {
- self.score = 0;
- };
- self.getScore = function () {
- return self.score;
- };
-};
-var birds = [];
-game.down = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.setChildIndex(game.reticle, 7); // Set reticle to be rendered after the tree
+ }, {
+ key: "_updateGraphics",
+ value: function _updateGraphics() {
+ var _this$options5, _this$currentState2, _this$object4;
+ if (!((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.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']);
}
- game.reticle.x = x;
- game.reticle.y = y;
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle
+ _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;
}
-};
-var VOLUME_BGM1 = 0.02;
-var VOLUME_BREEZE1 = 0.02;
-var VOLUME_CRICKET1 = 0.02;
-var VOLUME_FROG1 = 0.02;
-var VOLUME_SONGBIRD1 = 0.02;
-var VOLUME_UFO1 = 0.02;
-var VOLUME_WINGS1 = 0.02;
-game.move = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
+ _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;
}
- if (obj.event) {
- var x = obj.event.x;
- var y = obj.event.y;
- }
- game.reticle.x = x;
- game.reticle.y = y;
+ _inherits(Cat, _GameObject3);
+ return _createClass(Cat);
+}(GameObject);
+var ENTITY_TYPES = {
+ CLOUD: ['cloud1', 'cloud2'],
+ GRASS: ['grass-front', 'grass-back']
};
-// Add a sun to the game in the top left corner
-var sun = new Sun();
-sun.x = 480;
-sun.y = 680;
-layerManager.addToLayer(sun, LAYERS.SUN);
-var light1 = new Light1();
-light1.x = 510; // Move light1 right by 50px
-light1.y = 1500; // Move light1 down by 210px
-layerManager.addToLayer(light1, LAYERS.EFFECTS);
-// Function to add a UFO to the game
-function addUFO() {
- if (!ufo) {
- ufo = new UFO();
- game.addChild(ufo);
+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;
+ var config = GameObjectMovement.MovementConfigs[type];
+ if (config) {
+ _this11.movement = new GameObjectMovement(_this11, _this11.graphics, config);
+ }
+ return _this11;
}
- // Ensure UFO is added to the game before setting its index
- if (game.children.includes(ufo) && game.children.includes(clouds[0])) {
- game.setChildIndex(ufo, game.getChildIndex(clouds[0]) + 1); // Set UFO to be rendered after the first cloud
+ _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;
}
- ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen
- ufo.y = Math.random() * (2732 / 2 - ufo.height); // Random initial y position within the top half of the screen
- ufo.customUpdate = function () {
- ufo.update();
- };
- // Removed ufo sound playing at startup
- return ufo;
-}
-// Initialize clouds array
-var clouds = [];
-for (var i = 0; i < 3; i++) {
- // Add 3 clouds for variety
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
- layerManager.addToLayer(cloud, LAYERS.CLOUDS);
- clouds.push(cloud);
-}
-for (var i = 0; i < 3; i++) {
- // Add 3 cloud2 for variety
- var cloud2 = new Cloud();
- cloud2.x = Math.random() * 2048;
- cloud2.y = Math.random() * (2732 / 2); // Position cloud in the upper half of the screen
- layerManager.addToLayer(cloud2, LAYERS.CLOUDS);
- clouds.push(cloud2);
-}
-var bird1; // Define bird1 variable in the global scope
-var bird; // Define bird variable in the global scope
-// Initialize birds
-spawnBird1();
-spawnBird2();
-spawnBird2();
-// Initialize a timer to add a UFO at a random time between 20 and 30 seconds
-var ufo; // Define the ufo variable in the global scope
-var laser; // Define the laser variable in the global scope
-var ufoTimer = LK.setTimeout(function () {
- addUFO();
- // Reset the timer for the UFO to reappear between 10-20 seconds
- ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000);
-}, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds
-game.update = function () {
- // Update clouds
- for (var i = 0; i < clouds.length; i++) {
- clouds[i].update();
- }
- // Add a jet to the game if it doesn't exist and no jet spawn timer is active
- if (!game.jet && !game.jetSpawnTimer) {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; // Start from either the far right or left edge of the screen
- jet.y = Math.random() * (2732 / 2); // Random initial y position in the top half of the screen
- game.addChild(jet);
- if (game.children.includes(jet) && game.children.includes(clouds[0])) {
- // Set jet to render after cloud1 but before cloud2
- game.setChildIndex(jet, game.getChildIndex(clouds[0]) + 1);
+ _inherits(Cloud, _EnvironmentEntity);
+ return _createClass(Cloud, [{
+ key: "update",
+ value: function update(deltaTime) {
+ if (!this.active) {
+ return;
+ }
+ _superPropGet(Cloud, "update", this, 3)([deltaTime]);
}
- game.jet = jet;
- if (!game.jetSoundPlayed) {
- LK.getSound('jetSound').play(); // Play jet sound when it appears
- game.jetSoundPlayed = true; // Ensure it only plays once
+ }]);
+}(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]);
}
- // Update jet
- if (game.jet) {
- game.jet.update();
+ _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;
}
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
- });
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
+ _inherits(Jet1, _GameObject5);
+ return _createClass(Jet1, [{
+ key: "update",
+ value: function update(deltaTime) {
+ if (!this.active) {
+ return;
}
- });
- // Check for intersections between UFO and birds
- birds.forEach(function (bird) {
- if (!ufo.lastIntersecting && ufo.intersects(bird)) {
- bird.destroy(); // Remove the bird when touched by the UFO
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- LK.getSound('electro').play(); // Play the 'electro' sound
+ _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;
}
- ufo.lastIntersecting = birds.some(function (bird) {
- return ufo.intersects(bird);
- });
+ }
+ }, {
+ 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
});
- if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
- // Destroy the UFO and set it to null
- ufo.destroy();
- ufo = null;
- // Start a timer for the UFO to reappear between 30-50 seconds
- ufoTimer = LK.setTimeout(function () {
- ufo = addUFO();
- }, Math.random() * 20000 + 30000);
- } else {}
- ufo.lastX = ufo.x; // Update lastX for the UFO
+ 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;
}
- // Removed auto-targeting update function
-};
-// Function to spawn a third kind of bird
-function spawnBird1() {
- var bird1 = new Bird1();
- bird1.x = Math.random() * 2048;
- bird1.y = -bird1.height;
- bird1.speed = 1 + Math.random() * 0.6;
- bird1.lastIntersecting = false;
- bird1.type = 'bird1'; // Specific property for Bird1
- bird1.color = 0x746130; // Specific color for Bird1
- LK.setTimeout(function () {
- game.addChild(bird1);
- // Ensure bird1 is added to the game before setting its index
- if (game.children.includes(bird1)) {
- if (game.children.includes(bird1) && game.children.includes(tree)) {
- game.setChildIndex(bird1, game.getChildIndex(tree)); // Set Bird1 to be rendered before tree
+ _inherits(Laser, _Container2);
+ return _createClass(Laser, [{
+ key: "destroy",
+ value: function destroy() {
+ if (game.layerManager) {
+ game.layerManager.removeFromTracking(this);
}
+ _superPropGet(Laser, "destroy", this, 3)([]);
}
- birds.push(bird1);
- }, 2000);
-}
-function spawnBird2() {
- var bird = new Bird2();
- bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half
- bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- bird.speed = 1 + Math.random() * 0.6;
- bird.lastIntersecting = false;
- bird.type = 'bird2'; // Specific property for Bird2
- bird.color = 0xFFFFFF; // Specific color for Bird2
- LK.setTimeout(function () {
- game.addChild(bird);
- // Ensure bird is added to the game before setting its index
- if (game.children.includes(bird)) {
- game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1
+ }, {
+ 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();
+ }
}
- birds.push(bird);
- }, 2000);
-}
-// Update the main game update function to include bird updates
-var originalUpdate = game.update;
-game.update = function () {
- // Call the original update function first
- originalUpdate.call(this);
- // Update each bird
- birds.forEach(function (bird) {
- bird.update();
- // Check if the bird has moved off-screen
- if (bird.lastY <= 2732 && bird.y > 2732) {
- bird.y = -bird.height; // Respawn the bird at the top
- bird.x = Math.random() * 2048; // Randomize the x position
- bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
+ }]);
+}(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();
}
- });
- // Update UFO and check for collisions
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
+ }, {
+ 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$options6 = this.options,
+ minScale = _this$options6.minScale,
+ maxScale = _this$options6.maxScale,
+ duration = _this$options6.duration,
+ easing = _this$options6.easing;
+ tween.to(this.graphics, {
+ scale: maxScale
+ }, duration / 2, {
+ ease: easing
+ }).then(function () {
+ return tween.to(_this15.graphics, {
+ scale: minScale
+ }, duration / 2, {
+ ease: easing
});
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
+ }).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
+ }]);
}
-};
-// Add a tree to the game
-var tree = game.addChild(new Tree());
-tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
-tree.y = 2500; // Position the tree on the grass
-// Ensure tree is added to the game before setting its index
-if (game.children.includes(tree) && game.children.includes(bird1)) {
- game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
-}
-var score = 0;
-// Add stack1 image to the game
-var stack1 = game.addChild(new Stack1());
-stack1.x = 1700; // Move 700px to the right
-stack1.y = 2250; // Move down by 800px
-// Ensure stack1 is added to the game before setting its index
-if (game.children.includes(stack1) && game.children.includes(tree)) {
- game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
-}
-// Add the grass floor to the game
-var grassBack = new GrassBack();
-grassBack.x = 1020;
-grassBack.y = 2735; // Position grassBack at the bottom
-game.addChild(grassBack);
-// Ensure grassBack is added to the game before setting its index
-if (game.children.includes(grassBack)) {
- game.setChildIndex(grassBack, 5); // Set grassBack to be rendered after Bird3
-}
-var grassFront = new GrassFront();
-grassFront.x = 1020;
-grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
-game.addChild(grassFront);
-// Ensure grassFront is added to the game before setting its index
-if (game.children.includes(grassFront) && game.children.includes(bird2)) {
- game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
-}
-var scoreDisplay = new Mirror();
-scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
-scoreDisplay.y = 2732 - 185 - 80 - 390 + 30; // Move the score display up by an additional 80px and down by 30px
-game.addChild(scoreDisplay);
-var mirror = new Mirror();
-mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
-mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
-game.addChild(mirror);
-// Ensure mirror is added to the game before setting its index
-if (game.children.includes(mirror) && game.children.includes(stack1)) {
- game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
-}
-// Ensure laser is added to the game before setting mirror's index
-if (game.children.includes(laser) && game.children.includes(mirror)) {
- game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
-}
-// Function to handle bgm1 end event
-function onBgm1End() {
- // Set a timer to replay bgm1 after 50-80 seconds
- var bgmTimer = LK.setTimeout(function () {
- LK.playMusic('bgm1', {
- loop: true,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: onBgm1End
- });
- }, Math.random() * 30000 + 50000);
-}
-;
-// Add the cat to the game
-var cat = game.addChild(new Cat());
-cat.x = 230; // Move the cat 20px to the left
-cat.y = 2732; // Position the cat at the bottom of the screen
-// Ensure cat is added to the game before setting its index
-if (game.children.includes(cat)) {
- game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
-}
-// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
-LK.playMusic('bgm1', {
- loop: false,
- // Play once
- fade: {
- start: 0,
- end: 0.02,
- // Set to the lowest volume
- duration: 4000
- },
- onEnd: function onEnd() {
- // Set a timer to replay bgm1 every 20-50 seconds
- LK.setTimeout(function () {
- LK.playMusic('bgm1', {
- loop: false,
- // Play once
- fade: {
- start: 0,
- end: 0.5,
- // Set to the lowest volume
- duration: 4000
- },
- onEnd: onEnd // Set the onEnd function to replay bgm1
- });
- }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
+ _inherits(Light, _GameObject6);
+ return _createClass(Light);
+}(GameObject);
+var UFO = /*#__PURE__*/function (_GameObject7) {
+ function UFO(type) {
+ var _this16;
+ _classCallCheck(this, UFO);
+ if (!type || !['ufo1', 'ufo2'].includes(type)) {
+ type = 'ufo1';
+ }
+ var asset = LK.init.getImage(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;
}
-});
-// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
-var wingsTimer = LK.setTimeout(function () {
- LK.getSound('wings1').play();
- wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
-}, Math.random() * 20000 + 10000);
-// Create an array for all sounds except ufo1, including all birdsong sounds
-var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
-var currentAmbientSound = null;
-// Sound volumes configuration
-// Initialize random timers for each sound to play between 30-50 seconds
-sounds.forEach(function (soundId) {
- var sound = LK.getSound(soundId);
- var ambientSoundTimer = LK.setTimeout(function () {
- if (currentAmbientSound) {
- currentAmbientSound.stop(); // Stop the currently playing ambient sound
+ _inherits(UFO, _GameObject7);
+ 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;
+ }
}
- sound.play();
- currentAmbientSound = sound; // Set the current ambient sound
- // Set a timeout to reset the current ambient sound after it finishes playing
- LK.setTimeout(function () {
- currentAmbientSound = null;
- }, sound.duration * 1000); // Convert duration from seconds to milliseconds
- // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
- ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
- }, Math.random() * 20000 + 30000);
-});
-/****
-* Layer Constants
-****/
-var LAYERS = {
- BACKGROUND: 0,
- CLOUDS: 1,
- SUN: 2,
- BIRDS: 3,
- UFO: 4,
- TREE: 5,
- GRASS_BACK: 6,
- CAT: 7,
- GRASS_FRONT: 8,
- STACK: 9,
- LASER: 10,
- JET: 11,
- RETICLE: 12,
- UI: 13,
- EFFECTS: 14
-};
-/****
-* Layer Management System
-****/
-var LayerManager = function LayerManager(gameInstance) {
- var self = this;
- self.game = gameInstance;
- self.layerMap = {}; // Maps objects to their layers
- /**
- * Add an object to a specific layer
- * @param {Object} object - The game object to add
- * @param {Number} layerId - The layer ID to add the object to
- */
- self.addToLayer = function (object, layerId) {
- if (!object) {
- return;
+ }, {
+ key: "isOnScreen",
+ value: function isOnScreen() {
+ return this.x >= -this.width / 2 && this.x <= LK.width + this.width / 2;
}
- // Add to game if not already added
- if (!self.game.children.includes(object)) {
- self.game.addChild(object);
+ }, {
+ 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)([]);
}
- // Set the object's index based on the layer
- self.setLayerIndex(object, layerId);
- // Store the layer information for this object
- self.layerMap[object.id] = layerId;
- return object;
- };
- /**
- * Set the layer index for an object
- * @param {Object} object - The game object
- * @param {Number} layerId - The layer ID
- */
- self.setLayerIndex = function (object, layerId) {
- if (!object || !self.game.children.includes(object)) {
- return;
+ }]);
+}(GameObject);
+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();
}
- // Ensure the layer ID is valid
- layerId = Math.max(0, Math.min(layerId, self.game.children.length - 1));
- // Set the child index
- self.game.setChildIndex(object, layerId);
- // Update the layer map
- self.layerMap[object.id] = layerId;
- };
- /**
- * Get the current layer of an object
- * @param {Object} object - The game object
- * @returns {Number} The layer ID or -1 if not found
- */
- self.getObjectLayer = function (object) {
- if (!object || !object.id) {
- return -1;
+ if (typeConfig) {
+ this.maxCount = typeConfig.maxCount;
+ this.respawnTime = typeConfig.respawnTime;
+ this.exclusiveWith = typeConfig.exclusiveWith;
}
- return self.layerMap[object.id] || -1;
- };
- /**
- * Move an object to a different layer
- * @param {Object} object - The game object
- * @param {Number} newLayerId - The new layer ID
- */
- self.moveToLayer = function (object, newLayerId) {
- if (!object) {
- return;
+ }
+ 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();
}
- self.setLayerIndex(object, newLayerId);
- };
- /**
- * Get all objects in a specific layer
- * @param {Number} layerId - The layer ID
- * @returns {Array} Array of objects in the layer
- */
- self.getObjectsInLayer = function (layerId) {
- var objects = [];
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id) {
- objects.push(child);
- break;
+ }, {
+ key: "validateMovementConfig",
+ value: function validateMovementConfig(config) {
+ if (!config) {
+ return {};
+ }
+ return {
+ speed: config.speed || 1,
+ speedRange: config.speedRange || 0,
+ arcEnabled: config.arcEnabled || false,
+ arcAmplitude: config.arcAmplitude || 0,
+ arcFrequency: config.arcFrequency || 0,
+ canFlip: config.canFlip || false,
+ moveSound: config.moveSound || null
+ };
+ }
+ }, {
+ 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$options7,
+ _this17 = this;
+ if (!((_this$options7 = this.options) !== null && _this$options7 !== void 0 && _this$options7.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;
}
+ });
+ }
+ }]);
+}();
+_defineProperty(GameObjectMovement, "CommonConfig", {
+ screenDimensions: {
+ width: 2048,
+ height: 2732
+ },
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ soundTriggerBounds: {
+ min: -100,
+ max: 2148
+ }
+});
+_defineProperty(GameObjectMovement, "MovementConfigs", {
+ bird1: {
+ speed: 3,
+ speedRange: 1,
+ arcEnabled: true,
+ arcAmplitude: 50,
+ arcFrequency: 200,
+ canFlip: true,
+ moveSound: 'wings1'
+ },
+ bird2: {
+ speed: 2,
+ speedRange: 0.5,
+ arcEnabled: true,
+ arcAmplitude: 30,
+ arcFrequency: 150,
+ canFlip: true,
+ moveSound: 'wings1'
+ },
+ cloud1: {
+ speed: 0.5,
+ speedRange: 0.2
+ },
+ cloud2: {
+ speed: 0.3,
+ speedRange: 0.1
+ },
+ ufo1: {
+ speed: 2,
+ speedRange: 0.5,
+ arcEnabled: true,
+ arcAmplitude: 20,
+ arcFrequency: 300,
+ canFlip: true,
+ moveSound: 'ufo1'
+ },
+ ufo2: {
+ speed: 1.5,
+ speedRange: 0.3,
+ arcEnabled: true,
+ arcAmplitude: 15,
+ arcFrequency: 250,
+ canFlip: true,
+ moveSound: 'ufo1'
+ },
+ jet1: {
+ speed: 8,
+ speedRange: 1,
+ canFlip: true,
+ moveSound: 'jet1'
+ }
+});
+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;
}
- return objects;
- };
- /**
- * Remove an object from layer tracking
- * @param {Object} object - The game object to remove
- */
- self.removeFromTracking = function (object) {
- if (!object || !object.id) {
- return;
+ }, {
+ 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();
+ }
}
- delete self.layerMap[object.id];
- };
- /**
- * Bring an object to the front of its layer
- * @param {Object} object - The game object
- */
- self.bringToFrontOfLayer = function (object) {
- if (!object || !object.id) {
- return;
+ }, {
+ key: "_setupGameState",
+ value: function _setupGameState() {
+ if (!this.game.state) {
+ this.game.state = new GameState();
+ }
+ this.game.state.reset();
}
- var layerId = self.getObjectLayer(object);
- if (layerId === -1) {
- return;
+ }, {
+ key: "_loadResources",
+ value: function _loadResources() {
+ // Placeholder for resource loading logic
+ // This would typically load textures, sounds, etc.
}
- // Find the highest index within this layer
- var highestIndex = layerId;
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id && i > highestIndex) {
- highestIndex = i;
- }
- }
- }
+ }]);
+}();
+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;
}
- // Set the object to the highest index within its layer
- self.game.setChildIndex(object, highestIndex);
- };
- /**
- * Send an object to the back of its layer
- * @param {Object} object - The game object
- */
- self.sendToBackOfLayer = function (object) {
- if (!object || !object.id) {
- return;
+ }]);
+}();
+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');
}
- var layerId = self.getObjectLayer(object);
- if (layerId === -1) {
- return;
+ 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');
}
- // Find the lowest index within this layer
- var lowestIndex = layerId;
- for (var id in self.layerMap) {
- if (self.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < self.game.children.length; i++) {
- var child = self.game.children[i];
- if (child.id === id && i < lowestIndex) {
- lowestIndex = i;
- }
+ 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();
}
- // Set the object to the lowest index within its layer
- self.game.setChildIndex(object, lowestIndex);
- };
- /**
- * Helper function to add multiple objects to a layer at once
- * @param {Array} objects - Array of game objects
- * @param {Number} layerId - The layer ID
- */
- self.addMultipleToLayer = function (objects, layerId) {
- if (!Array.isArray(objects)) {
- return;
+ }, {
+ 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;
+ }
}
- objects.forEach(function (object) {
- self.addToLayer(object, layerId);
- });
- };
-};
-// Initialize the layer manager
-var layerManager = new LayerManager(game);
-// Using UFO sound ID as placeholder
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-var SunPulse = function SunPulse(sunGraphics) {
- this.sunGraphics = sunGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.sunGraphics, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.sunGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
+ }, {
+ 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;
+ }
}
- pulsate.call(this);
- };
-};
-// Light1Pulse class to handle the pulsating effect for Light1
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- this.lightGraphics = lightGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.lightGraphics, {
- scaleX: 1.6,
- scaleY: 1.6
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.lightGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1500,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
+ }]);
+}();
+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;
+ }
}
- pulsate.call(this);
- };
-};
-var bird2; // Define bird2 variable in the global scope
-// Bird2Effects class to handle effects and animations for Bird2
-// Function to create a pulsating effect
-// UFOSound class to manage UFO sound effects
-// UFOMovement class to handle UFO movement
-var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- this.ufo = ufo;
- this.ufoGraphics = ufoGraphics;
- this.ufo.speed = 3.2; // Decrease speed by 20%
- this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.ufo.lastX = this.ufo.x; // Track last X position for future checks
- this.ufo.update = function () {
- this.x += this.speed * this.direction;
- this.y = 100 + Math.sin(this.x / 200) * 250; // Slow down the wave pattern further
- // Stop playing ufo1 sound after UFO leaves the screen
- if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- this.destroy();
- ufo = null;
- LK.getSound('ufo1').stop();
+ }, {
+ key: "resetGraphics",
+ value: function resetGraphics() {
+ this.updateGraphics(this.options.min);
}
- this.lastX = this.x; // Update lastX after movement
- };
-};
-var UFOSound = function UFOSound() {
- this.play = function () {
- LK.getSound('ufo1').play();
- };
-};
-// BackgroundMusic class to manage background music
-var BackgroundMusic = function BackgroundMusic() {
- this.play = function () {
- LK.playMusic('bgm1', {
- loop: true,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: onBgm1End
- });
- };
-};
-// LaserSound class to manage laser sound effects
-var LaserSound = function LaserSound() {
- this.play = function () {
- LK.getSound('laser1').play();
- };
-};
-var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird1_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird1_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = -this.height;
- this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
+ }]);
+}(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;
}
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird1_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird1_lastY = this.lastY; // Store lastY using storage plugin
- };
-};
-var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = Math.random() * 2732; // Random initial y position within the screen height
- this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ }, {
+ key: "resetGraphics",
+ value: function resetGraphics() {
+ this.updateGraphics(this.options.min);
}
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
- };
-};
-var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
- this.cloud = cloud;
- this.cloudGraphics = cloudGraphics;
- this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
- this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated
- this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.cloud.lastX = this.cloud.x; // Track last X position for future checks
- this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
- this.cloud.update = function () {
- flipImageVerticallyBasedOnDirection(this.cloudGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- this.x += this.speed * this.direction;
- // If the cloud moves off-screen, reposition it to the opposite side
- if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
- this.x = -this.width / 2;
- } else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- this.x = 2048 + this.width / 2;
+ }]);
+}(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;
}
- // Check for overlap with other clouds
- for (var i = 0; i < clouds.length; i++) {
- if (clouds[i] !== this && this.intersects(clouds[i])) {
- if (!this.hasAccelerated) {
- this.speed *= 1.5; // Increase speed by 50%
- this.hasAccelerated = true; // Mark as accelerated
- }
- break;
- } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
- this.speed /= 1.5; // Reset speed to original
- this.hasAccelerated = false; // Reset acceleration state
+ 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;
}
- // Check if the cloud intersects with the sun
- if (!this.lastIntersecting && this.intersects(sun)) {
- this.speed *= 2; // Double the speed when touching the sun
- if (this.cloudGraphics) {
- tween(this.cloudGraphics, {
- alpha: 0.5
- }, {
- duration: 3000,
- easing: tween.linear
- });
+ }, {
+ key: "stopEffects",
+ value: function stopEffects() {
+ if (this.pulseTimer) {
+ LK.clearInterval(this.pulseTimer);
+ this.pulseTimer = null;
}
- } else if (this.lastIntersecting && !this.intersects(sun)) {
- this.speed /= 2; // Reset speed to original when not touching the sun
- if (this.cloudGraphics) {
- tween(this.cloudGraphics, {
- alpha: 1.0
- }, {
- duration: 3000,
- easing: tween.linear
- });
+ 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;
}
- this.lastIntersecting = this.intersects(sun);
- this.lastX = this.x; // Update lastX after movement
- };
-};
-var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird2 here
- };
-};
-// Bird1Effects class to handle effects and animations for Bird1
-var Bird1Effects = function Bird1Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird1 here
- };
-};
-// Add background to the BACKGROUND layer
-var background = new Background();
-background.x = 2048 / 2;
-background.y = 2732 / 2 - 140;
-layerManager.addToLayer(background, LAYERS.BACKGROUND);
-// ScoreManager class to manage score logic
-var ScoreManager = function ScoreManager() {
- var self = this;
- self.score = 0;
- self.addScore = function (points) {
- self.score += points;
- return self.score;
- };
- self.resetScore = function () {
- self.score = 0;
- };
- self.getScore = function () {
- return self.score;
- };
-};
-var birds = [];
-game.down = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.setChildIndex(game.reticle, 7); // Set reticle to be rendered after the tree
- }
+ }]);
+}();
+var Reticle = /*#__PURE__*/function (_GameObject8) {
+ function Reticle() {
+ var _this18;
+ _classCallCheck(this, Reticle);
+ _this18 = _callSuper(this, Reticle, ['reticle1']);
+ _this18.pulse = new ReticlePulse(_this18.graphics);
+ _this18.pulse.startPulsating();
+ return _this18;
}
- game.reticle.x = x;
- game.reticle.y = y;
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle
+ _inherits(Reticle, _GameObject8);
+ 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);
}
-};
-var VOLUME_BGM1 = 0.02;
-var VOLUME_BREEZE1 = 0.02;
-var VOLUME_CRICKET1 = 0.02;
-var VOLUME_FROG1 = 0.02;
-var VOLUME_SONGBIRD1 = 0.02;
-var VOLUME_UFO1 = 0.02;
-var VOLUME_WINGS1 = 0.02;
-game.move = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
+ if (game.reticle) {
+ game.reticle.x = x;
+ game.reticle.y = y;
}
- if (obj.event) {
- var x = obj.event.x;
- var y = obj.event.y;
- }
- game.reticle.x = x;
- game.reticle.y = y;
};
-// Add a sun to the game in the top left corner
+var scoreDisplay = game.mirror;
var sun = new Sun();
sun.x = 480;
sun.y = 680;
-layerManager.addToLayer(sun, LAYERS.SUN);
-var light1 = new Light1();
-light1.x = 510; // Move light1 right by 50px
-light1.y = 1500; // Move light1 down by 210px
-layerManager.addToLayer(light1, LAYERS.EFFECTS);
-// Function to add a UFO to the game
-// Initialize clouds array
-var clouds = [];
-for (var i = 0; i < 3; i++) {
- // Add 3 clouds for variety
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
- layerManager.addToLayer(cloud, LAYERS.CLOUDS);
- clouds.push(cloud);
+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;
+ }
+ });
}
-for (var i = 0; i < 3; i++) {
- // Add 3 cloud2 for variety
- var cloud2 = new Cloud();
- cloud2.x = Math.random() * 2048;
- cloud2.y = Math.random() * (2732 / 2); // Position cloud in the upper half of the screen
- layerManager.addToLayer(cloud2, LAYERS.CLOUDS);
- clouds.push(cloud2);
-}
-var bird1; // Define bird1 variable in the global scope
-var bird; // Define bird variable in the global scope
-// Initialize birds
-spawnBird1();
-spawnBird2();
-spawnBird2();
-// Initialize a timer to add a UFO at a random time between 20 and 30 seconds
-var ufo; // Define the ufo variable in the global scope
-var laser; // Define the laser variable in the global scope
-var ufoTimer = LK.setTimeout(function () {
- addUFO();
- // Reset the timer for the UFO to reappear between 10-20 seconds
- ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000);
-}, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds
-game.update = function () {
- // Update clouds
- for (var i = 0; i < clouds.length; i++) {
- clouds[i].update();
+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;
}
- // Add a jet to the game if it doesn't exist and no jet spawn timer is active
- if (!game.jet && !game.jetSpawnTimer) {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; // Start from either the far right or left edge of the screen
- jet.y = Math.random() * (2732 / 2); // Random initial y position in the top half of the screen
- game.addChild(jet);
- if (game.children.includes(jet) && game.children.includes(clouds[0])) {
- // Set jet to render after cloud1 but before cloud2
- game.setChildIndex(jet, game.getChildIndex(clouds[0]) + 1);
+ 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;
}
- game.jet = jet;
- if (!game.jetSoundPlayed) {
- LK.getSound('jet1').play(); // Play jet sound when it appears
- game.jetSoundPlayed = true; // Ensure it only plays once
+ 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;
}
- // Update jet
- if (game.jet) {
- game.jet.update();
- }
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- LK.getSound('dead1').play(); // Play the 'dead1' sound when a bird is hit
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
+ 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;
+ })));
}
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
- });
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
}
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
+ } catch (err) {
+ _iterator.e(err);
+ } finally {
+ _iterator.f();
}
- });
- // Check for intersections between UFO and birds
- birds.forEach(function (bird) {
- if (!ufo.lastIntersecting && ufo.intersects(bird)) {
- bird.destroy(); // Remove the bird when touched by the UFO
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- LK.getSound('dead2').play(); // Play the 'dead2' sound
+ return enemies;
+ }
+ }, {
+ key: "createQuadrantMap",
+ value: function createQuadrantMap(enemies) {
+ var _this19 = this;
+ if (!Array.isArray(enemies)) {
+ return;
}
- ufo.lastIntersecting = birds.some(function (bird) {
- return ufo.intersects(bird);
+ 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);
});
- });
- if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
- // Destroy the UFO and set it to null
- ufo.destroy();
- ufo = null;
- // Start a timer for the UFO to reappear between 30-50 seconds
- ufoTimer = LK.setTimeout(function () {
- ufo = addUFO();
- }, Math.random() * 20000 + 30000);
- } else {}
- ufo.lastX = ufo.x; // Update lastX for the UFO
- }
- // Removed auto-targeting update function
-};
-// Function to spawn a third kind of bird
-// Update the main game update function to include bird updates
-var originalUpdate = game.update;
-game.update = function () {
- // Call the original update function first
- originalUpdate.call(this);
- // Update each bird
- birds.forEach(function (bird) {
- bird.update();
- // Check if the bird has moved off-screen
- if (bird.lastY <= 2732 && bird.y > 2732) {
- bird.y = -bird.height; // Respawn the bird at the top
- bird.x = Math.random() * 2048; // Randomize the x position
- bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
}
- });
- // Update UFO and check for collisions
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
+ }], [{
+ 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;
});
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
+ 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;
}
-};
-// Add a tree to the game
-var tree = game.addChild(new Tree());
-tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
-tree.y = 2500; // Position the tree on the grass
-// Ensure tree is added to the game before setting its index
-if (game.children.includes(tree) && game.children.includes(bird1)) {
- game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
-}
-var score = 0;
-// Add stack1 image to the game
-var stack1 = game.addChild(new Stack1());
-stack1.x = 1700; // Move 700px to the right
-stack1.y = 2250; // Move down by 800px
-// Ensure stack1 is added to the game before setting its index
-if (game.children.includes(stack1) && game.children.includes(tree)) {
- game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
-}
-// Add the grass floor to the game
-var grassBack = new GrassBack();
-grassBack.x = 1020;
-grassBack.y = 2735; // Position grassBack at the bottom
-game.addChild(grassBack);
-// Ensure grassBack is added to the game before setting its index
-if (game.children.includes(grassBack)) {
- game.setChildIndex(grassBack, 5); // Set grassBack to be rendered after Bird3
-}
-var grassFront = new GrassFront();
-grassFront.x = 1020;
-grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
-game.addChild(grassFront);
-// Ensure grassFront is added to the game before setting its index
-if (game.children.includes(grassFront) && game.children.includes(bird2)) {
- game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
-}
-var scoreDisplay = new Mirror();
-scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
-scoreDisplay.y = 2732 - 185 - 80 - 390 + 30; // Move the score display up by an additional 80px and down by 30px
-game.addChild(scoreDisplay);
-var mirror = new Mirror();
-mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
-mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
-game.addChild(mirror);
-layerManager.addToLayer(mirror, LAYERS.MIRROR);
-// Ensure mirror is added to the game before setting its index
-if (game.children.includes(mirror) && game.children.includes(stack1)) {
- game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
-}
-// Ensure laser is added to the game before setting mirror's index
-if (game.children.includes(laser) && game.children.includes(mirror)) {
- game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
-}
-// Function to handle bgm1 end event
-;
-// Add the cat to the game
-var cat = game.addChild(new Cat());
-cat.x = 230; // Move the cat 20px to the left
-cat.y = 2732; // Position the cat at the bottom of the screen
-// Ensure cat is added to the game before setting its index
-if (game.children.includes(cat)) {
- game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
-}
-// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
-LK.playMusic('bgm1', {
- loop: false,
- // Play once
- fade: {
- start: 0,
- end: 0.02,
- // Set to the lowest volume
- duration: 4000
- },
- onEnd: function onEnd() {
- // Set a timer to replay bgm1 every 20-50 seconds
- LK.setTimeout(function () {
- LK.playMusic('bgm1', {
- loop: false,
- // Play once
- fade: {
- start: 0,
- end: 0.5,
- // Set to the lowest volume
- duration: 4000
- },
- onEnd: onEnd // Set the onEnd function to replay bgm1
- });
- }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
- }
-});
-// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
-var wingsTimer = LK.setTimeout(function () {
- LK.getSound('wings1').play();
- wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
-}, Math.random() * 20000 + 10000);
-// Create an array for all sounds except ufo1, including all birdsong sounds
-var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
-var currentAmbientSound = null;
-// Display volumes of all sounds in the console
-// Sound volumes configuration
-// Initialize random timers for each sound to play between 30-50 seconds
-sounds.forEach(function (soundId) {
- var sound = LK.getSound(soundId);
- var ambientSoundTimer = LK.setTimeout(function () {
- if (currentAmbientSound) {
- currentAmbientSound.stop(); // Stop the currently playing ambient sound
+ 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);
+ }
}
- sound.play();
- currentAmbientSound = sound; // Set the current ambient sound
- // Set a timeout to reset the current ambient sound after it finishes playing
- LK.setTimeout(function () {
- currentAmbientSound = null;
- }, sound.duration * 1000); // Convert duration from seconds to milliseconds
- // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
- ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
- }, Math.random() * 20000 + 30000);
-});
\ No newline at end of file
+ }, {
+ key: "reset",
+ value: function reset() {
+ this.updateScore(0);
+ }
+ }, {
+ key: "cleanup",
+ value: function cleanup() {
+ this.score = 0;
+ this.mirror = null;
+ }
+ }]);
+}();
\ No newline at end of file
an orange and white cat facing away from the camera. the cat is sitting straight up and looking up, ready to pounce. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
remove black box
fluffy translucent cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bright sun with wincing cartoon face and a black eye. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a goofy ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red gaming reticle. Minimal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sunny day, hilly landscape. there is an alien invasion taking place in the distance. cities burning.
large AUTUMN SHADES tree with sparse bunches of leaves. branches are exposed, but the tree is tough and old.. true-color, realistic, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
glowing orange sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sideway view of a fighter jet. . . In-Game 2d asset. transparent background. horizontal. No shadows.
shiny purple and black attack ufo.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
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