Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 184 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
assign bird images to bird objects, ufo image to ufo object, etc.
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: 1075 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'var gameInstance = new LK.Game({' Line Number: 956 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (6 edits merged)
Please save this source code
User prompt
find bugs in the code
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'app is not defined' in or related to this line: 'app.stage.addChild(layer);' Line Number: 112
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseSpeed')' in or related to this line: 'self.cloud = {' Line Number: 155
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'baseSpeed is not defined' in or related to this line: 'self.cloud = {' Line Number: 153
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1931
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1496
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1465
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1463
User prompt
Please fix the bug: 'cloudGraphics is not defined' in or related to this line: 'self.addChild(cloudGraphics);' Line Number: 185
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'sounds')' in or related to this line: 'if (config.sounds && config.sounds.move) {' Line Number: 542
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Cat class to manage cat behavior var Cat = Container.expand(function () { var self = Container.call(this); try { var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 1 }); self.update = function () { try { // Add any specific update logic for the cat here } catch (error) { console.error('Error in cat update:', error); } }; return self; } catch (error) { console.error('Error creating cat:', error); return null; } }); // CloudMovement class to handle cloud movement and fade effects // GrassBack class to represent the grass image var GrassBack = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1 }); self.update = function () { try { // 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 } catch (error) { console.error('Error in grass update:', error); } }; self.addChild(grassGraphics); // Add grass graphics to the container return self; }); // GrassFront class to represent the second grass image var GrassFront = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass-front', { anchorX: 0.5, anchorY: 1 }); self.lastX = self.x; // Initialize lastX for tracking changes on X self.addChild(grass2Graphics); // Add grass2 graphics to the container self.update = function () { updateMovement(self, { movementType: 'sinusoidal', amplitude: 0.125, frequency: 100, offset: 50 }); }; }); // Jet class to represent a jet flying across the screen var Jet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-right', { x: 0, y: 0 }); createMovementSystem(self, jetGraphics, { speed: 10, direction: Math.random() < 0.5 ? -1 : 1, boundaryCheck: true, boundaryWidth: 2048, sounds: { move: 'jetSound', destroy: 'jetSound' }, onDestroy: function onDestroy() { LK.getSound('jetSound').stop(); handleJetReappearance(); }, entityType: 'jet' }); self.update = function () { this.movementSystem.update(); updateDirection(this, jetGraphics, 'jet-right', 'jet-left'); }; }); // 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(); // Initializes entity movement parameters LaserMovement(self, laserGraphics, startX, startY, targetX, targetY); return self; }); // Light1 class to represent a light object var Light1 = Container.expand(function () { var self = Container.call(this); var lightGraphics = self.attachAsset('light1', { anchorX: 0.5, anchorY: 0.5, alpha: 0.2 // Set transparency to 20% }); self.x = 450, self.y = 440; self.update = function () { try { // Add any specific update logic for the light here } catch (error) { console.error('Error in light update:', error); } }; self.pulse = new Light1Pulse(lightGraphics); self.pulse.startPulsating(); }); // Mirror class to manage score display var Mirror = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 14 // Rotate image right 15 degrees }); var scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = 40; // Move score text up by 20px scoreText.x = -145; // Move score text left by 10px scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // Mirror1 class to represent the mirror image var Mirror1 = Container.expand(function () { var self = Container.call(this); var mirror1Graphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(mirror1Graphics); }); var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); var pulse = new Pulse(self, { scaleMax: 1.2, duration: 800 }); self.update = function () { try { // Update reticle position based on current target if needed if (self.target) { self.x = self.target.x; self.y = self.target.y; } } catch (error) { console.error('Error in reticle update:', error); } }; self.setTarget = function (target) { self.target = target; }; self.destroy = function () { if (pulse) { pulse.stop(); } self.target = null; Container.prototype.destroy.call(self); }; // Start the pulsating effect pulse.startPulsating(); return self; }); // Reticle1 class to represent the reticle image var Reticle1 = Container.expand(function () { var self = Container.call(this); var reticle1Graphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(reticle1Graphics); }); // ScoreImage class to represent the score image var ScoreImage = Container.expand(function () { var self = Container.call(this); var scoreImageGraphics = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(scoreImageGraphics); }); // Stack1 class to represent the stack1 image var Stack1 = Container.expand(function () { var self = Container.call(this); var stackGraphics = self.attachAsset('stack1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / -12 }); self.update = function () { try { // Add any specific update logic for stack1 here } catch (error) { console.error('Error in stack update:', error); } }; return self; }); // ScoreManager class to manage score logic // Sun class to represent a sun in the top right corner var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); self.pulse = new SunPulse(sunGraphics); self.pulse.startPulsating(); }); // Function to create a pulsating effect // Tree class to represent a tree with a 9:16 aspect ratio var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, antialias: true, // Apply antialias effect stroke: 0x000000, // Add a black stroke strokeThickness: 15 // Set stroke thickness to 15px }); self.update = function () { try { // Add any specific update logic for the tree here } catch (error) { console.error('Error in tree update:', error); } }; }); // Tree2 class to represent the second type of tree var Tree2 = Container.expand(function () { var self = Container.call(this); var tree2Graphics = self.attachAsset('tree2', { anchorX: 0.5, anchorY: 1 }); self.addChild(tree2Graphics); }); // UFO class to represent a UFO // Unified UFO class with improved cleanup var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); // Initialize movement with cleanup tracking self._timers = new Set(); self._sounds = new Set(); // Initializes entity movement parameters UFOMovement(self, ufoGraphics); self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; self.destroy = function () { if (this._destroyed) { return; } // Use EntityManager for proper cleanup EntityManager.cleanup(this); }.bind(self); return self; }); /**** * Initialize Game ****/ // Game instance already initialized above // Layer structure initialization with proper cleanup handling var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Sound configuration /**** * Game Configuration ****/ // Music and Sounds // 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 _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 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 = 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 BirdMovement(_this2, _this2.birdGraphics, 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); return _callSuper(this, Bird1, ['bird1']); } _inherits(Bird1, _Bird); return _createClass(Bird1); }(Bird); var Bird2 = /*#__PURE__*/function (_Bird2) { function Bird2() { _classCallCheck(this, Bird2); return _callSuper(this, Bird2, ['bird2']); } _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 EntityManager = { cleanup: function cleanup(entity) { if (!entity || entity._cleaned) { return; } entity._cleaned = true; // Stop all associated sounds and clear references if (entity._sounds instanceof Set) { var _iterator = _createForOfIteratorHelper(entity._sounds), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _sound; var soundName = _step.value; var sound = LK.getSound(soundName); if ((_sound = sound) !== null && _sound !== void 0 && _sound.stop) { sound.stop(); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } entity._sounds.clear(); entity._sounds = null; } // Clear all timers and references if (entity._timers instanceof Set) { var _iterator2 = _createForOfIteratorHelper(entity._timers), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var timer = _step2.value; LK.clearTimeout(timer); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } entity._timers.clear(); entity._timers = null; } // Return to pool or remove from parent if (entity.type && EntityPool.pools && EntityPool.pools[entity.type]) { var _entity$reset; (_entity$reset = entity.reset) === null || _entity$reset === void 0 || _entity$reset.call(entity); EntityPool["return"](entity.type, entity); } else if (entity.parent) { entity.parent.removeChild(entity); } // Clear any remaining references entity._destroyed = true; entity.parent = null; // Clear any graphics references if (entity.birdGraphics) { entity.birdGraphics = null; } }, spawn: function spawn(type) { var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (!type) { throw new Error('Entity type is required'); } var entity = EntityPool.get(type); if (!entity) { var EntityTypes = { bird1: Bird1, bird2: Bird2, laser: function laser(config) { return new Laser(config.startX, config.startY, config.targetX, config.targetY); } }; var EntityConstructor = EntityTypes[type]; if (!EntityConstructor) { throw new Error("Unknown entity type: ".concat(type)); } entity = typeof EntityConstructor === 'function' ? EntityConstructor.length ? EntityConstructor(config) : new EntityConstructor() : null; if (!entity) { throw new Error("Failed to create entity of type: ".concat(type)); } } entity.type = type; entity._sounds = new Set(); entity._timers = new Set(); entity._cleaned = false; entity._destroyed = false; return entity; } }; var EntityPool = { pools: {}, get: function get(type) { if (this.pools[type] && this.pools[type].length > 0) { return this.pools[type].pop(); } return null; }, "return": function _return(type, entity) { if (!this.pools[type]) { this.pools[type] = []; } this.pools[type].push(entity); } }; function createMovementSystem(entity, entityGraphics, config) { try { var _settings$sounds; if (!entity || !entityGraphics) { console.error('Entity and entityGraphics are required for movement system'); return null; } // Initialize entity management systems if (!entity._timers) { entity._timers = new Set(); } if (!entity._sounds) { entity._sounds = new Set(); } var soundManager = window.soundManager || null; var defaults = { baseSpeed: 1, speedVariation: 0, horizontalMovement: false, useWaveMotion: false, waveAmplitude: 0, waveFrequency: 100, screenBounds: { width: 2048, height: 2732 }, respawnPosition: 'top', textures: { left: null, right: null }, sounds: { move: null, destroy: null }, scoreValue: 0, entityType: null, onDestroy: null, onUpdate: null, handleScreenWrap: false }; var settings = Object.assign({}, defaults, config || {}); entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation; entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1; entity.lastX = entity.x || 0; entity.lastY = entity.y || 0; entity.scoreValue = settings.scoreValue; // Initialize movement sound if ((_settings$sounds = settings.sounds) !== null && _settings$sounds !== void 0 && _settings$sounds.move && soundManager) { var moveSound = soundManager.play(settings.sounds.move, { loop: true }); if (moveSound) { entity._sounds.add(settings.sounds.move); } } entity.update = function () { try { var _settings$textures, _settings$textures2; if (settings.entityType === 'laser') { if (!this.vx || !this.vy) { return; } this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) { EntityManager.cleanup(this); } } else if (settings.horizontalMovement) { var _settings$onUpdate; this.x += this.speed * this.direction; if (settings.useWaveMotion && settings.baseY !== undefined) { this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude; } if (settings.handleScreenWrap) { if (this.x > settings.screenBounds.width + this.width / 2) { this.x = -this.width / 2; } else if (this.x < -this.width / 2) { this.x = settings.screenBounds.width + this.width / 2; } } (_settings$onUpdate = settings.onUpdate) === null || _settings$onUpdate === void 0 || _settings$onUpdate.call(settings, this); } else { this.y += this.speed; if (settings.useWaveMotion) { this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude; } } if (entityGraphics && (_settings$textures = settings.textures) !== null && _settings$textures !== void 0 && _settings$textures.left && (_settings$textures2 = settings.textures) !== null && _settings$textures2 !== void 0 && _settings$textures2.right) { try { var rightAsset = LK.getAsset(settings.textures.right, {}); var leftAsset = LK.getAsset(settings.textures.left, {}); if (rightAsset !== null && rightAsset !== void 0 && rightAsset.texture && leftAsset !== null && leftAsset !== void 0 && leftAsset.texture) { entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture; } } catch (error) { console.error('Error updating entity texture:', error); } } if (settings.horizontalMovement) { if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { var _settings$onDestroy; EntityManager.cleanup(this); (_settings$onDestroy = settings.onDestroy) === null || _settings$onDestroy === void 0 || _settings$onDestroy.call(settings, this); } } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) { switch (settings.respawnPosition) { case 'random': this.y = Math.random() * settings.screenBounds.height; this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width; break; case 'side': this.y = Math.random() * settings.screenBounds.height; this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width; break; default: this.y = -this.height; this.x = Math.random() * settings.screenBounds.width; } } this.lastX = this.x; this.lastY = this.y; } catch (error) { console.error('Error in entity update:', error); EntityManager.cleanup(this); } }.bind(entity); if (typeof entity.destroy !== 'function') { entity.destroy = function () { var _settings$sounds2; if (this._destroyed) { return; } this._destroyed = true; EntityManager.cleanup(this); if ((_settings$sounds2 = settings.sounds) !== null && _settings$sounds2 !== void 0 && _settings$sounds2.destroy && soundManager) { soundManager.stop(settings.sounds.destroy); } }.bind(entity); } return entity; } catch (error) { console.error('Error in createMovementSystem:', error); return null; } } var CloudMovement = { init: function init(cloud) { if (!cloud) { throw new Error('Cloud entity is required'); } cloud._movement = { speed: Math.random() * 0.5 + 0.2, direction: Math.random() < 0.5 ? -1 : 1, bounds: { left: -cloud.width, right: game.width + cloud.width } }; this.update(cloud); }, update: function update(cloud) { if (!cloud || !cloud._movement) { return; } cloud.x += cloud._movement.speed * cloud._movement.direction; // Handle bounds checking and wrapping if (cloud.x < cloud._movement.bounds.left) { cloud.x = cloud._movement.bounds.right; } else if (cloud.x > cloud._movement.bounds.right) { cloud.x = cloud._movement.bounds.left; } }, cleanup: function cleanup(cloud) { if (!cloud) { return; } delete cloud._movement; } }; var Cloud = /*#__PURE__*/function (_Container3) { function Cloud() { var _this3; _classCallCheck(this, Cloud); _this3 = _callSuper(this, Cloud); try { _this3.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); CloudMovement.init(_this3); } catch (error) { console.error('Error in cloud constructor:', error); throw error; } return _possibleConstructorReturn(_this3, _this3); } _inherits(Cloud, _Container3); return _createClass(Cloud, [{ key: "update", value: function update() { try { CloudMovement.update(this); } catch (error) { console.error('Error in cloud update:', error); } } }, { key: "destroy", value: function destroy() { try { CloudMovement.cleanup(this); _superPropGet(Cloud, "destroy", this, 3)([]); } catch (error) { console.error('Error in cloud destroy:', error); } } }]); }(Container); // Game instance already initialized above // Layer structure initialization with proper cleanup handling var initializeLayers = function initializeLayers() { game.layers = { background: new Container(), sun: new Container(), light1: new Container(), jetLeft: new Container(), jetRight: new Container(), clouds: new Container(), ufo: new Container(), grassBack: new Container(), bird1: new Container(), tree: new Container(), stack1: new Container(), bird2: new Container(), mirror: new Container(), grassFront: new Container(), cat: new Container(), laser: new Container(), reticle: new Container(), enemies: new Container(), birds: new Container() }; // Add cleanup methods to each layer Object.values(game.layers).forEach(function (layer) { layer.cleanup = function () { while (this.children.length > 0) { var child = this.children[0]; if (typeof child.destroy === 'function') { child.destroy(); } } }; }); }; // Factory functions for specific pulse effects var Light1Pulse = function Light1Pulse(lightGraphics) { return new Pulse(lightGraphics, { scaleMax: 1.6, duration: 1500 }); }; var SunPulse = function SunPulse(sunGraphics) { return new Pulse(sunGraphics, { scaleMax: 1.1, duration: 1000 }); }; // Removed redundant startPulsating function as it's now handled by Pulse class // Sound system is already initialized above SoundManager = { playEffect: function playEffect(soundName) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; try { var sound = this._sounds.get(soundName) || LK.getSound(soundName); if (!sound) { console.warn("Sound '".concat(soundName, "' not found")); return; } var _options$volume = options.volume, volume = _options$volume === void 0 ? this._volumes[soundName] || 1 : _options$volume, _options$loops = options.loops, loops = _options$loops === void 0 ? false : _options$loops; sound.play({ volume: volume, loops: loops }); return sound; } catch (error) { console.error("Error playing sound effect '".concat(soundName, "':"), error); } }, playMusic: function playMusic() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; try { var _options$volume2 = options.volume, volume = _options$volume2 === void 0 ? this._volumes[this.effects.bgm] || 1 : _options$volume2, _options$fade = options.fade, fade = _options$fade === void 0 ? true : _options$fade; return LK.playMusic(this.effects.bgm, { loop: false, volume: volume, fade: fade ? { start: 0, end: 1, duration: 4000 } : undefined }); } catch (error) { console.error('Error playing background music:', error); } }, stopSoundFunc: function stopSoundFunc(soundName) { try { var sound = this._sounds.get(soundName) || LK.getSound(soundName); if (sound !== null && sound !== void 0 && sound.stop) { sound.stop(); } } catch (error) { console.error("Error stopping sound '".concat(soundName, "':"), error); } }, pauseSound: function pauseSound(soundName) { try { var sound = this._sounds.get(soundName) || LK.getSound(soundName); if (sound !== null && sound !== void 0 && sound.pause) { sound.pause(); } } catch (error) { console.error("Error pausing sound '".concat(soundName, "':"), error); } }, setVolume: function setVolume(soundName, volume) { try { var sound = this._sounds.get(soundName); if (sound) { sound.volume = volume; this._volumes[soundName] = volume; } } catch (error) { console.error("Error setting volume for '".concat(soundName, "':"), error); } } }; // Initialize sound system SoundManager.init(); // Sound effect wrapper classes using the unified system var UFOSound = function UFOSound() { this.play = function () { return SoundManager.playEffect(SoundManager.effects.ufo); }; }; var LaserSound = function LaserSound() { this.play = function () { return SoundManager.playEffect(SoundManager.effects.laser); }; }; var BackgroundMusic = function BackgroundMusic() { this.play = function () { return SoundManager.playMusic(); }; }; // Unified movement system for all entities // Unified movement system with improved cleanup and state management // Note: This is the main implementation of createMovementSystem used throughout the code /** * Unified movement system for all moving entities * @param {Object} entity - The entity to apply movement to * @param {Object} entityGraphics - The graphics object for the entity * @param {Object} config - Configuration options for movement */ // Removed duplicate createMovementSystem function as it's already defined above /** * Bird1 movement configuration */ /** * Bird2 movement configuration */ /** * UFO movement configuration */ // Entity movement configurations var MOVEMENT_CONFIGS = { bird1: { baseSpeed: 1, speedVariation: 0.5, useWaveMotion: true, waveAmplitude: 4.5, waveFrequency: 120, horizontalMovement: false, textures: { left: 'bird1-left', right: 'bird1-right' }, respawnPosition: 'top', sounds: { move: 'wings1', destroy: null }, scoreValue: 5 }, bird2: { baseSpeed: 1.5, speedVariation: 1.6, useWaveMotion: true, waveAmplitude: 6.5, waveFrequency: 100, horizontalMovement: false, textures: { left: 'bird2-left', right: 'bird2-right' }, respawnPosition: 'random', sounds: { move: 'wings1', destroy: null }, scoreValue: 10 }, ufo: { baseSpeed: 3, speedVariation: 1, useWaveMotion: true, waveAmplitude: 50, waveFrequency: 100, horizontalMovement: true, baseY: function baseY() { return Math.random() * 300 + 100; }, textures: null, sounds: { move: 'ufo1', destroy: null }, scoreValue: 20 } }; function BirdMovement(bird, birdGraphics, birdType) { var config = Object.assign({}, MOVEMENT_CONFIGS[birdType], { entityType: birdType, onDestroy: function onDestroy(entity) { var index = birds.indexOf(entity); if (index > -1) { birds.splice(index, 1); LK.setTimeout(function () { if (birdType === 'bird1') { spawnBird1(); } else { spawnBird2(); } }, Math.random() * 2000 + 1000); } } }); createMovementSystem(bird, birdGraphics, config); } function UFOMovement(ufo, ufoGraphics) { var config = Object.assign({}, MOVEMENT_CONFIGS.ufo, { baseY: MOVEMENT_CONFIGS.ufo.baseY(), entityType: 'ufo', onDestroy: function onDestroy(entity) { if (entity.sounds && entity.sounds.move) { LK.getSound(entity.sounds.move).stop(); } entity.destroy(); ufo = null; handleUFOReappearance(); }, handleLaserCollision: function handleLaserCollision(laser) { var angle = Math.atan2(laser.vy, laser.vx) + Math.PI; laser.vx = Math.cos(angle) * laser.speed; laser.vy = Math.sin(angle) * laser.speed; return false; } }); createMovementSystem(ufo, ufoGraphics, config); } /** * 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; } // CloudMovement class is already defined earlier in the file 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); } }; }; // BirdMovement is already defined with MOVEMENT_CONFIGS above // 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 _iterator3 = _createForOfIteratorHelper(this._cleanupQueue), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var laser = _step3.value; this.activeLasers["delete"](laser); EntityManager.cleanup(laser); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } this._cleanupQueue.clear(); } // Update active lasers var _iterator4 = _createForOfIteratorHelper(this.activeLasers), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var laser = _step4.value; if (!laser || laser._destroyed) { this.queueForCleanup(laser); continue; } if (laser.update) { laser.update(); } } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } } }, { key: "clear", value: function clear() { var _iterator5 = _createForOfIteratorHelper(this.activeLasers), _step5; try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { var laser = _step5.value; EntityManager.cleanup(laser); } } catch (err) { _iterator5.e(err); } finally { _iterator5.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); 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 clouds array 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 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 spawnBird1(); spawnBird2(); spawnBird2(); // Start UFO 3 seconds after game loads var ufoTimer = LK.setTimeout(function () { GameState.ufo = addUFO(); 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 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 < clouds.length; i++) { clouds[i].update(); } // Ensure minimum cloud count while (clouds.length < 3) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); clouds.push(cloud); game.layers.clouds.addChild(cloud); } } function updateEnemies() { var enemies = game.layers.enemies.children; var screenWidth = 2048; var screenHeight = 2732; enemies.forEach(function (enemy) { if (!enemy || !enemy.movementSystem) { return; } enemy.movementSystem.update(); if (enemy instanceof Bird1 || enemy instanceof Bird2) { handleBirdCollisions(enemy, enemies); handleBirdRespawn(enemy, screenWidth, screenHeight); } }); } function handleBirdCollisions(bird, enemies) { if (!bird.lastIntersecting) { enemies.forEach(function (otherEnemy) { if (bird === otherEnemy || !(otherEnemy instanceof Bird1 || otherEnemy instanceof Bird2)) { return; } if (bird.intersects(otherEnemy)) { var dx = bird.x - otherEnemy.x; var dy = bird.y - otherEnemy.y; var distance = Math.sqrt(dx * dx + dy * dy) || 1; var bounceFactor = 5; bird.x += dx / distance * bounceFactor; bird.y += dy / distance * bounceFactor; otherEnemy.x -= dx / distance * bounceFactor; otherEnemy.y -= dy / distance * bounceFactor; bird.lastIntersecting = true; otherEnemy.lastIntersecting = true; } }); } bird.lastIntersecting = enemies.some(function (otherEnemy) { return bird !== otherEnemy && bird.intersects(otherEnemy); }); } function handleBirdRespawn(bird, screenWidth, screenHeight) { if (bird.lastY <= screenHeight && bird.y > screenHeight) { bird.y = -bird.height; bird.x = Math.random() * screenWidth; bird.speed = 1 + Math.random() * 0.6; } } 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 // This section is redundant and can be removed as it causes duplicate rendering // SoundManager is already defined earlier in the code // This is a helper function that uses the SoundManager 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; game.layers.cat.addChild(GameState.cat); var AudioSystem = { _initialized: false, _bgmPlaying: false, init: function init() { var _this4 = this; return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!_this4._initialized) { _context.next = 5; break; } return _context.abrupt("return"); case 5: _context.prev = 6; _context.next = 10; return Promise.all([_this4._initBackgroundMusic(), _this4._initAmbientSounds()]); case 10: _this4._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 _this5 = 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 _this5._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 _iterator6 = _createForOfIteratorHelper(lasers), _step6; try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { var laser = _step6.value; if (!laser || laser._destroyed) { continue; } var _iterator8 = _createForOfIteratorHelper(enemies), _step8; try { for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { var enemy = _step8.value; if (!enemy || enemy._destroyed) { continue; } if (this.handleLaserCollision(laser, enemy)) { break; } } } catch (err) { _iterator8.e(err); } finally { _iterator8.f(); } } // Process UFO collisions } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } var ufo = enemies.find(function (child) { return child instanceof UFO && !child._destroyed; }); if (ufo) { var _iterator7 = _createForOfIteratorHelper(enemies), _step7; try { for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { var enemy = _step7.value; if (!enemy || enemy._destroyed || enemy === ufo) { continue; } this.handleUFOCollision(ufo, enemy); } } catch (err) { _iterator7.e(err); } finally { _iterator7.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
@@ -8,87 +8,25 @@
****/
// Cat class to manage cat behavior
var Cat = Container.expand(function () {
var self = Container.call(this);
- var catGraphics = self.attachAsset('cat', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.update = function () {
- // Add any specific update logic for the cat here
- };
-});
-// Cloud container with 80% opacity
-var Cloud = Container.expand(function () {
- var self = Container.call(this);
- var cloudGraphics = self.attachAsset('cloud', {
- alpha: 0.8
- });
- self.cloudGraphics = cloudGraphics;
- self.cloud = {
- speed: Math.random() * 0.55 + 0.25,
- direction: 1,
- x: 0,
- y: 0
- };
- self.movement = createMovementSystem(self, cloudGraphics, {
- baseSpeed: self.cloud.speed,
- horizontalMovement: true,
- entityType: 'cloud'
- });
- self.update = function () {
- try {
- // Update position based on current speed and direction
- this.x += this.speed * this.direction;
- // Handle cloud interactions
- for (var i = 0; i < clouds.length; i++) {
- if (clouds[i] !== this && this.intersects(clouds[i])) {
- if (!this.hasAccelerated) {
- this.speed *= 1.5;
- this.hasAccelerated = true;
- }
- break;
- } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
- this.speed /= 1.5;
- this.hasAccelerated = false;
- }
+ try {
+ var catGraphics = self.attachAsset('cat', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.update = function () {
+ try {
+ // Add any specific update logic for the cat here
+ } catch (error) {
+ console.error('Error in cat update:', error);
}
- // Handle sun interaction
- if (sun && typeof this.intersects === 'function') {
- if (!this.lastIntersecting && this.intersects(sun)) {
- this.speed *= 2;
- tween(this.cloudGraphics, {
- alpha: 0.5
- }, {
- duration: 3000,
- easing: tween.linear
- });
- } else if (this.lastIntersecting && !this.intersects(sun)) {
- this.speed /= 2;
- tween(this.cloudGraphics, {
- alpha: 1.0
- }, {
- duration: 3000,
- easing: tween.linear
- });
- }
- this.lastIntersecting = this.intersects(sun);
- }
- // Handle screen boundaries
- if (this.x > 2048 + this.width / 2) {
- this.x = -this.width / 2;
- } else if (this.x < -this.width / 2) {
- this.x = 2048 + this.width / 2;
- }
- } catch (error) {
- console.error('Cloud update error:', error);
- // Fallback to local simulation
- if (this.__proto__ && typeof this.__proto__.update === 'function') {
- this.__proto__.update.call(this);
- }
- }
- };
- self.addChild(cloudGraphics);
+ };
+ return self;
+ } catch (error) {
+ console.error('Error creating cat:', error);
+ return null;
+ }
});
// CloudMovement class to handle cloud movement and fade effects
// GrassBack class to represent the grass image
var GrassBack = Container.expand(function () {
@@ -97,13 +35,18 @@
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
+ try {
+ // 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
+ } catch (error) {
+ console.error('Error in grass update:', error);
+ }
};
self.addChild(grassGraphics); // Add grass graphics to the container
+ return self;
});
// GrassFront class to represent the second grass image
var GrassFront = Container.expand(function () {
var self = Container.call(this);
@@ -125,111 +68,31 @@
// Jet class to represent a jet flying across the screen
var Jet = Container.expand(function () {
var self = Container.call(this);
var jetGraphics = self.attachAsset('jet-right', {
- anchorX: 0.5,
- anchorY: 0.5
+ x: 0,
+ y: 0
});
- // Initializes entity movement parameters
createMovementSystem(self, jetGraphics, {
- baseSpeed: 8,
- speedVariation: 0,
- useWaveMotion: true,
- waveAmplitude: 100,
- waveFrequency: 100,
- horizontalMovement: true,
- baseY: 300,
- textures: {
- left: 'jet-left',
- right: 'jet-right'
- },
- respawnPosition: 'side',
+ speed: 10,
+ direction: Math.random() < 0.5 ? -1 : 1,
+ boundaryCheck: true,
+ boundaryWidth: 2048,
sounds: {
move: 'jetSound',
destroy: 'jetSound'
},
- onDestroy: function onDestroy(entity) {
+ onDestroy: function onDestroy() {
+ LK.getSound('jetSound').stop();
handleJetReappearance();
},
entityType: 'jet'
});
- self.onDestroy = function () {
- LK.getSound('jetSound').stop(); // Ensure sound stops when jet is destroyed
+ self.update = function () {
+ this.movementSystem.update();
+ updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
};
- self.setChildIndex = function (index) {
- if (game.children.includes(self)) {
- game.setChildIndex(self, index);
- }
- };
});
-var JetLeft = Container.expand(function () {
- var self = Container.call(this);
- var jetGraphics = self.attachAsset('jet-left', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Initializes entity movement parameters with fixed left direction
- createMovementSystem(self, jetGraphics, {
- baseSpeed: 8,
- speedVariation: 0,
- useWaveMotion: true,
- waveAmplitude: 100,
- waveFrequency: 100,
- horizontalMovement: true,
- baseY: 300,
- textures: {
- left: 'jet-left',
- right: 'jet-right'
- },
- respawnPosition: 'side',
- sounds: {
- move: 'jetSound',
- destroy: 'jetSound'
- },
- onDestroy: function onDestroy(entity) {
- handleJetReappearance();
- },
- entityType: 'jet'
- });
- self.direction = -1; // Always left
- self.onDestroy = function () {
- LK.getSound('jetSound').stop();
- };
-});
-var JetRight = Container.expand(function () {
- var self = Container.call(this);
- var jetGraphics = self.attachAsset('jet-right', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Initializes entity movement parameters with fixed right direction
- createMovementSystem(self, jetGraphics, {
- baseSpeed: 8,
- speedVariation: 0,
- useWaveMotion: true,
- waveAmplitude: 100,
- waveFrequency: 100,
- horizontalMovement: true,
- baseY: 300,
- textures: {
- left: 'jet-left',
- right: 'jet-right'
- },
- respawnPosition: 'side',
- sounds: {
- move: 'jetSound',
- destroy: 'jetSound'
- },
- onDestroy: function onDestroy(entity) {
- handleJetReappearance();
- },
- entityType: 'jet'
- });
- self.direction = 1; // Always right
- self.onDestroy = function () {
- LK.getSound('jetSound').stop();
- };
-});
// 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', {
@@ -252,9 +115,13 @@
alpha: 0.2 // Set transparency to 20%
});
self.x = 450, self.y = 440;
self.update = function () {
- // Add any specific update logic for the light here
+ try {
+ // Add any specific update logic for the light here
+ } catch (error) {
+ console.error('Error in light update:', error);
+ }
};
self.pulse = new Light1Pulse(lightGraphics);
self.pulse.startPulsating();
});
@@ -295,20 +162,42 @@
anchorY: 0.5
});
self.addChild(mirror1Graphics);
});
-// Reticle class to manage reticle behavior
var Reticle = Container.expand(function () {
var self = Container.call(this);
var reticleGraphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
+ var pulse = new Pulse(self, {
+ scaleMax: 1.2,
+ duration: 800
+ });
self.update = function () {
- // Add any specific update logic for the reticle here
+ try {
+ // Update reticle position based on current target if needed
+ if (self.target) {
+ self.x = self.target.x;
+ self.y = self.target.y;
+ }
+ } catch (error) {
+ console.error('Error in reticle update:', error);
+ }
};
- // Start the pulsating effect for the reticle
- startPulsating(self);
+ self.setTarget = function (target) {
+ self.target = target;
+ };
+ self.destroy = function () {
+ if (pulse) {
+ pulse.stop();
+ }
+ self.target = null;
+ Container.prototype.destroy.call(self);
+ };
+ // Start the pulsating effect
+ pulse.startPulsating();
+ return self;
});
// Reticle1 class to represent the reticle image
var Reticle1 = Container.expand(function () {
var self = Container.call(this);
@@ -335,10 +224,15 @@
anchorY: 0.5,
rotation: Math.PI / -12
});
self.update = function () {
- // Add any specific update logic for stack1 here
+ try {
+ // Add any specific update logic for stack1 here
+ } catch (error) {
+ console.error('Error in stack update:', error);
+ }
};
+ return self;
});
// ScoreManager class to manage score logic
// Sun class to represent a sun in the top right corner
var Sun = Container.expand(function () {
@@ -363,9 +257,13 @@
// Add a black stroke
strokeThickness: 15 // Set stroke thickness to 15px
});
self.update = function () {
- // Add any specific update logic for the tree here
+ try {
+ // Add any specific update logic for the tree here
+ } catch (error) {
+ console.error('Error in tree update:', error);
+ }
};
});
// Tree2 class to represent the second type of tree
var Tree2 = Container.expand(function () {
@@ -376,32 +274,34 @@
});
self.addChild(tree2Graphics);
});
// UFO class to represent a UFO
+// Unified UFO class with improved cleanup
var UFO = Container.expand(function () {
var self = Container.call(this);
var ufoGraphics = self.attachAsset('ufo2', {
anchorX: 0.5,
anchorY: 0.5
});
+ // Initialize movement with cleanup tracking
+ self._timers = new Set();
+ self._sounds = new Set();
// Initializes entity movement parameters
UFOMovement(self, ufoGraphics);
self.setChildIndex = function (index) {
if (game.children.includes(self)) {
game.setChildIndex(self, index);
}
};
+ self.destroy = function () {
+ if (this._destroyed) {
+ return;
+ }
+ // Use EntityManager for proper cleanup
+ EntityManager.cleanup(this);
+ }.bind(self);
+ return self;
});
-// UFO2 class to represent the second type of UFO
-var UFO2 = Container.expand(function () {
- var self = Container.call(this);
- var ufo2Graphics = self.attachAsset('ufo2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Initializes entity movement parameters
- UFOMovement(self, ufo2Graphics);
-});
/****
* Initialize Game
****/
@@ -427,8 +327,477 @@
} : 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 _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);
@@ -535,10 +904,9 @@
var layers = {
background: new Container(),
sun: new Container(),
light1: new Container(),
- jetLeft: new Container(),
- jetRight: new Container(),
+ jet: new Container(),
clouds: new Container(),
ufo: new Container(),
grassBack: new Container()
};
@@ -560,13 +928,16 @@
function Bird(type) {
var _this2;
_classCallCheck(this, Bird);
_this2 = _callSuper(this, Bird);
- var birdGraphics = _this2.attachAsset("".concat(type, "-right"), {
+ if (!type) {
+ throw new Error('Bird type is required');
+ }
+ _this2.birdGraphics = _this2.attachAsset("".concat(type, "-right"), {
anchorX: 0.5,
anchorY: 0.5
});
- _this2.birdGraphics = birdGraphics;
+ // The attachAsset method will throw an error if it fails, so we don't need to check again
BirdMovement(_this2, _this2.birdGraphics, type);
return _this2;
}
_inherits(Bird, _Container2);
@@ -576,8 +947,17 @@
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() {
@@ -610,151 +990,334 @@
* @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
-function createMovementSystem(entity, entityGraphics, config) {
- if (!entity || !entityGraphics) {
- console.error('Entity and entityGraphics are required for movement system');
- return null;
- }
- var defaults = {
- baseSpeed: 1,
- speedVariation: 0,
- horizontalMovement: false,
- useWaveMotion: false,
- waveAmplitude: 0,
- waveFrequency: 100,
- screenBounds: {
- width: 2048,
- height: 2732
- },
- respawnDelay: {
- min: 10000,
- max: 20000
- },
- respawnPosition: 'top',
- textures: {
- left: null,
- right: null
- },
- sounds: {
- move: null,
- destroy: null
- },
- scoreValue: 0,
- entityType: null,
- onDestroy: null,
- spawnInterval: {
- min: 2000,
- max: 5000
- },
- maxRetries: 3
- };
- // Enhanced state tracking
- entity.movementState = {
- isMovingDown: false,
- isMovingHorizontal: false,
- lastUpdate: Date.now(),
- retryCount: 0
- };
- var settings = Object.assign({}, defaults, config || {});
- entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation;
- entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1;
- entity.lastX = entity.x || 0;
- entity.lastY = entity.y || 0;
- if (settings.sounds && settings.sounds.move) {
- try {
- var sound = LK.getSound(settings.sounds.move);
- if (sound && typeof sound.play === 'function') {
- sound.play({
- loop: true
- });
- }
- } catch (error) {
- console.error('Error playing movement sound:', error);
+// Unified entity management system with improved cleanup
+var EntityManager = {
+ cleanup: function cleanup(entity) {
+ if (!entity || entity._cleaned) {
+ return;
}
- }
- entity.scoreValue = settings.scoreValue;
- entity.update = function () {
- try {
- if (settings.entityType === 'laser') {
- if (!this.vx || !this.vy) {
- return;
- }
- this.x += this.vx;
- this.y += this.vy;
- if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) {
- if (typeof this.destroy === 'function') {
- this.destroy();
+ entity._cleaned = true;
+ // Stop all associated sounds and clear references
+ if (entity._sounds instanceof Set) {
+ var _iterator = _createForOfIteratorHelper(entity._sounds),
+ _step;
+ try {
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
+ var _sound;
+ var soundName = _step.value;
+ var sound = LK.getSound(soundName);
+ if ((_sound = sound) !== null && _sound !== void 0 && _sound.stop) {
+ sound.stop();
}
}
- } else if (settings.horizontalMovement) {
- this.x += this.speed * this.direction;
- if (settings.useWaveMotion && settings.baseY !== undefined) {
- this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude;
+ } catch (err) {
+ _iterator.e(err);
+ } finally {
+ _iterator.f();
+ }
+ entity._sounds.clear();
+ entity._sounds = null;
+ }
+ // Clear all timers and references
+ if (entity._timers instanceof Set) {
+ var _iterator2 = _createForOfIteratorHelper(entity._timers),
+ _step2;
+ try {
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
+ var timer = _step2.value;
+ LK.clearTimeout(timer);
}
- } else {
- this.y += this.speed;
- if (settings.useWaveMotion) {
- this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude;
+ } catch (err) {
+ _iterator2.e(err);
+ } finally {
+ _iterator2.f();
+ }
+ entity._timers.clear();
+ entity._timers = null;
+ }
+ // Return to pool or remove from parent
+ if (entity.type && EntityPool.pools && EntityPool.pools[entity.type]) {
+ var _entity$reset;
+ (_entity$reset = entity.reset) === null || _entity$reset === void 0 || _entity$reset.call(entity);
+ EntityPool["return"](entity.type, entity);
+ } else if (entity.parent) {
+ entity.parent.removeChild(entity);
+ }
+ // Clear any remaining references
+ entity._destroyed = true;
+ entity.parent = null;
+ // Clear any graphics references
+ if (entity.birdGraphics) {
+ entity.birdGraphics = null;
+ }
+ },
+ spawn: function spawn(type) {
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ if (!type) {
+ throw new Error('Entity type is required');
+ }
+ var entity = EntityPool.get(type);
+ if (!entity) {
+ var EntityTypes = {
+ bird1: Bird1,
+ bird2: Bird2,
+ laser: function laser(config) {
+ return new Laser(config.startX, config.startY, config.targetX, config.targetY);
}
+ };
+ var EntityConstructor = EntityTypes[type];
+ if (!EntityConstructor) {
+ throw new Error("Unknown entity type: ".concat(type));
}
- if (entityGraphics && settings.textures && settings.textures.left && settings.textures.right) {
- try {
- var rightAsset = LK.getAsset(settings.textures.right, {});
- var leftAsset = LK.getAsset(settings.textures.left, {});
- if (rightAsset && leftAsset) {
- entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture;
+ entity = typeof EntityConstructor === 'function' ? EntityConstructor.length ? EntityConstructor(config) : new EntityConstructor() : null;
+ if (!entity) {
+ throw new Error("Failed to create entity of type: ".concat(type));
+ }
+ }
+ entity.type = type;
+ entity._sounds = new Set();
+ entity._timers = new Set();
+ entity._cleaned = false;
+ entity._destroyed = false;
+ return entity;
+ }
+};
+var EntityPool = {
+ pools: {},
+ get: function get(type) {
+ if (this.pools[type] && this.pools[type].length > 0) {
+ return this.pools[type].pop();
+ }
+ return null;
+ },
+ "return": function _return(type, entity) {
+ if (!this.pools[type]) {
+ this.pools[type] = [];
+ }
+ this.pools[type].push(entity);
+ }
+};
+function createMovementSystem(entity, entityGraphics, config) {
+ try {
+ var _settings$sounds;
+ if (!entity || !entityGraphics) {
+ console.error('Entity and entityGraphics are required for movement system');
+ return null;
+ }
+ // Initialize entity management systems
+ if (!entity._timers) {
+ entity._timers = new Set();
+ }
+ if (!entity._sounds) {
+ entity._sounds = new Set();
+ }
+ var soundManager = window.soundManager || null;
+ var defaults = {
+ baseSpeed: 1,
+ speedVariation: 0,
+ horizontalMovement: false,
+ useWaveMotion: false,
+ waveAmplitude: 0,
+ waveFrequency: 100,
+ screenBounds: {
+ width: 2048,
+ height: 2732
+ },
+ respawnPosition: 'top',
+ textures: {
+ left: null,
+ right: null
+ },
+ sounds: {
+ move: null,
+ destroy: null
+ },
+ scoreValue: 0,
+ entityType: null,
+ onDestroy: null,
+ onUpdate: null,
+ handleScreenWrap: false
+ };
+ var settings = Object.assign({}, defaults, config || {});
+ entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation;
+ entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1;
+ entity.lastX = entity.x || 0;
+ entity.lastY = entity.y || 0;
+ entity.scoreValue = settings.scoreValue;
+ // Initialize movement sound
+ if ((_settings$sounds = settings.sounds) !== null && _settings$sounds !== void 0 && _settings$sounds.move && soundManager) {
+ var moveSound = soundManager.play(settings.sounds.move, {
+ loop: true
+ });
+ if (moveSound) {
+ entity._sounds.add(settings.sounds.move);
+ }
+ }
+ entity.update = function () {
+ try {
+ var _settings$textures, _settings$textures2;
+ if (settings.entityType === 'laser') {
+ if (!this.vx || !this.vy) {
+ return;
}
- } catch (error) {
- console.error('Error updating entity texture:', error);
+ this.x += this.vx;
+ this.y += this.vy;
+ if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) {
+ EntityManager.cleanup(this);
+ }
+ } else if (settings.horizontalMovement) {
+ var _settings$onUpdate;
+ this.x += this.speed * this.direction;
+ if (settings.useWaveMotion && settings.baseY !== undefined) {
+ this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude;
+ }
+ if (settings.handleScreenWrap) {
+ if (this.x > settings.screenBounds.width + this.width / 2) {
+ this.x = -this.width / 2;
+ } else if (this.x < -this.width / 2) {
+ this.x = settings.screenBounds.width + this.width / 2;
+ }
+ }
+ (_settings$onUpdate = settings.onUpdate) === null || _settings$onUpdate === void 0 || _settings$onUpdate.call(settings, this);
+ } else {
+ this.y += this.speed;
+ if (settings.useWaveMotion) {
+ this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude;
+ }
}
- }
- if (settings.horizontalMovement) {
- if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
- if (settings.sounds && settings.sounds.destroy) {
- try {
- var sound = LK.getSound(settings.sounds.destroy);
- if (sound && typeof sound.stop === 'function') {
- sound.stop();
- }
- } catch (error) {
- console.error('Error stopping destroy sound:', error);
+ if (entityGraphics && (_settings$textures = settings.textures) !== null && _settings$textures !== void 0 && _settings$textures.left && (_settings$textures2 = settings.textures) !== null && _settings$textures2 !== void 0 && _settings$textures2.right) {
+ try {
+ var rightAsset = LK.getAsset(settings.textures.right, {});
+ var leftAsset = LK.getAsset(settings.textures.left, {});
+ if (rightAsset !== null && rightAsset !== void 0 && rightAsset.texture && leftAsset !== null && leftAsset !== void 0 && leftAsset.texture) {
+ entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture;
}
+ } catch (error) {
+ console.error('Error updating entity texture:', error);
}
- if (typeof this.destroy === 'function') {
- this.destroy();
+ }
+ if (settings.horizontalMovement) {
+ if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ var _settings$onDestroy;
+ EntityManager.cleanup(this);
+ (_settings$onDestroy = settings.onDestroy) === null || _settings$onDestroy === void 0 || _settings$onDestroy.call(settings, this);
}
- if (settings.onDestroy) {
- settings.onDestroy(this);
+ } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) {
+ switch (settings.respawnPosition) {
+ case 'random':
+ this.y = Math.random() * settings.screenBounds.height;
+ this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width;
+ break;
+ case 'side':
+ this.y = Math.random() * settings.screenBounds.height;
+ this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width;
+ break;
+ default:
+ this.y = -this.height;
+ this.x = Math.random() * settings.screenBounds.width;
}
}
- } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) {
- switch (settings.respawnPosition) {
- case 'random':
- this.y = Math.random() * settings.screenBounds.height;
- this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width;
- break;
- case 'side':
- this.y = Math.random() * settings.screenBounds.height;
- this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width;
- break;
- case 'top':
- default:
- this.y = -this.height;
- this.x = Math.random() * settings.screenBounds.width;
- break;
+ this.lastX = this.x;
+ this.lastY = this.y;
+ } catch (error) {
+ console.error('Error in entity update:', error);
+ EntityManager.cleanup(this);
+ }
+ }.bind(entity);
+ if (typeof entity.destroy !== 'function') {
+ entity.destroy = function () {
+ var _settings$sounds2;
+ if (this._destroyed) {
+ return;
}
+ this._destroyed = true;
+ EntityManager.cleanup(this);
+ if ((_settings$sounds2 = settings.sounds) !== null && _settings$sounds2 !== void 0 && _settings$sounds2.destroy && soundManager) {
+ soundManager.stop(settings.sounds.destroy);
+ }
+ }.bind(entity);
+ }
+ return entity;
+ } catch (error) {
+ console.error('Error in createMovementSystem:', error);
+ return null;
+ }
+}
+var CloudMovement = {
+ init: function init(cloud) {
+ if (!cloud) {
+ throw new Error('Cloud entity is required');
+ }
+ cloud._movement = {
+ speed: Math.random() * 0.5 + 0.2,
+ direction: Math.random() < 0.5 ? -1 : 1,
+ bounds: {
+ left: -cloud.width,
+ right: game.width + cloud.width
}
- this.lastX = this.x;
- this.lastY = this.y;
+ };
+ this.update(cloud);
+ },
+ update: function update(cloud) {
+ if (!cloud || !cloud._movement) {
+ return;
+ }
+ cloud.x += cloud._movement.speed * cloud._movement.direction;
+ // Handle bounds checking and wrapping
+ if (cloud.x < cloud._movement.bounds.left) {
+ cloud.x = cloud._movement.bounds.right;
+ } else if (cloud.x > cloud._movement.bounds.right) {
+ cloud.x = cloud._movement.bounds.left;
+ }
+ },
+ cleanup: function cleanup(cloud) {
+ if (!cloud) {
+ return;
+ }
+ delete cloud._movement;
+ }
+};
+var Cloud = /*#__PURE__*/function (_Container3) {
+ function Cloud() {
+ var _this3;
+ _classCallCheck(this, Cloud);
+ _this3 = _callSuper(this, Cloud);
+ try {
+ _this3.attachAsset('cloud', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ CloudMovement.init(_this3);
} catch (error) {
- console.error('Error in entity update:', error);
+ console.error('Error in cloud constructor:', error);
+ throw error;
}
- }.bind(entity);
- return entity;
-}
-// Game instance already initialized above
+ return _possibleConstructorReturn(_this3, _this3);
+ }
+ _inherits(Cloud, _Container3);
+ return _createClass(Cloud, [{
+ key: "update",
+ value: function update() {
+ try {
+ CloudMovement.update(this);
+ } catch (error) {
+ console.error('Error in cloud update:', error);
+ }
+ }
+ }, {
+ key: "destroy",
+ value: function destroy() {
+ try {
+ CloudMovement.cleanup(this);
+ _superPropGet(Cloud, "destroy", this, 3)([]);
+ } catch (error) {
+ console.error('Error in cloud destroy:', error);
+ }
+ }
+ }]);
+}(Container); // Game instance already initialized above
// Layer structure initialization with proper cleanup handling
var initializeLayers = function initializeLayers() {
game.layers = {
background: new Container(),
@@ -784,450 +1347,196 @@
var child = this.children[0];
if (typeof child.destroy === 'function') {
child.destroy();
}
- this.removeChild(child);
}
};
});
- return game.layers;
};
-game.layers = initializeLayers();
-/****
-* Game State
-****/
-// Add base BirdMovement class (missing)
-// Initialize game state as a module-level singleton
-var GameState = {
- birds: [],
- clouds: [],
- ufo: null,
- score: 0,
- scoreDisplay: null,
- cat: null,
- sounds: new Set(),
- reticle: null,
- jet: null,
- jetSoundPlayed: false,
- reset: function reset() {
- // Clean up birds
- this.birds.forEach(function (bird) {
- if (typeof bird.destroy === 'function') {
- bird.destroy();
- }
- });
- this.birds = [];
- // Clean up clouds
- this.clouds.forEach(function (cloud) {
- if (typeof cloud.destroy === 'function') {
- cloud.destroy();
- }
- });
- this.clouds = [];
- // Clean up UFO
- if (this.ufo && typeof this.ufo.destroy === 'function') {
- this.ufo.destroy();
- this.ufo = null;
- }
- // Clean up reticle
- if (this.reticle && typeof this.reticle.destroy === 'function') {
- this.reticle.destroy();
- this.reticle = null;
- }
- // Clean up jet
- if (this.jet && typeof this.jet.destroy === 'function') {
- this.jet.destroy();
- this.jet = null;
- this.jetSoundPlayed = false;
- }
- // Stop all active sounds
- this.sounds.forEach(function (soundName) {
- try {
- var sound = LK.getSound(soundName);
- if (sound && typeof sound.stop === 'function') {
- sound.stop();
- }
- } catch (error) {
- console.error("Error stopping sound ".concat(soundName, ":"), error);
- }
- });
- this.sounds.clear();
- // Reset score
- this.score = 0;
- if (this.scoreDisplay) {
- this.scoreDisplay.updateScore(0);
- }
- }
+// Factory functions for specific pulse effects
+var Light1Pulse = function Light1Pulse(lightGraphics) {
+ return new Pulse(lightGraphics, {
+ scaleMax: 1.6,
+ duration: 1500
+ });
};
-// Use GameState for all game-related variables
-var gameState = GameState;
-// Initialize game layers with a single, organized structure
-game.layers = {
- background: new Container(),
- sun: new Container(),
- // z-index: 1
- light1: new Container(),
- // z-index: 2
- jetLeft: new Container(),
- // z-index: 3
- jetRight: new Container(),
- // z-index: 3
- clouds: new Container(),
- // z-index: 4
- ufo: new Container(),
- // z-index: 5
- grassBack: new Container(),
- // z-index: 6
- bird1: new Container(),
- // z-index: 7
- tree: new Container(),
- // z-index: 8
- stack1: new Container(),
- // z-index: 9
- bird2: new Container(),
- // z-index: 10
- mirror: new Container(),
- // z-index: 11
- grassFront: new Container(),
- // z-index: 12
- cat: new Container(),
- // z-index: 13
- laser: new Container(),
- // z-index: 14
- reticle: new Container(),
- // z-index: 15
- enemies: new Container(),
- // Container for collision detection
- birds: new Container() // Container for all birds
+var SunPulse = function SunPulse(sunGraphics) {
+ return new Pulse(sunGraphics, {
+ scaleMax: 1.1,
+ duration: 1000
+ });
};
-// Add these layers to the game and set their z-indices
-var layerOrder = ['background', 'sun', 'light1', 'jetLeft', 'jetRight', 'clouds', 'ufo', 'grassBack', 'bird1', 'tree', 'stack1', 'bird2', 'mirror', 'grassFront', 'cat', 'laser', 'reticle', 'enemies', 'birds'];
-layerOrder.forEach(function (key, index) {
- if (game.layers[key]) {
- game.layers[key].zIndex = index;
- game.addChild(game.layers[key]);
- }
-});
-// Duplicate game.layers initialization removed
-/**
-* Creates and adds a UFO to the game
-* @returns {Object} The created UFO object
-*/
-function addUFO() {
- if (ufo) {
- return ufo;
- }
- // Create new UFO instance
- var ufo = new UFO();
- // Add to UFO layer
- game.layers.ufo.addChild(ufo);
- // Add to enemies layer for collision detection
- game.layers.enemies.addChild(ufo);
- // Set initial position (either left or right side of screen)
- ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2;
- ufo.y = Math.random() * (2732 / 2 - ufo.height);
- // Play UFO sound
- LK.getSound('ufo1').play();
- return ufo;
-}
-// Enhanced entity spawning system with structured intervals and error handling
-var EntitySpawner = {
- spawnIntervals: {
- bird1: {
- min: 2000,
- max: 5000
- },
- bird2: {
- min: 3000,
- max: 6000
+// Removed redundant startPulsating function as it's now handled by Pulse class
+// Sound system is already initialized above
+SoundManager = {
+ playEffect: function playEffect(soundName) {
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ try {
+ var sound = this._sounds.get(soundName) || LK.getSound(soundName);
+ if (!sound) {
+ console.warn("Sound '".concat(soundName, "' not found"));
+ return;
+ }
+ var _options$volume = options.volume,
+ volume = _options$volume === void 0 ? this._volumes[soundName] || 1 : _options$volume,
+ _options$loops = options.loops,
+ loops = _options$loops === void 0 ? false : _options$loops;
+ sound.play({
+ volume: volume,
+ loops: loops
+ });
+ return sound;
+ } catch (error) {
+ console.error("Error playing sound effect '".concat(soundName, "':"), error);
}
},
- removeEntity: function removeEntity(entity) {
+ playMusic: function playMusic() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
try {
- if (entity.parent) {
- entity.parent.removeChild(entity);
+ var _options$volume2 = options.volume,
+ volume = _options$volume2 === void 0 ? this._volumes[this.effects.bgm] || 1 : _options$volume2,
+ _options$fade = options.fade,
+ fade = _options$fade === void 0 ? true : _options$fade;
+ return LK.playMusic(this.effects.bgm, {
+ loop: false,
+ volume: volume,
+ fade: fade ? {
+ start: 0,
+ end: 1,
+ duration: 4000
+ } : undefined
+ });
+ } catch (error) {
+ console.error('Error playing background music:', error);
+ }
+ },
+ stopSoundFunc: function stopSoundFunc(soundName) {
+ try {
+ var sound = this._sounds.get(soundName) || LK.getSound(soundName);
+ if (sound !== null && sound !== void 0 && sound.stop) {
+ sound.stop();
}
- if (birds.includes(entity)) {
- birds.splice(birds.indexOf(entity), 1);
- }
- if (typeof entity.destroy === 'function') {
- entity.destroy();
- }
} catch (error) {
- console.error('Error removing entity:', error);
+ console.error("Error stopping sound '".concat(soundName, "':"), error);
}
},
- spawnBird1: function spawnBird1() {
+ pauseSound: function pauseSound(soundName) {
try {
- var bird = new Bird1();
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- birds.push(bird);
- game.layers.birds.addChild(bird);
- game.layers.enemies.addChild(bird);
- return bird;
+ var sound = this._sounds.get(soundName) || LK.getSound(soundName);
+ if (sound !== null && sound !== void 0 && sound.pause) {
+ sound.pause();
+ }
} catch (error) {
- console.error('Error spawning Bird1:', error);
- return null;
+ console.error("Error pausing sound '".concat(soundName, "':"), error);
}
},
- spawnBird2: function spawnBird2() {
+ setVolume: function setVolume(soundName, volume) {
try {
- var bird = new Bird2();
- bird.x = Math.random() * 2048;
- bird.y = -bird.height;
- birds.push(bird);
- game.layers.birds.addChild(bird);
- game.layers.enemies.addChild(bird);
- return bird;
+ var sound = this._sounds.get(soundName);
+ if (sound) {
+ sound.volume = volume;
+ this._volumes[soundName] = volume;
+ }
} catch (error) {
- console.error('Error spawning Bird2:', error);
- return null;
+ console.error("Error setting volume for '".concat(soundName, "':"), error);
}
}
};
-// Consolidated bird spawning functions
-// Consolidated bird spawning functions are inserted below
-// Jet timer function
-var jetTimer = LK.setTimeout(function spawnJet() {
- 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;
- }
- jetTimer = LK.setTimeout(spawnJet, 5000);
-}, Math.random() * 5000 + 5000);
-// Cloud initialization
-for (var i = 0; i < 4; i++) {
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2);
- clouds.push(cloud);
- game.layers.clouds.addChild(cloud);
-}
-// Handle click/tap events with proper cleanup and error handling
-game.down = function (x, y, obj) {
- try {
- // Clean up old reticle if it exists
- if (game.reticle && typeof game.reticle.destroy === 'function') {
- game.reticle.destroy();
- }
- // Create new reticle
- game.reticle = game.layers.reticle.addChild(new Reticle());
- game.reticle.x = x;
- game.reticle.y = y;
- // Create and add laser with proper positioning
- if (cat) {
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
- game.layers.laser.addChild(laser);
- // Clean up laser after animation
- setTimeout(function () {
- if (laser && typeof laser.destroy === 'function') {
- laser.destroy();
- }
- game.layers.laser.removeChild(laser);
- }, 2000);
- }
- } catch (error) {
- console.error('Error in game.down:', error);
- }
-};
-// This is a duplicate checkInteractions function that has been consolidated elsewhere
-// Object placements are handled in the main initialization section
-// This is a duplicate addUFO function that has been consolidated elsewhere
-// Consolidated bird spawning functions
-// Consolidated bird spawning functions are inserted below
-// Removing duplicate jetTimer code as it's already defined elsewhere
-for (var i = 0; i < 4; i++) {
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2);
- clouds.push(cloud);
- game.layers.clouds.addChild(cloud);
-}
-game.down = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.layers.reticle.addChild(new Reticle());
- }
- game.reticle.x = x;
- game.reticle.y = y;
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
- game.layers.laser.addChild(laser);
-};
-// This is a duplicate checkInteractions function that has been consolidated elsewhere
-// Layer structure and initialization is already handled at the beginning of the file
-// Layer z-index management is handled by the layerStructure configuration
-// The spawn functions for UFO, Bird1, Bird2, and Jet are already defined earlier in the code
-// Layer z-index management is handled by the layerStructure configuration
-// The game.down function is already defined earlier in the code
-game.addChild(game.layers.enemies);
-// CloudMovement class to handle cloud movement and fade effects
-// UFOMovement class to handle UFO movement
-// UFOMovement has been moved to js/movements.js
-// Generic Pulse class that can be used for both Sun and Light1
-/**
-* Reusable animation controller for pulsating effects using tween
-* @param {Graphics} graphics - Target graphics object to animate
-* @param {number} [scaleMax=1.1] - Maximum scale multiplier
-* @param {number} [duration=1000] - Full animation cycle duration in ms
-*/
-var Pulse = function Pulse(graphics, scaleMax, duration) {
- this.graphics = graphics;
- this.scaleMax = scaleMax || 1.1;
- this.duration = duration || 1000;
- /**
- * Starts continuous pulsating animation using recursive tween calls
- * Creates smooth scale oscillation through easeInOut timing
- */
- this.startPulsating = function () {
- function pulsate() {
- tween(this.graphics, {
- scaleX: this.scaleMax,
- scaleY: this.scaleMax
- }, {
- duration: this.duration,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.graphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: this.duration,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
- }
- pulsate.call(this);
- };
-};
-// Light1Pulse now uses the generic Pulse class
-/** Factory for light fixture pulse (higher intensity/longer duration) */
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- return new Pulse(lightGraphics, 1.6, 1500);
-};
-// SunPulse now uses the generic Pulse class
-/** Factory for subtle solar glow pulse (conservative scaling) */
-var SunPulse = function SunPulse(sunGraphics) {
- return new Pulse(sunGraphics, 1.1, 1000);
-};
-// Bird2Effects class to handle effects and animations for Bird2
-// Consolidated function to create a pulsating effect
-function startPulsating(target, duration) {
- duration = duration || 888;
- function pulsate() {
- tween(target, {
- scaleX: 1.1,
- // Use consistent scale value
- scaleY: 1.1
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(target, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: pulsate
- });
- }
- });
- }
- pulsate();
-}
+// Initialize sound system
+SoundManager.init();
+// Sound effect wrapper classes using the unified system
var UFOSound = function UFOSound() {
this.play = function () {
- LK.getSound('ufo1').play();
+ return SoundManager.playEffect(SoundManager.effects.ufo);
};
};
-// BackgroundMusic class to manage background music
-function playSoundEffect(soundName, action) {
- var volume = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
- var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
- try {
- var sound = LK.getSound(soundName);
- if (!sound) {
- console.warn("Sound '".concat(soundName, "' not found"));
- return;
- }
- switch (action) {
- case 'play':
- if (typeof sound.play === 'function') {
- sound.play({
- volume: volume,
- loops: loops
- });
- }
- break;
- case 'stop':
- if (typeof sound.stop === 'function') {
- sound.stop();
- }
- break;
- case 'pause':
- if (typeof sound.pause === 'function') {
- sound.pause();
- }
- break;
- default:
- console.warn("Unknown sound action: ".concat(action));
- }
- } catch (error) {
- console.error("Error playing sound '".concat(soundName, "':"), error);
- }
-}
-var BackgroundMusic = function BackgroundMusic() {
+var LaserSound = function LaserSound() {
this.play = function () {
- LK.playMusic('bgm1', {
- loop: false,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- }
- });
+ return SoundManager.playEffect(SoundManager.effects.laser);
};
};
-// LaserSound class to manage laser sound effects
-var LaserSound = function LaserSound() {
+var BackgroundMusic = function BackgroundMusic() {
this.play = function () {
- LK.getSound('laser1').play();
+ return SoundManager.playMusic();
};
};
// Unified movement system for all entities
+// Unified movement system with improved cleanup and state management
+// Note: This is the main implementation of createMovementSystem used throughout the code
/**
+* Unified movement system for all moving entities
+* @param {Object} entity - The entity to apply movement to
+* @param {Object} entityGraphics - The graphics object for the entity
+* @param {Object} config - Configuration options for movement
+*/
+// Removed duplicate createMovementSystem function as it's already defined above
+/**
* Bird1 movement configuration
*/
-function BirdMovement(bird, birdGraphics, birdType) {
- var config = {
- baseSpeed: birdType === 'bird1' ? 1 : 1.5,
- speedVariation: birdType === 'bird1' ? 0.5 : 1.6,
+/**
+* Bird2 movement configuration
+*/
+/**
+* UFO movement configuration
+*/
+// Entity movement configurations
+var MOVEMENT_CONFIGS = {
+ bird1: {
+ baseSpeed: 1,
+ speedVariation: 0.5,
useWaveMotion: true,
- waveAmplitude: birdType === 'bird1' ? 4.5 : 6.5,
- waveFrequency: birdType === 'bird1' ? 120 : 100,
+ waveAmplitude: 4.5,
+ waveFrequency: 120,
horizontalMovement: false,
textures: {
- left: "".concat(birdType, "-left"),
- right: "".concat(birdType, "-right")
+ left: 'bird1-left',
+ right: 'bird1-right'
},
- respawnPosition: birdType === 'bird1' ? 'top' : 'random',
+ respawnPosition: 'top',
sounds: {
move: 'wings1',
destroy: null
},
- scoreValue: birdType === 'bird1' ? 5 : 10,
+ scoreValue: 5
+ },
+ bird2: {
+ baseSpeed: 1.5,
+ speedVariation: 1.6,
+ useWaveMotion: true,
+ waveAmplitude: 6.5,
+ waveFrequency: 100,
+ horizontalMovement: false,
+ textures: {
+ left: 'bird2-left',
+ right: 'bird2-right'
+ },
+ respawnPosition: 'random',
+ sounds: {
+ move: 'wings1',
+ destroy: null
+ },
+ scoreValue: 10
+ },
+ ufo: {
+ baseSpeed: 3,
+ speedVariation: 1,
+ useWaveMotion: true,
+ waveAmplitude: 50,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: function baseY() {
+ return Math.random() * 300 + 100;
+ },
+ textures: null,
+ sounds: {
+ move: 'ufo1',
+ destroy: null
+ },
+ scoreValue: 20
+ }
+};
+function BirdMovement(bird, birdGraphics, birdType) {
+ var config = Object.assign({}, MOVEMENT_CONFIGS[birdType], {
entityType: birdType,
onDestroy: function onDestroy(entity) {
var index = birds.indexOf(entity);
if (index > -1) {
@@ -1240,42 +1549,30 @@
}
}, Math.random() * 2000 + 1000);
}
}
- };
+ });
createMovementSystem(bird, birdGraphics, config);
}
function UFOMovement(ufo, ufoGraphics) {
- var config = {
- baseSpeed: 3,
- speedVariation: 1,
- useWaveMotion: true,
- waveAmplitude: 50,
- waveFrequency: 100,
- horizontalMovement: true,
- baseY: Math.random() * 300 + 100,
- textures: null,
- sounds: {
- move: 'ufo1',
- destroy: null
- },
+ var config = Object.assign({}, MOVEMENT_CONFIGS.ufo, {
+ baseY: MOVEMENT_CONFIGS.ufo.baseY(),
+ entityType: 'ufo',
onDestroy: function onDestroy(entity) {
if (entity.sounds && entity.sounds.move) {
LK.getSound(entity.sounds.move).stop();
}
entity.destroy();
ufo = null;
handleUFOReappearance();
},
- scoreValue: 20,
- entityType: 'ufo',
handleLaserCollision: function handleLaserCollision(laser) {
var angle = Math.atan2(laser.vy, laser.vx) + Math.PI;
laser.vx = Math.cos(angle) * laser.speed;
laser.vy = Math.sin(angle) * laser.speed;
return false;
}
- };
+ });
createMovementSystem(ufo, ufoGraphics, config);
}
/**
* Jet movement configuration
@@ -1312,44 +1609,41 @@
// CloudMovement class is already defined earlier in the file
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
- // 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) {
+ try {
+ // Apply swooping animation effect
tween(this.bird, {
- scaleX: 1.1,
- scaleY: 1.1
+ rotation: Math.sin(this.bird.y / 100) * 0.2
}, {
- duration: 500,
- easing: tween.easeOut,
- onFinish: function () {
- tween(this.bird, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 500,
- easing: tween.easeIn
- });
- }.bind(this)
+ 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);
}
};
};
-var background = LK.getAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
-});
-background.x = 2048 / 2;
-background.y = 2732 / 2 - 100;
-game.layers.background.addChild(background);
-game.addChild(background);
+// BirdMovement is already defined with MOVEMENT_CONFIGS above
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
var self = this;
self.score = 0;
@@ -1363,50 +1657,117 @@
self.getScore = function () {
return self.score;
};
};
-// Removed duplicate gameState declaration as it's now handled by GameState
-game.down = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = new Reticle();
- game.layers.reticle.addChild(game.reticle);
+// Game input handlers with proper cleanup
+var LaserSystem = /*#__PURE__*/function () {
+ function LaserSystem() {
+ _classCallCheck(this, LaserSystem);
+ this.activeLasers = new Set();
+ this._cleanupQueue = new Set();
}
- if (GameState.cat) {
- game.reticle.x = x;
- game.reticle.y = y;
- var laser = new Laser(GameState.cat.x - 140, GameState.cat.y - 440, x, y);
- game.layers.laser.addChild(laser);
- }
-};
+ 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 _iterator3 = _createForOfIteratorHelper(this._cleanupQueue),
+ _step3;
+ try {
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
+ var laser = _step3.value;
+ this.activeLasers["delete"](laser);
+ EntityManager.cleanup(laser);
+ }
+ } catch (err) {
+ _iterator3.e(err);
+ } finally {
+ _iterator3.f();
+ }
+ this._cleanupQueue.clear();
+ }
+ // Update active lasers
+ var _iterator4 = _createForOfIteratorHelper(this.activeLasers),
+ _step4;
+ try {
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
+ var laser = _step4.value;
+ if (!laser || laser._destroyed) {
+ this.queueForCleanup(laser);
+ continue;
+ }
+ if (laser.update) {
+ laser.update();
+ }
+ }
+ } catch (err) {
+ _iterator4.e(err);
+ } finally {
+ _iterator4.f();
+ }
+ }
+ }, {
+ key: "clear",
+ value: function clear() {
+ var _iterator5 = _createForOfIteratorHelper(this.activeLasers),
+ _step5;
+ try {
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
+ var laser = _step5.value;
+ EntityManager.cleanup(laser);
+ }
+ } catch (err) {
+ _iterator5.e(err);
+ } finally {
+ _iterator5.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) {
- if (!game.reticle) {
- game.reticle = new Reticle();
- game.layers.reticle.addChild(game.reticle);
+ 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);
}
- 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;
- }
};
-// Initialize sun and light1
-var sun = game.layers.background.addChild(new Sun());
-sun.x = 1800;
-sun.y = 300;
-var light1 = game.layers.background.addChild(new Light1());
-light1.x = 450;
-light1.y = 440;
-// Add a sun to the game in the top left corner
-// Duplicate sun placement removed
-// Duplicate light1 placement removed // Move light1 down by 210px
-// Ensure light1 is added to the game before setting its index
-if (game.children.includes(light1)) {
- game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun
- // Add score display
- var scoreDisplay = game.addChild(new Mirror());
- scoreDisplay.x = 1700;
- scoreDisplay.y = 300;
+// Initialize sun and light1 (already added to layers)
+var sun = game.layers.sun.getChildAt(0);
+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 clouds array
GameState.clouds = [];
@@ -1474,252 +1835,367 @@
if (enemy instanceof UFO) {
enemy.movementSystem = new UFOMovement(enemy, enemy.graphics);
}
}
-// Main game loop
function gameTick() {
- game.layers.enemies.children.forEach(function (enemy) {
- var _enemy$movementSystem;
- (_enemy$movementSystem = enemy.movementSystem) === null || _enemy$movementSystem === void 0 || _enemy$movementSystem.update();
- });
- checkInteractions();
- requestAnimationFrame(gameTick);
+ try {
+ updateClouds();
+ updateEnemies();
+ updateLasers();
+ checkInteractions();
+ requestAnimationFrame(gameTick);
+ } catch (error) {
+ console.error('Error in game tick:', error);
+ requestAnimationFrame(gameTick);
+ }
}
-/**
-* Main game update function
-* Uses the unified movement system for all entities
-*/
-game.update = function () {
- // Update all clouds
+function updateClouds() {
+ // Update existing clouds
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
- // Ensure at least 3 clouds are visible
+ // Ensure minimum cloud count
while (clouds.length < 3) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
+ cloud.y = Math.random() * (2732 / 2);
clouds.push(cloud);
game.layers.clouds.addChild(cloud);
}
- // Update all birds
- birds.forEach(function (bird) {
- bird.update();
- });
- // Ensure we have enough birds
- while (birds.length < 3) {
- if (birds.length % 2 === 0) {
- spawnBird1();
- } else {
- spawnBird2();
+}
+function updateEnemies() {
+ var enemies = game.layers.enemies.children;
+ var screenWidth = 2048;
+ var screenHeight = 2732;
+ enemies.forEach(function (enemy) {
+ if (!enemy || !enemy.movementSystem) {
+ return;
}
- }
- // Update all lasers
- game.layers.laser.children.forEach(function (laser) {
- laser.update();
+ enemy.movementSystem.update();
+ if (enemy instanceof Bird1 || enemy instanceof Bird2) {
+ handleBirdCollisions(enemy, enemies);
+ handleBirdRespawn(enemy, screenWidth, screenHeight);
+ }
});
- // Update UFO if it exists
- if (GameState.ufo) {
- GameState.ufo.update();
- }
- // Check for all interactions between game entities
- checkInteractions();
-};
-// Function to spawn a third kind of bird
-// Consolidated bird spawning functions are inserted below
-// Ensure there are always 3 birds on screen
-// Initialize enemy movement systems
-game.update = function () {
- // Update each bird
- birds.forEach(function (bird, index) {
- bird.update();
- // Check for intersections with other birds
- birds.forEach(function (otherBird, otherIndex) {
- if (index !== otherIndex && !bird.lastIntersecting && bird.intersects(otherBird)) {
- // Calculate bounce direction
- var dx = bird.x - otherBird.x;
- var dy = bird.y - otherBird.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- var bounceFactor = 5; // Adjust bounce factor for desired effect
- // Apply bounce with acceleration
+}
+function handleBirdCollisions(bird, enemies) {
+ if (!bird.lastIntersecting) {
+ enemies.forEach(function (otherEnemy) {
+ if (bird === otherEnemy || !(otherEnemy instanceof Bird1 || otherEnemy instanceof Bird2)) {
+ return;
+ }
+ if (bird.intersects(otherEnemy)) {
+ var dx = bird.x - otherEnemy.x;
+ var dy = bird.y - otherEnemy.y;
+ var distance = Math.sqrt(dx * dx + dy * dy) || 1;
+ var bounceFactor = 5;
bird.x += dx / distance * bounceFactor;
bird.y += dy / distance * bounceFactor;
- otherBird.x -= dx / distance * bounceFactor;
- otherBird.y -= dy / distance * bounceFactor;
- // Mark as intersecting
+ otherEnemy.x -= dx / distance * bounceFactor;
+ otherEnemy.y -= dy / distance * bounceFactor;
bird.lastIntersecting = true;
- otherBird.lastIntersecting = true;
+ otherEnemy.lastIntersecting = true;
}
});
- // Reset intersection state
- bird.lastIntersecting = birds.some(function (otherBird, otherIndex) {
- return index !== otherIndex && bird.intersects(otherBird);
- });
- // 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
+ }
+ bird.lastIntersecting = enemies.some(function (otherEnemy) {
+ return bird !== otherEnemy && bird.intersects(otherEnemy);
+ });
+}
+function handleBirdRespawn(bird, screenWidth, screenHeight) {
+ if (bird.lastY <= screenHeight && bird.y > screenHeight) {
+ bird.y = -bird.height;
+ bird.x = Math.random() * screenWidth;
+ bird.speed = 1 + Math.random() * 0.6;
+ }
+}
+function updateLasers() {
+ if (!game.layers.laser) {
+ return;
+ }
+ game.layers.laser.children.forEach(function (laser) {
+ if (laser && typeof laser.update === 'function') {
+ laser.update();
}
});
-};
-// Note: Tree and stack1 are already added to their respective layers earlier in the code
-// This section is redundant and can be removed
-// Add the grass floor to the game
-var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer
-grassBack.x = 1020;
-grassBack.y = 2735; // Position grassBack at the bottom
-// Note: grassFront and mirror are already added to their respective layers earlier in the code
+}
+// Start the game loop
+requestAnimationFrame(gameTick);
+// Note: Tree, stack1, grassBack, grassFront and mirror are already added to their respective layers earlier in the code
// This section is redundant and can be removed as it causes duplicate rendering
-// Function to handle bgm1 end event
+// SoundManager is already defined earlier in the code
+// This is a helper function that uses the SoundManager
+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;
game.layers.cat.addChild(GameState.cat);
-function initBackgroundMusic() {
- try {
- LK.playMusic('bgm1', {
- loop: false,
- volume: SOUND_VOLUMES.bgm1,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: function onEnd() {
- LK.setTimeout(function () {
- initBackgroundMusic();
- }, Math.random() * 30000 + 20000);
- }
- });
- } catch (error) {
- console.error('Error initializing background music:', error);
- }
-}
-// Initialize background music
-initBackgroundMusic();
-// 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
+var AudioSystem = {
+ _initialized: false,
+ _bgmPlaying: false,
+ init: function init() {
+ var _this4 = this;
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
+ while (1) {
+ switch (_context.prev = _context.next) {
+ case 0:
+ if (!_this4._initialized) {
+ _context.next = 5;
+ break;
+ }
+ return _context.abrupt("return");
+ case 5:
+ _context.prev = 6;
+ _context.next = 10;
+ return Promise.all([_this4._initBackgroundMusic(), _this4._initAmbientSounds()]);
+ case 10:
+ _this4._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 _this5 = 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
+ _this5._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;
}
- 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);
-});
+ if (this._bgmPlaying) {
+ bgm.stop();
+ } else {
+ bgm.play();
+ }
+ this._bgmPlaying = !this._bgmPlaying;
+ }
+};
+// Initialize audio system
+AudioSystem.init();
/**
* Check for interactions between game entities
*/
-function checkInteractions() {
- try {
- // Lasers vs Enemies
- if (game.layers.laser && game.layers.enemies) {
- game.layers.laser.children.forEach(function (laser) {
- if (!laser || !laser.intersects) {
- return;
- }
- game.layers.enemies.children.forEach(function (enemy) {
- if (!enemy || !enemy.intersects) {
- return;
+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 _iterator6 = _createForOfIteratorHelper(lasers),
+ _step6;
+ try {
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
+ var laser = _step6.value;
+ if (!laser || laser._destroyed) {
+ continue;
}
- if (laser.intersects(enemy)) {
- try {
- // Use the handleLaserCollision method if available
- if (typeof enemy.handleLaserCollision === 'function') {
- var destroyed = enemy.handleLaserCollision(laser);
- if (destroyed && typeof enemy.getScoreValue === 'function') {
- score += enemy.getScoreValue();
- if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
- scoreDisplay.updateScore(score);
- }
- }
- } else {
- enemy.destroy();
- laser.destroy();
- if (typeof enemy.getScoreValue === 'function') {
- score += enemy.getScoreValue();
- if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
- scoreDisplay.updateScore(score);
- }
- } else {
- // Default score increment if getScoreValue is not available
- score += 5;
- if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
- scoreDisplay.updateScore(score);
- }
- }
+ var _iterator8 = _createForOfIteratorHelper(enemies),
+ _step8;
+ try {
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
+ var enemy = _step8.value;
+ if (!enemy || enemy._destroyed) {
+ continue;
}
- } catch (error) {
- console.error('Error handling laser collision:', error);
+ if (this.handleLaserCollision(laser, enemy)) {
+ break;
+ }
}
+ } catch (err) {
+ _iterator8.e(err);
+ } finally {
+ _iterator8.f();
}
- });
+ }
+ // Process UFO collisions
+ } catch (err) {
+ _iterator6.e(err);
+ } finally {
+ _iterator6.f();
+ }
+ var ufo = enemies.find(function (child) {
+ return child instanceof UFO && !child._destroyed;
});
- }
- // UFO vs Enemies
- if (game.layers.enemies) {
- var ufo = game.layers.enemies.children.find(function (child) {
- return child instanceof UFO;
- });
- if (ufo && typeof ufo.intersects === 'function') {
- game.layers.enemies.children.forEach(function (enemy) {
- if (!enemy || !enemy.intersects || enemy === ufo) {
- return;
- }
- if (ufo.intersects(enemy)) {
- try {
- enemy.destroy();
- var sound = LK.getSound('electro');
- if (sound && typeof sound.play === 'function') {
- sound.play();
- }
- } catch (error) {
- console.error('Error handling UFO collision:', error);
+ if (ufo) {
+ var _iterator7 = _createForOfIteratorHelper(enemies),
+ _step7;
+ try {
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
+ var enemy = _step7.value;
+ if (!enemy || enemy._destroyed || enemy === ufo) {
+ continue;
}
+ this.handleUFOCollision(ufo, enemy);
}
- });
+ } catch (err) {
+ _iterator7.e(err);
+ } finally {
+ _iterator7.f();
+ }
}
+ } catch (error) {
+ console.error('Error in checkCollisions:', error);
}
- } catch (error) {
- console.error('Error in checkInteractions:', 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) {
- // 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;
+ 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);
}
- // Otherwise apply simple movement
- obj.x += params.speed * params.direction;
- if (params.boundaryCheck) {
- handleScreenBoundaries(obj, params.boundaryWidth);
- }
}
function updateDirection(obj, graphics, rightAsset, leftAsset) {
graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture;
}
@@ -1746,13 +2222,20 @@
}
obj.lastIntersecting = intersecting;
}
function handleDestruction(obj, sounds) {
+ if (!obj) {
+ return;
+ }
if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) {
- sounds.forEach(function (sound) {
- return LK.getSound(sound).stop();
- });
- obj.destroy();
+ 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 () {
@@ -1792,8 +2275,5 @@
direction: this.direction
});
updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
handleDestruction(this, ['jetSound']);
-};
-// Note: Tree and stack1 are already added to their respective layers earlier in the code
-// This section is redundant and can be removed
-// Add the grass floor to the game
\ No newline at end of file
+};
\ 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