User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'window.Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'var EntityManager = {' Line Number: 969
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: 'gameInstance = new LK.Game({' Line Number: 813
User prompt
debug the game
Code edit (1 edits merged)
Please save this source code
User prompt
debug the game
User prompt
apply the sun image to the sun object
Code edit (4 edits merged)
Please save this source code
User prompt
debug the game
User prompt
Assign bird1 image to Bird1 object
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Images 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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) { throw Error("Generator is already running"); } if (o === s) { if ("throw" === i) { throw a; } return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) { continue; } return u; } } if ("next" === n.method) { n.sent = n._sent = n.arg; } else if ("throw" === n.method) { if (o === h) { throw o = s, n.arg; } n.dispatchException(n.arg); } else { "return" === n.method && n.abrupt("return", n.arg); } o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) { continue; } return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) { return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; } var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) { return r.method = "throw", r.arg = i.arg, r.delegate = null, y; } var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) { return r.call(e); } if ("function" == typeof e.next) { return e; } if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) { if (n.call(e, o)) { return next.value = e[o], next.done = !1, next; } } return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) { r.push(n); } return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) { return next.value = t, next.done = !1, next; } } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) { for (var r in this) { "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); } } }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) { throw t.arg; } return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) { throw e; } var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) { return handle("end"); } if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) { return handle(i.catchLoc, !0); } if (this.prev < i.finallyLoc) { return handle(i.finallyLoc); } } else if (c) { if (this.prev < i.catchLoc) { return handle(i.catchLoc, !0); } } else { if (!u) { throw Error("try statement without catch or finally"); } if (this.prev < i.finallyLoc) { return handle(i.finallyLoc); } } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) { throw t.arg; } return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) { return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } 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 _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) { throw o; } } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) { return _arrayLikeToArray(r, a); } var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; } function _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 _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } 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 _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); } var assets = { scoreImage: { type: 'shape', width: 100, height: 100, color: 0xcd1966, shape: 'box' }, background: { type: 'image', width: 2048, height: 2732, id: '67cb14d582516b65d7d56166' }, bird1Left: { type: 'image', width: 300, height: 295, id: '67c8f938120d8830ebbf56ab' }, bird1Right: { type: 'image', width: 300, height: 295, id: '67c8f938120d8830ebbf56ab', flipX: 1 }, bird2Left: { type: 'image', width: 150, height: 168.42, id: '67c9027e120d8830ebbf5715', flipX: 1 }, bird2Right: { type: 'image', width: 150, height: 168.42, id: '67c9027e120d8830ebbf5715' }, cat: { type: 'image', width: 433.13, height: 475.89, id: '67c8fd9b120d8830ebbf56e9' }, cloud: { type: 'image', width: 500, height: 250, id: '67c915be120d8830ebbf582c' }, grassBack: { type: 'image', width: 2204.72, height: 1505.21, id: '67c90d44120d8830ebbf57b9' }, grassFront: { type: 'image', width: 2400, height: 1856.25, id: '67c90db6120d8830ebbf57c5', flipX: 1 }, jetLeft: { type: 'image', width: 200, height: 75.78, id: '67cbdf3f8f0bb65062649f12', flipX: 1 }, jetRight: { type: 'image', width: 200, height: 75.78, id: '67cbdf3f8f0bb65062649f12' }, laser2: { type: 'image', width: 100, height: 101.19, id: '67c9f7067f021452b5f9dcd8' }, light1: { type: 'image', width: 120, height: 120, id: '67cbd61a8f0bb65062649e53' }, mirror1: { type: 'image', width: 500, height: 800, id: '67cb7aec82516b65d7d56434' }, reticle1: { type: 'image', width: 400, height: 379.69, id: '67c935fd120d8830ebbf5944' }, stack1: { type: 'image', width: 700, height: 737.45, id: '67cb6ce882516b65d7d563cc' }, sun: { type: 'image', width: 500, height: 500, id: '67c92a9f120d8830ebbf58c6' }, tree: { type: 'image', width: 1900, height: 2500, id: '67c911c5120d8830ebbf5807', flipX: 1 }, tree2: { type: 'image', width: 1900, height: 2300, id: '67cb5a3d82516b65d7d56300' }, ufo: { type: 'image', width: 300, height: 228.52, id: '67c932df120d8830ebbf591b' }, ufo2: { type: 'image', width: 400, height: 162.5, id: '67cc62364e271169e42de9e4' } }; Object.keys(assets).forEach(function (key) { var asset = assets[key]; if (asset.type === 'shape') {} else if (asset.type === 'image') {} }); // Music and Sounds /**** * Game Configuration ****/ // Sound configuration var GAME_SOUND_VOLUMES = { bgm1: 0.02, breeze1: 0.02, cricket1: 0.02, frog1: 0.02, songbird1: 0.02, ufo1: 0.02, wings1: 0.02, laser1: 0.1, laser2: 0.1, jetSound: 0.3 }; /**** * Core Game Setup ****/ // Initialize game instance var gameInstance; if (!gameInstance) { gameInstance = new LK.Game({ backgroundColor: 0x000000 }); } // Layer structure initialization var layers = { background: new Container(), sun: new Container(), light1: new Container(), jet: new Container(), clouds: new Container(), ufo: new Container(), grassBack: new Container() }; var Background = /*#__PURE__*/function (_Container) { function Background() { var _this; _classCallCheck(this, Background); _this = _callSuper(this, Background); _this.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); return _this; } _inherits(Background, _Container); return _createClass(Background); }(Container); // Branch asset var Bird = /*#__PURE__*/function (_Container2) { function Bird(type) { var _this2; _classCallCheck(this, Bird); _this2 = _callSuper(this, Bird); if (!type) { throw new Error('Bird type is required'); } _this2.birdGraphics = _this2.attachAsset("".concat(type, "Right"), { anchorX: 0.5, anchorY: 0.5 }); // The attachAsset method will throw an error if it fails, so we don't need to check again createMovementSystem(_this2, _this2.birdGraphics, MOVEMENT_CONFIGS[type]); return _this2; } _inherits(Bird, _Container2); return _createClass(Bird, [{ key: "setChildIndex", value: function setChildIndex(index) { if (game.children.includes(this)) { game.setChildIndex(this, index); } } }, { key: "destroy", value: function destroy() { if (this.birdGraphics) { this.birdGraphics.destroy(); this.birdGraphics = null; } _superPropGet(Bird, "destroy", this, 3)([]); } }]); }(Container); var Bird1 = /*#__PURE__*/function (_Bird) { function Bird1() { _classCallCheck(this, Bird1); var self = _callSuper(this, Bird1, ['bird1']); self.lastX = self.x; return self; } _inherits(Bird1, _Bird); return _createClass(Bird1); }(Bird); var Bird2 = /*#__PURE__*/function (_Bird2) { function Bird2() { _classCallCheck(this, Bird2); var self = _callSuper(this, Bird2, ['bird2']); self.lastX = self.x; return self; } _inherits(Bird2, _Bird2); return _createClass(Bird2); }(Bird); // Layer z-index management is handled by the layerStructure configuration // Layer structure and initialization is already handled at the beginning of the file // Consolidated checkInteractions function is inserted below // Bird2Movement class to handle Bird2 movement // Bird2Movement class to handle Bird2 movement /** * Configures movement behavior for game entities with tween-based animations * @param {Container} entity - Target entity container * @param {Graphics} graphics - Visual representation to animate * @param {Object} config - Movement configuration: * @param {number} [config.baseSpeed=1] - Base movement speed * @param {Object} config.textures - Directional sprites {left, right} * @param {boolean} [config.useWaveMotion=false] - Enable sine-based path * @param {number} [config.waveAmplitude=0] - Vertical deviation magnitude * @param {number} [config.waveFrequency=100] - Horizontal wave cycle length */ // Consolidated movement system with state tracking and error boundaries // Unified entity management system with improved cleanup var EntityPool = { pools: {}, maxPoolSize: 50, initialize: function initialize(entityType, factory) { var initialSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10; if (!this.pools[entityType]) { this.pools[entityType] = []; for (var i = 0; i < initialSize; i++) { var entity = factory(); entity.type = entityType; entity.reset = function () { this.x = 0; this.y = 0; this.alpha = 1; this.scale.set(1); this.rotation = 0; this._destroyed = false; this._cleaned = false; }; this.pools[entityType].push(entity); } } }, get: function get(entityType) { if (!this.pools[entityType] || this.pools[entityType].length === 0) { return null; } var entity = this.pools[entityType].pop(); entity.reset(); return entity; }, "return": function _return(entityType, entity) { if (!this.pools[entityType]) { return; } if (this.pools[entityType].length >= this.maxPoolSize) { entity.destroy(); return; } if (!this.pools[entityType].includes(entity)) { this.pools[entityType].push(entity); } }, clear: function clear(entityType) { if (this.pools[entityType]) { this.pools[entityType].forEach(function (entity) { if (entity.destroy) { entity.destroy(); } }); this.pools[entityType] = []; } }, clearAll: function clearAll() { var _this3 = this; Object.keys(this.pools).forEach(function (type) { return _this3.clear(type); }); this.pools = {}; } }; var EntityManager = { entities: new Set(), updateSystems: new Set(), register: function register(entity) { if (!entity) { return; } this.entities.add(entity); }, unregister: function unregister(entity) { if (!entity) { return; } this.entities["delete"](entity); }, addUpdateSystem: function addUpdateSystem(system) { if (typeof system.update === 'function') { this.updateSystems.add(system); } }, removeUpdateSystem: function removeUpdateSystem(system) { this.updateSystems["delete"](system); }, update: function update(deltaTime) { var _iterator = _createForOfIteratorHelper(this.updateSystems), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var system = _step.value; system.update(deltaTime); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } var _iterator2 = _createForOfIteratorHelper(this.entities), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var entity = _step2.value; if (entity.update) { try { entity.update(deltaTime); } catch (error) { console.error('Error updating entity:', error); this.cleanup(entity); } } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } }, cleanup: function cleanup(entity) { if (!entity || entity._cleaned) { return; } entity._cleaned = true; // Stop all associated sounds if (entity._sounds instanceof Set) { var _iterator3 = _createForOfIteratorHelper(entity._sounds), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var _sound; var soundName = _step3.value; var sound = LK.getSound(soundName); if ((_sound = sound) !== null && _sound !== void 0 && _sound.stop) { sound.stop(); } } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } entity._sounds.clear(); entity._sounds = null; } // Clear all timers if (entity._timers instanceof Set) { var _iterator4 = _createForOfIteratorHelper(entity._timers), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var timer = _step4.value; LK.clearTimeout(timer); } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } entity._timers.clear(); entity._timers = null; } // Return to pool or remove from parent this.unregister(entity); if (entity.type && EntityPool.pools[entity.type]) { EntityPool["return"](entity.type, entity); } else if (entity.parent) { entity.parent.removeChild(entity); } entity._destroyed = true; entity.parent = null; }, cleanupAll: function cleanupAll() { var _iterator5 = _createForOfIteratorHelper(this.entities), _step5; try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { var entity = _step5.value; this.cleanup(entity); } } catch (err) { _iterator5.e(err); } finally { _iterator5.f(); } this.entities.clear(); EntityPool.clearAll(); } }; function BirdMovement(bird, birdGraphics, birdType) { return MovementFactory.createMovement(bird, birdGraphics, birdType); } function UFOMovement(ufo, ufoGraphics) { return MovementFactory.createMovement(ufo, ufoGraphics, 'ufo'); } /** * Jet movement configuration */ /** * Laser movement configuration */ function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) { // 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 laser.vx = dx / distance * speed; laser.vy = dy / distance * speed; // Set initial position laser.x = startX; laser.y = startY; // Initializes entity movement parameters with laser-specific configuration createMovementSystem(laser, laserGraphics, { entityType: 'laser', sounds: { move: 'laser2', destroy: null }, scoreValue: 0, screenBounds: { width: 2048, height: 2732 } }); return laser; } // Bird2Effects class to handle bird visual effects var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { try { // Apply swooping animation effect tween(this.bird, { rotation: Math.sin(this.bird.y / 100) * 0.2 }, { duration: 1000, easing: tween.easeInOut }); // Apply scale pulsing effect when moving fast if (Math.abs(this.bird.x - this.bird.lastX) > 5) { tween(this.bird, { scaleX: 1.1, scaleY: 1.1 }, { duration: 500, easing: tween.easeOut, onFinish: function () { tween(this.bird, { scaleX: 1.0, scaleY: 1.0 }, { duration: 500, easing: tween.easeIn }); }.bind(this) }); } } catch (error) { console.error('Error in Bird2Effects:', error); } }; }; // 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; }; }; // Game input handlers with proper cleanup var LaserSystem = /*#__PURE__*/function () { function LaserSystem() { _classCallCheck(this, LaserSystem); this.activeLasers = new Set(); this._cleanupQueue = new Set(); } return _createClass(LaserSystem, [{ key: "addLaser", value: function addLaser(laser) { if (!laser) { return; } this.activeLasers.add(laser); } }, { key: "queueForCleanup", value: function queueForCleanup(laser) { if (!laser) { return; } this._cleanupQueue.add(laser); } }, { key: "update", value: function update() { // Handle cleanup queue if (this._cleanupQueue.size > 0) { var _iterator6 = _createForOfIteratorHelper(this._cleanupQueue), _step6; try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { var laser = _step6.value; this.activeLasers["delete"](laser); EntityManager.cleanup(laser); } } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } this._cleanupQueue.clear(); } // Update active lasers var _iterator7 = _createForOfIteratorHelper(this.activeLasers), _step7; try { for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { var laser = _step7.value; if (!laser || laser._destroyed) { this.queueForCleanup(laser); continue; } if (laser.update) { laser.update(); } } } catch (err) { _iterator7.e(err); } finally { _iterator7.f(); } } }, { key: "clear", value: function clear() { var _iterator8 = _createForOfIteratorHelper(this.activeLasers), _step8; try { for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { var laser = _step8.value; EntityManager.cleanup(laser); } } catch (err) { _iterator8.e(err); } finally { _iterator8.f(); } this.activeLasers.clear(); this._cleanupQueue.clear(); } }]); }(); // Initialize laser system var laserSystem = new LaserSystem(); // game.down is already defined above with proper laser system integration game.move = function (x, y, obj) { try { if (!game.reticle) { game.reticle = new Reticle(); game.layers.reticle.addChild(game.reticle); } var eventX = obj && obj.event ? obj.event.x : x; var eventY = obj && obj.event ? obj.event.y : y; if (game.reticle) { game.reticle.x = eventX; game.reticle.y = eventY; } } catch (error) { console.error('Error in game.move:', error); } }; // Initialize sun and light1 (already added to layers) var sun = game.layers.sun.getChildAt(0); sun.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); var light1 = game.layers.light1.getChildAt(0); // Add score display if not already present if (!game.scoreDisplay) { game.scoreDisplay = game.addChild(new Mirror()); game.scoreDisplay.x = 1700; game.scoreDisplay.y = 300; } // Function to add a UFO to the game // Initialize game state var GameState = { clouds: [], birds: [], ufo: null, score: 0, cat: null, scoreDisplay: null }; // Initialize clouds array var clouds = []; //GameState.clouds = []; //GameState.birds = []; //GameState.score = 0; for (var i = 0; i < 4; 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 GameState.clouds.push(cloud); game.layers.clouds.addChild(cloud); // No need to add cloud directly to game since it's already in the clouds layer } // Initialize birds function spawnBird1() { var bird = EntityManager.spawn('bird1'); if (bird) { bird.x = Math.random() * 2048; bird.y = -bird.height; game.layers.birds.addChild(bird); GameState.birds.push(bird); } } function spawnBird2() { var bird = EntityManager.spawn('bird2'); if (bird) { bird.x = Math.random() * 2048; bird.y = -bird.height; game.layers.birds.addChild(bird); GameState.birds.push(bird); } } // Initial bird spawns spawnBird1(); spawnBird2(); spawnBird2(); // Start UFO 3 seconds after game loads var ufo; var ufoTimer = LK.setTimeout(function () { ufo = new UFO(); GameState.ufo = ufo; game.layers.enemies.addChild(GameState.ufo); }, 3000); // Function to handle UFO reappearance logic function handleUFOReappearance() { if (!ufo) { LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 10000 + 20000); } } // Function to handle jet reappearance logic var jetTimer; function handleJetReappearance() { try { jetTimer = LK.setTimeout(function () { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2 - jet.height); // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); game.jetSoundPlayed = true; } }, Math.random() * 5000 + 5000); } catch (error) { console.error('Error in handleJetReappearance:', error); } } // Initialize a timer to add a Jet at a random time between 5 and 10 seconds // Initial interval for Jet appearances 5-10 seconds after page load // Initialize enemy movement systems function initEnemyMovement(enemy) { if (enemy instanceof Bird1) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1'); } if (enemy instanceof Bird2) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2'); } if (enemy instanceof UFO) { enemy.movementSystem = new UFOMovement(enemy, enemy.graphics); } } function gameTick() { try { updateClouds(); updateEnemies(); updateLasers(); checkInteractions(); requestAnimationFrame(gameTick); } catch (error) { console.error('Error in game tick:', error); requestAnimationFrame(gameTick); } } function updateClouds() { // Update existing clouds for (var i = 0; i < GameState.clouds.length; i++) { GameState.clouds[i].update(); } // Ensure minimum cloud count while (GameState.clouds.length < 3) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); GameState.clouds.push(cloud); game.layers.clouds.addChild(cloud); } } var EntityUpdateSystem = { screenWidth: 2048, screenHeight: 2732, bounceFactor: 5, update: function update() { var _this4 = this; var enemies = game.layers.enemies.children; enemies.forEach(function (enemy) { if (!(enemy !== null && enemy !== void 0 && enemy.update)) { return; } enemy.update(); if (enemy instanceof Bird1 || enemy instanceof Bird2) { _this4._handleBirdUpdate(enemy, enemies); } }); }, _handleBirdUpdate: function _handleBirdUpdate(bird, enemies) { this._checkCollisions(bird, enemies); this._checkRespawn(bird); }, _checkCollisions: function _checkCollisions(bird, enemies) { var _this5 = this; if (bird.lastIntersecting) { bird.lastIntersecting = this._isIntersectingAny(bird, enemies); return; } enemies.forEach(function (otherEnemy) { if (_this5._shouldSkipCollision(bird, otherEnemy)) { return; } if (bird.intersects(otherEnemy)) { _this5._resolveBirdCollision(bird, otherEnemy); } }); }, _shouldSkipCollision: function _shouldSkipCollision(bird, otherEnemy) { return bird === otherEnemy || !(otherEnemy instanceof Bird1 || otherEnemy instanceof Bird2); }, _resolveBirdCollision: function _resolveBirdCollision(bird, otherEnemy) { var _this$_getCollisionVe = this._getCollisionVectors(bird, otherEnemy), _this$_getCollisionVe2 = _slicedToArray(_this$_getCollisionVe, 3), dx = _this$_getCollisionVe2[0], dy = _this$_getCollisionVe2[1], distance = _this$_getCollisionVe2[2]; bird.x += dx / distance * this.bounceFactor; bird.y += dy / distance * this.bounceFactor; otherEnemy.x -= dx / distance * this.bounceFactor; otherEnemy.y -= dy / distance * this.bounceFactor; bird.lastIntersecting = true; otherEnemy.lastIntersecting = true; }, _getCollisionVectors: function _getCollisionVectors(bird, otherEnemy) { var dx = bird.x - otherEnemy.x; var dy = bird.y - otherEnemy.y; var distance = Math.sqrt(dx * dx + dy * dy) || 1; return [dx, dy, distance]; }, _isIntersectingAny: function _isIntersectingAny(bird, enemies) { return enemies.some(function (otherEnemy) { return bird !== otherEnemy && bird.intersects(otherEnemy); }); }, _checkRespawn: function _checkRespawn(bird) { if (bird.lastY <= this.screenHeight && bird.y > this.screenHeight) { bird.y = -bird.height; bird.x = Math.random() * this.screenWidth; bird.speed = 1 + Math.random() * 0.6; } } }; function updateEnemies() { EntityUpdateSystem.update(); } function updateLasers() { if (!game.layers.laser) { return; } game.layers.laser.children.forEach(function (laser) { if (laser && typeof laser.update === 'function') { laser.update(); } }); } // Start the game loop requestAnimationFrame(gameTick); // Note: Tree, stack1, grassBack, grassFront and mirror are already added to their respective layers earlier in the code function playSoundEffect(soundName) { var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'play'; var volume = arguments.length > 2 ? arguments[2] : undefined; var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var effectVolume = volume || GAME_SOUND_VOLUMES[soundName] || 1; if (action === 'play') { SoundManager.play(soundName, { volume: effectVolume, loops: loops }); } else if (action === 'stop') { SoundManager.stop(soundName); } } // Initialize sound system SoundManager.init(); // Initialize cat instance GameState.cat = new Cat(); GameState.cat.x = 2048 / 2; GameState.cat.y = 2732 - 100; GameState.cat.lastX = GameState.cat.x; game.layers.cat.addChild(GameState.cat); var AudioSystem = { _initialized: false, _bgmPlaying: false, init: function init() { var _this6 = this; return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!_this6._initialized) { _context.next = 5; break; } return _context.abrupt("return"); case 5: _context.prev = 6; _context.next = 10; return Promise.all([_this6._initBackgroundMusic(), _this6._initAmbientSounds()]); case 10: _this6._initialized = true; _context.next = 18; break; case 14: _context.prev = 14; _context.t0 = _context["catch"](6); console.error('Failed to initialize audio system:', _context.t0); case 18: case "end": return _context.stop(); } } }, _callee, null, [[6, 14]]); }))(); }, _initBackgroundMusic: function _initBackgroundMusic() { var _this7 = this; return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { var bgm; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: bgm = LK.getSound('bgm1'); if (bgm) { _context2.next = 7; break; } return _context2.abrupt("return"); case 7: bgm.volume = GAME_SOUND_VOLUMES.bgm1 || 0.1; bgm.loop = true; // Start background music _this7._bgmPlaying = true; _context2.next = 16; return bgm.play(); case 16: case "end": return _context2.stop(); } } }, _callee2); }))(); }, _initAmbientSounds: function _initAmbientSounds() { return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { var ambientSounds, _i, _ambientSounds, soundName, sound; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: ambientSounds = ['breeze1', 'cricket1', 'frog1', 'songbird1']; _i = 0, _ambientSounds = ambientSounds; case 5: if (!(_i < _ambientSounds.length)) { _context3.next = 25; break; } soundName = _ambientSounds[_i]; sound = LK.getSound(soundName); if (sound) { _context3.next = 15; break; } return _context3.abrupt("continue", 22); case 15: sound.volume = GAME_SOUND_VOLUMES[soundName] || 0.1; sound.loop = true; _context3.next = 22; return sound.play(); case 22: _i++; _context3.next = 5; break; case 25: case "end": return _context3.stop(); } } }, _callee3); }))(); }, toggleBackgroundMusic: function toggleBackgroundMusic() { var bgm = LK.getSound('bgm1'); if (!bgm) { return; } if (this._bgmPlaying) { bgm.stop(); } else { bgm.play(); } this._bgmPlaying = !this._bgmPlaying; } }; // Initialize audio system AudioSystem.init(); /** * Check for interactions between game entities */ var CollisionSystem = { handleLaserCollision: function handleLaserCollision(laser, enemy) { if (!(laser !== null && laser !== void 0 && laser.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || !laser.intersects(enemy)) { return false; } try { var destroyed = enemy.handleLaserCollision ? enemy.handleLaserCollision(laser) : function () { EntityManager.cleanup(enemy); EntityManager.cleanup(laser); return true; }(); if (destroyed) { var _enemy$getScoreValue, _GameState$scoreDispl, _GameState$scoreDispl2; var points = ((_enemy$getScoreValue = enemy.getScoreValue) === null || _enemy$getScoreValue === void 0 ? void 0 : _enemy$getScoreValue.call(enemy)) || enemy.scoreValue || 5; GameState.score += points; (_GameState$scoreDispl = GameState.scoreDisplay) === null || _GameState$scoreDispl === void 0 || (_GameState$scoreDispl2 = _GameState$scoreDispl.updateScore) === null || _GameState$scoreDispl2 === void 0 || _GameState$scoreDispl2.call(_GameState$scoreDispl, GameState.score); return true; } } catch (error) { console.error('Error handling laser collision:', error); } return false; }, handleUFOCollision: function handleUFOCollision(ufo, enemy) { if (!(ufo !== null && ufo !== void 0 && ufo.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || enemy === ufo || !ufo.intersects(enemy)) { return; } try { EntityManager.cleanup(enemy); SoundManager.play('electro'); } catch (error) { console.error('Error handling UFO collision:', error); } }, checkCollisions: function checkCollisions() { try { var _game$layers$enemies, _game$layers$laser; var enemies = ((_game$layers$enemies = game.layers.enemies) === null || _game$layers$enemies === void 0 ? void 0 : _game$layers$enemies.children) || []; var lasers = ((_game$layers$laser = game.layers.laser) === null || _game$layers$laser === void 0 ? void 0 : _game$layers$laser.children) || []; // Process laser collisions var _iterator9 = _createForOfIteratorHelper(lasers), _step9; try { for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { var laser = _step9.value; if (!laser || laser._destroyed) { continue; } var _iterator11 = _createForOfIteratorHelper(enemies), _step11; try { for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) { var enemy = _step11.value; if (!enemy || enemy._destroyed) { continue; } if (this.handleLaserCollision(laser, enemy)) { break; } } } catch (err) { _iterator11.e(err); } finally { _iterator11.f(); } } // Process UFO collisions } catch (err) { _iterator9.e(err); } finally { _iterator9.f(); } var ufo = enemies.find(function (child) { return child instanceof UFO && !child._destroyed; }); if (ufo) { var _iterator10 = _createForOfIteratorHelper(enemies), _step10; try { for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) { var enemy = _step10.value; if (!enemy || enemy._destroyed || enemy === ufo) { continue; } this.handleUFOCollision(ufo, enemy); } } catch (err) { _iterator10.e(err); } finally { _iterator10.f(); } } } catch (error) { console.error('Error in checkCollisions:', error); } } }; function checkInteractions() { CollisionSystem.checkCollisions(); } /***** * Utility Functions ****/ /** * Simple movement update function that works with the consolidated movement system * This is kept for backward compatibility with existing code that uses it */ function updateMovement(obj, params) { try { if (!obj || !params) { console.error('Invalid parameters for updateMovement'); return; } // If the object already has a movement system applied, use that if (typeof obj.update === 'function' && obj.speed !== undefined) { obj.speed = params.speed || obj.speed; obj.direction = params.direction || obj.direction; return; } // Otherwise apply simple movement obj.x += (params.speed || 1) * (params.direction || 1); if (params.boundaryCheck) { handleScreenBoundaries(obj, params.boundaryWidth); } // Store last position for next update obj.lastX = obj.x; obj.lastY = obj.y; } catch (error) { console.error('Error in updateMovement:', error); } } function updateDirection(obj, graphics, rightAsset, leftAsset) { graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture; } function handleScreenBoundaries(obj, screenWidth) { if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) { obj.x = -obj.width / 2; } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) { obj.x = screenWidth + obj.width / 2; } } function handleCollisions(obj, others, collisionHandler) { others.forEach(function (other) { if (other !== obj && obj.intersects(other)) { collisionHandler(obj, other); } }); } function handleSunInteraction(obj, sun, enterHandler, exitHandler) { var intersecting = obj.intersects(sun); if (!obj.lastIntersecting && intersecting) { enterHandler(obj); } else if (obj.lastIntersecting && !intersecting) { exitHandler(obj); } obj.lastIntersecting = intersecting; } function handleDestruction(obj, sounds) { if (!obj) { return; } if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) { if (Array.isArray(sounds)) { sounds.forEach(function (sound) { return SoundManager.stop(sound); }); } if (typeof obj.destroy === 'function') { obj.destroy(); } } } // Updated Cloud update method self.cloud.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction, boundaryCheck: true, boundaryWidth: 2048 }); handleCollisions(this, clouds, function (cloud, other) { if (!cloud.hasAccelerated) { cloud.speed *= 1.5; cloud.hasAccelerated = true; } }); handleSunInteraction(this, sun, function (cloud) { cloud.speed *= 2; tween(cloud.cloudGraphics, { alpha: 0.5 }, { duration: 3000 }); }, function (cloud) { cloud.speed /= 2; tween(cloud.cloudGraphics, { alpha: 1.0 }, { duration: 3000 }); }); this.lastX = this.x; }; // Updated Jet update method self.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction }); updateDirection(this, jetGraphics, 'jet-right', 'jet-left'); handleDestruction(this, ['jetSound']); };
===================================================================
--- original.js
+++ change.js
@@ -3,626 +3,1847 @@
****/
var tween = LK.import("@upit/tween.v1");
/****
-* Classes
+* Initialize Game
****/
-// 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-right', {
- anchorX: 0.5,
- anchorY: 0.5
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+// Images
+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 _regeneratorRuntime() {
+ "use strict";
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
+ _regeneratorRuntime = function _regeneratorRuntime() {
+ return e;
+ };
+ var t,
+ e = {},
+ r = Object.prototype,
+ n = r.hasOwnProperty,
+ o = Object.defineProperty || function (t, e, r) {
+ t[e] = r.value;
+ },
+ i = "function" == typeof Symbol ? Symbol : {},
+ a = i.iterator || "@@iterator",
+ c = i.asyncIterator || "@@asyncIterator",
+ u = i.toStringTag || "@@toStringTag";
+ function define(t, e, r) {
+ return Object.defineProperty(t, e, {
+ value: r,
+ enumerable: !0,
+ configurable: !0,
+ writable: !0
+ }), t[e];
+ }
+ try {
+ define({}, "");
+ } catch (t) {
+ define = function define(t, e, r) {
+ return t[e] = r;
+ };
+ }
+ function wrap(t, e, r, n) {
+ var i = e && e.prototype instanceof Generator ? e : Generator,
+ a = Object.create(i.prototype),
+ c = new Context(n || []);
+ return o(a, "_invoke", {
+ value: makeInvokeMethod(t, r, c)
+ }), a;
+ }
+ function tryCatch(t, e, r) {
+ try {
+ return {
+ type: "normal",
+ arg: t.call(e, r)
+ };
+ } catch (t) {
+ return {
+ type: "throw",
+ arg: t
+ };
+ }
+ }
+ e.wrap = wrap;
+ var h = "suspendedStart",
+ l = "suspendedYield",
+ f = "executing",
+ s = "completed",
+ y = {};
+ function Generator() {}
+ function GeneratorFunction() {}
+ function GeneratorFunctionPrototype() {}
+ var p = {};
+ define(p, a, function () {
+ return this;
});
- self.speed = Math.random() * 1.6 + 1;
- self.lastY = self.y; // Initialize lastY for tracking changes on Y
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- self.update = function () {
- self.y += self.speed;
- self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- // Check if the bird has moved off-screen
- if (self.lastY <= 2732 && self.y > 2732) {
- self.y = -self.height;
- self.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
+ var d = Object.getPrototypeOf,
+ v = d && d(d(values([])));
+ v && v !== r && n.call(v, a) && (p = v);
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
+ function defineIteratorMethods(t) {
+ ["next", "throw", "return"].forEach(function (e) {
+ define(t, e, function (t) {
+ return this._invoke(e, t);
+ });
+ });
+ }
+ function AsyncIterator(t, e) {
+ function invoke(r, o, i, a) {
+ var c = tryCatch(t[r], t, o);
+ if ("throw" !== c.type) {
+ var u = c.arg,
+ h = u.value;
+ return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
+ invoke("next", t, i, a);
+ }, function (t) {
+ invoke("throw", t, i, a);
+ }) : e.resolve(h).then(function (t) {
+ u.value = t, i(u);
+ }, function (t) {
+ return invoke("throw", t, i, a);
+ });
+ }
+ a(c.arg);
}
- if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
- birdGraphics.texture = LK.getAsset('bird1-right', {}).texture;
- } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
- birdGraphics.texture = LK.getAsset('bird1-left', {}).texture;
+ var r;
+ o(this, "_invoke", {
+ value: function value(t, n) {
+ function callInvokeWithMethodAndArg() {
+ return new e(function (e, r) {
+ invoke(t, n, e, r);
+ });
+ }
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
+ }
+ });
+ }
+ function makeInvokeMethod(e, r, n) {
+ var o = h;
+ return function (i, a) {
+ if (o === f) {
+ throw Error("Generator is already running");
+ }
+ if (o === s) {
+ if ("throw" === i) {
+ throw a;
+ }
+ return {
+ value: t,
+ done: !0
+ };
+ }
+ for (n.method = i, n.arg = a;;) {
+ var c = n.delegate;
+ if (c) {
+ var u = maybeInvokeDelegate(c, n);
+ if (u) {
+ if (u === y) {
+ continue;
+ }
+ return u;
+ }
+ }
+ if ("next" === n.method) {
+ n.sent = n._sent = n.arg;
+ } else if ("throw" === n.method) {
+ if (o === h) {
+ throw o = s, n.arg;
+ }
+ n.dispatchException(n.arg);
+ } else {
+ "return" === n.method && n.abrupt("return", n.arg);
+ }
+ o = f;
+ var p = tryCatch(e, r, n);
+ if ("normal" === p.type) {
+ if (o = n.done ? s : l, p.arg === y) {
+ continue;
+ }
+ return {
+ value: p.arg,
+ done: n.done
+ };
+ }
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
+ }
+ };
+ }
+ function maybeInvokeDelegate(e, r) {
+ var n = r.method,
+ o = e.iterator[n];
+ if (o === t) {
+ return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
}
- self.lastY = self.y; // Update lastY after movement
- self.lastX = self.x; // Update lastX after movement
+ var i = tryCatch(o, e.iterator, r.arg);
+ if ("throw" === i.type) {
+ return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
+ }
+ var a = i.arg;
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
+ }
+ function pushTryEntry(t) {
+ var e = {
+ tryLoc: t[0]
+ };
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
+ }
+ function resetTryEntry(t) {
+ var e = t.completion || {};
+ e.type = "normal", delete e.arg, t.completion = e;
+ }
+ function Context(t) {
+ this.tryEntries = [{
+ tryLoc: "root"
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
+ }
+ function values(e) {
+ if (e || "" === e) {
+ var r = e[a];
+ if (r) {
+ return r.call(e);
+ }
+ if ("function" == typeof e.next) {
+ return e;
+ }
+ if (!isNaN(e.length)) {
+ var o = -1,
+ i = function next() {
+ for (; ++o < e.length;) {
+ if (n.call(e, o)) {
+ return next.value = e[o], next.done = !1, next;
+ }
+ }
+ return next.value = t, next.done = !0, next;
+ };
+ return i.next = i;
+ }
+ }
+ throw new TypeError(_typeof(e) + " is not iterable");
+ }
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
+ value: GeneratorFunctionPrototype,
+ configurable: !0
+ }), o(GeneratorFunctionPrototype, "constructor", {
+ value: GeneratorFunction,
+ configurable: !0
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
+ var e = "function" == typeof t && t.constructor;
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
+ }, e.mark = function (t) {
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
+ }, e.awrap = function (t) {
+ return {
+ __await: t
+ };
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
+ return this;
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
+ void 0 === i && (i = Promise);
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
+ return t.done ? t.value : a.next();
+ });
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
+ return this;
+ }), define(g, "toString", function () {
+ return "[object Generator]";
+ }), e.keys = function (t) {
+ var e = Object(t),
+ r = [];
+ for (var n in e) {
+ r.push(n);
+ }
+ return r.reverse(), function next() {
+ for (; r.length;) {
+ var t = r.pop();
+ if (t in e) {
+ return next.value = t, next.done = !1, next;
+ }
+ }
+ return next.done = !0, next;
+ };
+ }, e.values = values, Context.prototype = {
+ constructor: Context,
+ reset: function reset(e) {
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) {
+ for (var r in this) {
+ "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
+ }
+ }
+ },
+ stop: function stop() {
+ this.done = !0;
+ var t = this.tryEntries[0].completion;
+ if ("throw" === t.type) {
+ throw t.arg;
+ }
+ return this.rval;
+ },
+ dispatchException: function dispatchException(e) {
+ if (this.done) {
+ throw e;
+ }
+ var r = this;
+ function handle(n, o) {
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
+ }
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
+ var i = this.tryEntries[o],
+ a = i.completion;
+ if ("root" === i.tryLoc) {
+ return handle("end");
+ }
+ if (i.tryLoc <= this.prev) {
+ var c = n.call(i, "catchLoc"),
+ u = n.call(i, "finallyLoc");
+ if (c && u) {
+ if (this.prev < i.catchLoc) {
+ return handle(i.catchLoc, !0);
+ }
+ if (this.prev < i.finallyLoc) {
+ return handle(i.finallyLoc);
+ }
+ } else if (c) {
+ if (this.prev < i.catchLoc) {
+ return handle(i.catchLoc, !0);
+ }
+ } else {
+ if (!u) {
+ throw Error("try statement without catch or finally");
+ }
+ if (this.prev < i.finallyLoc) {
+ return handle(i.finallyLoc);
+ }
+ }
+ }
+ }
+ },
+ abrupt: function abrupt(t, e) {
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
+ var o = this.tryEntries[r];
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
+ var i = o;
+ break;
+ }
+ }
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
+ var a = i ? i.completion : {};
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
+ },
+ complete: function complete(t, e) {
+ if ("throw" === t.type) {
+ throw t.arg;
+ }
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
+ },
+ finish: function finish(t) {
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
+ var r = this.tryEntries[e];
+ if (r.finallyLoc === t) {
+ return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
+ }
+ }
+ },
+ "catch": function _catch(t) {
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
+ var r = this.tryEntries[e];
+ if (r.tryLoc === t) {
+ var n = r.completion;
+ if ("throw" === n.type) {
+ var o = n.arg;
+ resetTryEntry(r);
+ }
+ return o;
+ }
+ }
+ throw Error("illegal catch attempt");
+ },
+ delegateYield: function delegateYield(e, r, n) {
+ return this.delegate = {
+ iterator: values(e),
+ resultName: r,
+ nextLoc: n
+ }, "next" === this.method && (this.arg = t), y;
+ }
+ }, e;
+}
+function asyncGeneratorStep(n, t, e, r, o, a, c) {
+ try {
+ var i = n[a](c),
+ u = i.value;
+ } catch (n) {
+ return void e(n);
+ }
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
+}
+function _asyncToGenerator(n) {
+ return function () {
+ var t = this,
+ e = arguments;
+ return new Promise(function (r, o) {
+ var a = n.apply(t, e);
+ function _next(n) {
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
+ }
+ function _throw(n) {
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
+ }
+ _next(void 0);
+ });
};
-});
-// Bird2 class to represent the second kind of bird
-var Bird2 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird2-right', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = Math.random() * 1.6 + 1;
- self.lastY = self.y; // Initialize lastY for tracking changes on Y
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- self.update = function () {
- self.y += self.speed;
- self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
- birdGraphics.texture = LK.getAsset('bird2-right', {}).texture;
- } else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
- birdGraphics.texture = LK.getAsset('bird2-left', {}).texture;
+}
+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;
+ }
+ }
}
- self.lastX = self.x; // Update lastX after movement
- // Check if the bird has moved off-screen
- if (self.lastY <= 2732 && self.y > 2732) {
- self.y = Math.random() * 2732; // Random initial y position within the screen height
- self.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ return a;
+ }
+}
+function _arrayWithHoles(r) {
+ if (Array.isArray(r)) {
+ return r;
+ }
+}
+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
+ };
}
- self.lastY = self.y; // Update lastY after movement
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+ }
+ var o,
+ a = !0,
+ u = !1;
+ return {
+ s: function s() {
+ t = t.call(r);
+ },
+ n: function n() {
+ var r = t.next();
+ return a = r.done, r;
+ },
+ e: function e(r) {
+ u = !0, o = r;
+ },
+ f: function f() {
+ try {
+ a || null == t["return"] || t["return"]();
+ } finally {
+ if (u) {
+ throw o;
+ }
+ }
+ }
};
+}
+function _unsupportedIterableToArray(r, a) {
+ if (r) {
+ if ("string" == typeof r) {
+ return _arrayLikeToArray(r, a);
+ }
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
+ }
+}
+function _arrayLikeToArray(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) {
+ n[e] = r[e];
+ }
+ return n;
+}
+function _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 _defineProperties(e, r) {
+ for (var t = 0; t < r.length; t++) {
+ var o = r[t];
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
+ }
+}
+function _createClass(e, r, t) {
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
+ writable: !1
+ }), e;
+}
+function _toPropertyKey(t) {
+ var i = _toPrimitive(t, "string");
+ return "symbol" == _typeof(i) ? i : i + "";
+}
+function _toPrimitive(t, r) {
+ if ("object" != _typeof(t) || !t) {
+ return t;
+ }
+ var e = t[Symbol.toPrimitive];
+ if (void 0 !== e) {
+ var i = e.call(t, r || "default");
+ if ("object" != _typeof(i)) {
+ return i;
+ }
+ throw new TypeError("@@toPrimitive must return a primitive value.");
+ }
+ return ("string" === r ? String : Number)(t);
+}
+function _classCallCheck(a, n) {
+ if (!(a instanceof n)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+}
+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 _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);
+}
+var assets = {
+ scoreImage: {
+ type: 'shape',
+ width: 100,
+ height: 100,
+ color: 0xcd1966,
+ shape: 'box'
+ },
+ background: {
+ type: 'image',
+ width: 2048,
+ height: 2732,
+ id: '67cb14d582516b65d7d56166'
+ },
+ bird1Left: {
+ type: 'image',
+ width: 300,
+ height: 295,
+ id: '67c8f938120d8830ebbf56ab'
+ },
+ bird1Right: {
+ type: 'image',
+ width: 300,
+ height: 295,
+ id: '67c8f938120d8830ebbf56ab',
+ flipX: 1
+ },
+ bird2Left: {
+ type: 'image',
+ width: 150,
+ height: 168.42,
+ id: '67c9027e120d8830ebbf5715',
+ flipX: 1
+ },
+ bird2Right: {
+ type: 'image',
+ width: 150,
+ height: 168.42,
+ id: '67c9027e120d8830ebbf5715'
+ },
+ cat: {
+ type: 'image',
+ width: 433.13,
+ height: 475.89,
+ id: '67c8fd9b120d8830ebbf56e9'
+ },
+ cloud: {
+ type: 'image',
+ width: 500,
+ height: 250,
+ id: '67c915be120d8830ebbf582c'
+ },
+ grassBack: {
+ type: 'image',
+ width: 2204.72,
+ height: 1505.21,
+ id: '67c90d44120d8830ebbf57b9'
+ },
+ grassFront: {
+ type: 'image',
+ width: 2400,
+ height: 1856.25,
+ id: '67c90db6120d8830ebbf57c5',
+ flipX: 1
+ },
+ jetLeft: {
+ type: 'image',
+ width: 200,
+ height: 75.78,
+ id: '67cbdf3f8f0bb65062649f12',
+ flipX: 1
+ },
+ jetRight: {
+ type: 'image',
+ width: 200,
+ height: 75.78,
+ id: '67cbdf3f8f0bb65062649f12'
+ },
+ laser2: {
+ type: 'image',
+ width: 100,
+ height: 101.19,
+ id: '67c9f7067f021452b5f9dcd8'
+ },
+ light1: {
+ type: 'image',
+ width: 120,
+ height: 120,
+ id: '67cbd61a8f0bb65062649e53'
+ },
+ mirror1: {
+ type: 'image',
+ width: 500,
+ height: 800,
+ id: '67cb7aec82516b65d7d56434'
+ },
+ reticle1: {
+ type: 'image',
+ width: 400,
+ height: 379.69,
+ id: '67c935fd120d8830ebbf5944'
+ },
+ stack1: {
+ type: 'image',
+ width: 700,
+ height: 737.45,
+ id: '67cb6ce882516b65d7d563cc'
+ },
+ sun: {
+ type: 'image',
+ width: 500,
+ height: 500,
+ id: '67c92a9f120d8830ebbf58c6'
+ },
+ tree: {
+ type: 'image',
+ width: 1900,
+ height: 2500,
+ id: '67c911c5120d8830ebbf5807',
+ flipX: 1
+ },
+ tree2: {
+ type: 'image',
+ width: 1900,
+ height: 2300,
+ id: '67cb5a3d82516b65d7d56300'
+ },
+ ufo: {
+ type: 'image',
+ width: 300,
+ height: 228.52,
+ id: '67c932df120d8830ebbf591b'
+ },
+ ufo2: {
+ type: 'image',
+ width: 400,
+ height: 162.5,
+ id: '67cc62364e271169e42de9e4'
+ }
+};
+Object.keys(assets).forEach(function (key) {
+ var asset = assets[key];
+ if (asset.type === 'shape') {} else if (asset.type === 'image') {}
});
-// Cat class to manage cat behavior
-var Cat = Container.expand(function () {
- var self = Container.call(this);
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- var catGraphics = self.attachAsset('cat', {
- anchorX: 0.5,
- anchorY: 1
+// Music and Sounds
+/****
+* Game Configuration
+****/
+// Sound configuration
+var GAME_SOUND_VOLUMES = {
+ bgm1: 0.02,
+ breeze1: 0.02,
+ cricket1: 0.02,
+ frog1: 0.02,
+ songbird1: 0.02,
+ ufo1: 0.02,
+ wings1: 0.02,
+ laser1: 0.1,
+ laser2: 0.1,
+ jetSound: 0.3
+};
+/****
+* Core Game Setup
+****/
+// Initialize game instance
+var gameInstance;
+if (!gameInstance) {
+ gameInstance = new LK.Game({
+ backgroundColor: 0x000000
});
- 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 cloudGraphics = self.attachAsset('cloud', {
- 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 () {
- 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;
+}
+// Layer structure initialization
+var layers = {
+ background: new Container(),
+ sun: new Container(),
+ light1: new Container(),
+ jet: new Container(),
+ clouds: new Container(),
+ ufo: new Container(),
+ grassBack: new Container()
+};
+var Background = /*#__PURE__*/function (_Container) {
+ function Background() {
+ var _this;
+ _classCallCheck(this, Background);
+ _this = _callSuper(this, Background);
+ _this.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return _this;
+ }
+ _inherits(Background, _Container);
+ return _createClass(Background);
+}(Container); // Branch asset
+var Bird = /*#__PURE__*/function (_Container2) {
+ function Bird(type) {
+ var _this2;
+ _classCallCheck(this, Bird);
+ _this2 = _callSuper(this, Bird);
+ if (!type) {
+ throw new Error('Bird type is required');
}
- // 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
- }
- break;
- } else if (self.hasAccelerated && !self.intersects(clouds[i])) {
- self.speed /= 1.5; // Reset speed to original
- self.hasAccelerated = false; // Reset acceleration state
+ _this2.birdGraphics = _this2.attachAsset("".concat(type, "Right"), {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // The attachAsset method will throw an error if it fails, so we don't need to check again
+ createMovementSystem(_this2, _this2.birdGraphics, MOVEMENT_CONFIGS[type]);
+ return _this2;
+ }
+ _inherits(Bird, _Container2);
+ return _createClass(Bird, [{
+ key: "setChildIndex",
+ value: function setChildIndex(index) {
+ if (game.children.includes(this)) {
+ game.setChildIndex(this, index);
}
}
- // 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
+ }, {
+ key: "destroy",
+ value: function destroy() {
+ if (this.birdGraphics) {
+ this.birdGraphics.destroy();
+ this.birdGraphics = null;
+ }
+ _superPropGet(Bird, "destroy", this, 3)([]);
+ }
+ }]);
+}(Container);
+var Bird1 = /*#__PURE__*/function (_Bird) {
+ function Bird1() {
+ _classCallCheck(this, Bird1);
+ var self = _callSuper(this, Bird1, ['bird1']);
+ self.lastX = self.x;
+ return self;
+ }
+ _inherits(Bird1, _Bird);
+ return _createClass(Bird1);
+}(Bird);
+var Bird2 = /*#__PURE__*/function (_Bird2) {
+ function Bird2() {
+ _classCallCheck(this, Bird2);
+ var self = _callSuper(this, Bird2, ['bird2']);
+ self.lastX = self.x;
+ return self;
+ }
+ _inherits(Bird2, _Bird2);
+ return _createClass(Bird2);
+}(Bird); // Layer z-index management is handled by the layerStructure configuration
+// Layer structure and initialization is already handled at the beginning of the file
+// Consolidated checkInteractions function is inserted below
+// Bird2Movement class to handle Bird2 movement
+// Bird2Movement class to handle Bird2 movement
+/**
+* Configures movement behavior for game entities with tween-based animations
+* @param {Container} entity - Target entity container
+* @param {Graphics} graphics - Visual representation to animate
+* @param {Object} config - Movement configuration:
+* @param {number} [config.baseSpeed=1] - Base movement speed
+* @param {Object} config.textures - Directional sprites {left, right}
+* @param {boolean} [config.useWaveMotion=false] - Enable sine-based path
+* @param {number} [config.waveAmplitude=0] - Vertical deviation magnitude
+* @param {number} [config.waveFrequency=100] - Horizontal wave cycle length
+*/
+// Consolidated movement system with state tracking and error boundaries
+// Unified entity management system with improved cleanup
+var EntityPool = {
+ pools: {},
+ maxPoolSize: 50,
+ initialize: function initialize(entityType, factory) {
+ var initialSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
+ if (!this.pools[entityType]) {
+ this.pools[entityType] = [];
+ for (var i = 0; i < initialSize; i++) {
+ var entity = factory();
+ entity.type = entityType;
+ entity.reset = function () {
+ this.x = 0;
+ this.y = 0;
+ this.alpha = 1;
+ this.scale.set(1);
+ this.rotation = 0;
+ this._destroyed = false;
+ this._cleaned = false;
+ };
+ this.pools[entityType].push(entity);
+ }
+ }
+ },
+ get: function get(entityType) {
+ if (!this.pools[entityType] || this.pools[entityType].length === 0) {
+ return null;
+ }
+ var entity = this.pools[entityType].pop();
+ entity.reset();
+ return entity;
+ },
+ "return": function _return(entityType, entity) {
+ if (!this.pools[entityType]) {
+ return;
+ }
+ if (this.pools[entityType].length >= this.maxPoolSize) {
+ entity.destroy();
+ return;
+ }
+ if (!this.pools[entityType].includes(entity)) {
+ this.pools[entityType].push(entity);
+ }
+ },
+ clear: function clear(entityType) {
+ if (this.pools[entityType]) {
+ this.pools[entityType].forEach(function (entity) {
+ if (entity.destroy) {
+ entity.destroy();
+ }
});
- } 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
- });
+ this.pools[entityType] = [];
}
- self.lastIntersecting = self.intersects(sun);
- self.lastX = self.x; // Update lastX after movement
- };
-});
-// CloudMovement class to handle cloud movement and fade effects
-var CloudMovement = Container.expand(function () {
- var self = Container.call(this);
- var cloudGraphics = self.attachAsset('cloud', {
- 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 () {
- 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;
+ },
+ clearAll: function clearAll() {
+ var _this3 = this;
+ Object.keys(this.pools).forEach(function (type) {
+ return _this3.clear(type);
+ });
+ this.pools = {};
+ }
+};
+var EntityManager = {
+ entities: new Set(),
+ updateSystems: new Set(),
+ register: function register(entity) {
+ if (!entity) {
+ return;
}
- // 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
+ this.entities.add(entity);
+ },
+ unregister: function unregister(entity) {
+ if (!entity) {
+ return;
+ }
+ this.entities["delete"](entity);
+ },
+ addUpdateSystem: function addUpdateSystem(system) {
+ if (typeof system.update === 'function') {
+ this.updateSystems.add(system);
+ }
+ },
+ removeUpdateSystem: function removeUpdateSystem(system) {
+ this.updateSystems["delete"](system);
+ },
+ update: function update(deltaTime) {
+ var _iterator = _createForOfIteratorHelper(this.updateSystems),
+ _step;
+ try {
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
+ var system = _step.value;
+ system.update(deltaTime);
+ }
+ } catch (err) {
+ _iterator.e(err);
+ } finally {
+ _iterator.f();
+ }
+ var _iterator2 = _createForOfIteratorHelper(this.entities),
+ _step2;
+ try {
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
+ var entity = _step2.value;
+ if (entity.update) {
+ try {
+ entity.update(deltaTime);
+ } catch (error) {
+ console.error('Error updating entity:', error);
+ this.cleanup(entity);
+ }
}
- break;
- } else if (self.hasAccelerated && !self.intersects(clouds[i])) {
- self.speed /= 1.5; // Reset speed to original
- self.hasAccelerated = false; // Reset acceleration state
}
+ } catch (err) {
+ _iterator2.e(err);
+ } finally {
+ _iterator2.f();
}
- // 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
- });
+ },
+ cleanup: function cleanup(entity) {
+ if (!entity || entity._cleaned) {
+ return;
}
- self.lastIntersecting = self.intersects(sun);
- self.lastX = self.x; // Update lastX after movement
- };
-});
-// Grass class to represent the grass image
-var Grass = Container.expand(function () {
- var self = Container.call(this);
- var grassGraphics = self.attachAsset('grass', {
- 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
- };
-});
-// Grass2 class to represent the second grass image
-var Grass2 = Container.expand(function () {
- var self = Container.call(this);
- var grass2Graphics = self.attachAsset('grass2', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.lastX = self.x; // Initialize lastX for tracking changes on X
- 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
- };
-});
-// 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();
+ entity._cleaned = true;
+ // Stop all associated sounds
+ if (entity._sounds instanceof Set) {
+ var _iterator3 = _createForOfIteratorHelper(entity._sounds),
+ _step3;
+ try {
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
+ var _sound;
+ var soundName = _step3.value;
+ var sound = LK.getSound(soundName);
+ if ((_sound = sound) !== null && _sound !== void 0 && _sound.stop) {
+ sound.stop();
+ }
+ }
+ } catch (err) {
+ _iterator3.e(err);
+ } finally {
+ _iterator3.f();
+ }
+ entity._sounds.clear();
+ entity._sounds = null;
+ }
+ // Clear all timers
+ if (entity._timers instanceof Set) {
+ var _iterator4 = _createForOfIteratorHelper(entity._timers),
+ _step4;
+ try {
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
+ var timer = _step4.value;
+ LK.clearTimeout(timer);
+ }
+ } catch (err) {
+ _iterator4.e(err);
+ } finally {
+ _iterator4.f();
+ }
+ entity._timers.clear();
+ entity._timers = null;
+ }
+ // Return to pool or remove from parent
+ this.unregister(entity);
+ if (entity.type && EntityPool.pools[entity.type]) {
+ EntityPool["return"](entity.type, entity);
+ } else if (entity.parent) {
+ entity.parent.removeChild(entity);
+ }
+ entity._destroyed = true;
+ entity.parent = null;
+ },
+ cleanupAll: function cleanupAll() {
+ var _iterator5 = _createForOfIteratorHelper(this.entities),
+ _step5;
+ try {
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
+ var entity = _step5.value;
+ this.cleanup(entity);
+ }
+ } catch (err) {
+ _iterator5.e(err);
+ } finally {
+ _iterator5.f();
+ }
+ this.entities.clear();
+ EntityPool.clearAll();
+ }
+};
+function BirdMovement(bird, birdGraphics, birdType) {
+ return MovementFactory.createMovement(bird, birdGraphics, birdType);
+}
+function UFOMovement(ufo, ufoGraphics) {
+ return MovementFactory.createMovement(ufo, ufoGraphics, 'ufo');
+}
+/**
+* Jet movement configuration
+*/
+/**
+* Laser movement configuration
+*/
+function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) {
// 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;
+ var speed = 60; // Speed of the laser
+ laser.vx = dx / distance * speed;
+ laser.vy = dy / distance * speed;
// Set initial position
- self.x = startX;
- self.y = startY;
- // Update function to move the laser
- self.update = function () {
- 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();
+ laser.x = startX;
+ laser.y = startY;
+ // Initializes entity movement parameters with laser-specific configuration
+ createMovementSystem(laser, laserGraphics, {
+ entityType: 'laser',
+ sounds: {
+ move: 'laser2',
+ destroy: null
+ },
+ scoreValue: 0,
+ screenBounds: {
+ width: 2048,
+ height: 2732
}
- };
-});
-// 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
- };
-});
-// ScoreDisplay class to manage score display
-var ScoreDisplay = Container.expand(function () {
- var self = Container.call(this);
- var scoreGraphics = self.attachAsset('scoreImage', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- var scoreText = new Text2('0', {
- size: 175,
- fill: 0x00FF00,
- font: "Courier New, Courier, monospace",
- // Segmented clock style font
- stroke: 0x000000,
- strokeThickness: 5,
- dropShadow: true,
- dropShadowColor: 0x000000,
- dropShadowBlur: 5,
- dropShadowAngle: Math.PI / 6,
- dropShadowDistance: 6
- });
- scoreText.y = -100; // Move score text up by 10px
- scoreText.x = -155; // Move score text right by 10px
- x = 100;
- y = 100;
- self.addChild(scoreText);
- self.updateScore = function (newScore) {
- scoreText.setText(newScore);
- };
-});
-// ScoreManager class to manage score logic
-// 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
- });
- startPulsating(self); // Start the pulsating effect
-});
-// 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('tree', {
- anchorX: 0.5,
- anchorY: 1,
- antialias: true // Apply antialias effect
- });
- self.update = function () {
- // Add any specific update logic for the tree here
- };
-});
-// UFO class to represent a UFO flying across the screen
-var UFO = Container.expand(function () {
- var self = Container.call(this);
- var ufoGraphics = self.attachAsset('ufo', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3.2; // Decrease speed by 20%
- 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.update = function () {
- self.x += self.speed * self.direction;
- self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10%
- // If the UFO moves off-screen, destroy it and set to null
- 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();
- ufo = null;
- }
- self.lastX = self.x; // Update lastX after movement
- };
-});
-
-/****
-* Initialize Game
-****/
-/****
-* 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: 0x000000 // Black
-});
-
-/****
-* Game Code
-****/
-// Initialize UFO variable
-/****
-* Assets
-LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
-****/
-// Initialize clouds array
-var clouds = [];
-var ufo = null;
-// Bird2Effects class to handle effects and animations for Bird2
+ return laser;
+}
+// Bird2Effects class to handle bird visual effects
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
- // Add any specific effects or animations for Bird2 here
+ try {
+ // Apply swooping animation effect
+ tween(this.bird, {
+ rotation: Math.sin(this.bird.y / 100) * 0.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ // Apply scale pulsing effect when moving fast
+ if (Math.abs(this.bird.x - this.bird.lastX) > 5) {
+ tween(this.bird, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function () {
+ tween(this.bird, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ }.bind(this)
+ });
+ }
+ } catch (error) {
+ console.error('Error in Bird2Effects:', error);
+ }
};
};
-// 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
+// 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;
+ };
};
-function startPulsating(target) {
- function pulsate() {
- tween(target, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 444,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(target, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 444,
- easing: tween.easeInOut,
- onFinish: pulsate
- });
- }
- });
+// Game input handlers with proper cleanup
+var LaserSystem = /*#__PURE__*/function () {
+ function LaserSystem() {
+ _classCallCheck(this, LaserSystem);
+ this.activeLasers = new Set();
+ this._cleanupQueue = new Set();
}
- pulsate();
-}
-// Define layers and layer management
-var LAYER_BACKGROUND = 0;
-var LAYER_CLOUDS = 1;
-var LAYER_BIRDS = 2;
-var LAYER_UFO = 3;
-var LAYER_GRASS = 4;
-var LAYER_CAT = 5;
-var LAYER_RETICLE = 6;
-var LAYER_LASER = 7;
-var LAYER_SCORE = 8;
-// Layer management functions
-function setLayerIndex(object, layer) {
- game.setChildIndex(object, layer);
-}
-// Cleanup methods for each layer
-function cleanupLayer(layer) {
- var children = game.children.slice();
- for (var i = children.length - 1; i >= 0; i--) {
- var child = children[i];
- if (game.getChildIndex(child) === layer) {
- if (child.destroy) {
- child.destroy();
- } else {
- game.removeChild(child);
+ return _createClass(LaserSystem, [{
+ key: "addLaser",
+ value: function addLaser(laser) {
+ if (!laser) {
+ return;
}
+ this.activeLasers.add(laser);
}
+ }, {
+ key: "queueForCleanup",
+ value: function queueForCleanup(laser) {
+ if (!laser) {
+ return;
+ }
+ this._cleanupQueue.add(laser);
+ }
+ }, {
+ key: "update",
+ value: function update() {
+ // Handle cleanup queue
+ if (this._cleanupQueue.size > 0) {
+ var _iterator6 = _createForOfIteratorHelper(this._cleanupQueue),
+ _step6;
+ try {
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
+ var laser = _step6.value;
+ this.activeLasers["delete"](laser);
+ EntityManager.cleanup(laser);
+ }
+ } catch (err) {
+ _iterator6.e(err);
+ } finally {
+ _iterator6.f();
+ }
+ this._cleanupQueue.clear();
+ }
+ // Update active lasers
+ var _iterator7 = _createForOfIteratorHelper(this.activeLasers),
+ _step7;
+ try {
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
+ var laser = _step7.value;
+ if (!laser || laser._destroyed) {
+ this.queueForCleanup(laser);
+ continue;
+ }
+ if (laser.update) {
+ laser.update();
+ }
+ }
+ } catch (err) {
+ _iterator7.e(err);
+ } finally {
+ _iterator7.f();
+ }
+ }
+ }, {
+ key: "clear",
+ value: function clear() {
+ var _iterator8 = _createForOfIteratorHelper(this.activeLasers),
+ _step8;
+ try {
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
+ var laser = _step8.value;
+ EntityManager.cleanup(laser);
+ }
+ } catch (err) {
+ _iterator8.e(err);
+ } finally {
+ _iterator8.f();
+ }
+ this.activeLasers.clear();
+ this._cleanupQueue.clear();
+ }
+ }]);
+}(); // Initialize laser system
+var laserSystem = new LaserSystem();
+// game.down is already defined above with proper laser system integration
+game.move = function (x, y, obj) {
+ try {
+ if (!game.reticle) {
+ game.reticle = new Reticle();
+ game.layers.reticle.addChild(game.reticle);
+ }
+ var eventX = obj && obj.event ? obj.event.x : x;
+ var eventY = obj && obj.event ? obj.event.y : y;
+ if (game.reticle) {
+ game.reticle.x = eventX;
+ game.reticle.y = eventY;
+ }
+ } catch (error) {
+ console.error('Error in game.move:', error);
}
-}
-function cleanupBackground() {
- cleanupLayer(LAYER_BACKGROUND);
-}
-function cleanupClouds() {
- cleanupLayer(LAYER_CLOUDS);
- clouds = [];
-}
-function cleanupBirds() {
- cleanupLayer(LAYER_BIRDS);
- birds = [];
-}
-function cleanupUFO() {
- cleanupLayer(LAYER_UFO);
- ufo = null;
-}
-function cleanupGrass() {
- cleanupLayer(LAYER_GRASS);
-}
-function cleanupCat() {
- cleanupLayer(LAYER_CAT);
-}
-function cleanupReticle() {
- cleanupLayer(LAYER_RETICLE);
-}
-function cleanupLaser() {
- cleanupLayer(LAYER_LASER);
-}
-function cleanupScore() {
- cleanupLayer(LAYER_SCORE);
-}
-// Function to cleanup all layers
-function cleanupAllLayers() {
- for (var i = 0; i <= LAYER_SCORE; i++) {
- cleanupLayer(i);
- }
- clouds = [];
- birds = [];
- ufo = null;
-}
-// Initialize game objects with layers
-var background = LK.getAsset('background', {
+};
+// Initialize sun and light1 (already added to layers)
+var sun = game.layers.sun.getChildAt(0);
+sun.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5
});
-background.x = 2048 / 2;
-background.y = 2732 / 2 - 200;
-game.addChild(background);
-setLayerIndex(background, LAYER_BACKGROUND);
-// Add a sun to the game in the top left corner
-var sun = game.addChild(new Sun());
-sun.x = 480;
-sun.y = 590;
-setLayerIndex(sun, LAYER_CLOUDS);
+var light1 = game.layers.light1.getChildAt(0);
+// Add score display if not already present
+if (!game.scoreDisplay) {
+ game.scoreDisplay = game.addChild(new Mirror());
+ game.scoreDisplay.x = 1700;
+ game.scoreDisplay.y = 300;
+}
+// Function to add a UFO to the game
+// Initialize game state
+var GameState = {
+ clouds: [],
+ birds: [],
+ ufo: null,
+ score: 0,
+ cat: null,
+ scoreDisplay: null
+};
// Initialize clouds array
var clouds = [];
+//GameState.clouds = [];
+//GameState.birds = [];
+//GameState.score = 0;
for (var i = 0; i < 4; i++) {
+ // Add 3 clouds for variety
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2);
- clouds.push(cloud);
- game.addChild(cloud);
- setLayerIndex(cloud, LAYER_CLOUDS);
+ cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
+ GameState.clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+ // No need to add cloud directly to game since it's already in the clouds layer
}
-// Initialize birds array
-var birds = [];
// Initialize birds
+function spawnBird1() {
+ var bird = EntityManager.spawn('bird1');
+ if (bird) {
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ game.layers.birds.addChild(bird);
+ GameState.birds.push(bird);
+ }
+}
+function spawnBird2() {
+ var bird = EntityManager.spawn('bird2');
+ if (bird) {
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ game.layers.birds.addChild(bird);
+ GameState.birds.push(bird);
+ }
+}
+// Initial bird spawns
spawnBird1();
spawnBird2();
-// Function to spawn a Bird2 and set its layer
-function spawnBird2() {
- var bird = new Bird2();
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- bird.speed = 1 + Math.random() * 0.6;
- bird.lastIntersecting = false;
- bird.type = 'Bird2';
- bird.color = 0x746130;
- LK.setTimeout(function () {
- game.addChild(bird);
- setLayerIndex(bird, LAYER_BIRDS);
- birds.push(bird);
- }, 2000);
+spawnBird2();
+// Start UFO 3 seconds after game loads
+var ufo;
+var ufoTimer = LK.setTimeout(function () {
+ ufo = new UFO();
+ GameState.ufo = ufo;
+ game.layers.enemies.addChild(GameState.ufo);
+}, 3000);
+// Function to handle UFO reappearance logic
+function handleUFOReappearance() {
+ if (!ufo) {
+ LK.setTimeout(function () {
+ ufo = addUFO();
+ }, Math.random() * 10000 + 20000);
+ }
}
-// Function to spawn a bird and set its layer
-function spawnBird1() {
- var bird = new Bird1();
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- bird.speed = 1 + Math.random() * 0.6;
- bird.lastIntersecting = false;
- bird.type = 'Bird1';
- bird.color = 0x746130;
- LK.setTimeout(function () {
- game.addChild(bird);
- setLayerIndex(bird, LAYER_BIRDS);
- birds.push(bird);
- }, 2000);
+// Function to handle jet reappearance logic
+var jetTimer;
+function handleJetReappearance() {
+ try {
+ jetTimer = LK.setTimeout(function () {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2 - jet.height);
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
+ }
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true);
+ game.jetSoundPlayed = true;
+ }
+ }, Math.random() * 5000 + 5000);
+ } catch (error) {
+ console.error('Error in handleJetReappearance:', error);
+ }
}
-// Ensure there are always 3 birds on screen
-game.update = function () {
- // 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
+// Initialize a timer to add a Jet at a random time between 5 and 10 seconds
+// Initial interval for Jet appearances 5-10 seconds after page load
+// Initialize enemy movement systems
+function initEnemyMovement(enemy) {
+ if (enemy instanceof Bird1) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1');
+ }
+ if (enemy instanceof Bird2) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2');
+ }
+ if (enemy instanceof UFO) {
+ enemy.movementSystem = new UFOMovement(enemy, enemy.graphics);
+ }
+}
+function gameTick() {
+ try {
+ updateClouds();
+ updateEnemies();
+ updateLasers();
+ checkInteractions();
+ requestAnimationFrame(gameTick);
+ } catch (error) {
+ console.error('Error in game tick:', error);
+ requestAnimationFrame(gameTick);
+ }
+}
+function updateClouds() {
+ // Update existing clouds
+ for (var i = 0; i < GameState.clouds.length; i++) {
+ GameState.clouds[i].update();
+ }
+ // Ensure minimum cloud count
+ while (GameState.clouds.length < 3) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2);
+ GameState.clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+ }
+}
+var EntityUpdateSystem = {
+ screenWidth: 2048,
+ screenHeight: 2732,
+ bounceFactor: 5,
+ update: function update() {
+ var _this4 = this;
+ var enemies = game.layers.enemies.children;
+ enemies.forEach(function (enemy) {
+ if (!(enemy !== null && enemy !== void 0 && enemy.update)) {
+ return;
+ }
+ enemy.update();
+ if (enemy instanceof Bird1 || enemy instanceof Bird2) {
+ _this4._handleBirdUpdate(enemy, enemies);
+ }
+ });
+ },
+ _handleBirdUpdate: function _handleBirdUpdate(bird, enemies) {
+ this._checkCollisions(bird, enemies);
+ this._checkRespawn(bird);
+ },
+ _checkCollisions: function _checkCollisions(bird, enemies) {
+ var _this5 = this;
+ if (bird.lastIntersecting) {
+ bird.lastIntersecting = this._isIntersectingAny(bird, enemies);
+ return;
}
- });
+ enemies.forEach(function (otherEnemy) {
+ if (_this5._shouldSkipCollision(bird, otherEnemy)) {
+ return;
+ }
+ if (bird.intersects(otherEnemy)) {
+ _this5._resolveBirdCollision(bird, otherEnemy);
+ }
+ });
+ },
+ _shouldSkipCollision: function _shouldSkipCollision(bird, otherEnemy) {
+ return bird === otherEnemy || !(otherEnemy instanceof Bird1 || otherEnemy instanceof Bird2);
+ },
+ _resolveBirdCollision: function _resolveBirdCollision(bird, otherEnemy) {
+ var _this$_getCollisionVe = this._getCollisionVectors(bird, otherEnemy),
+ _this$_getCollisionVe2 = _slicedToArray(_this$_getCollisionVe, 3),
+ dx = _this$_getCollisionVe2[0],
+ dy = _this$_getCollisionVe2[1],
+ distance = _this$_getCollisionVe2[2];
+ bird.x += dx / distance * this.bounceFactor;
+ bird.y += dy / distance * this.bounceFactor;
+ otherEnemy.x -= dx / distance * this.bounceFactor;
+ otherEnemy.y -= dy / distance * this.bounceFactor;
+ bird.lastIntersecting = true;
+ otherEnemy.lastIntersecting = true;
+ },
+ _getCollisionVectors: function _getCollisionVectors(bird, otherEnemy) {
+ var dx = bird.x - otherEnemy.x;
+ var dy = bird.y - otherEnemy.y;
+ var distance = Math.sqrt(dx * dx + dy * dy) || 1;
+ return [dx, dy, distance];
+ },
+ _isIntersectingAny: function _isIntersectingAny(bird, enemies) {
+ return enemies.some(function (otherEnemy) {
+ return bird !== otherEnemy && bird.intersects(otherEnemy);
+ });
+ },
+ _checkRespawn: function _checkRespawn(bird) {
+ if (bird.lastY <= this.screenHeight && bird.y > this.screenHeight) {
+ bird.y = -bird.height;
+ bird.x = Math.random() * this.screenWidth;
+ bird.speed = 1 + Math.random() * 0.6;
+ }
+ }
};
-// Add a tree to the game
-var tree = game.addChild(new Tree());
-tree.x = 2048 / 2 + 500; // Move the tree 500px to the right
-tree.y = 2765; // Position the tree on the grass
-var treeChildIndex = Math.min(7, game.children.length - 1);
-game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered after Bird1
-var score = 0;
-// Add the grass floor to the game
-var grass = new Grass();
-grass.x = 1020;
-grass.y = 2735;
-game.addChild(grass);
-setLayerIndex(grass, LAYER_GRASS);
-var grass2 = new Grass2();
-grass2.x = 1020;
-grass2.y = 2735; // Position grass2 at the bottom
-game.addChild(grass2);
-var grass2ChildIndex = game.getChildIndex(tree) + 1;
-game.setChildIndex(grass2, grass2ChildIndex); // Set grass2 to be rendered after the tree
-var scoreDisplay = new ScoreDisplay();
-scoreDisplay.x = 2048 / 2 + 520;
-scoreDisplay.y = 2732 - 185;
-game.addChild(scoreDisplay);
-setLayerIndex(scoreDisplay, LAYER_SCORE);
-// 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
+function updateEnemies() {
+ EntityUpdateSystem.update();
+}
+function updateLasers() {
+ if (!game.layers.laser) {
+ return;
+ }
+ game.layers.laser.children.forEach(function (laser) {
+ if (laser && typeof laser.update === 'function') {
+ laser.update();
+ }
+ });
+}
+// Start the game loop
+requestAnimationFrame(gameTick);
+// Note: Tree, stack1, grassBack, grassFront and mirror are already added to their respective layers earlier in the code
+function playSoundEffect(soundName) {
+ var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'play';
+ var volume = arguments.length > 2 ? arguments[2] : undefined;
+ var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
+ var effectVolume = volume || GAME_SOUND_VOLUMES[soundName] || 1;
+ if (action === 'play') {
+ SoundManager.play(soundName, {
+ volume: effectVolume,
+ loops: loops
});
- }, Math.random() * 30000 + 50000);
+ } else if (action === 'stop') {
+ SoundManager.stop(soundName);
+ }
}
-;
-// Add the cat to the game
-var cat = game.addChild(new Cat());
-cat.x = 200; // Position the cat to the far left
-cat.y = 2732; // Position the cat at the bottom of the screen
-var catChildIndex = Math.min(10, game.children.length - 1);
-game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass
-// 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
+// Initialize sound system
+SoundManager.init();
+// Initialize cat instance
+GameState.cat = new Cat();
+GameState.cat.x = 2048 / 2;
+GameState.cat.y = 2732 - 100;
+GameState.cat.lastX = GameState.cat.x;
+game.layers.cat.addChild(GameState.cat);
+var AudioSystem = {
+ _initialized: false,
+ _bgmPlaying: false,
+ init: function init() {
+ var _this6 = this;
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
+ while (1) {
+ switch (_context.prev = _context.next) {
+ case 0:
+ if (!_this6._initialized) {
+ _context.next = 5;
+ break;
+ }
+ return _context.abrupt("return");
+ case 5:
+ _context.prev = 6;
+ _context.next = 10;
+ return Promise.all([_this6._initBackgroundMusic(), _this6._initAmbientSounds()]);
+ case 10:
+ _this6._initialized = true;
+ _context.next = 18;
+ break;
+ case 14:
+ _context.prev = 14;
+ _context.t0 = _context["catch"](6);
+ console.error('Failed to initialize audio system:', _context.t0);
+ case 18:
+ case "end":
+ return _context.stop();
+ }
+ }
+ }, _callee, null, [[6, 14]]);
+ }))();
},
- 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
+ _initBackgroundMusic: function _initBackgroundMusic() {
+ var _this7 = this;
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
+ var bgm;
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
+ while (1) {
+ switch (_context2.prev = _context2.next) {
+ case 0:
+ bgm = LK.getSound('bgm1');
+ if (bgm) {
+ _context2.next = 7;
+ break;
+ }
+ return _context2.abrupt("return");
+ case 7:
+ bgm.volume = GAME_SOUND_VOLUMES.bgm1 || 0.1;
+ bgm.loop = true;
+ // Start background music
+ _this7._bgmPlaying = true;
+ _context2.next = 16;
+ return bgm.play();
+ case 16:
+ case "end":
+ return _context2.stop();
+ }
+ }
+ }, _callee2);
+ }))();
+ },
+ _initAmbientSounds: function _initAmbientSounds() {
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
+ var ambientSounds, _i, _ambientSounds, soundName, sound;
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
+ while (1) {
+ switch (_context3.prev = _context3.next) {
+ case 0:
+ ambientSounds = ['breeze1', 'cricket1', 'frog1', 'songbird1'];
+ _i = 0, _ambientSounds = ambientSounds;
+ case 5:
+ if (!(_i < _ambientSounds.length)) {
+ _context3.next = 25;
+ break;
+ }
+ soundName = _ambientSounds[_i];
+ sound = LK.getSound(soundName);
+ if (sound) {
+ _context3.next = 15;
+ break;
+ }
+ return _context3.abrupt("continue", 22);
+ case 15:
+ sound.volume = GAME_SOUND_VOLUMES[soundName] || 0.1;
+ sound.loop = true;
+ _context3.next = 22;
+ return sound.play();
+ case 22:
+ _i++;
+ _context3.next = 5;
+ break;
+ case 25:
+ case "end":
+ return _context3.stop();
+ }
+ }
+ }, _callee3);
+ }))();
+ },
+ toggleBackgroundMusic: function toggleBackgroundMusic() {
+ var bgm = LK.getSound('bgm1');
+ if (!bgm) {
+ return;
+ }
+ if (this._bgmPlaying) {
+ bgm.stop();
+ } else {
+ bgm.play();
+ }
+ this._bgmPlaying = !this._bgmPlaying;
+ }
+};
+// Initialize audio system
+AudioSystem.init();
+/**
+* Check for interactions between game entities
+*/
+var CollisionSystem = {
+ handleLaserCollision: function handleLaserCollision(laser, enemy) {
+ if (!(laser !== null && laser !== void 0 && laser.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || !laser.intersects(enemy)) {
+ return false;
+ }
+ try {
+ var destroyed = enemy.handleLaserCollision ? enemy.handleLaserCollision(laser) : function () {
+ EntityManager.cleanup(enemy);
+ EntityManager.cleanup(laser);
+ return true;
+ }();
+ if (destroyed) {
+ var _enemy$getScoreValue, _GameState$scoreDispl, _GameState$scoreDispl2;
+ var points = ((_enemy$getScoreValue = enemy.getScoreValue) === null || _enemy$getScoreValue === void 0 ? void 0 : _enemy$getScoreValue.call(enemy)) || enemy.scoreValue || 5;
+ GameState.score += points;
+ (_GameState$scoreDispl = GameState.scoreDisplay) === null || _GameState$scoreDispl === void 0 || (_GameState$scoreDispl2 = _GameState$scoreDispl.updateScore) === null || _GameState$scoreDispl2 === void 0 || _GameState$scoreDispl2.call(_GameState$scoreDispl, GameState.score);
+ return true;
+ }
+ } catch (error) {
+ console.error('Error handling laser collision:', error);
+ }
+ return false;
+ },
+ handleUFOCollision: function handleUFOCollision(ufo, enemy) {
+ if (!(ufo !== null && ufo !== void 0 && ufo.intersects) || !(enemy !== null && enemy !== void 0 && enemy.intersects) || enemy === ufo || !ufo.intersects(enemy)) {
+ return;
+ }
+ try {
+ EntityManager.cleanup(enemy);
+ SoundManager.play('electro');
+ } catch (error) {
+ console.error('Error handling UFO collision:', error);
+ }
+ },
+ checkCollisions: function checkCollisions() {
+ try {
+ var _game$layers$enemies, _game$layers$laser;
+ var enemies = ((_game$layers$enemies = game.layers.enemies) === null || _game$layers$enemies === void 0 ? void 0 : _game$layers$enemies.children) || [];
+ var lasers = ((_game$layers$laser = game.layers.laser) === null || _game$layers$laser === void 0 ? void 0 : _game$layers$laser.children) || [];
+ // Process laser collisions
+ var _iterator9 = _createForOfIteratorHelper(lasers),
+ _step9;
+ try {
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
+ var laser = _step9.value;
+ if (!laser || laser._destroyed) {
+ continue;
+ }
+ var _iterator11 = _createForOfIteratorHelper(enemies),
+ _step11;
+ try {
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
+ var enemy = _step11.value;
+ if (!enemy || enemy._destroyed) {
+ continue;
+ }
+ if (this.handleLaserCollision(laser, enemy)) {
+ break;
+ }
+ }
+ } catch (err) {
+ _iterator11.e(err);
+ } finally {
+ _iterator11.f();
+ }
+ }
+ // Process UFO collisions
+ } catch (err) {
+ _iterator9.e(err);
+ } finally {
+ _iterator9.f();
+ }
+ var ufo = enemies.find(function (child) {
+ return child instanceof UFO && !child._destroyed;
});
- }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
+ if (ufo) {
+ var _iterator10 = _createForOfIteratorHelper(enemies),
+ _step10;
+ try {
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
+ var enemy = _step10.value;
+ if (!enemy || enemy._destroyed || enemy === ufo) {
+ continue;
+ }
+ this.handleUFOCollision(ufo, enemy);
+ }
+ } catch (err) {
+ _iterator10.e(err);
+ } finally {
+ _iterator10.f();
+ }
+ }
+ } catch (error) {
+ console.error('Error in checkCollisions:', error);
+ }
}
-});
-// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
-var wingsTimer = LK.setTimeout(function () {
- LK.getSound('wings1').play();
- wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
-}, Math.random() * 20000 + 10000);
-// Create an array for all sounds except ufo1, including all birdsong sounds
-var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
-var currentAmbientSound = null;
-// Initialize random timers for each sound to play between 30-50 seconds
-sounds.forEach(function (soundId) {
- var sound = LK.getSound(soundId);
- var ambientSoundTimer = LK.setTimeout(function () {
- if (currentAmbientSound) {
- currentAmbientSound.stop(); // Stop the currently playing ambient sound
+};
+function checkInteractions() {
+ CollisionSystem.checkCollisions();
+}
+/*****
+* Utility Functions
+****/
+/**
+* Simple movement update function that works with the consolidated movement system
+* This is kept for backward compatibility with existing code that uses it
+*/
+function updateMovement(obj, params) {
+ try {
+ if (!obj || !params) {
+ console.error('Invalid parameters for updateMovement');
+ return;
}
- 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
+ // If the object already has a movement system applied, use that
+ if (typeof obj.update === 'function' && obj.speed !== undefined) {
+ obj.speed = params.speed || obj.speed;
+ obj.direction = params.direction || obj.direction;
+ return;
+ }
+ // Otherwise apply simple movement
+ obj.x += (params.speed || 1) * (params.direction || 1);
+ if (params.boundaryCheck) {
+ handleScreenBoundaries(obj, params.boundaryWidth);
+ }
+ // Store last position for next update
+ obj.lastX = obj.x;
+ obj.lastY = obj.y;
+ } catch (error) {
+ console.error('Error in updateMovement:', error);
+ }
+}
+function updateDirection(obj, graphics, rightAsset, leftAsset) {
+ graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture;
+}
+function handleScreenBoundaries(obj, screenWidth) {
+ if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) {
+ obj.x = -obj.width / 2;
+ } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) {
+ obj.x = screenWidth + obj.width / 2;
+ }
+}
+function handleCollisions(obj, others, collisionHandler) {
+ others.forEach(function (other) {
+ if (other !== obj && obj.intersects(other)) {
+ collisionHandler(obj, other);
+ }
+ });
+}
+function handleSunInteraction(obj, sun, enterHandler, exitHandler) {
+ var intersecting = obj.intersects(sun);
+ if (!obj.lastIntersecting && intersecting) {
+ enterHandler(obj);
+ } else if (obj.lastIntersecting && !intersecting) {
+ exitHandler(obj);
+ }
+ obj.lastIntersecting = intersecting;
+}
+function handleDestruction(obj, sounds) {
+ if (!obj) {
+ return;
+ }
+ if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) {
+ if (Array.isArray(sounds)) {
+ sounds.forEach(function (sound) {
+ return SoundManager.stop(sound);
+ });
+ }
+ if (typeof obj.destroy === 'function') {
+ obj.destroy();
+ }
+ }
+}
+// Updated Cloud update method
+self.cloud.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction,
+ boundaryCheck: true,
+ boundaryWidth: 2048
+ });
+ handleCollisions(this, clouds, function (cloud, other) {
+ if (!cloud.hasAccelerated) {
+ cloud.speed *= 1.5;
+ cloud.hasAccelerated = true;
+ }
+ });
+ handleSunInteraction(this, sun, function (cloud) {
+ cloud.speed *= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000
+ });
+ }, function (cloud) {
+ cloud.speed /= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000
+ });
+ });
+ this.lastX = this.x;
+};
+// Updated Jet update method
+self.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction
+ });
+ updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
+ handleDestruction(this, ['jetSound']);
+};
\ 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