Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'getImage')' in or related to this line: 'var asset = LK.init.getImage(assetName);' Line Number: 356
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'storage is not defined' in or related to this line: 'this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y' Line Number: 832 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'self.lastX = self.x;' Line Number: 164
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);' Line Number: 684
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'MovementConfigs')' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);' Line Number: 591
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 361
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'getImage')' in or related to this line: 'var asset = LK.init.getImage(assetName);' Line Number: 356
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 338
User prompt
Please fix the bug: 'LK.getImage is not a function' in or related to this line: 'var asset = LK.getImage(assetName);' Line Number: 333
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'MovementConfigs is not defined' in or related to this line: '_this8.movement = new GameObjectMovement(_this8, _this8.graphics, MovementConfigs[type]);' Line Number: 568
User prompt
Please fix the bug: 'Sprite is not a constructor' in or related to this line: 'var sprite = new Sprite(asset);' Line Number: 338
User prompt
Please fix the bug: 'LK.getImage is not a function' in or related to this line: 'var asset = LK.getImage(assetName);' Line Number: 333
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'expand')' in or related to this line: 'var Laser = Container.expand(function (startX, startY, targetX, targetY) {' Line Number: 48
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'expand')' in or related to this line: 'var Laser = Container.expand(function (startX, startY, targetX, targetY) {' Line Number: 48
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'expand')' in or related to this line: 'var Laser = Container.expand(function (startX, startY, targetX, targetY) {' Line Number: 48
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'expand')' in or related to this line: 'var Laser = Container.expand(function (startX, startY, targetX, targetY) {' Line Number: 48
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'expand')' in or related to this line: 'var GrassFront = GameObject.expand(function () {' Line Number: 49
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Initialize Game ****/ // BaseEntityManager removed - using EntityManager defined at the beginning of the file // Initialize clouds array var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue }); /**** * Game Code ****/ // Base GameObject class to handle common functionality // Unified GameObjectMovement class with improved movement patterns and sound management // Modern ES6 class implementation for game object movement var _GameObjectMovement; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof2(e) || "function" == typeof e)) { return e; } if (void 0 !== e) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); } function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));) { ; } return t; } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) { throw new TypeError("Super expression must either be null or a function"); } t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _typeof2(o) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof2(o); } function _classCallCheck2(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function __defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey2(o.key), o); } } function _createClass2(e, r, t) { return r && __defineProperties(e.prototype, r), t && __defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey2(t) { var i = _toPrimitive2(t, "string"); return "symbol" == _typeof2(i) ? i : i + ""; } function _toPrimitive2(t, r) { if ("object" != _typeof2(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof2(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var SoundManager = /*#__PURE__*/function () { function SoundManager(config) { _classCallCheck2(this, SoundManager); this.config = config || {}; this.soundTimers = {}; this.soundCallbacks = {}; this.soundIntervals = { ambient: { min: 20000, max: 30000 }, background: { min: 20000, max: 30000 }, ufo: { min: 20000, max: 30000 }, jet: { min: 20000, max: 30000 } }; } return _createClass2(SoundManager, [{ key: "initialize", value: function initialize() { var _this = this; var ambientSounds = [{ id: 'songbird1', volume: 0.1, minDelay: 5000, maxDelay: 15000 }, { id: 'cricket1', volume: 0.1, minDelay: 8000, maxDelay: 20000 }, { id: 'breeze1', volume: 0.1, minDelay: 10000, maxDelay: 25000 }, { id: 'frog1', volume: 0.1, minDelay: 12000, maxDelay: 30000 }, { id: 'chitter', volume: 0.1, minDelay: 15000, maxDelay: 35000 }]; ambientSounds.forEach(function (sound) { var initialDelay = Math.random() * (sound.maxDelay - sound.minDelay) + sound.minDelay; LK.setTimeout(function () { _this.playSound(sound.id, { volume: sound.volume, interval: { min: sound.minDelay, max: sound.maxDelay } }); }, initialDelay); }); this.playSound('bgm1', { isMusic: true, volume: 0.1, loop: true, autoRestart: false }); } }, { key: "playSound", value: function playSound(soundId, options) { var _this2 = this; options = Object.assign({ interval: this.soundIntervals.ambient, isMusic: false, volume: 0.1, loop: false, autoRestart: true, onPlay: null, onStop: null }, options); var _playFunction = function playFunction() { if (options.isMusic) { LK.playMusic(soundId, { volume: options.volume }); } else { var sound = LK.getSound(soundId); if (sound) { sound.volume = options.volume; if (options.loop) { sound.loop = true; } sound.play(); if (options.onPlay) { options.onPlay(); } } } if (options.autoRestart) { var nextInterval = Math.random() * (options.interval.max - options.interval.min) + options.interval.min; _this2.soundTimers[soundId] = LK.setTimeout(_playFunction.bind(_this2), nextInterval); } }; this.soundCallbacks[soundId] = options; _playFunction(); return this.soundTimers[soundId]; } }, { key: "stopSound", value: function stopSound(soundId) { if (this.soundTimers[soundId]) { LK.clearTimeout(this.soundTimers[soundId]); delete this.soundTimers[soundId]; } var sound = LK.getSound(soundId); if (sound) { sound.stop(); if (this.soundCallbacks[soundId] && this.soundCallbacks[soundId].onStop) { this.soundCallbacks[soundId].onStop(); } delete this.soundCallbacks[soundId]; } } }, { key: "stopAllSounds", value: function stopAllSounds() { var _this3 = this; Object.keys(this.soundTimers).forEach(function (soundId) { _this3.stopSound(soundId); }); } }]); }(); var Container = /*#__PURE__*/function () { function Container() { _classCallCheck2(this, Container); this.children = []; } return _createClass2(Container, [{ key: "attachAsset", value: function attachAsset(assetName, options) { if (!assetName) { console.error('Asset name is required for attachAsset'); return null; } var asset = LK.init.getImage(assetName); if (!asset) { console.error('Failed to load asset:', assetName); return null; } var sprite = new Sprite(asset); if (options) { Object.assign(sprite, options); } this.addChild(sprite); return sprite; } }, { key: "addChild", value: function addChild(child) { if (child && !this.children.includes(child)) { this.children.push(child); } return child; } }, { key: "destroy", value: function destroy() { if (this.children) { this.children.forEach(function (child) { if (child && child.destroy) { child.destroy(); } }); this.children = []; } } }]); }(); var EntityManager = /*#__PURE__*/function () { function EntityManager() { _classCallCheck2(this, EntityManager); this.entities = []; this.pendingRemovals = []; } return _createClass2(EntityManager, [{ key: "add", value: function add(entity) { if (!entity) { return; } if (!this.entities.includes(entity)) { this.entities.push(entity); if (entity.type && game.spawnManager && game.spawnManager.objectCounts) { game.spawnManager.objectCounts[entity.type] = (game.spawnManager.objectCounts[entity.type] || 0) + 1; } } } }, { key: "remove", value: function remove(entity) { if (!entity) { return; } var index = this.entities.indexOf(entity); if (index > -1) { this.entities.splice(index, 1); // First mark as destroyed to prevent re-entry if (entity.destroy && !entity.destroyed) { entity.destroy(); } // Then update layer tracking if (game.layerManager) { game.layerManager.removeFromTracking(entity); } // Finally update spawn counts if (entity.type && game.spawnManager && game.spawnManager.objectCounts) { var currentCount = game.spawnManager.objectCounts[entity.type] || 0; game.spawnManager.objectCounts[entity.type] = Math.max(0, currentCount - 1); } } } }, { key: "update", value: function update(deltaTime) { var _this4 = this; // Clear pending removals from previous update this.pendingRemovals = []; // Update entities and mark destroyed ones for removal for (var i = this.entities.length - 1; i >= 0; i--) { var entity = this.entities[i]; if (!entity || entity.destroyed) { this.pendingRemovals.push(entity); continue; } if (entity.update) { entity.update(deltaTime); } } // Remove destroyed entities this.pendingRemovals.forEach(function (entity) { return _this4.remove(entity); }); } }, { key: "getAllOfType", value: function getAllOfType(type) { return this.entities.filter(function (entity) { return entity && !entity.destroyed && entity instanceof type; }); } }, { key: "clear", value: function clear() { // First remove all entities from layer tracking if (game.layerManager) { this.entities.forEach(function (entity) { if (entity && !entity.destroyed) { game.layerManager.removeFromTracking(entity); } }); } // Then destroy all entities this.entities.forEach(function (entity) { if (entity && !entity.destroyed && entity.destroy) { entity.destroy(); } }); this.entities = []; this.pendingRemovals = []; // Finally clear spawn timers if they exist if (game.spawnManager) { // Clear all spawn timers Object.keys(game.spawnManager.spawnTimers || {}).forEach(function (type) { if (game.spawnManager.spawnTimers[type]) { LK.clearTimeout(game.spawnManager.spawnTimers[type]); delete game.spawnManager.spawnTimers[type]; } }); game.spawnManager.spawnTimers = {}; // Reset all object counts game.spawnManager.objectCounts = { bird1: 0, bird2: 0, cloud1: 0, cloud2: 0, ufo1: 0, ufo2: 0, jet1: 0 }; } } }]); }(); var GameObject = /*#__PURE__*/function (_Container) { function GameObject(assetName) { var _this5; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck2(this, GameObject); _this5 = _callSuper(this, GameObject); _this5.graphics = _this5.attachAsset(assetName, {}); return _this5; } // Common destroy method _inherits(GameObject, _Container); return _createClass2(GameObject, [{ key: "destroy", value: function destroy() { if (game.layerManager) { game.layerManager.removeFromTracking(this); } if (this.movement && this.movement.cleanup) { this.movement.cleanup(); } _superPropGet(GameObject, "destroy", this, 3)([]); } // Common update method }, { key: "update", value: function update() { if (this.movement) { this.movement.update(); } } }]); }(Container); var Background = /*#__PURE__*/function (_GameObject) { function Background() { _classCallCheck2(this, Background); return _callSuper(this, Background, ['background']); } _inherits(Background, _GameObject); return _createClass2(Background); }(GameObject); var Bird1 = /*#__PURE__*/function (_GameObject2) { function Bird1() { var _this6; _classCallCheck2(this, Bird1); _this6 = _callSuper(this, Bird1, ['bird1']); _this6.type = 'bird1'; _this6.movement = new GameObjectMovement(_this6, _this6.graphics, GameObjectMovement.MovementConfigs.bird1); return _this6; } _inherits(Bird1, _GameObject2); return _createClass2(Bird1); }(GameObject); var Bird2 = /*#__PURE__*/function (_GameObject3) { function Bird2() { var _this7; _classCallCheck2(this, Bird2); _this7 = _callSuper(this, Bird2, ['bird2']); _this7.type = 'bird2'; _this7.movement = new GameObjectMovement(_this7, _this7.graphics, GameObjectMovement.MovementConfigs.bird2); return _this7; } _inherits(Bird2, _GameObject3); return _createClass2(Bird2); }(GameObject); var Cat = /*#__PURE__*/function (_GameObject4) { function Cat() { _classCallCheck2(this, Cat); return _callSuper(this, Cat, ['cat', { anchorX: 0.5, anchorY: 1 }]); } _inherits(Cat, _GameObject4); return _createClass2(Cat); }(GameObject); // Define cloud types at the beginning var CLOUD_TYPES = ['cloud1', 'cloud2']; var GrassLayer = /*#__PURE__*/function (_GameObject5) { function GrassLayer(type) { var _this8; _classCallCheck2(this, GrassLayer); _this8 = _callSuper(this, GrassLayer, [type, { anchorX: 0.5, anchorY: 0.5, alpha: 1 }]); _this8.type = type; _this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]); return _this8; } _inherits(GrassLayer, _GameObject5); return _createClass2(GrassLayer, [{ key: "update", value: function update(deltaTime) { _superPropGet(GrassLayer, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }]); }(GameObject); var GRASS_TYPES = ['grass-front', 'grass-back']; // Initialize grass layers var grassFront = new GrassLayer('grass-front'); grassFront.x = LK.width / 2; grassFront.y = LK.height - 100; var grassBack = new GrassLayer('grass-back'); grassBack.x = LK.width / 2; grassBack.y = LK.height - 150; // Add grass layers to the game game.entityManager.add(grassBack); game.entityManager.add(grassFront); var Cloud = /*#__PURE__*/function (_GameObject6) { function Cloud() { var _this9; _classCallCheck2(this, Cloud); var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)]; _this9 = _callSuper(this, Cloud, [cloudType, { anchorX: 0.5, anchorY: 0.5, alpha: 0.8 }]); _this9.type = cloudType; _this9.movement = new GameObjectMovement(_this9, _this9.graphics, GameObjectMovement.MovementConfigs[_this9.type]); return _this9; } _inherits(Cloud, _GameObject6); return _createClass2(Cloud, [{ key: "destroy", value: function destroy() { if (spawnManager) { spawnManager.objectCounts[this.type === 'cloud1' ? 'cloud1' : 'cloud2']--; } this.movement = null; _superPropGet(Cloud, "destroy", this, 3)([]); } }]); }(GameObject); // Using GrassLayer class for grass-back implementation var GrassFront = /*#__PURE__*/function (_GameObject7) { function GrassFront() { _classCallCheck2(this, GrassFront); return _callSuper(this, GrassFront, ['grass-front', { anchorX: 0.5, anchorY: 1 }]); } _inherits(GrassFront, _GameObject7); return _createClass2(GrassFront, [{ key: "update", value: function update() { // Swaying effect with bounds checking and smoother movement var maxOffset = 2.0; var offset = Math.sin(LK.ticks / 90) * 0.15; this.x += Math.max(-maxOffset, Math.min(maxOffset, offset)); } }]); }(GameObject); var Jet1 = /*#__PURE__*/function (_GameObject8) { function Jet1() { var _this10; _classCallCheck2(this, Jet1); _this10 = _callSuper(this, Jet1, ['jet1']); _this10.type = 'jet1'; _this10.movement = new GameObjectMovement(_this10, _this10.graphics, GameObjectMovement.MovementConfigs.jet1); _this10.soundPlayed = false; return _this10; } _inherits(Jet1, _GameObject8); return _createClass2(Jet1, [{ key: "update", value: function update() { _superPropGet(Jet1, "update", this, 3)([]); // Play jet1 sound when on screen if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('jet1').play(); this.soundPlayed = true; } } }]); }(GameObject); function respawnJet() { if (game.jet === null) { var jet = new Jet1(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2); addEntityToLayer(jet, LAYERS.JET1); game.jet = jet; } game.jetSpawnTimer = null; } var Laser = /*#__PURE__*/function (_Container2) { function Laser(startX, startY, targetX, targetY) { var _this11; _classCallCheck2(this, Laser); _this11 = _callSuper(this, Laser); _this11.laserGraphics = _this11.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 }); var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; _this11.vx = dx / distance * speed; _this11.vy = dy / distance * speed; _this11.x = startX; _this11.y = startY; _this11.lastIntersecting = false; _this11.active = true; LK.getSound('laser1').play(); return _this11; } _inherits(Laser, _Container2); return _createClass2(Laser, [{ key: "destroy", value: function destroy() { if (game.layerManager) { game.layerManager.removeFromTracking(this); } _superPropGet(Laser, "destroy", this, 3)([]); } }, { key: "update", value: function update() { if (!this.active) { return; } // Move first this.x += this.vx; this.y += this.vy; // Check collisions only with relevant layers var collided = false; var targets = game.layerManager.getAllInteractiveLayers(); for (var i = 0; i < targets.length && !collided; i++) { for (var j = 0; j < targets.length && !collided; j++) { var target = targets[j]; if (!this.lastIntersecting && this.intersects(target)) { var soundEffect = game.layerManager.isInLayer(target, 'ufos') ? 'dead3' : 'dead2'; LK.getSound(soundEffect).play(); // Update score based on target type var scoreValue = 0; if (game.layerManager.isInLayer(target, LAYERS.BIRD1)) { scoreValue = 5; } else if (game.layerManager.isInLayer(target, LAYERS.BIRD2)) { scoreValue = 1; } else if (game.layerManager.isInLayer(target, LAYERS.UFO1) || game.layerManager.isInLayer(target, LAYERS.UFO2)) { scoreValue = 25; } score += scoreValue; if (game.mirror) { game.mirror.updateScore(score); } target.destroy(); collided = true; } } } // Update intersection state this.lastIntersecting = collided; // Destroy if out of bounds if (this.x < 0 || this.x > 2048 || this.y < 0 || this.y > 2732) { this.destroy(); } } }]); }(Container); var Light1 = /*#__PURE__*/function (_GameObject9) { function Light1() { var _this12; _classCallCheck2(this, Light1); _this12 = _callSuper(this, Light1, ['light1', { anchorX: 0.5, anchorY: 0.5, alpha: 1.0 }]); _this12.x = 450; _this12.y = 450; _this12.pulse = new Light1Pulse(_this12.graphics); _this12.pulse.startPulsating(); return _this12; } _inherits(Light1, _GameObject9); return _createClass2(Light1, [{ key: "update", value: function update() { // Swaying effect with bounds checking and smoother movement var maxOffset = 1.5; var offset = Math.sin(LK.ticks / 90) * 0.1; this.x += Math.max(-maxOffset, Math.min(maxOffset, offset)); } }]); }(GameObject); var Mirror = /*#__PURE__*/function (_GameObject10) { function Mirror() { var _this13; _classCallCheck2(this, Mirror); _this13 = _callSuper(this, Mirror, ['mirror1']); _this13.scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); _this13.scoreText.y = 260 + 50; _this13.scoreText.x = -155; _this13.scoreText.rotation = (-83 - 3) * (Math.PI / 180); addEntityToLayer(_this13.scoreText, LAYERS.UI); return _this13; } _inherits(Mirror, _GameObject10); return _createClass2(Mirror, [{ key: "updateScore", value: function updateScore(newScore) { this.scoreText.setText(newScore); } }]); }(GameObject); var Reticle = /*#__PURE__*/function (_GameObject11) { function Reticle() { _classCallCheck2(this, Reticle); return _callSuper(this, Reticle, ['reticle1']); } _inherits(Reticle, _GameObject11); return _createClass2(Reticle, [{ key: "update", value: function update() { if (!this.pulse) { this.pulse = new ReticlePulse(this.graphics); this.pulse.startPulsating(); } _superPropGet(Reticle, "update", this, 3)([]); } }]); }(GameObject); var Stack1 = /*#__PURE__*/function (_GameObject12) { function Stack1() { _classCallCheck2(this, Stack1); return _callSuper(this, Stack1, ['stack1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / -12 }]); } _inherits(Stack1, _GameObject12); return _createClass2(Stack1); }(GameObject); var Sun = /*#__PURE__*/function (_GameObject13) { function Sun() { var _this14; _classCallCheck2(this, Sun); _this14 = _callSuper(this, Sun, ['sun']); _this14.pulse = new SunPulse(_this14.graphics); _this14.pulse.startPulsating(); return _this14; } _inherits(Sun, _GameObject13); return _createClass2(Sun); }(GameObject); var Tree = /*#__PURE__*/function (_GameObject14) { function Tree() { var _this15; _classCallCheck2(this, Tree); _this15 = _callSuper(this, Tree, ['tree1', { anchorX: 0.5, anchorY: 1, antialias: true, stroke: 0x000000, strokeThickness: 15 }]); _this15.type = 'tree1'; _this15.movement = new GameObjectMovement(_this15, _this15.graphics, GameObjectMovement.MovementConfigs.tree1); return _this15; } _inherits(Tree, _GameObject14); return _createClass2(Tree, [{ key: "update", value: function update(deltaTime) { _superPropGet(Tree, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }, { key: "destroy", value: function destroy() { this.movement = null; _superPropGet(Tree, "destroy", this, 3)([]); } }]); }(GameObject); var Tree2 = /*#__PURE__*/function (_GameObject15) { function Tree2() { var _this16; _classCallCheck2(this, Tree2); _this16 = _callSuper(this, Tree2, ['tree2', { anchorX: 0.5, anchorY: 1 }]); _this16.type = 'tree2'; _this16.movement = new GameObjectMovement(_this16, _this16.graphics, GameObjectMovement.MovementConfigs.tree2); return _this16; } _inherits(Tree2, _GameObject15); return _createClass2(Tree2, [{ key: "update", value: function update(deltaTime) { _superPropGet(Tree2, "update", this, 3)([deltaTime]); if (this.movement) { this.movement.update(deltaTime); } } }, { key: "destroy", value: function destroy() { this.movement = null; _superPropGet(Tree2, "destroy", this, 3)([]); } }]); }(GameObject); var UFO1 = /*#__PURE__*/function (_GameObject16) { function UFO1() { var _this17; _classCallCheck2(this, UFO1); _this17 = _callSuper(this, UFO1, ['ufo1']); _this17.type = 'ufo1'; _this17.movement = new GameObjectMovement(_this17, _this17.graphics, GameObjectMovement.MovementConfigs.ufo1); _this17.soundPlayed = false; return _this17; } _inherits(UFO1, _GameObject16); return _createClass2(UFO1, [{ key: "update", value: function update() { _superPropGet(UFO1, "update", this, 3)([]); if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('ufo1').play(); this.soundPlayed = true; } } }]); }(GameObject); var UFO2 = /*#__PURE__*/function (_GameObject17) { function UFO2() { var _this18; _classCallCheck2(this, UFO2); _this18 = _callSuper(this, UFO2, ['ufo2']); _this18.type = 'ufo2'; _this18.movement = new GameObjectMovement(_this18, _this18.graphics, GameObjectMovement.MovementConfigs.ufo2); _this18.soundPlayed = false; return _this18; } _inherits(UFO2, _GameObject17); return _createClass2(UFO2, [{ key: "update", value: function update() { _superPropGet(UFO2, "update", this, 3)([]); if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('ufo1').play(); this.soundPlayed = true; } } }]); }(GameObject); var GameObjectMovement = /*#__PURE__*/function () { function GameObjectMovement(object, graphics) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; _classCallCheck2(this, GameObjectMovement); this.object = object; this.graphics = graphics; this.options = _objectSpread(_objectSpread({}, GameObjectMovement.defaultOptions), options); this.speed = this.options.speed + Math.random() * this.options.speedRange; this.direction = Math.random() < 0.5 ? 1 : -1; this.lastX = this.object.x; this.lastY = this.object.y; this.soundPlayed = false; this.soundTimer = null; this.movementOffset = Math.random() * Math.PI * 2; // Random starting phase for smoother movement } return _createClass2(GameObjectMovement, [{ key: "update", value: function update() { if (!this.object || this.object.destroyed) { this.cleanup(); return; } var _this$object = this.object, currentX = _this$object.x, currentY = _this$object.y, width = _this$object.width, height = _this$object.height; var halfWidth = width / 2; var _this$options = this.options, isVertical = _this$options.isVertical, arcFrequency = _this$options.arcFrequency, arcAmplitude = _this$options.arcAmplitude, screenWidth = _this$options.screenWidth, screenHeight = _this$options.screenHeight; if (isVertical) { this.object.y += this.speed; // Enhanced sinusoidal movement with optimized calculations var phaseOffset = currentY / arcFrequency + this.movementOffset; this.object.x += Math.sin(phaseOffset) * arcAmplitude; if (currentY > screenHeight + height) { this.cleanup(); return; } } else { // Optimized horizontal movement with wave pattern this.object.x += this.speed * this.direction; if (arcAmplitude > 0) { var phaseOffset = currentX / arcFrequency + this.movementOffset; this.object.y += Math.sin(phaseOffset) * (arcAmplitude * 0.5); } var isOutOfBounds = currentX <= screenWidth + halfWidth && this.object.x > screenWidth + halfWidth || currentX >= -halfWidth && this.object.x < -halfWidth; if (isOutOfBounds) { this.cleanup(); return; } } if (this.options.canFlip) { flipImageVerticallyBasedOnDirection(this.graphics, currentX, this.object.x); } if (this.options.moveSound && !this.soundPlayed && this.object.x > 0 && this.object.x < this.options.screenWidth) { this.playMovementSound(); } this.lastX = this.object.x; this.lastY = this.object.y; } }, { key: "cleanup", value: function cleanup() { if (!this.object || this.object.destroyed) { return; } var moveSound = this.options.moveSound; var soundManager = game.soundManager, spawnManager = game.spawnManager; // Stop movement sound if active if (moveSound && soundManager) { soundManager.stopSound(moveSound); } // Destroy object and schedule respawn this.object.destroy(); if (spawnManager !== null && spawnManager !== void 0 && spawnManager.scheduleRespawn) { spawnManager.scheduleRespawn(this.object.type, this.object.constructor); } // Clear references this.object = null; this.soundTimer = null; this.soundPlayed = false; } }, { key: "playMovementSound", value: function playMovementSound() { var _this19 = this; var moveSound = this.options.moveSound; if (!moveSound || !game.soundManager) { return; } game.soundManager.playSound(moveSound, { volume: 0.1, interval: { min: 20000, max: 30000 }, onPlay: function onPlay() { _this19.soundPlayed = true; }, onStop: function onStop() { _this19.soundPlayed = false; _this19.soundTimer = null; } }); } }]); }(); _GameObjectMovement = GameObjectMovement; _defineProperty(GameObjectMovement, "MovementConfigs", { base: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: false, canFlip: true, moveSound: null, respawnTime: { min: 20000, max: 30000 }, screenWidth: 2048, screenHeight: 2732 }, bird1: { speed: 2, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, bird2: { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, moveSound: 'wings1' }, ufo1: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, ufo2: { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, moveSound: 'ufo1' }, jet1: { speed: 10, speedRange: 0, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: true, moveSound: 'jet1' }, cloud1: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, cloud2: { speed: 0.25, speedRange: 0.55, arcAmplitude: 0, arcFrequency: 0, isVertical: false, canFlip: false }, 'grass-front': { speed: 0, speedRange: 0, arcAmplitude: 1.2, arcFrequency: 120, isVertical: false, moveSound: null, canFlip: false }, 'grass-back': { speed: 0, speedRange: 0, arcAmplitude: 0.8, arcFrequency: 150, isVertical: false, moveSound: null, canFlip: false } }); _defineProperty(GameObjectMovement, "defaultOptions", _GameObjectMovement.MovementConfigs.base); ; // Cloud class already defined above function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /***** * Layer Constants ******/ var LAYERS = { BACKGROUND: 0, SUN: 1, LIGHT1: 2, UFO2: 3, CLOUD1: 4, JET1: 5, CLOUD2: 6, UFO1: 7, BIRD1: 8, GRASS_BACK: 9, TREE: 10, STACK: 11, BIRD2: 12, MIRROR: 13, GRASS_FRONT: 14, CAT: 15, LASER: 16, RETICLE: 17 }; // Initialize LayerManager var layerManager = new LayerManager(); game.layerManager = layerManager; // Cloud management is now handled by SpawnManager // Initialize birds array for tracking var birds = []; var score = 0; var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; mirror.y = 2732 - 185 - 80 - 390 + 30 + 50; game.layerManager.addToLayer(mirror, LAYERS.MIRROR); game.mirror = mirror; var scoreDisplay = mirror; var soundManager = new SoundManager(); soundManager.initialize(); // Initialize spawn manager // Ensure all entities use LayerManager consistently function addEntityToLayer(entity, layer) { if (!entity || !layer) { console.error('Invalid entity or layer provided to addEntityToLayer'); return entity; } game.layerManager.addToLayer(entity, layer); if (!game.children.includes(entity)) { game.addChild(entity); } return entity; } var _SpawnManager = function SpawnManager() { this.spawnTimers = {}; this.spawnRules = { bird1: { max: 1, layer: LAYERS.BIRD1, movement: Bird1Movement, scoreValue: 5 }, bird2: { min: 3, max: 3, layer: LAYERS.BIRD2, movement: Bird2Movement, scoreValue: 1 }, cloud1: { min: 1, max: 3, layer: LAYERS.CLOUD1, movement: CloudMovement }, cloud2: { min: 1, max: 3, layer: LAYERS.CLOUD2, movement: CloudMovement }, // Ensure 3-5 total clouds ufo1: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.UFO1, movement: UFOMovement, sound: 'ufo1', scoreValue: 25 }, ufo2: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.UFO2, movement: UFOMovement, sound: 'ufo1', scoreValue: 25 }, jet1: { max: 1, respawnTime: { min: 20000, max: 30000 }, layer: LAYERS.JET1, movement: GameObjectMovement, sound: 'jet1' } }; // Initialize sound manager with ambient sounds configuration this.soundManager = new SoundManager({ ambient: { breeze1: { volume: 0.1, interval: { min: 15000, max: 25000 } }, cricket1: { volume: 0.1, interval: { min: 10000, max: 20000 } }, frog1: { volume: 0.1, interval: { min: 20000, max: 30000 } }, songbird1: { volume: 0.1, interval: { min: 15000, max: 25000 } } } }); this.scoreManager = new ScoreManager(); this.exclusiveGroups = [['ufo1', 'ufo2']]; // Correct layer order as per requirements this.layerOrder = game.layerManager.getLayerOrder(); this.spawnObject = function (type, Constructor, options) { var _this20 = this; var rule = this.spawnRules[type]; if (!rule) { return; } var count = this.objectCounts[type] || 0; var maxCount = rule.max || 1; // Early exit conditions if (count >= maxCount) { return; } // Check exclusive groups (UFO1 and UFO2) if (this.exclusiveGroups.some(function (group) { if (group.includes(type)) { return group.some(function (groupType) { return _this20.objectCounts[groupType] > 0; }); } return false; })) { return; } // Handle minimum count requirements if (rule.min && count < rule.min) { while (count < rule.min) { this.createObject(type, Constructor, rule); count++; } return; } // Ensure proper cloud count (3-5 total) if (type === 'cloud1' || type === 'cloud2') { var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds >= 5) { return; } if (totalClouds < 3) { while (totalClouds < 3) { this.createObject(type, Constructor, rule); totalClouds++; } return; } } // Ensure proper bird counts if (type === 'bird1' && count >= 1) { return; } // Max 1 bird1 if (type === 'bird2' && count >= 3) { return; } // Max 3 bird2 // Create object with respawn timer for specific types this.createObject(type, Constructor, rule); if (rule.respawnTime) { var respawnDelay = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min; this.spawnTimers[type] = LK.setTimeout(function () { delete _this20.spawnTimers[type]; _this20.spawnObject(type, Constructor, options); }, respawnDelay); } }; this.createObject = function (type, Constructor, rule) { if (!Constructor || !rule) { return null; } var obj = new Constructor(); obj.type = type; // Initialize position based on object type var screenWidth = 2048; var screenHeight = 2732; var isVerticalMovement = type.startsWith('bird'); obj.x = isVerticalMovement ? Math.random() * screenWidth : Math.random() < 0.5 ? screenWidth + obj.width / 2 : -obj.width / 2; obj.y = isVerticalMovement ? -obj.height : Math.random() * (screenHeight / 2); // Add to appropriate layer using addEntityToLayer addEntityToLayer(obj, rule.layer); // Initialize movement with appropriate options if (rule.movement) { // Get movement configuration based on object type var params = GameObjectMovement.MovementConfigs[type] || GameObjectMovement.MovementConfigs.base; // Create movement options with the selected parameters var movementOptions = _objectSpread(_objectSpread({}, params), {}, { moveSound: rule.sound || params.moveSound, respawnTime: rule.respawnTime }); obj.movement = new rule.movement(obj, obj.children[0], movementOptions); } if (rule.respawnTime) { this.scheduleRespawn(type, Constructor); } return obj; }; this.scheduleRespawn = function (type, Constructor) { if (!type || !Constructor || !this.spawnRules) { return; } var rule = this.spawnRules[type]; if (!rule) { return; } // Ensure respawn timers for ufo1, ufo2, and jet1 are set to 20-30 seconds var respawnTime; if (type === 'ufo1' || type === 'ufo2' || type === 'jet1') { respawnTime = Math.random() * 10000 + 20000; // 20-30 seconds } else if (rule.respawnTime) { respawnTime = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min; } else { respawnTime = Math.random() * 10000 + 5000; // Default 5-15 seconds } // Clear existing timer if present if (this.spawnTimers[type]) { LK.clearTimeout(this.spawnTimers[type]); this.spawnTimers[type] = null; } // Initialize object counts if not present if (!this.objectCounts[type]) { this.objectCounts[type] = 0; } this.spawnTimers[type] = LK.setTimeout(function () { // Cleanup timer reference delete this.spawnTimers[type]; // Update object count if (this.objectCounts[type] > 0) { this.objectCounts[type]--; } var shouldSpawn = true; // Check exclusive groups (e.g., only one UFO type at a time) if (this.exclusiveGroups) { for (var i = 0; i < this.exclusiveGroups.length; i++) { var group = this.exclusiveGroups[i]; if (group && group.includes(type)) { var groupTotal = 0; for (var j = 0; j < group.length; j++) { groupTotal += this.objectCounts[group[j]] || 0; } if (groupTotal > 0) { shouldSpawn = false; break; } } } } if (shouldSpawn) { this.spawnObject(type, Constructor); } else { // Reschedule spawn attempt if blocked by exclusive group this.scheduleRespawn(type, Constructor); } }.bind(this), respawnTime); // Start the game var spawnManager = new _SpawnManager(); spawnManager.initialize(); this.initialize = function () { // Initialize birds - exactly 1 Bird1 and 3 Bird2s this.spawnObject('bird1', Bird1); for (var i = 0; i < this.spawnRules.bird2.min; i++) { this.spawnObject('bird2', Bird2); } // Initialize clouds - ensure 3-5 total clouds var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3; var cloud1ToSpawn = Math.min(totalCloudsToSpawn, this.spawnRules.cloud1.max); var cloud2ToSpawn = totalCloudsToSpawn - cloud1ToSpawn; for (var i = 0; i < cloud1ToSpawn; i++) { this.spawnObject('cloud1', Cloud); } for (var i = 0; i < cloud2ToSpawn; i++) { this.spawnObject('cloud2', Cloud); } // Initialize UFOs and Jet with respawn timers // Randomly choose between UFO1 and UFO2 if (Math.random() < 0.5) { this.spawnObject('ufo1', UFO1); } else { this.spawnObject('ufo2', UFO2); } this.spawnObject('jet1', Jet1); // Set up periodic check for object counts and layer ordering LK.setInterval(function () { // Update layer ordering game.layerManager.getLayerOrder().forEach(function (layerId, index) { var objects = game.layerManager.getObjectsInLayer(layerId); objects.forEach(function (obj) { game.layerManager.setLayerIndex(obj, index); }); }.bind(this)); // Maintain bird counts if (game.layerManager.getLayerEntityCount(LAYERS.BIRD1) < 1) { this.spawnObject('bird1', Bird1); } while (game.layerManager.getLayerEntityCount(LAYERS.BIRD2) < 3) { this.spawnObject('bird2', Bird2); } // Maintain cloud counts - ensure 3-5 total clouds var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds < 3) { var cloudsNeeded = 3 - totalClouds; for (var i = 0; i < cloudsNeeded; i++) { if (Math.random() < 0.5 && game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) < this.spawnRules.cloud1.max) { this.spawnObject('cloud1', Cloud); } else if (game.layerManager.getLayerEntityCount(LAYERS.CLOUD2) < this.spawnRules.cloud2.max) { this.spawnObject('cloud2', Cloud); } } } else if (totalClouds > 5) { // If there are more than 5 clouds, don't spawn any more until some are removed // This is handled automatically when clouds move off-screen } // Ensure one UFO (either UFO1 or UFO2) is on screen if (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) { if (Math.random() < 0.5) { this.spawnObject('ufo1', UFO1); } else { this.spawnObject('ufo2', UFO2); } } // Ensure one jet is on screen if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) { this.spawnObject('jet1', Jet1); } }.bind(this), 1000); }.bind(this); }; var spawnManager = new _SpawnManager(); // Initialize the spawn manager _SpawnManager.prototype.initialize = function () { // Initialize sound and score managers this.soundManager.initialize(); // Set up initial spawns with consistent behavior this.spawnObject('bird1', Bird1); for (var i = 0; i < this.spawnRules.bird2.min; i++) { this.spawnObject('bird2', Bird2); } }; // Set up cloud spawning - 3-5 total clouds var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3; var cloud1ToSpawn = Math.min(totalCloudsToSpawn, this.spawnRules.cloud1.max); var cloud2ToSpawn = totalCloudsToSpawn - cloud1ToSpawn; for (var i = 0; i < cloud1ToSpawn; i++) { this.spawnObject('cloud1', Cloud); } for (var i = 0; i < cloud2ToSpawn; i++) { this.spawnObject('cloud2', Cloud); } // Schedule initial UFO and Jet spawns if (Math.random() < 0.5) { this.spawnObject('ufo1', UFO1); } else { this.spawnObject('ufo2', UFO2); } this.spawnObject('jet1', Jet1); // Set up periodic checks for maintaining entity counts LK.setInterval(function () { // Maintain bird counts if (this.objectCounts.bird1 < 1) { this.spawnObject('bird1', Bird1); } while (this.objectCounts.bird2 < 3) { this.spawnObject('bird2', Bird2); } // Maintain cloud counts (3-5 total) var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2); if (totalClouds < 3) { var type = Math.random() < 0.5 ? 'cloud1' : 'cloud2'; this.spawnObject(type, Cloud); } // Ensure one UFO (either UFO1 or UFO2) is scheduled if (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) { var ufoType = Math.random() < 0.5 ? 'ufo1' : 'ufo2'; this.scheduleRespawn(ufoType, ufoType === 'ufo1' ? UFO1 : UFO2); } // Ensure one Jet1 is scheduled if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) { this.scheduleRespawn('jet1', Jet1); } }.bind(this), 1000); }; spawnManager.initialize(); // Main game update function game.update = function () { // Update all game objects game.children.forEach(function (entity) { if (entity.update) { entity.update(); } // Handle off-screen objects if (game.layerManager.isInLayer(entity, LAYERS.BIRD1) || game.layerManager.isInLayer(entity, LAYERS.BIRD2)) { if (entity.y > 2732) { entity.y = -entity.height; entity.x = Math.random() * 2048; } } }); // Update score display if (game.mirror && game.mirror.updateScore) { game.mirror.updateScore(game.score || 0); } // Ensure correct number of birds using SpawnManager spawnManager.spawnObject('bird1', Bird1); spawnManager.spawnObject('bird2', Bird2); // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); }; // Removed redundant checkAndRespawnBirds function as it's handled by SpawnManager // Update bird positions and states function updateGameBirds() { maintainBirdCount(Bird1, 1, LAYERS.BIRD1); maintainBirdCount(Bird2, 3, LAYERS.BIRD2); } function maintainBirdCount(BirdType, targetCount, layerIndex) { var birdCount = game.layerManager.getLayerGroup('birds').length; if (birdCount < targetCount) { for (var i = 0; i < targetCount - birdCount; i++) { var newBird = new BirdType(); newBird.x = Math.random() * 2048; newBird.y = Math.random() * (2732 / 2); newBird.speed = 1 + Math.random() * 0.6; game.layerManager.addToLayer(newBird, layerIndex); birds.push(newBird); } } else if (birdCount > targetCount) { var extraBirds = birds.filter(function (b) { return game.layerManager.isInLayer(b, 'birds'); }).slice(targetCount); extraBirds.forEach(function (b) { b.destroy(); birds.splice(birds.indexOf(b), 1); }); } } // Update existing birds birds.forEach(function (bird) { bird.update(); if (bird.lastY <= 2732 && bird.y > 2732) { bird.y = -bird.height; bird.x = Math.random() * 2048; bird.speed = 1 + Math.random() * 0.6; } }); // Maintain bird counts maintainBirdCount(Bird1, 1, LAYERS.BIRD1); maintainBirdCount(Bird2, 3, LAYERS.BIRD2); // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); // Add a tree to the game var tree = addEntityToLayer(new Tree(), LAYERS.TREE); tree.x = 2048 / 2 + 600; // Move the tree 500px to the right tree.y = 2500; // Position the tree on the grass // Add tree to the proper layer if (game.children.includes(tree)) { game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer } var score = 0; // Add stack1 image to the game var stack1 = addEntityToLayer(new Stack1(), LAYERS.STACK); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Add stack1 to the proper layer if (game.children.includes(stack1)) { game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer } var scoreDisplay = new Mirror(); scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px addEntityToLayer(scoreDisplay, LAYERS.UI); var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Add mirror to the proper layer if (game.children.includes(mirror)) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer } // Function to handle bgm1 end event function onBgm1End() { // Set a timer to replay bgm1 after 50-80 seconds var bgmTimer = LK.setTimeout(function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }, Math.random() * 30000 + 50000); } ; // Add the cat to the game var cat = addEntityToLayer(new Cat(), LAYERS.CAT); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Add cat to the proper layer if (game.children.includes(cat)) { game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer } // Play bgm1 once on load and set a timer to replay it every 20-30 seconds LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 0.1, duration: 4000 }, onEnd: onEnd }); }, Math.random() * 10000 + 20000); } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Sound volumes configuration // Initialize random timers for each sound to play between 20-30 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); } sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000); }, Math.random() * 10000 + 20000); }); // Using UFO sound ID as placeholder // Using existing CLOUD_TYPES definition var Pulse = function Pulse(graphics, options) { this.graphics = graphics; this.options = Object.assign({ minScale: 1.0, maxScale: 1.2, expandDuration: 1000, contractDuration: 1000, easing: tween.easeInOut }, options); this.startPulsating = function () { function pulsate() { tween(this.graphics, { scaleX: this.options.maxScale, scaleY: this.options.maxScale }, { duration: this.options.expandDuration, easing: this.options.easing, onFinish: function () { tween(this.graphics, { scaleX: this.options.minScale, scaleY: this.options.minScale }, { duration: this.options.contractDuration, easing: this.options.easing, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; var SunPulse = function SunPulse(sunGraphics) { return new Pulse(sunGraphics, { maxScale: 1.1 }); }; // Light1Pulse class to handle the pulsating effect for Light1 var Light1Pulse = function Light1Pulse(graphics) { ; this.graphics = graphics; this.pulseTimer = null; this.startPulsating = function () { var self = this; var brightness = 1.0; var direction = 1; this.pulseTimer = LK.setInterval(function () { brightness += direction * 0.05; if (brightness >= 2.0) { direction = -1; brightness = 2.0; } else if (brightness <= 1.0) { direction = 1; brightness = 1.0; } self.graphics.brightness = brightness; }, 50); }; this.stopPulsating = function () { if (this.pulseTimer) { LK.clearInterval(this.pulseTimer); } }; }; var bird2; // Define bird2 variable in the global scope // UFOMovement class to handle UFO movement var UFOMovement = function UFOMovement(ufo, ufoGraphics) { return new GameObjectMovement(ufo, ufoGraphics, { speed: 3.2, speedRange: 0.8, arcAmplitude: 4.5, arcFrequency: 80, isVertical: false, canFlip: true, moveSound: 'ufo1' }); }; ; var UFOSound = function UFOSound() { ; this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music var BackgroundMusic = function BackgroundMusic() { ; this.play = function () { LK.playMusic('bgm1', { loop: true, fade: { start: 0, end: 1, duration: 4000 }, onEnd: onBgm1End }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { ; this.play = function () { LK.getSound('laser1').play(); }; }; var Bird1Movement = function Bird1Movement(bird, birdGraphics) { return new GameObjectMovement(bird, birdGraphics, { speed: 2.5, speedRange: 1.2, arcAmplitude: 6.5, arcFrequency: 100, isVertical: true, canFlip: true, moveSound: 'wings1' }); }; // Bird2 movement is handled by MovementConfigs.bird2 var Bird2Effects = function Bird2Effects(bird) { ; this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; var ReticlePulse = function ReticlePulse(reticleGraphics) { return new Pulse(reticleGraphics, { minScale: 0.9, maxScale: 1.3, expandDuration: 800, contractDuration: 1200 }); }; // Bird1Effects class to handle effects and animations for Bird1 var Bird1Effects = function Bird1Effects(bird) { ; this.bird = bird; this.applyEffects = function () { // Add any specific effects or animations for Bird1 here }; }; // Bird2 spawning is now handled by SpawnManager // Add background to the BACKGROUND layer var background = new Background(); background.x = 2048 / 2; background.y = 2732 / 2 - 140; game.layerManager.addToLayer(background, LAYERS.BACKGROUND); // Initialize bird spawning spawnBird2(); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { ; var self = this; var currentScore = 0; var highScore = storage.highScore || 0; self.scoreValues = { bird1: 100, bird2: 50, ufo1: 250, ufo2: 250 }; self.addScore = function (objectType) { var points = self.scoreValues[objectType] || 0; if (points > 0) { currentScore += points; if (currentScore > highScore) { highScore = currentScore; storage.highScore = highScore; } // Update score display if (scoreDisplay && scoreDisplay.updateScore) { scoreDisplay.updateScore(currentScore); } if (mirror && mirror.updateScore) { mirror.updateScore(currentScore); } } return currentScore; }; self.resetScore = function () { currentScore = 0; if (scoreDisplay && scoreDisplay.updateScore) { scoreDisplay.updateScore(currentScore); } if (mirror && mirror.updateScore) { mirror.updateScore(currentScore); } return currentScore; }; self.getScore = function () { return currentScore; }; self.getHighScore = function () { return highScore; }; }; var birds = []; game.down = function (x, y, obj) { if (obj && obj.event) { x = obj.event.x; y = obj.event.y; } if (!game.reticle) { game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE); } game.reticle.x = x; game.reticle.y = y; if (typeof x === 'undefined' || typeof y === 'undefined') { console.error('Invalid coordinates for laser'); return; } var laser = new Laser(cat.x - 140, cat.y - 440, x, y); addEntityToLayer(laser, LAYERS.LASER); }; var VOLUME_BGM1 = 0.02; var VOLUME_BREEZE1 = 0.02; var VOLUME_CRICKET1 = 0.02; var VOLUME_FROG1 = 0.02; var VOLUME_SONGBIRD1 = 0.02; var VOLUME_UFO1 = 0.02; var VOLUME_WINGS1 = 0.02; game.move = function (x, y, obj) { if (!game.reticle) { game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE); } if (obj.event) { x = obj.event.x; y = obj.event.y; } game.reticle.x = x; game.reticle.y = y; }; // Add a sun to the game in the top left corner var sun = new Sun(); sun.x = 480; sun.y = 680; game.layerManager.addToLayer(sun, LAYERS.SUN); var light1 = new Light1(); light1.x = 510; light1.y = 1500; game.layerManager.addToLayer(light1, LAYERS.LIGHT1); light1.visible = true; // Function to add a UFO to the game // Using existing CLOUD_TYPES definition // initializeClouds already called earlier var bird1; // Define bird1 variable in the global scope var bird; // Define bird variable in the global scope var ufo; // Define the ufo variable in the global scope var laser; // Define the laser variable in the global scope var ufoTimer = LK.setTimeout(function () { addUFO(); // Reset the timer for the UFO to reappear between 10-20 seconds ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000); }, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds // Helper functions for game update function updateEntityPositions() { game.children.forEach(function (entity) { if (entity.update) { entity.update(); } // Handle off-screen objects if (game.layerManager.isInLayer(entity, 'birds') && entity.y > 2732) { entity.y = -entity.height; entity.x = Math.random() * 2048; } }); } function handleCollisions() { var projectiles = game.layerManager.getLayerEntities('projectiles'); projectiles.forEach(function (laser) { laser.update(); checkLaserCollisions(laser); }); } function checkLaserCollisions(laser) { var enemies = game.layerManager.getLayerEntities('enemies'); enemies.forEach(function (target) { if (!laser.lastIntersecting && AABBIntersect(laser, target)) { handleCollisionPoints(laser, target); } }); laser.lastIntersecting = enemies.some(function (target) { return laser.intersects(target); }); } function handleCollisionPoints(laser, target) { var points = 0; var soundEffect = ''; if (target instanceof Bird1) { points = 100; soundEffect = 'dead1'; spawnManager.objectCounts.bird1--; } else if (target instanceof Bird2) { points = 50; soundEffect = 'dead2'; spawnManager.objectCounts.bird2--; } else if (target instanceof UFO1 || target instanceof UFO2) { points = 250; soundEffect = 'dead3'; spawnManager.objectCounts[target instanceof UFO1 ? 'ufo1' : 'ufo2']--; } if (points > 0) { game.score = (game.score || 0) + points; if (scoreDisplay && scoreDisplay.updateScore) { scoreDisplay.updateScore(game.score); } if (game.mirror && game.mirror.updateScore) { game.mirror.updateScore(game.score); } LK.getSound(soundEffect).play(); target.destroy(); laser.destroy(); } game.update = function () { updateEntityPositions(); handleCollisions(); if (ufo) { ufo.customUpdate(); // Check if UFO is out of bounds if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) { ufo.destroy(); ufo = null; ufoTimer = LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 20000 + 30000); } ufo.lastX = ufo.x; } }; // Update existing birds game.children.forEach(function (bird) { if (game.layerManager.isInLayer(bird, 'birds')) { if (bird.y > 2732) { bird.y = -bird.height; bird.x = Math.random() * 2048; } } }); } // Update UFOs and play sounds game.children.forEach(function (entity) { if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) { LK.getSound('ufo1').play(); entity.soundPlayed = true; } }); // Update each laser and check collisions game.children.forEach(function (laser) { if (laser instanceof Laser) { laser.update(); checkLaserCollisions(laser); } }); // Add a tree to the game var tree = addEntityToLayer(new Tree(), LAYERS.TREE); tree.x = 2048 / 2 + 600; // Move the tree 500px to the right tree.y = 2500; // Position the tree on the grass // Add tree to the proper layer if (game.children.includes(tree)) { game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer } var score = 0; // Add stack1 image to the game var stack1 = addEntityToLayer(new Stack1(), LAYERS.STACK); stack1.x = 1700; // Move 700px to the right stack1.y = 2250; // Move down by 800px // Add stack1 to the proper layer if (game.children.includes(stack1)) { game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer } var scoreDisplay = new Mirror(); scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px addEntityToLayer(scoreDisplay, LAYERS.UI); var mirror = new Mirror(); mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Add mirror to the proper layer using the layer manager // Add mirror to the proper layer if (game.children.includes(mirror)) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer } // Function to handle bgm1 end event // Add the cat to the game var cat = addEntityToLayer(new Cat(), LAYERS.CAT); cat.x = 230; // Move the cat 20px to the left cat.y = 2732; // Position the cat at the bottom of the screen // Add cat to the proper layer if (game.children.includes(cat)) { game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer } // Play bgm1 once on load and set a timer to replay it every 20-50 seconds LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.02, // Set to the lowest volume duration: 4000 }, onEnd: function onEnd() { // Set a timer to replay bgm1 every 20-50 seconds LK.setTimeout(function () { LK.playMusic('bgm1', { loop: false, // Play once fade: { start: 0, end: 0.5, // Set to the lowest volume duration: 4000 }, onEnd: onEnd // Set the onEnd function to replay bgm1 }); }, Math.random() * 30000 + 20000); // Random time between 20-50 seconds } }); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Initialize random timers for each sound to play between 20-30 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); } sound.play(); currentAmbientSound = sound; LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000); }, Math.random() * 10000 + 20000); }); // Initialize EntityManager var entityManager = new EntityManager(); // Initial entity spawning will be handled by the managers if (typeof x !== 'undefined' && typeof y !== 'undefined') { var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point entityManager.add(laser); } else { console.error('Invalid coordinates for laser creation'); } // Ensure timers for ambient sounds and bgm1 are set to repeat every 20-30 seconds function initializeAmbientSounds() { var _playAmbientSounds = function playAmbientSounds() { LK.getSound('songbird1').play(); LK.getSound('cricket1').play(); LK.setTimeout(_playAmbientSounds, Math.random() * 10000 + 20000); // 20-30 seconds }; _playAmbientSounds(); // Set initial interval LK.setInterval(_playAmbientSounds, 25000); // Average of 20-30 seconds } function initializeBGM() { var playBGM = function playBGM() { LK.playMusic('bgm1'); }; playBGM(); // Set regular interval for background music LK.setInterval(playBGM, 25000); // Average of 20-30 seconds } // Fix scoring var scoreManager = new ScoreManager(); var score = 0; game.down = function (x, y, obj) { if (obj && obj.event) { x = obj.event.x; y = obj.event.y; } if (!game.reticle) { game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE); } game.reticle.x = x; game.reticle.y = y; if (typeof x === 'undefined' || typeof y === 'undefined') { console.error('Invalid coordinates for laser'); return; } var laser = new Laser(cat.x - 140, cat.y - 440, x, y); addEntityToLayer(laser, LAYERS.LASER); }; // Adjust layer display order // Ensure light1 layer is displayed after background if (light1) { game.layerManager.addToLayer(light1, LAYERS.LIGHT1); } // Ensure jet layer is displayed before cloud2 layer if (jet) { game.layerManager.addToLayer(jet, LAYERS.JET1); } // Ensure mirror layer is displayed behind grass-front if (mirror) { game.layerManager.addToLayer(mirror, LAYERS.MIRROR); } // Ensure jet1 and ufo1 sounds play when on screen Jet1.prototype.update = function () { // Fix: Use 'this' instead of 'self' since this is a prototype method var jetGraphics = this.children[0]; flipImageVerticallyBasedOnDirection(jetGraphics, this.lastX, this.x); this.x += this.speed * this.direction; // Play jet sound when on screen if (!this.soundPlayed && this.x > 0 && this.x < 2048) { LK.getSound('jet1').play(); this.soundPlayed = true; } // Stop sound and destroy when off screen if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { LK.getSound('jet1').stop(); this.destroy(); game.jet = null; // Use spawn manager to handle respawn if (game.spawnManager) { game.spawnManager.scheduleRespawn('jet1', Jet1); } } this.lastX = this.x; }; UFOMovement.prototype.update = function () { var currentX = this.x; var screenWidth = 2048; var halfWidth = this.width / 2; var tickCos = Math.cos(LK.ticks / 60); var tickSin = Math.sin(LK.ticks / 120); this.x += this.speed * tickCos; this.y = 100 + tickSin * 250; if (this.x > 0 && this.x < screenWidth && !this.soundPlayed) { LK.getSound('ufo1').play(); this.soundPlayed = true; } if (this.x < 0 || this.x > screenWidth) { this.soundPlayed = false; } if (currentX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || currentX >= -halfWidth && this.x < -halfWidth) { LK.getSound('ufo1').stop(); this.destroy(); } this.lastX = this.x; };
===================================================================
--- original.js
+++ change.js
@@ -4,1226 +4,1732 @@
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
-* Classes
-****/
-var Background = Container.expand(function () {
- var self = Container.call(this);
- var backgroundGraphics = self.attachAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(backgroundGraphics);
- game.layerManager.addToLayer(self, LAYERS.BACKGROUND);
-});
-var Bird1 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new Bird1Movement(self, birdGraphics);
- game.layerManager.addToLayer(self, LAYERS.BIRD1);
-});
-var Bird2 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new Bird2Movement(self, birdGraphics);
- game.layerManager.addToLayer(self, LAYERS.BIRD2);
-});
-var Cat = Container.expand(function () {
- var self = Container.call(this);
- var catGraphics = self.attachAsset('cat', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.update = function () {};
- game.layerManager.addToLayer(self, LAYERS.CAT);
-});
-var Cloud = Container.expand(function () {
- var self = Container.call(this);
- var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)];
- var cloudGraphics = self.attachAsset(cloudType, {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8
- });
- var layerIndex = cloudType === 'cloud1' ? LAYERS.CLOUD1 : LAYERS.CLOUD2;
- game.layerManager.addToLayer(self, layerIndex);
- self.movement = new CloudMovement(self, cloudGraphics);
- self.update = function () {
- self.movement.update();
- };
- return self;
-});
-var GrassBack = Container.expand(function () {
- var self = Container.call(this);
- var grassGraphics = self.attachAsset('grass-back', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.update = function () {
- self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
- };
- self.addChild(grassGraphics); // Add grass graphics to the container
- // Set the layer index for grass-back
- game.layerManager.addToLayer(self, LAYERS.GRASS_BACK);
-});
-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 () {
- self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
- self.lastX = self.x; // Update lastX after movement
- };
- // Set the layer index for grass-front
- game.layerManager.addToLayer(self, LAYERS.GRASS_FRONT);
-});
-var Jet1 = Container.expand(function () {
- var self = Container.call(this);
- var jetGraphics = self.attachAsset('jet1', {
- anchorX: 0.5,
- anchorY: 0.5,
- flipX: 1
- });
- game.layerManager.addToLayer(self, LAYERS.JET1);
- self.speed = 10;
- self.direction = Math.random() < 0.5 ? 1 : -1;
- self.lastX = self.x;
- self.soundPlayed = false;
- self.x = Math.random() < 0.5 ? 2048 + self.width / 2 : -self.width / 2;
- self.update = function () {
- flipImageVerticallyBasedOnDirection(jetGraphics, self.lastX, self.x);
- self.x += self.speed * self.direction;
- if (!self.soundPlayed && self.x > 0 && self.x < 2048) {
- LK.getSound('jet1').play();
- self.soundPlayed = true;
- } else if (self.soundPlayed && (self.x <= 0 || self.x >= 2048)) {
- LK.getSound('jet1').stop();
- self.soundPlayed = false;
- }
- if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
- self.destroy();
- game.jet = null;
- var respawnTime = Math.random() * 10000 + 10000;
- game.jetSpawnTimer = LK.setTimeout(function () {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
- jet.y = Math.random() * (2732 / 2);
- game.addChild(jet);
- game.jet = jet;
- game.jetSpawnTimer = null;
- }, respawnTime);
- }
- self.lastX = self.x;
- };
-});
-var Laser = Container.expand(function (startX, startY, targetX, targetY) {
- var self = Container.call(this);
- var laserGraphics = self.attachAsset('laser2', {
- anchorX: 0.5,
- anchorY: 0.5,
- brightness: 2.0 // Increase brightness by 200%
- });
- // Play the laser1 sound when the laser is created
- LK.getSound('laser1').play();
- // Calculate direction and speed
- var dx = targetX - startX;
- var dy = targetY - startY;
- var distance = Math.sqrt(dx * dx + dy * dy);
- var speed = 60; // Speed of the laser increased by 200%
- self.vx = dx / distance * speed;
- self.vy = dy / distance * speed;
- // Set initial position
- self.x = startX;
- self.y = startY;
- self.update = function () {
- game.children.forEach(function (child) {
- if ((child instanceof Bird1 || child instanceof Bird2) && self.intersects(child)) {
- child.destroy();
- self.destroy();
- }
- });
- self.x += self.vx;
- self.y += self.vy;
- if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
- self.destroy();
- }
- };
- // Set the layer index for laser
- game.layerManager.addToLayer(self, LAYERS.LASER);
-});
-var Light1 = Container.expand(function () {
- var self = Container.call(this);
- var lightGraphics = self.attachAsset('light1', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 1.0
- });
- self.x = 450;
- self.y = 450;
- self.update = function () {
- self.x += Math.sin(LK.ticks / 90) * 0.1;
- };
- self.pulse = new Light1Pulse(lightGraphics);
- self.pulse.startPulsating();
- game.layerManager.addToLayer(self, LAYERS.LIGHT1);
-});
-var Mirror = Container.expand(function () {
- var self = Container.call(this);
- var mirrorGraphics = self.attachAsset('mirror1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(mirrorGraphics);
- // Set the layer index for mirror
- game.layerManager.addToLayer(self, LAYERS.MIRROR);
- // Score display functionality
- var scoreText = new Text2('0', {
- size: 175,
- fill: 0x800080,
- font: "Courier New, Courier, monospace",
- stroke: 0x00FF00,
- strokeThickness: 15,
- dropShadow: true,
- dropShadowColor: 0x000000,
- dropShadowBlur: 5,
- dropShadowAngle: Math.PI / 6,
- dropShadowDistance: 6
- });
- scoreText.y = 260;
- scoreText.x = -155;
- scoreText.rotation = (-83 + 2) * (Math.PI / 180);
- self.addChild(scoreText);
- self.updateScore = function (newScore) {
- scoreText.setText(newScore);
- };
- return self;
-});
-var Reticle = Container.expand(function () {
- var self = Container.call(this);
- var reticleGraphics = self.attachAsset('reticle1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- if (!self.pulse) {
- self.pulse = new ReticlePulse(reticleGraphics);
- self.pulse.startPulsating();
- }
- };
- game.layerManager.addToLayer(self, LAYERS.RETICLE);
-});
-var Reticle1 = Container.expand(function () {
- var self = Container.call(this);
- var reticle1Graphics = self.attachAsset('reticle1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(reticle1Graphics);
- // Set the layer index for reticle
- game.layerManager.addToLayer(self, LAYERS.RETICLE);
-});
-var Stack1 = Container.expand(function () {
- var self = Container.call(this);
- var stackGraphics = self.attachAsset('stack1', {
- anchorX: 0.5,
- anchorY: 0.5,
- rotation: Math.PI / -12
- });
- self.update = function () {
- // Add any specific update logic for stack1 here
- };
- // Set the layer index for stack
- game.layerManager.addToLayer(self, LAYERS.STACK);
-});
-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();
- // Set the layer index for sun
- game.layerManager.addToLayer(self, LAYERS.SUN);
-});
-var Tree = Container.expand(function () {
- var self = Container.call(this);
- var treeGraphics = self.attachAsset('tree1', {
- anchorX: 0.5,
- anchorY: 1,
- antialias: true,
- // Apply antialias effect
- stroke: 0x000000,
- // Add a black stroke
- strokeThickness: 15 // Set stroke thickness to 15px
- });
- self.update = function () {
- // Add any specific update logic for the tree here
- };
- // Set the layer index for tree
- game.layerManager.addToLayer(self, LAYERS.TREE);
-});
-var Tree2 = Container.expand(function () {
- var self = Container.call(this);
- var tree2Graphics = self.attachAsset('tree2', {
- anchorX: 0.5,
- anchorY: 1
- });
- self.addChild(tree2Graphics);
- // Set the layer index for tree2
- game.layerManager.addToLayer(self, LAYERS.TREE);
-});
-var UFO = Container.expand(function () {
- var self = Container.call(this);
- var ufoGraphics = self.attachAsset('ufo2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new UFOMovement(self, ufoGraphics);
- game.layerManager.addToLayer(self, LAYERS.UFO2);
-});
-var UFO1 = Container.expand(function () {
- var self = Container.call(this);
- var ufo1Graphics = self.attachAsset('ufo1', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new UFOMovement(self, ufo1Graphics);
- // Set the layer index for ufo1
- game.layerManager.addToLayer(self, LAYERS.UFO1);
-});
-var UFO2 = Container.expand(function () {
- var self = Container.call(this);
- var ufo2Graphics = self.attachAsset('ufo2', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.movement = new UFOMovement(self, ufo2Graphics);
- game.layerManager.addToLayer(self, LAYERS.UFO2);
-});
-
-/****
* Initialize Game
****/
+// BaseEntityManager removed - using EntityManager defined at the beginning of the file
// Initialize clouds array
var game = new LK.Game({
- // No title, no description
backgroundColor: 0x87CEEB // Sky blue
});
/****
* Game Code
****/
-// CloudMovement class to handle cloud movement and fade effects
-var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
- this.cloud = cloud;
- this.cloudGraphics = cloudGraphics;
- this.speed = Math.random() * 0.55 + 0.25;
- this.direction = Math.random() < 0.5 ? 1 : -1;
- this.update = function () {
- this.cloud.x += this.speed * this.direction;
- var screenWidth = 2048;
- var halfWidth = this.cloud.width / 2;
- if (this.cloud.x > screenWidth + halfWidth) {
- this.cloud.x = -halfWidth;
- } else if (this.cloud.x < -halfWidth) {
- this.cloud.x = screenWidth + halfWidth;
+// Base GameObject class to handle common functionality
+// Unified GameObjectMovement class with improved movement patterns and sound management
+// Modern ES6 class implementation for game object movement
+var _GameObjectMovement;
+function ownKeys(e, r) {
+ var t = Object.keys(e);
+ if (Object.getOwnPropertySymbols) {
+ var o = Object.getOwnPropertySymbols(e);
+ r && (o = o.filter(function (r) {
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
+ })), t.push.apply(t, o);
+ }
+ return t;
+}
+function _objectSpread(e) {
+ for (var r = 1; r < arguments.length; r++) {
+ var t = null != arguments[r] ? arguments[r] : {};
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
+ _defineProperty(e, r, t[r]);
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
+ });
+ }
+ return e;
+}
+function _defineProperty(e, r, t) {
+ return (r = _toPropertyKey2(r)) in e ? Object.defineProperty(e, r, {
+ value: t,
+ enumerable: !0,
+ configurable: !0,
+ writable: !0
+ }) : e[r] = t, e;
+}
+function _callSuper(t, o, e) {
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
+}
+function _possibleConstructorReturn(t, e) {
+ if (e && ("object" == _typeof2(e) || "function" == typeof e)) {
+ return e;
+ }
+ if (void 0 !== e) {
+ throw new TypeError("Derived constructors may only return object or undefined");
+ }
+ return _assertThisInitialized(t);
+}
+function _assertThisInitialized(e) {
+ if (void 0 === e) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
+ return e;
+}
+function _isNativeReflectConstruct() {
+ try {
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
+ } catch (t) {}
+ return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
+ return !!t;
+ })();
+}
+function _superPropGet(t, o, e, r) {
+ var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e);
+ return 2 & r && "function" == typeof p ? function (t) {
+ return p.apply(e, t);
+ } : p;
+}
+function _get() {
+ return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
+ var p = _superPropBase(e, t);
+ if (p) {
+ var n = Object.getOwnPropertyDescriptor(p, t);
+ return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
}
- }.bind(this);
-};
-function _typeof(o) {
+ }, _get.apply(null, arguments);
+}
+function _superPropBase(t, o) {
+ for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));) {
+ ;
+ }
+ return t;
+}
+function _getPrototypeOf(t) {
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
+ return t.__proto__ || Object.getPrototypeOf(t);
+ }, _getPrototypeOf(t);
+}
+function _inherits(t, e) {
+ if ("function" != typeof e && null !== e) {
+ throw new TypeError("Super expression must either be null or a function");
+ }
+ t.prototype = Object.create(e && e.prototype, {
+ constructor: {
+ value: t,
+ writable: !0,
+ configurable: !0
+ }
+ }), Object.defineProperty(t, "prototype", {
+ writable: !1
+ }), e && _setPrototypeOf(t, e);
+}
+function _setPrototypeOf(t, e) {
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
+ return t.__proto__ = e, t;
+ }, _setPrototypeOf(t, e);
+}
+function _typeof2(o) {
"@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
+ return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
- }, _typeof(o);
+ }, _typeof2(o);
}
-function _classCallCheck(a, n) {
+function _classCallCheck2(a, n) {
if (!(a instanceof n)) {
throw new TypeError("Cannot call a class as a function");
}
}
-function _defineProperties(e, r) {
+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);
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey2(o.key), o);
}
}
-function _createClass(e, r, t) {
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
+function _createClass2(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 _toPropertyKey2(t) {
+ var i = _toPrimitive2(t, "string");
+ return "symbol" == _typeof2(i) ? i : i + "";
}
-function _toPrimitive(t, r) {
- if ("object" != _typeof(t) || !t) {
+function _toPrimitive2(t, r) {
+ if ("object" != _typeof2(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
- if ("object" != _typeof(i)) {
+ if ("object" != _typeof2(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
-var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
- this.cloud = cloud;
- this.cloudGraphics = cloudGraphics;
- this.speed = Math.random() * 0.55 + 0.25;
- this.direction = Math.random() < 0.5 ? 1 : -1;
- this.update = function () {
- this.cloud.x += this.speed * this.direction;
- var screenWidth = 2048;
- var halfWidth = this.cloud.width / 2;
- if (this.cloud.x > screenWidth + halfWidth) {
- this.cloud.x = -halfWidth;
- } else if (this.cloud.x < -halfWidth) {
- this.cloud.x = screenWidth + halfWidth;
- }
- }.bind(this);
-};
-/****
-* Layer Constants
-****/
-var LAYERS = {
- BACKGROUND: 0,
- SUN: 1,
- LIGHT1: 2,
- UFO2: 3,
- CLOUD1: 4,
- JET1: 5,
- CLOUD2: 6,
- UFO1: 7,
- BIRD1: 8,
- GRASS_BACK: 9,
- TREE: 10,
- STACK: 11,
- BIRD2: 12,
- MIRROR: 13,
- GRASS_FRONT: 14,
- CAT: 15,
- LASER: 16,
- RETICLE: 17
-};
-/****
-* Layer Management System
-****/
-var LayerManager = /*#__PURE__*/function () {
- function LayerManager(gameInstance) {
- _classCallCheck(this, LayerManager);
- this.game = gameInstance;
- this.layerMap = {};
- }
- return _createClass(LayerManager, [{
- key: "setLayerIndex",
- value: function setLayerIndex(object, layerId) {
- if (!object || !this.game.children.includes(object)) {
- return;
+var SoundManager = /*#__PURE__*/function () {
+ function SoundManager(config) {
+ _classCallCheck2(this, SoundManager);
+ this.config = config || {};
+ this.soundTimers = {};
+ this.soundCallbacks = {};
+ this.soundIntervals = {
+ ambient: {
+ min: 20000,
+ max: 30000
+ },
+ background: {
+ min: 20000,
+ max: 30000
+ },
+ ufo: {
+ min: 20000,
+ max: 30000
+ },
+ jet: {
+ min: 20000,
+ max: 30000
}
- // Ensure the layer ID is valid and within bounds
- layerId = Math.max(0, Math.min(layerId, this.game.children.length));
- // Set the child index
- if (layerId < this.game.children.length) {
- this.game.setChildIndex(object, layerId);
- }
- // Update the layer map
- this.layerMap[object.id] = layerId;
+ };
+ }
+ return _createClass2(SoundManager, [{
+ key: "initialize",
+ value: function initialize() {
+ var _this = this;
+ var ambientSounds = [{
+ id: 'songbird1',
+ volume: 0.1,
+ minDelay: 5000,
+ maxDelay: 15000
+ }, {
+ id: 'cricket1',
+ volume: 0.1,
+ minDelay: 8000,
+ maxDelay: 20000
+ }, {
+ id: 'breeze1',
+ volume: 0.1,
+ minDelay: 10000,
+ maxDelay: 25000
+ }, {
+ id: 'frog1',
+ volume: 0.1,
+ minDelay: 12000,
+ maxDelay: 30000
+ }, {
+ id: 'chitter',
+ volume: 0.1,
+ minDelay: 15000,
+ maxDelay: 35000
+ }];
+ ambientSounds.forEach(function (sound) {
+ var initialDelay = Math.random() * (sound.maxDelay - sound.minDelay) + sound.minDelay;
+ LK.setTimeout(function () {
+ _this.playSound(sound.id, {
+ volume: sound.volume,
+ interval: {
+ min: sound.minDelay,
+ max: sound.maxDelay
+ }
+ });
+ }, initialDelay);
+ });
+ this.playSound('bgm1', {
+ isMusic: true,
+ volume: 0.1,
+ loop: true,
+ autoRestart: false
+ });
}
}, {
- key: "getObjectsInLayer",
- value: function getObjectsInLayer(layerId) {
- var objects = [];
- for (var id in this.layerMap) {
- if (this.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < this.game.children.length; i++) {
- var child = this.game.children[i];
- if (child.id === id) {
- objects.push(child);
- break;
+ key: "playSound",
+ value: function playSound(soundId, options) {
+ var _this2 = this;
+ options = Object.assign({
+ interval: this.soundIntervals.ambient,
+ isMusic: false,
+ volume: 0.1,
+ loop: false,
+ autoRestart: true,
+ onPlay: null,
+ onStop: null
+ }, options);
+ var _playFunction = function playFunction() {
+ if (options.isMusic) {
+ LK.playMusic(soundId, {
+ volume: options.volume
+ });
+ } else {
+ var sound = LK.getSound(soundId);
+ if (sound) {
+ sound.volume = options.volume;
+ if (options.loop) {
+ sound.loop = true;
}
+ sound.play();
+ if (options.onPlay) {
+ options.onPlay();
+ }
}
}
- }
- return objects;
+ if (options.autoRestart) {
+ var nextInterval = Math.random() * (options.interval.max - options.interval.min) + options.interval.min;
+ _this2.soundTimers[soundId] = LK.setTimeout(_playFunction.bind(_this2), nextInterval);
+ }
+ };
+ this.soundCallbacks[soundId] = options;
+ _playFunction();
+ return this.soundTimers[soundId];
}
- /**
- * Add an object to a specific layer
- * @param {Object} object - The game object to add
- * @param {Number} layerId - The layer ID
- */
}, {
- key: "addToLayer",
- value: function addToLayer(object, layerId) {
- if (!object || !object.id) {
- return;
+ key: "stopSound",
+ value: function stopSound(soundId) {
+ if (this.soundTimers[soundId]) {
+ LK.clearTimeout(this.soundTimers[soundId]);
+ delete this.soundTimers[soundId];
}
- // Add the object if it's not already a child
- if (!this.game.children.includes(object)) {
- this.game.addChild(object);
+ var sound = LK.getSound(soundId);
+ if (sound) {
+ sound.stop();
+ if (this.soundCallbacks[soundId] && this.soundCallbacks[soundId].onStop) {
+ this.soundCallbacks[soundId].onStop();
+ }
+ delete this.soundCallbacks[soundId];
}
- // Set the child index to match the LAYERS order
- this.game.setChildIndex(object, layerId);
- // Update the layer map
- this.layerMap[object.id] = layerId;
}
- /**
- * Get the layer of an object
- * @param {Object} object - The game object
- * @return {Number} The layer ID or -1 if not found
- */
}, {
- key: "getObjectLayer",
- value: function getObjectLayer(object) {
- if (!object || !object.id) {
- return -1;
+ key: "stopAllSounds",
+ value: function stopAllSounds() {
+ var _this3 = this;
+ Object.keys(this.soundTimers).forEach(function (soundId) {
+ _this3.stopSound(soundId);
+ });
+ }
+ }]);
+}();
+var Container = /*#__PURE__*/function () {
+ function Container() {
+ _classCallCheck2(this, Container);
+ this.children = [];
+ }
+ return _createClass2(Container, [{
+ key: "attachAsset",
+ value: function attachAsset(assetName, options) {
+ if (!assetName) {
+ console.error('Asset name is required for attachAsset');
+ return null;
}
- return this.layerMap[object.id] !== undefined ? this.layerMap[object.id] : -1;
+ var asset = LK.init.getImage(assetName);
+ if (!asset) {
+ console.error('Failed to load asset:', assetName);
+ return null;
+ }
+ var sprite = new Sprite(asset);
+ if (options) {
+ Object.assign(sprite, options);
+ }
+ this.addChild(sprite);
+ return sprite;
}
- /**
- * Remove an object from layer tracking
- * @param {Object} object - The game object to remove
- */
}, {
- key: "removeFromTracking",
- value: function removeFromTracking(object) {
- if (!object || !object.id) {
- return;
+ key: "addChild",
+ value: function addChild(child) {
+ if (child && !this.children.includes(child)) {
+ this.children.push(child);
}
- delete this.layerMap[object.id];
+ return child;
}
- /**
- * Bring an object to the front of its layer
- * @param {Object} object - The game object
- */
}, {
- key: "bringToFrontOfLayer",
- value: function bringToFrontOfLayer(object) {
- if (!object || !object.id) {
- return;
+ key: "destroy",
+ value: function destroy() {
+ if (this.children) {
+ this.children.forEach(function (child) {
+ if (child && child.destroy) {
+ child.destroy();
+ }
+ });
+ this.children = [];
}
- var layerId = this.getObjectLayer(object);
- if (layerId === -1) {
+ }
+ }]);
+}();
+var EntityManager = /*#__PURE__*/function () {
+ function EntityManager() {
+ _classCallCheck2(this, EntityManager);
+ this.entities = [];
+ this.pendingRemovals = [];
+ }
+ return _createClass2(EntityManager, [{
+ key: "add",
+ value: function add(entity) {
+ if (!entity) {
return;
}
- // Find the highest index within this layer
- var highestIndex = layerId;
- for (var id in this.layerMap) {
- if (this.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < this.game.children.length; i++) {
- var child = this.game.children[i];
- if (child.id === id && i > highestIndex) {
- highestIndex = i;
- }
- }
+ if (!this.entities.includes(entity)) {
+ this.entities.push(entity);
+ if (entity.type && game.spawnManager && game.spawnManager.objectCounts) {
+ game.spawnManager.objectCounts[entity.type] = (game.spawnManager.objectCounts[entity.type] || 0) + 1;
}
}
- // Set the object to the highest index within its layer
- this.game.setChildIndex(object, highestIndex);
}
- /**
- * Send an object to the back of its layer
- * @param {Object} object - The game object
- */
}, {
- key: "sendToBackOfLayer",
- value: function sendToBackOfLayer(object) {
- if (!object || !object.id) {
+ key: "remove",
+ value: function remove(entity) {
+ if (!entity) {
return;
}
- var layerId = this.getObjectLayer(object);
- if (layerId === -1) {
- return;
+ var index = this.entities.indexOf(entity);
+ if (index > -1) {
+ this.entities.splice(index, 1);
+ // First mark as destroyed to prevent re-entry
+ if (entity.destroy && !entity.destroyed) {
+ entity.destroy();
+ }
+ // Then update layer tracking
+ if (game.layerManager) {
+ game.layerManager.removeFromTracking(entity);
+ }
+ // Finally update spawn counts
+ if (entity.type && game.spawnManager && game.spawnManager.objectCounts) {
+ var currentCount = game.spawnManager.objectCounts[entity.type] || 0;
+ game.spawnManager.objectCounts[entity.type] = Math.max(0, currentCount - 1);
+ }
}
- // Find the lowest index within this layer
- var lowestIndex = layerId;
- for (var id in this.layerMap) {
- if (this.layerMap[id] === layerId) {
- // Find the object in the game's children
- for (var i = 0; i < this.game.children.length; i++) {
- var child = this.game.children[i];
- if (child.id === id && i < lowestIndex) {
- lowestIndex = i;
- }
- }
+ }
+ }, {
+ key: "update",
+ value: function update(deltaTime) {
+ var _this4 = this;
+ // Clear pending removals from previous update
+ this.pendingRemovals = [];
+ // Update entities and mark destroyed ones for removal
+ for (var i = this.entities.length - 1; i >= 0; i--) {
+ var entity = this.entities[i];
+ if (!entity || entity.destroyed) {
+ this.pendingRemovals.push(entity);
+ continue;
}
+ if (entity.update) {
+ entity.update(deltaTime);
+ }
}
- // Set the object to the lowest index within its layer
- this.game.setChildIndex(object, lowestIndex);
+ // Remove destroyed entities
+ this.pendingRemovals.forEach(function (entity) {
+ return _this4.remove(entity);
+ });
}
- /**
- * Helper function to add multiple objects to a layer at once
- * @param {Array} objects - Array of game objects
- * @param {Number} layerId - The layer ID
- */
}, {
- key: "addMultipleToLayer",
- value: function addMultipleToLayer(objects, layerId) {
- var _this2 = this;
- if (!Array.isArray(objects)) {
- return;
+ key: "getAllOfType",
+ value: function getAllOfType(type) {
+ return this.entities.filter(function (entity) {
+ return entity && !entity.destroyed && entity instanceof type;
+ });
+ }
+ }, {
+ key: "clear",
+ value: function clear() {
+ // First remove all entities from layer tracking
+ if (game.layerManager) {
+ this.entities.forEach(function (entity) {
+ if (entity && !entity.destroyed) {
+ game.layerManager.removeFromTracking(entity);
+ }
+ });
}
- objects.forEach(function (object) {
- return _this2.addToLayer(object, layerId);
+ // Then destroy all entities
+ this.entities.forEach(function (entity) {
+ if (entity && !entity.destroyed && entity.destroy) {
+ entity.destroy();
+ }
});
+ this.entities = [];
+ this.pendingRemovals = [];
+ // Finally clear spawn timers if they exist
+ if (game.spawnManager) {
+ // Clear all spawn timers
+ Object.keys(game.spawnManager.spawnTimers || {}).forEach(function (type) {
+ if (game.spawnManager.spawnTimers[type]) {
+ LK.clearTimeout(game.spawnManager.spawnTimers[type]);
+ delete game.spawnManager.spawnTimers[type];
+ }
+ });
+ game.spawnManager.spawnTimers = {};
+ // Reset all object counts
+ game.spawnManager.objectCounts = {
+ bird1: 0,
+ bird2: 0,
+ cloud1: 0,
+ cloud2: 0,
+ ufo1: 0,
+ ufo2: 0,
+ jet1: 0
+ };
+ }
}
}]);
}();
-game.layerManager = new LayerManager(game);
-// Using UFO sound ID as placeholder
-function flipImageVerticallyBasedOnDirection(graphics, lastX, currentX) {
- if (graphics) {
- if (lastX < currentX && graphics.scaleX < 0) {
- graphics.scaleX *= -1; // Flip horizontally to face right
- } else if (lastX > currentX && graphics.scaleX > 0) {
- graphics.scaleX *= -1; // Flip horizontally to face left
- }
+var GameObject = /*#__PURE__*/function (_Container) {
+ function GameObject(assetName) {
+ var _this5;
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
+ _classCallCheck2(this, GameObject);
+ _this5 = _callSuper(this, GameObject);
+ _this5.graphics = _this5.attachAsset(assetName, {});
+ return _this5;
}
-}
-function flipImageBasedOnDirection(graphics, lastX, currentX) {
- if (graphics) {
- if (lastX < currentX) {
- graphics.scaleY = Math.abs(graphics.scaleY); // Face right when moving right by ensuring scaleY is positive
- } else if (lastX > currentX) {
- graphics.scaleY = -Math.abs(graphics.scaleY); // Face left when moving left by ensuring scaleY is negative
+ // Common destroy method
+ _inherits(GameObject, _Container);
+ return _createClass2(GameObject, [{
+ key: "destroy",
+ value: function destroy() {
+ if (game.layerManager) {
+ game.layerManager.removeFromTracking(this);
+ }
+ if (this.movement && this.movement.cleanup) {
+ this.movement.cleanup();
+ }
+ _superPropGet(GameObject, "destroy", this, 3)([]);
}
+ // Common update method
+ }, {
+ key: "update",
+ value: function update() {
+ if (this.movement) {
+ this.movement.update();
+ }
+ }
+ }]);
+}(Container);
+var Background = /*#__PURE__*/function (_GameObject) {
+ function Background() {
+ _classCallCheck2(this, Background);
+ return _callSuper(this, Background, ['background']);
}
-}
-// SunPulse class to handle the pulsating effect for Sun
-function AABBIntersect(obj1, obj2) {
- if (obj1 && obj2) {
- return obj1.x < obj2.x + obj2.width && obj1.x + obj1.width > obj2.x && obj1.y < obj2.y + obj2.height && obj1.y + obj1.height > obj2.y;
+ _inherits(Background, _GameObject);
+ return _createClass2(Background);
+}(GameObject);
+var Bird1 = /*#__PURE__*/function (_GameObject2) {
+ function Bird1() {
+ var _this6;
+ _classCallCheck2(this, Bird1);
+ _this6 = _callSuper(this, Bird1, ['bird1']);
+ _this6.type = 'bird1';
+ _this6.movement = new GameObjectMovement(_this6, _this6.graphics, GameObjectMovement.MovementConfigs.bird1);
+ return _this6;
}
- return false;
-}
+ _inherits(Bird1, _GameObject2);
+ return _createClass2(Bird1);
+}(GameObject);
+var Bird2 = /*#__PURE__*/function (_GameObject3) {
+ function Bird2() {
+ var _this7;
+ _classCallCheck2(this, Bird2);
+ _this7 = _callSuper(this, Bird2, ['bird2']);
+ _this7.type = 'bird2';
+ _this7.movement = new GameObjectMovement(_this7, _this7.graphics, GameObjectMovement.MovementConfigs.bird2);
+ return _this7;
+ }
+ _inherits(Bird2, _GameObject3);
+ return _createClass2(Bird2);
+}(GameObject);
+var Cat = /*#__PURE__*/function (_GameObject4) {
+ function Cat() {
+ _classCallCheck2(this, Cat);
+ return _callSuper(this, Cat, ['cat', {
+ anchorX: 0.5,
+ anchorY: 1
+ }]);
+ }
+ _inherits(Cat, _GameObject4);
+ return _createClass2(Cat);
+}(GameObject); // Define cloud types at the beginning
var CLOUD_TYPES = ['cloud1', 'cloud2'];
-var SunPulse = function SunPulse(sunGraphics) {
- this.sunGraphics = sunGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.sunGraphics, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.sunGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
+var GrassLayer = /*#__PURE__*/function (_GameObject5) {
+ function GrassLayer(type) {
+ var _this8;
+ _classCallCheck2(this, GrassLayer);
+ _this8 = _callSuper(this, GrassLayer, [type, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 1
+ }]);
+ _this8.type = type;
+ _this8.movement = new GameObjectMovement(_this8, _this8.graphics, GameObjectMovement.MovementConfigs[type]);
+ return _this8;
+ }
+ _inherits(GrassLayer, _GameObject5);
+ return _createClass2(GrassLayer, [{
+ key: "update",
+ value: function update(deltaTime) {
+ _superPropGet(GrassLayer, "update", this, 3)([deltaTime]);
+ if (this.movement) {
+ this.movement.update(deltaTime);
+ }
}
- pulsate.call(this);
- };
-};
-// Light1Pulse class to handle the pulsating effect for Light1
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- this.lightGraphics = lightGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.lightGraphics, {
- scaleX: 1.6,
- scaleY: 1.6
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.lightGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1500,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
- }
- pulsate.call(this);
- };
-};
-var bird2; // Define bird2 variable in the global scope
-function startPulsating(target) {
- var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
- function pulsate() {
- tween(target, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(target, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: duration,
- easing: tween.easeInOut,
- onFinish: pulsate
- });
+ }]);
+}(GameObject);
+var GRASS_TYPES = ['grass-front', 'grass-back'];
+// Initialize grass layers
+var grassFront = new GrassLayer('grass-front');
+grassFront.x = LK.width / 2;
+grassFront.y = LK.height - 100;
+var grassBack = new GrassLayer('grass-back');
+grassBack.x = LK.width / 2;
+grassBack.y = LK.height - 150;
+// Add grass layers to the game
+game.entityManager.add(grassBack);
+game.entityManager.add(grassFront);
+var Cloud = /*#__PURE__*/function (_GameObject6) {
+ function Cloud() {
+ var _this9;
+ _classCallCheck2(this, Cloud);
+ var cloudType = CLOUD_TYPES[Math.floor(Math.random() * CLOUD_TYPES.length)];
+ _this9 = _callSuper(this, Cloud, [cloudType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.8
+ }]);
+ _this9.type = cloudType;
+ _this9.movement = new GameObjectMovement(_this9, _this9.graphics, GameObjectMovement.MovementConfigs[_this9.type]);
+ return _this9;
+ }
+ _inherits(Cloud, _GameObject6);
+ return _createClass2(Cloud, [{
+ key: "destroy",
+ value: function destroy() {
+ if (spawnManager) {
+ spawnManager.objectCounts[this.type === 'cloud1' ? 'cloud1' : 'cloud2']--;
}
- });
+ this.movement = null;
+ _superPropGet(Cloud, "destroy", this, 3)([]);
+ }
+ }]);
+}(GameObject); // Using GrassLayer class for grass-back implementation
+var GrassFront = /*#__PURE__*/function (_GameObject7) {
+ function GrassFront() {
+ _classCallCheck2(this, GrassFront);
+ return _callSuper(this, GrassFront, ['grass-front', {
+ anchorX: 0.5,
+ anchorY: 1
+ }]);
}
- pulsate();
-}
-// UFOMovement class to handle UFO movement
-var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- this.ufo = ufo;
- this.ufoGraphics = ufoGraphics;
- this.ufo.speed = 3.2;
- this.ufo.direction = Math.random() < 0.5 ? 1 : -1;
- this.ufo.lastX = this.ufo.x;
- this.ufo.soundPlayed = false;
- this.ufo.update = function () {
- var currentX = this.x;
- var screenWidth = 2048;
- var halfWidth = this.width / 2;
- var tickCos = Math.cos(LK.ticks / 60);
- var tickSin = Math.sin(LK.ticks / 120);
- this.x += this.speed * tickCos;
- this.y = 100 + tickSin * 250;
- if (this.x > 0 && this.x < screenWidth && !this.soundPlayed) {
- LK.getSound('ufo1').play();
- this.soundPlayed = true;
+ _inherits(GrassFront, _GameObject7);
+ return _createClass2(GrassFront, [{
+ key: "update",
+ value: function update() {
+ // Swaying effect with bounds checking and smoother movement
+ var maxOffset = 2.0;
+ var offset = Math.sin(LK.ticks / 90) * 0.15;
+ this.x += Math.max(-maxOffset, Math.min(maxOffset, offset));
}
- if (this.x < 0 || this.x > screenWidth) {
- this.soundPlayed = false;
+ }]);
+}(GameObject);
+var Jet1 = /*#__PURE__*/function (_GameObject8) {
+ function Jet1() {
+ var _this10;
+ _classCallCheck2(this, Jet1);
+ _this10 = _callSuper(this, Jet1, ['jet1']);
+ _this10.type = 'jet1';
+ _this10.movement = new GameObjectMovement(_this10, _this10.graphics, GameObjectMovement.MovementConfigs.jet1);
+ _this10.soundPlayed = false;
+ return _this10;
+ }
+ _inherits(Jet1, _GameObject8);
+ return _createClass2(Jet1, [{
+ key: "update",
+ value: function update() {
+ _superPropGet(Jet1, "update", this, 3)([]);
+ // Play jet1 sound when on screen
+ if (!this.soundPlayed && this.x > 0 && this.x < 2048) {
+ LK.getSound('jet1').play();
+ this.soundPlayed = true;
+ }
}
- if (currentX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || currentX >= -halfWidth && this.x < -halfWidth) {
- LK.getSound('ufo1').stop();
- this.destroy();
- ufo = null;
- }
- this.lastX = this.x;
- };
-};
-var UFOSound = function UFOSound() {
- this.play = function () {
- LK.getSound('ufo1').play();
- };
-};
-// BackgroundMusic class to manage background music
-var BackgroundMusic = function BackgroundMusic() {
- this.play = function () {
- LK.playMusic('bgm1', {
- loop: true,
- fade: {
- start: 0,
- end: 1,
- duration: 4000
- },
- onEnd: onBgm1End
+ }]);
+}(GameObject);
+function respawnJet() {
+ if (game.jet === null) {
+ var jet = new Jet1();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2);
+ addEntityToLayer(jet, LAYERS.JET1);
+ game.jet = jet;
+ }
+ game.jetSpawnTimer = null;
+}
+var Laser = /*#__PURE__*/function (_Container2) {
+ function Laser(startX, startY, targetX, targetY) {
+ var _this11;
+ _classCallCheck2(this, Laser);
+ _this11 = _callSuper(this, Laser);
+ _this11.laserGraphics = _this11.attachAsset('laser2', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ brightness: 2.0
});
- };
-};
-// LaserSound class to manage laser sound effects
-var LaserSound = function LaserSound() {
- this.play = function () {
+ var dx = targetX - startX;
+ var dy = targetY - startY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var speed = 60;
+ _this11.vx = dx / distance * speed;
+ _this11.vy = dy / distance * speed;
+ _this11.x = startX;
+ _this11.y = startY;
+ _this11.lastIntersecting = false;
+ _this11.active = true;
LK.getSound('laser1').play();
- };
-};
-var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = this.bird.y;
- this.bird.lastX = this.bird.x;
- this.bird.update = function () {
- var currentX = this.x;
- var currentY = this.y;
- var screenWidth = 2048;
- var screenHeight = 2732;
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5;
- if (currentY > screenHeight + this.height) {
- this.y = -this.height;
- var rand = Math.random();
- this.x = rand < 0.33 ? rand * screenWidth : rand < 0.5 ? 0 : screenWidth;
+ return _this11;
+ }
+ _inherits(Laser, _Container2);
+ return _createClass2(Laser, [{
+ key: "destroy",
+ value: function destroy() {
+ if (game.layerManager) {
+ game.layerManager.removeFromTracking(this);
+ }
+ _superPropGet(Laser, "destroy", this, 3)([]);
}
- this.rotation = Math.atan2(this.y - currentY, this.x - currentX) * 0.1;
- var isIntersectingCloud = false;
- for (var i = 0; i < clouds.length; i++) {
- if (this.intersects(clouds[i])) {
- isIntersectingCloud = true;
- break;
+ }, {
+ key: "update",
+ value: function update() {
+ if (!this.active) {
+ return;
}
+ // Move first
+ this.x += this.vx;
+ this.y += this.vy;
+ // Check collisions only with relevant layers
+ var collided = false;
+ var targets = game.layerManager.getAllInteractiveLayers();
+ for (var i = 0; i < targets.length && !collided; i++) {
+ for (var j = 0; j < targets.length && !collided; j++) {
+ var target = targets[j];
+ if (!this.lastIntersecting && this.intersects(target)) {
+ var soundEffect = game.layerManager.isInLayer(target, 'ufos') ? 'dead3' : 'dead2';
+ LK.getSound(soundEffect).play();
+ // Update score based on target type
+ var scoreValue = 0;
+ if (game.layerManager.isInLayer(target, LAYERS.BIRD1)) {
+ scoreValue = 5;
+ } else if (game.layerManager.isInLayer(target, LAYERS.BIRD2)) {
+ scoreValue = 1;
+ } else if (game.layerManager.isInLayer(target, LAYERS.UFO1) || game.layerManager.isInLayer(target, LAYERS.UFO2)) {
+ scoreValue = 25;
+ }
+ score += scoreValue;
+ if (game.mirror) {
+ game.mirror.updateScore(score);
+ }
+ target.destroy();
+ collided = true;
+ }
+ }
+ }
+ // Update intersection state
+ this.lastIntersecting = collided;
+ // Destroy if out of bounds
+ if (this.x < 0 || this.x > 2048 || this.y < 0 || this.y > 2732) {
+ this.destroy();
+ }
}
- if (isIntersectingCloud && !this.lastIntersecting) {
- this.speed *= 0.8;
- LK.getSound('wings1').play();
+ }]);
+}(Container);
+var Light1 = /*#__PURE__*/function (_GameObject9) {
+ function Light1() {
+ var _this12;
+ _classCallCheck2(this, Light1);
+ _this12 = _callSuper(this, Light1, ['light1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 1.0
+ }]);
+ _this12.x = 450;
+ _this12.y = 450;
+ _this12.pulse = new Light1Pulse(_this12.graphics);
+ _this12.pulse.startPulsating();
+ return _this12;
+ }
+ _inherits(Light1, _GameObject9);
+ return _createClass2(Light1, [{
+ key: "update",
+ value: function update() {
+ // Swaying effect with bounds checking and smoother movement
+ var maxOffset = 1.5;
+ var offset = Math.sin(LK.ticks / 90) * 0.1;
+ this.x += Math.max(-maxOffset, Math.min(maxOffset, offset));
}
- this.lastIntersecting = isIntersectingCloud;
- if (Math.abs(this.lastX - currentX) > 1 || Math.abs(this.lastY - currentY) > 1) {
- this.lastX = currentX;
- this.lastY = currentY;
- storage.bird1_lastX = currentX;
- storage.bird1_lastY = currentY;
+ }]);
+}(GameObject);
+var Mirror = /*#__PURE__*/function (_GameObject10) {
+ function Mirror() {
+ var _this13;
+ _classCallCheck2(this, Mirror);
+ _this13 = _callSuper(this, Mirror, ['mirror1']);
+ _this13.scoreText = new Text2('0', {
+ size: 175,
+ fill: 0x800080,
+ font: "Courier New, Courier, monospace",
+ stroke: 0x00FF00,
+ strokeThickness: 15,
+ dropShadow: true,
+ dropShadowColor: 0x000000,
+ dropShadowBlur: 5,
+ dropShadowAngle: Math.PI / 6,
+ dropShadowDistance: 6
+ });
+ _this13.scoreText.y = 260 + 50;
+ _this13.scoreText.x = -155;
+ _this13.scoreText.rotation = (-83 - 3) * (Math.PI / 180);
+ addEntityToLayer(_this13.scoreText, LAYERS.UI);
+ return _this13;
+ }
+ _inherits(Mirror, _GameObject10);
+ return _createClass2(Mirror, [{
+ key: "updateScore",
+ value: function updateScore(newScore) {
+ this.scoreText.setText(newScore);
}
- flipImageVerticallyBasedOnDirection(birdGraphics, currentX, this.x);
- };
-};
-var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = storage.bird2_lastY || this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = storage.bird2_lastX || this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = Math.random() * 2732; // Random initial y position within the screen height
- this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
+ }]);
+}(GameObject);
+var Reticle = /*#__PURE__*/function (_GameObject11) {
+ function Reticle() {
+ _classCallCheck2(this, Reticle);
+ return _callSuper(this, Reticle, ['reticle1']);
+ }
+ _inherits(Reticle, _GameObject11);
+ return _createClass2(Reticle, [{
+ key: "update",
+ value: function update() {
+ if (!this.pulse) {
+ this.pulse = new ReticlePulse(this.graphics);
+ this.pulse.startPulsating();
+ }
+ _superPropGet(Reticle, "update", this, 3)([]);
}
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
- storage.bird2_lastX = this.lastX; // Store lastX using storage plugin
- storage.bird2_lastY = this.lastY; // Store lastY using storage plugin
- };
-};
-var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {};
-};
-var ReticlePulse = function ReticlePulse(reticleGraphics) {
- this.reticleGraphics = reticleGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.reticleGraphics, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.reticleGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
+ }]);
+}(GameObject);
+var Stack1 = /*#__PURE__*/function (_GameObject12) {
+ function Stack1() {
+ _classCallCheck2(this, Stack1);
+ return _callSuper(this, Stack1, ['stack1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / -12
+ }]);
+ }
+ _inherits(Stack1, _GameObject12);
+ return _createClass2(Stack1);
+}(GameObject);
+var Sun = /*#__PURE__*/function (_GameObject13) {
+ function Sun() {
+ var _this14;
+ _classCallCheck2(this, Sun);
+ _this14 = _callSuper(this, Sun, ['sun']);
+ _this14.pulse = new SunPulse(_this14.graphics);
+ _this14.pulse.startPulsating();
+ return _this14;
+ }
+ _inherits(Sun, _GameObject13);
+ return _createClass2(Sun);
+}(GameObject);
+var Tree = /*#__PURE__*/function (_GameObject14) {
+ function Tree() {
+ var _this15;
+ _classCallCheck2(this, Tree);
+ _this15 = _callSuper(this, Tree, ['tree1', {
+ anchorX: 0.5,
+ anchorY: 1,
+ antialias: true,
+ stroke: 0x000000,
+ strokeThickness: 15
+ }]);
+ _this15.type = 'tree1';
+ _this15.movement = new GameObjectMovement(_this15, _this15.graphics, GameObjectMovement.MovementConfigs.tree1);
+ return _this15;
+ }
+ _inherits(Tree, _GameObject14);
+ return _createClass2(Tree, [{
+ key: "update",
+ value: function update(deltaTime) {
+ _superPropGet(Tree, "update", this, 3)([deltaTime]);
+ if (this.movement) {
+ this.movement.update(deltaTime);
+ }
}
- pulsate.call(this);
- };
-};
-// Bird1Effects class to handle effects and animations for Bird1
-var Bird1Effects = function Bird1Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {
- // Add any specific effects or animations for Bird1 here
- };
-};
-// Add background to the BACKGROUND layer
-var background = new Background();
-background.x = 2048 / 2;
-background.y = 2732 / 2 - 140;
-game.addChild(background);
-game.layerManager.addToLayer(background, LAYERS.BACKGROUND);
-// ScoreManager class to manage score logic
-var ScoreManager = function ScoreManager() {
- var self = this;
- var currentScore = 0;
- var highScore = 0;
- self.addScore = function (points) {
- if (typeof points !== 'number' || points < 0) {
- return currentScore;
+ }, {
+ key: "destroy",
+ value: function destroy() {
+ this.movement = null;
+ _superPropGet(Tree, "destroy", this, 3)([]);
}
- currentScore += Math.floor(points);
- if (currentScore > highScore) {
- highScore = currentScore;
+ }]);
+}(GameObject);
+var Tree2 = /*#__PURE__*/function (_GameObject15) {
+ function Tree2() {
+ var _this16;
+ _classCallCheck2(this, Tree2);
+ _this16 = _callSuper(this, Tree2, ['tree2', {
+ anchorX: 0.5,
+ anchorY: 1
+ }]);
+ _this16.type = 'tree2';
+ _this16.movement = new GameObjectMovement(_this16, _this16.graphics, GameObjectMovement.MovementConfigs.tree2);
+ return _this16;
+ }
+ _inherits(Tree2, _GameObject15);
+ return _createClass2(Tree2, [{
+ key: "update",
+ value: function update(deltaTime) {
+ _superPropGet(Tree2, "update", this, 3)([deltaTime]);
+ if (this.movement) {
+ this.movement.update(deltaTime);
+ }
}
- return currentScore;
- };
- self.resetScore = function () {
- currentScore = 0;
- return currentScore;
- };
- self.getScore = function () {
- return currentScore;
- };
- self.getHighScore = function () {
- return highScore;
- };
-};
-var birds = [];
-game.down = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); // Use layer manager to set reticle layer
+ }, {
+ key: "destroy",
+ value: function destroy() {
+ this.movement = null;
+ _superPropGet(Tree2, "destroy", this, 3)([]);
}
+ }]);
+}(GameObject);
+var UFO1 = /*#__PURE__*/function (_GameObject16) {
+ function UFO1() {
+ var _this17;
+ _classCallCheck2(this, UFO1);
+ _this17 = _callSuper(this, UFO1, ['ufo1']);
+ _this17.type = 'ufo1';
+ _this17.movement = new GameObjectMovement(_this17, _this17.graphics, GameObjectMovement.MovementConfigs.ufo1);
+ _this17.soundPlayed = false;
+ return _this17;
}
- game.reticle.x = x;
- game.reticle.y = y;
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(laser, LAYERS.LASER); // Use layer manager to set laser layer
+ _inherits(UFO1, _GameObject16);
+ return _createClass2(UFO1, [{
+ key: "update",
+ value: function update() {
+ _superPropGet(UFO1, "update", this, 3)([]);
+ if (!this.soundPlayed && this.x > 0 && this.x < 2048) {
+ LK.getSound('ufo1').play();
+ this.soundPlayed = true;
+ }
+ }
+ }]);
+}(GameObject);
+var UFO2 = /*#__PURE__*/function (_GameObject17) {
+ function UFO2() {
+ var _this18;
+ _classCallCheck2(this, UFO2);
+ _this18 = _callSuper(this, UFO2, ['ufo2']);
+ _this18.type = 'ufo2';
+ _this18.movement = new GameObjectMovement(_this18, _this18.graphics, GameObjectMovement.MovementConfigs.ufo2);
+ _this18.soundPlayed = false;
+ return _this18;
}
-};
-game.move = function (x, y, obj) {
- if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
+ _inherits(UFO2, _GameObject17);
+ return _createClass2(UFO2, [{
+ key: "update",
+ value: function update() {
+ _superPropGet(UFO2, "update", this, 3)([]);
+ if (!this.soundPlayed && this.x > 0 && this.x < 2048) {
+ LK.getSound('ufo1').play();
+ this.soundPlayed = true;
+ }
+ }
+ }]);
+}(GameObject);
+var GameObjectMovement = /*#__PURE__*/function () {
+ function GameObjectMovement(object, graphics) {
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
+ _classCallCheck2(this, GameObjectMovement);
+ this.object = object;
+ this.graphics = graphics;
+ this.options = _objectSpread(_objectSpread({}, GameObjectMovement.defaultOptions), options);
+ this.speed = this.options.speed + Math.random() * this.options.speedRange;
+ this.direction = Math.random() < 0.5 ? 1 : -1;
+ this.lastX = this.object.x;
+ this.lastY = this.object.y;
+ this.soundPlayed = false;
+ this.soundTimer = null;
+ this.movementOffset = Math.random() * Math.PI * 2; // Random starting phase for smoother movement
}
- if (obj.event) {
- var x = obj.event.x;
- var y = obj.event.y;
- }
- game.reticle.x = x;
- game.reticle.y = y;
-};
-// Add a sun to the game in the top left corner
-var sun = new Sun();
-sun.x = 480;
-sun.y = 680;
-game.layerManager.addToLayer(sun, LAYERS.SUN);
-var light1 = new Light1();
-light1.x = 510;
-light1.y = 1500;
-game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
-light1.visible = true;
-// Function to add a UFO to the game
-function addUFO() {
- var ufo = new UFO1();
- game.addChild(ufo);
- game.layerManager.addToLayer(ufo, LAYERS.UFO1);
- ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2;
- ufo.y = Math.random() * (2732 / 2 - ufo.height);
- ufo.customUpdate = function () {
- if (!ufo.soundPlayed && ufo.x > 0 && ufo.x < 2048) {
- LK.getSound('ufo1').play();
- ufo.soundPlayed = true;
- } else if (ufo.soundPlayed && (ufo.x <= 0 || ufo.x >= 2048)) {
- LK.getSound('ufo1').stop();
- ufo.soundPlayed = false;
+ return _createClass2(GameObjectMovement, [{
+ key: "update",
+ value: function update() {
+ if (!this.object || this.object.destroyed) {
+ this.cleanup();
+ return;
+ }
+ var _this$object = this.object,
+ currentX = _this$object.x,
+ currentY = _this$object.y,
+ width = _this$object.width,
+ height = _this$object.height;
+ var halfWidth = width / 2;
+ var _this$options = this.options,
+ isVertical = _this$options.isVertical,
+ arcFrequency = _this$options.arcFrequency,
+ arcAmplitude = _this$options.arcAmplitude,
+ screenWidth = _this$options.screenWidth,
+ screenHeight = _this$options.screenHeight;
+ if (isVertical) {
+ this.object.y += this.speed;
+ // Enhanced sinusoidal movement with optimized calculations
+ var phaseOffset = currentY / arcFrequency + this.movementOffset;
+ this.object.x += Math.sin(phaseOffset) * arcAmplitude;
+ if (currentY > screenHeight + height) {
+ this.cleanup();
+ return;
+ }
+ } else {
+ // Optimized horizontal movement with wave pattern
+ this.object.x += this.speed * this.direction;
+ if (arcAmplitude > 0) {
+ var phaseOffset = currentX / arcFrequency + this.movementOffset;
+ this.object.y += Math.sin(phaseOffset) * (arcAmplitude * 0.5);
+ }
+ var isOutOfBounds = currentX <= screenWidth + halfWidth && this.object.x > screenWidth + halfWidth || currentX >= -halfWidth && this.object.x < -halfWidth;
+ if (isOutOfBounds) {
+ this.cleanup();
+ return;
+ }
+ }
+ if (this.options.canFlip) {
+ flipImageVerticallyBasedOnDirection(this.graphics, currentX, this.object.x);
+ }
+ if (this.options.moveSound && !this.soundPlayed && this.object.x > 0 && this.object.x < this.options.screenWidth) {
+ this.playMovementSound();
+ }
+ this.lastX = this.object.x;
+ this.lastY = this.object.y;
}
- ufo.update();
- };
- return ufo;
-}
-// Initialize clouds array
-var clouds = [];
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-function initializeClouds() {
- function ensureCloudCount() {
- // Remove off-screen clouds
- clouds = clouds.filter(function (cloud) {
- if (cloud.x < -cloud.width || cloud.x > 2048 + cloud.width) {
- cloud.destroy();
- return false;
+ }, {
+ key: "cleanup",
+ value: function cleanup() {
+ if (!this.object || this.object.destroyed) {
+ return;
}
- return true;
- });
- // Add new clouds if needed
- while (clouds.length < 5) {
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * (2732 / 2);
- game.addChild(cloud);
- game.layerManager.addToLayer(cloud, clouds.length < 3 ? LAYERS.CLOUD1 : LAYERS.CLOUD2);
- clouds.push(cloud);
+ var moveSound = this.options.moveSound;
+ var soundManager = game.soundManager,
+ spawnManager = game.spawnManager;
+ // Stop movement sound if active
+ if (moveSound && soundManager) {
+ soundManager.stopSound(moveSound);
+ }
+ // Destroy object and schedule respawn
+ this.object.destroy();
+ if (spawnManager !== null && spawnManager !== void 0 && spawnManager.scheduleRespawn) {
+ spawnManager.scheduleRespawn(this.object.type, this.object.constructor);
+ }
+ // Clear references
+ this.object = null;
+ this.soundTimer = null;
+ this.soundPlayed = false;
}
+ }, {
+ key: "playMovementSound",
+ value: function playMovementSound() {
+ var _this19 = this;
+ var moveSound = this.options.moveSound;
+ if (!moveSound || !game.soundManager) {
+ return;
+ }
+ game.soundManager.playSound(moveSound, {
+ volume: 0.1,
+ interval: {
+ min: 20000,
+ max: 30000
+ },
+ onPlay: function onPlay() {
+ _this19.soundPlayed = true;
+ },
+ onStop: function onStop() {
+ _this19.soundPlayed = false;
+ _this19.soundTimer = null;
+ }
+ });
+ }
+ }]);
+}();
+_GameObjectMovement = GameObjectMovement;
+_defineProperty(GameObjectMovement, "MovementConfigs", {
+ base: {
+ speed: 2,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: false,
+ canFlip: true,
+ moveSound: null,
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ screenWidth: 2048,
+ screenHeight: 2732
+ },
+ bird1: {
+ speed: 2,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: true,
+ moveSound: 'wings1'
+ },
+ bird2: {
+ speed: 2.5,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: true,
+ moveSound: 'wings1'
+ },
+ ufo1: {
+ speed: 3.2,
+ speedRange: 0.8,
+ arcAmplitude: 4.5,
+ arcFrequency: 80,
+ isVertical: false,
+ moveSound: 'ufo1'
+ },
+ ufo2: {
+ speed: 3.2,
+ speedRange: 0.8,
+ arcAmplitude: 4.5,
+ arcFrequency: 80,
+ isVertical: false,
+ moveSound: 'ufo1'
+ },
+ jet1: {
+ speed: 10,
+ speedRange: 0,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: true,
+ moveSound: 'jet1'
+ },
+ cloud1: {
+ speed: 0.25,
+ speedRange: 0.55,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: false
+ },
+ cloud2: {
+ speed: 0.25,
+ speedRange: 0.55,
+ arcAmplitude: 0,
+ arcFrequency: 0,
+ isVertical: false,
+ canFlip: false
+ },
+ 'grass-front': {
+ speed: 0,
+ speedRange: 0,
+ arcAmplitude: 1.2,
+ arcFrequency: 120,
+ isVertical: false,
+ moveSound: null,
+ canFlip: false
+ },
+ 'grass-back': {
+ speed: 0,
+ speedRange: 0,
+ arcAmplitude: 0.8,
+ arcFrequency: 150,
+ isVertical: false,
+ moveSound: null,
+ canFlip: false
}
- // Initial cloud setup
- ensureCloudCount();
- // Check cloud count every second
- LK.setInterval(ensureCloudCount, 1000);
+});
+_defineProperty(GameObjectMovement, "defaultOptions", _GameObjectMovement.MovementConfigs.base);
+;
+// Cloud class already defined above
+function _typeof(o) {
+ "@babel/helpers - typeof";
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
+ return typeof o;
+ } : function (o) {
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
+ }, _typeof(o);
}
-// Call initializeClouds after game initialization
-initializeClouds();
-var bird1; // Define bird1 variable in the global scope
-var bird; // Define bird variable in the global scope
-// Initialize birds and score
-var birds = [];
-var score = 0;
-// Initialize ambient sounds timer
-function initializeAmbientSounds() {
- function playAmbientSounds() {
- LK.getSound('songbird1').play();
- LK.getSound('cricket1').play();
- LK.setTimeout(playAmbientSounds, Math.random() * 10000 + 20000);
+function _classCallCheck(a, n) {
+ if (!(a instanceof n)) {
+ throw new TypeError("Cannot call a class as a function");
}
- playAmbientSounds();
}
-// Initialize background music timer
-function initializeBGM() {
- function playBGM() {
- LK.playMusic('bgm1');
- LK.setTimeout(playBGM, Math.random() * 10000 + 20000);
+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);
}
- playBGM();
}
-// Start the game
-spawnBird1();
-spawnBird2();
-initializeAmbientSounds();
-initializeBGM();
-// Initialize variables for UFOs and laser
-var ufo1, ufo2, laser;
-var score = 0;
-// Initialize timers for UFOs with 20-30 second respawn
-function initializeUFOTimers() {
- // UFO1 Timer
- function spawnUFO1() {
- if (!game.children.some(function (c) {
- return c instanceof UFO1;
- })) {
- ufo1 = addUFO();
- }
- LK.setTimeout(spawnUFO1, Math.random() * 10000 + 20000);
+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;
}
- spawnUFO1();
- // UFO2 Timer
- function spawnUFO2() {
- if (!game.children.some(function (c) {
- return c instanceof UFO2;
- })) {
- ufo2 = new UFO2();
- game.addChild(ufo2);
- game.layerManager.addToLayer(ufo2, LAYERS.UFO2);
- ufo2.x = Math.random() < 0.5 ? 2048 + ufo2.width / 2 : -ufo2.width / 2;
- ufo2.y = Math.random() * (2732 / 2 - ufo2.height);
+ var e = t[Symbol.toPrimitive];
+ if (void 0 !== e) {
+ var i = e.call(t, r || "default");
+ if ("object" != _typeof(i)) {
+ return i;
}
- LK.setTimeout(spawnUFO2, Math.random() * 10000 + 20000);
+ throw new TypeError("@@toPrimitive must return a primitive value.");
}
- spawnUFO2();
+ return ("string" === r ? String : Number)(t);
}
-initializeUFOTimers();
-var originalUpdate = game.update;
-game.update = function () {
- // Call the original update function first
- originalUpdate.call(this);
- // Update clouds
- for (var i = 0; i < clouds.length; i++) {
- clouds[i].update();
+/*****
+* Layer Constants
+******/
+var LAYERS = {
+ BACKGROUND: 0,
+ SUN: 1,
+ LIGHT1: 2,
+ UFO2: 3,
+ CLOUD1: 4,
+ JET1: 5,
+ CLOUD2: 6,
+ UFO1: 7,
+ BIRD1: 8,
+ GRASS_BACK: 9,
+ TREE: 10,
+ STACK: 11,
+ BIRD2: 12,
+ MIRROR: 13,
+ GRASS_FRONT: 14,
+ CAT: 15,
+ LASER: 16,
+ RETICLE: 17
+};
+// Initialize LayerManager
+var layerManager = new LayerManager();
+game.layerManager = layerManager;
+// Cloud management is now handled by SpawnManager
+// Initialize birds array for tracking
+var birds = [];
+var score = 0;
+var mirror = new Mirror();
+mirror.x = 2048 / 2 + 400;
+mirror.y = 2732 - 185 - 80 - 390 + 30 + 50;
+game.layerManager.addToLayer(mirror, LAYERS.MIRROR);
+game.mirror = mirror;
+var scoreDisplay = mirror;
+var soundManager = new SoundManager();
+soundManager.initialize();
+// Initialize spawn manager
+// Ensure all entities use LayerManager consistently
+function addEntityToLayer(entity, layer) {
+ if (!entity || !layer) {
+ console.error('Invalid entity or layer provided to addEntityToLayer');
+ return entity;
}
- // Update each bird
- birds.forEach(function (bird) {
- bird.update();
- // Check if the bird has moved off-screen
- if (bird.lastY <= 2732 && bird.y > 2732) {
- bird.y = -bird.height; // Respawn the bird at the top
- bird.x = Math.random() * 2048; // Randomize the x position
- bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
+ game.layerManager.addToLayer(entity, layer);
+ if (!game.children.includes(entity)) {
+ game.addChild(entity);
+ }
+ return entity;
+}
+var _SpawnManager = function SpawnManager() {
+ this.spawnTimers = {};
+ this.spawnRules = {
+ bird1: {
+ max: 1,
+ layer: LAYERS.BIRD1,
+ movement: Bird1Movement,
+ scoreValue: 5
+ },
+ bird2: {
+ min: 3,
+ max: 3,
+ layer: LAYERS.BIRD2,
+ movement: Bird2Movement,
+ scoreValue: 1
+ },
+ cloud1: {
+ min: 1,
+ max: 3,
+ layer: LAYERS.CLOUD1,
+ movement: CloudMovement
+ },
+ cloud2: {
+ min: 1,
+ max: 3,
+ layer: LAYERS.CLOUD2,
+ movement: CloudMovement
+ },
+ // Ensure 3-5 total clouds
+ ufo1: {
+ max: 1,
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ layer: LAYERS.UFO1,
+ movement: UFOMovement,
+ sound: 'ufo1',
+ scoreValue: 25
+ },
+ ufo2: {
+ max: 1,
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ layer: LAYERS.UFO2,
+ movement: UFOMovement,
+ sound: 'ufo1',
+ scoreValue: 25
+ },
+ jet1: {
+ max: 1,
+ respawnTime: {
+ min: 20000,
+ max: 30000
+ },
+ layer: LAYERS.JET1,
+ movement: GameObjectMovement,
+ sound: 'jet1'
}
+ };
+ // Initialize sound manager with ambient sounds configuration
+ this.soundManager = new SoundManager({
+ ambient: {
+ breeze1: {
+ volume: 0.1,
+ interval: {
+ min: 15000,
+ max: 25000
+ }
+ },
+ cricket1: {
+ volume: 0.1,
+ interval: {
+ min: 10000,
+ max: 20000
+ }
+ },
+ frog1: {
+ volume: 0.1,
+ interval: {
+ min: 20000,
+ max: 30000
+ }
+ },
+ songbird1: {
+ volume: 0.1,
+ interval: {
+ min: 15000,
+ max: 25000
+ }
+ }
+ }
});
- // Update UFO and check for collisions
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
+ this.scoreManager = new ScoreManager();
+ this.exclusiveGroups = [['ufo1', 'ufo2']];
+ // Correct layer order as per requirements
+ this.layerOrder = game.layerManager.getLayerOrder();
+ this.spawnObject = function (type, Constructor, options) {
+ var _this20 = this;
+ var rule = this.spawnRules[type];
+ if (!rule) {
+ return;
+ }
+ var count = this.objectCounts[type] || 0;
+ var maxCount = rule.max || 1;
+ // Early exit conditions
+ if (count >= maxCount) {
+ return;
+ }
+ // Check exclusive groups (UFO1 and UFO2)
+ if (this.exclusiveGroups.some(function (group) {
+ if (group.includes(type)) {
+ return group.some(function (groupType) {
+ return _this20.objectCounts[groupType] > 0;
+ });
+ }
+ return false;
+ })) {
+ return;
+ }
+ // Handle minimum count requirements
+ if (rule.min && count < rule.min) {
+ while (count < rule.min) {
+ this.createObject(type, Constructor, rule);
+ count++;
+ }
+ return;
+ }
+ // Ensure proper cloud count (3-5 total)
+ if (type === 'cloud1' || type === 'cloud2') {
+ var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2);
+ if (totalClouds >= 5) {
+ return;
+ }
+ if (totalClouds < 3) {
+ while (totalClouds < 3) {
+ this.createObject(type, Constructor, rule);
+ totalClouds++;
+ }
+ return;
+ }
+ }
+ // Ensure proper bird counts
+ if (type === 'bird1' && count >= 1) {
+ return;
+ } // Max 1 bird1
+ if (type === 'bird2' && count >= 3) {
+ return;
+ } // Max 3 bird2
+ // Create object with respawn timer for specific types
+ this.createObject(type, Constructor, rule);
+ if (rule.respawnTime) {
+ var respawnDelay = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min;
+ this.spawnTimers[type] = LK.setTimeout(function () {
+ delete _this20.spawnTimers[type];
+ _this20.spawnObject(type, Constructor, options);
+ }, respawnDelay);
+ }
+ };
+ this.createObject = function (type, Constructor, rule) {
+ if (!Constructor || !rule) {
+ return null;
+ }
+ var obj = new Constructor();
+ obj.type = type;
+ // Initialize position based on object type
+ var screenWidth = 2048;
+ var screenHeight = 2732;
+ var isVerticalMovement = type.startsWith('bird');
+ obj.x = isVerticalMovement ? Math.random() * screenWidth : Math.random() < 0.5 ? screenWidth + obj.width / 2 : -obj.width / 2;
+ obj.y = isVerticalMovement ? -obj.height : Math.random() * (screenHeight / 2);
+ // Add to appropriate layer using addEntityToLayer
+ addEntityToLayer(obj, rule.layer);
+ // Initialize movement with appropriate options
+ if (rule.movement) {
+ // Get movement configuration based on object type
+ var params = GameObjectMovement.MovementConfigs[type] || GameObjectMovement.MovementConfigs.base;
+ // Create movement options with the selected parameters
+ var movementOptions = _objectSpread(_objectSpread({}, params), {}, {
+ moveSound: rule.sound || params.moveSound,
+ respawnTime: rule.respawnTime
+ });
+ obj.movement = new rule.movement(obj, obj.children[0], movementOptions);
+ }
+ if (rule.respawnTime) {
+ this.scheduleRespawn(type, Constructor);
+ }
+ return obj;
+ };
+ this.scheduleRespawn = function (type, Constructor) {
+ if (!type || !Constructor || !this.spawnRules) {
+ return;
+ }
+ var rule = this.spawnRules[type];
+ if (!rule) {
+ return;
+ }
+ // Ensure respawn timers for ufo1, ufo2, and jet1 are set to 20-30 seconds
+ var respawnTime;
+ if (type === 'ufo1' || type === 'ufo2' || type === 'jet1') {
+ respawnTime = Math.random() * 10000 + 20000; // 20-30 seconds
+ } else if (rule.respawnTime) {
+ respawnTime = Math.random() * (rule.respawnTime.max - rule.respawnTime.min) + rule.respawnTime.min;
+ } else {
+ respawnTime = Math.random() * 10000 + 5000; // Default 5-15 seconds
+ }
+ // Clear existing timer if present
+ if (this.spawnTimers[type]) {
+ LK.clearTimeout(this.spawnTimers[type]);
+ this.spawnTimers[type] = null;
+ }
+ // Initialize object counts if not present
+ if (!this.objectCounts[type]) {
+ this.objectCounts[type] = 0;
+ }
+ this.spawnTimers[type] = LK.setTimeout(function () {
+ // Cleanup timer reference
+ delete this.spawnTimers[type];
+ // Update object count
+ if (this.objectCounts[type] > 0) {
+ this.objectCounts[type]--;
+ }
+ var shouldSpawn = true;
+ // Check exclusive groups (e.g., only one UFO type at a time)
+ if (this.exclusiveGroups) {
+ for (var i = 0; i < this.exclusiveGroups.length; i++) {
+ var group = this.exclusiveGroups[i];
+ if (group && group.includes(type)) {
+ var groupTotal = 0;
+ for (var j = 0; j < group.length; j++) {
+ groupTotal += this.objectCounts[group[j]] || 0;
}
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
+ if (groupTotal > 0) {
+ shouldSpawn = false;
+ break;
+ }
}
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
- });
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
}
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
}
- });
+ if (shouldSpawn) {
+ this.spawnObject(type, Constructor);
+ } else {
+ // Reschedule spawn attempt if blocked by exclusive group
+ this.scheduleRespawn(type, Constructor);
+ }
+ }.bind(this), respawnTime);
+ // Start the game
+ var spawnManager = new _SpawnManager();
+ spawnManager.initialize();
+ this.initialize = function () {
+ // Initialize birds - exactly 1 Bird1 and 3 Bird2s
+ this.spawnObject('bird1', Bird1);
+ for (var i = 0; i < this.spawnRules.bird2.min; i++) {
+ this.spawnObject('bird2', Bird2);
+ }
+ // Initialize clouds - ensure 3-5 total clouds
+ var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3;
+ var cloud1ToSpawn = Math.min(totalCloudsToSpawn, this.spawnRules.cloud1.max);
+ var cloud2ToSpawn = totalCloudsToSpawn - cloud1ToSpawn;
+ for (var i = 0; i < cloud1ToSpawn; i++) {
+ this.spawnObject('cloud1', Cloud);
+ }
+ for (var i = 0; i < cloud2ToSpawn; i++) {
+ this.spawnObject('cloud2', Cloud);
+ }
+ // Initialize UFOs and Jet with respawn timers
+ // Randomly choose between UFO1 and UFO2
+ if (Math.random() < 0.5) {
+ this.spawnObject('ufo1', UFO1);
+ } else {
+ this.spawnObject('ufo2', UFO2);
+ }
+ this.spawnObject('jet1', Jet1);
+ // Set up periodic check for object counts and layer ordering
+ LK.setInterval(function () {
+ // Update layer ordering
+ game.layerManager.getLayerOrder().forEach(function (layerId, index) {
+ var objects = game.layerManager.getObjectsInLayer(layerId);
+ objects.forEach(function (obj) {
+ game.layerManager.setLayerIndex(obj, index);
+ });
+ }.bind(this));
+ // Maintain bird counts
+ if (game.layerManager.getLayerEntityCount(LAYERS.BIRD1) < 1) {
+ this.spawnObject('bird1', Bird1);
+ }
+ while (game.layerManager.getLayerEntityCount(LAYERS.BIRD2) < 3) {
+ this.spawnObject('bird2', Bird2);
+ }
+ // Maintain cloud counts - ensure 3-5 total clouds
+ var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2);
+ if (totalClouds < 3) {
+ var cloudsNeeded = 3 - totalClouds;
+ for (var i = 0; i < cloudsNeeded; i++) {
+ if (Math.random() < 0.5 && game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) < this.spawnRules.cloud1.max) {
+ this.spawnObject('cloud1', Cloud);
+ } else if (game.layerManager.getLayerEntityCount(LAYERS.CLOUD2) < this.spawnRules.cloud2.max) {
+ this.spawnObject('cloud2', Cloud);
+ }
+ }
+ } else if (totalClouds > 5) {
+ // If there are more than 5 clouds, don't spawn any more until some are removed
+ // This is handled automatically when clouds move off-screen
+ }
+ // Ensure one UFO (either UFO1 or UFO2) is on screen
+ if (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) {
+ if (Math.random() < 0.5) {
+ this.spawnObject('ufo1', UFO1);
+ } else {
+ this.spawnObject('ufo2', UFO2);
+ }
+ }
+ // Ensure one jet is on screen
+ if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) {
+ this.spawnObject('jet1', Jet1);
+ }
+ }.bind(this), 1000);
+ }.bind(this);
+ };
+ var spawnManager = new _SpawnManager();
+ // Initialize the spawn manager
+ _SpawnManager.prototype.initialize = function () {
+ // Initialize sound and score managers
+ this.soundManager.initialize();
+ // Set up initial spawns with consistent behavior
+ this.spawnObject('bird1', Bird1);
+ for (var i = 0; i < this.spawnRules.bird2.min; i++) {
+ this.spawnObject('bird2', Bird2);
+ }
+ };
+ // Set up cloud spawning - 3-5 total clouds
+ var totalCloudsToSpawn = Math.floor(Math.random() * 3) + 3;
+ var cloud1ToSpawn = Math.min(totalCloudsToSpawn, this.spawnRules.cloud1.max);
+ var cloud2ToSpawn = totalCloudsToSpawn - cloud1ToSpawn;
+ for (var i = 0; i < cloud1ToSpawn; i++) {
+ this.spawnObject('cloud1', Cloud);
+ }
+ for (var i = 0; i < cloud2ToSpawn; i++) {
+ this.spawnObject('cloud2', Cloud);
+ }
+ // Schedule initial UFO and Jet spawns
+ if (Math.random() < 0.5) {
+ this.spawnObject('ufo1', UFO1);
} else {
- // If there's no UFO, try to spawn one
- ufo = addUFO();
+ this.spawnObject('ufo2', UFO2);
}
+ this.spawnObject('jet1', Jet1);
+ // Set up periodic checks for maintaining entity counts
+ LK.setInterval(function () {
+ // Maintain bird counts
+ if (this.objectCounts.bird1 < 1) {
+ this.spawnObject('bird1', Bird1);
+ }
+ while (this.objectCounts.bird2 < 3) {
+ this.spawnObject('bird2', Bird2);
+ }
+ // Maintain cloud counts (3-5 total)
+ var totalClouds = game.layerManager.getLayerEntityCount(LAYERS.CLOUD1) + game.layerManager.getLayerEntityCount(LAYERS.CLOUD2);
+ if (totalClouds < 3) {
+ var type = Math.random() < 0.5 ? 'cloud1' : 'cloud2';
+ this.spawnObject(type, Cloud);
+ }
+ // Ensure one UFO (either UFO1 or UFO2) is scheduled
+ if (game.layerManager.getLayerEntityCount(LAYERS.UFO1) + game.layerManager.getLayerEntityCount(LAYERS.UFO2) === 0 && !this.spawnTimers.ufo1 && !this.spawnTimers.ufo2) {
+ var ufoType = Math.random() < 0.5 ? 'ufo1' : 'ufo2';
+ this.scheduleRespawn(ufoType, ufoType === 'ufo1' ? UFO1 : UFO2);
+ }
+ // Ensure one Jet1 is scheduled
+ if (game.layerManager.getLayerEntityCount(LAYERS.JET1) === 0 && !this.spawnTimers.jet1) {
+ this.scheduleRespawn('jet1', Jet1);
+ }
+ }.bind(this), 1000);
};
-function spawnBird1() {
- if (!birds.some(function (b) {
- return b instanceof Bird1;
- })) {
- var bird1 = new Bird1();
- bird1.x = Math.random() * 2048;
- bird1.y = -bird1.height;
- bird1.speed = Math.random() * 1.6 + 1;
- bird1.lastIntersecting = false;
- bird1.type = 'bird1';
- bird1.color = 0x746130;
- game.addChild(bird1);
- game.layerManager.addToLayer(bird1, LAYERS.BIRD1);
- birds.push(bird1);
- LK.setTimeout(function () {
- if (!birds.some(function (b) {
- return b instanceof Bird1;
- })) {
- spawnBird1();
+spawnManager.initialize();
+// Main game update function
+game.update = function () {
+ // Update all game objects
+ game.children.forEach(function (entity) {
+ if (entity.update) {
+ entity.update();
+ }
+ // Handle off-screen objects
+ if (game.layerManager.isInLayer(entity, LAYERS.BIRD1) || game.layerManager.isInLayer(entity, LAYERS.BIRD2)) {
+ if (entity.y > 2732) {
+ entity.y = -entity.height;
+ entity.x = Math.random() * 2048;
}
- }, Math.random() * 10000 + 20000);
+ }
+ });
+ // Update score display
+ if (game.mirror && game.mirror.updateScore) {
+ game.mirror.updateScore(game.score || 0);
}
-}
-function spawnBird2() {
- if (birds.filter(function (b) {
- return b instanceof Bird2;
- }).length < 3) {
- var bird = new Bird2();
- bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half
- bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- bird.speed = 1 + Math.random() * 0.6;
- bird.lastIntersecting = false;
- bird.type = 'bird2'; // Specific property for Bird2
- bird.color = 0xFFFFFF; // Specific color for Bird2
- LK.setTimeout(function () {
- game.addChild(bird);
- // Ensure bird is added to the game before setting its index
- if (game.children.includes(bird)) {
- game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1
- }
- birds.push(bird);
- }, 2000);
- }
-}
-// Update the main game update function to include bird updates
-var originalUpdate = game.update;
-game.update = function () {
- // Call the original update function first
- originalUpdate.call(this);
- // Update each bird
- birds.forEach(function (bird) {
- bird.update();
- // Check if the bird has moved off-screen
- if (bird.lastY <= 2732 && bird.y > 2732) {
- bird.y = -bird.height; // Respawn the bird at the top
- bird.x = Math.random() * 2048; // Randomize the x position
- bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
+ // Ensure correct number of birds using SpawnManager
+ spawnManager.spawnObject('bird1', Bird1);
+ spawnManager.spawnObject('bird2', Bird2);
+ // Update UFOs and play sounds
+ game.children.forEach(function (entity) {
+ if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
+ LK.getSound('ufo1').play();
+ entity.soundPlayed = true;
}
});
- // Update UFO and check for collisions
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
- });
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
- }
+ // Update each laser and check collisions
+ game.children.forEach(function (laser) {
+ if (laser instanceof Laser) {
+ laser.update();
+ checkLaserCollisions(laser);
+ }
+ });
+};
+// Removed redundant checkAndRespawnBirds function as it's handled by SpawnManager
+// Update bird positions and states
+function updateGameBirds() {
+ maintainBirdCount(Bird1, 1, LAYERS.BIRD1);
+ maintainBirdCount(Bird2, 3, LAYERS.BIRD2);
+}
+function maintainBirdCount(BirdType, targetCount, layerIndex) {
+ var birdCount = game.layerManager.getLayerGroup('birds').length;
+ if (birdCount < targetCount) {
+ for (var i = 0; i < targetCount - birdCount; i++) {
+ var newBird = new BirdType();
+ newBird.x = Math.random() * 2048;
+ newBird.y = Math.random() * (2732 / 2);
+ newBird.speed = 1 + Math.random() * 0.6;
+ game.layerManager.addToLayer(newBird, layerIndex);
+ birds.push(newBird);
+ }
+ } else if (birdCount > targetCount) {
+ var extraBirds = birds.filter(function (b) {
+ return game.layerManager.isInLayer(b, 'birds');
+ }).slice(targetCount);
+ extraBirds.forEach(function (b) {
+ b.destroy();
+ birds.splice(birds.indexOf(b), 1);
});
}
-};
+}
+// Update existing birds
+birds.forEach(function (bird) {
+ bird.update();
+ if (bird.lastY <= 2732 && bird.y > 2732) {
+ bird.y = -bird.height;
+ bird.x = Math.random() * 2048;
+ bird.speed = 1 + Math.random() * 0.6;
+ }
+});
+// Maintain bird counts
+maintainBirdCount(Bird1, 1, LAYERS.BIRD1);
+maintainBirdCount(Bird2, 3, LAYERS.BIRD2);
+// Update UFOs and play sounds
+game.children.forEach(function (entity) {
+ if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
+ LK.getSound('ufo1').play();
+ entity.soundPlayed = true;
+ }
+});
+// Update each laser and check collisions
+game.children.forEach(function (laser) {
+ if (laser instanceof Laser) {
+ laser.update();
+ checkLaserCollisions(laser);
+ }
+});
// Add a tree to the game
-var tree = game.addChild(new Tree());
+var tree = addEntityToLayer(new Tree(), LAYERS.TREE);
tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
tree.y = 2500; // Position the tree on the grass
-// Ensure tree is added to the game before setting its index
-if (game.children.includes(tree) && game.children.includes(bird1)) {
- game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
+// Add tree to the proper layer
+if (game.children.includes(tree)) {
+ game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer
}
var score = 0;
// Add stack1 image to the game
-var stack1 = game.addChild(new Stack1());
+var stack1 = addEntityToLayer(new Stack1(), LAYERS.STACK);
stack1.x = 1700; // Move 700px to the right
stack1.y = 2250; // Move down by 800px
-// Ensure stack1 is added to the game before setting its index
-if (game.children.includes(stack1) && game.children.includes(tree)) {
- game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
+// Add stack1 to the proper layer
+if (game.children.includes(stack1)) {
+ game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer
}
-// Add the grass floor to the game
-var grassBack = new GrassBack();
-grassBack.x = 1020;
-grassBack.y = 2735; // Position grassBack at the bottom
-game.addChild(grassBack);
-// Ensure grassBack is added to the game before setting its index
-if (game.children.includes(grassBack)) {
- // Make sure we don't set an index that's out of bounds
- var safeIndex = Math.min(5, game.children.length - 1);
- game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely
-}
-var grassFront = new GrassFront();
-grassFront.x = 1020;
-grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
-game.addChild(grassFront);
-// Ensure grassFront is added to the game before setting its index
-if (game.children.includes(grassFront) && game.children.includes(bird2)) {
- game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
-}
var scoreDisplay = new Mirror();
scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px
-game.addChild(scoreDisplay);
+addEntityToLayer(scoreDisplay, LAYERS.UI);
var mirror = new Mirror();
mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
-game.addChild(mirror);
-// Ensure mirror is added to the game before setting its index
-if (game.children.includes(mirror) && game.children.includes(stack1)) {
- game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
+game.layerManager.addToLayer(mirror, LAYERS.MIRROR);
+// Add mirror to the proper layer
+if (game.children.includes(mirror)) {
+ game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer
}
-// Ensure laser is added to the game before setting mirror's index
-if (game.children.includes(laser) && game.children.includes(mirror)) {
- game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
-}
// Function to handle bgm1 end event
function onBgm1End() {
// Set a timer to replay bgm1 after 50-80 seconds
var bgmTimer = LK.setTimeout(function () {
@@ -1239,40 +1745,35 @@
}, Math.random() * 30000 + 50000);
}
;
// Add the cat to the game
-var cat = game.addChild(new Cat());
+var cat = addEntityToLayer(new Cat(), LAYERS.CAT);
cat.x = 230; // Move the cat 20px to the left
cat.y = 2732; // Position the cat at the bottom of the screen
-// Ensure cat is added to the game before setting its index
+// Add cat to the proper layer
if (game.children.includes(cat)) {
- game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+ game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer
}
-// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
+// Play bgm1 once on load and set a timer to replay it every 20-30 seconds
LK.playMusic('bgm1', {
loop: false,
- // Play once
fade: {
start: 0,
- end: 0.02,
- // Set to the lowest volume
+ end: 0.1,
duration: 4000
},
onEnd: function onEnd() {
- // Set a timer to replay bgm1 every 20-50 seconds
LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: false,
- // Play once
fade: {
start: 0,
- end: 0.5,
- // Set to the lowest volume
+ end: 0.1,
duration: 4000
},
- onEnd: onEnd // Set the onEnd function to replay bgm1
+ onEnd: onEnd
});
- }, Math.random() * 10000 + 20000); // Random time between 20-30 seconds
+ }, Math.random() * 10000 + 20000);
}
});
// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
var wingsTimer = LK.setTimeout(function () {
@@ -1282,125 +1783,112 @@
// Create an array for all sounds except ufo1, including all birdsong sounds
var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
var currentAmbientSound = null;
// Sound volumes configuration
-// Initialize random timers for each sound to play between 30-50 seconds
+// Initialize random timers for each sound to play between 20-30 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
- currentAmbientSound.stop(); // Stop the currently playing ambient sound
+ currentAmbientSound.stop();
}
sound.play();
- currentAmbientSound = sound; // Set the current ambient sound
- // Set a timeout to reset the current ambient sound after it finishes playing
+ currentAmbientSound = sound;
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);
+ }, sound.duration * 1000);
+ ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000);
+ }, Math.random() * 10000 + 20000);
});
// Using UFO sound ID as placeholder
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-var SunPulse = function SunPulse(sunGraphics) {
- this.sunGraphics = sunGraphics;
+// Using existing CLOUD_TYPES definition
+var Pulse = function Pulse(graphics, options) {
+ this.graphics = graphics;
+ this.options = Object.assign({
+ minScale: 1.0,
+ maxScale: 1.2,
+ expandDuration: 1000,
+ contractDuration: 1000,
+ easing: tween.easeInOut
+ }, options);
this.startPulsating = function () {
function pulsate() {
- tween(this.sunGraphics, {
- scaleX: 1.1,
- scaleY: 1.1
+ tween(this.graphics, {
+ scaleX: this.options.maxScale,
+ scaleY: this.options.maxScale
}, {
- duration: 1000,
- easing: tween.easeInOut,
+ duration: this.options.expandDuration,
+ easing: this.options.easing,
onFinish: function () {
- tween(this.sunGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
+ tween(this.graphics, {
+ scaleX: this.options.minScale,
+ scaleY: this.options.minScale
}, {
- duration: 1000,
- easing: tween.easeInOut,
+ duration: this.options.contractDuration,
+ easing: this.options.easing,
onFinish: pulsate.bind(this)
});
}.bind(this)
});
}
pulsate.call(this);
};
};
+var SunPulse = function SunPulse(sunGraphics) {
+ return new Pulse(sunGraphics, {
+ maxScale: 1.1
+ });
+};
// Light1Pulse class to handle the pulsating effect for Light1
-var Light1Pulse = function Light1Pulse(lightGraphics) {
- this.lightGraphics = lightGraphics;
+var Light1Pulse = function Light1Pulse(graphics) {
+ ;
+ this.graphics = graphics;
+ this.pulseTimer = null;
this.startPulsating = function () {
- function pulsate() {
- tween(this.lightGraphics, {
- scaleX: 1.6,
- scaleY: 1.6
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.lightGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1500,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
+ var self = this;
+ var brightness = 1.0;
+ var direction = 1;
+ this.pulseTimer = LK.setInterval(function () {
+ brightness += direction * 0.05;
+ if (brightness >= 2.0) {
+ direction = -1;
+ brightness = 2.0;
+ } else if (brightness <= 1.0) {
+ direction = 1;
+ brightness = 1.0;
+ }
+ self.graphics.brightness = brightness;
+ }, 50);
+ };
+ this.stopPulsating = function () {
+ if (this.pulseTimer) {
+ LK.clearInterval(this.pulseTimer);
}
- pulsate.call(this);
};
};
var bird2; // Define bird2 variable in the global scope
// UFOMovement class to handle UFO movement
var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
- this.ufo = ufo;
- this.ufoGraphics = ufoGraphics;
- this.ufo.speed = 3.2; // Decrease speed by 20%
- this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
- this.ufo.lastX = this.ufo.x; // Track last X position for future checks
- this.ufo.update = function () {
- var _this5 = this;
- // Cache current position and dimensions
- var currentX = this.x;
- var screenWidth = 2048;
- var halfWidth = this.width / 2;
- // Update position based on pattern
- this.x += this.speed * Math.cos(LK.ticks / 60);
- this.y = 100 + Math.sin(LK.ticks / 120) * 250;
- // Optimize movement pattern
- var distanceFromCenter = Math.abs(this.x - screenWidth / 2);
- if (distanceFromCenter > screenWidth / 3) {
- this.speed *= -0.95; // Smooth direction change
- }
- // Cache intersection checks
- var isIntersectingCloud = clouds.some(function (cloud) {
- return _this5.intersects(cloud);
- });
- if (isIntersectingCloud && !this.lastIntersecting) {
- this.speed *= 1.2;
- LK.getSound('ufo1').play();
- }
- this.lastIntersecting = isIntersectingCloud;
- // Stop playing ufo1 sound after UFO leaves the screen
- if (this.lastX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || this.lastX >= -halfWidth && this.x < -halfWidth) {
- this.destroy();
- ufo = null;
- LK.getSound('ufo1').stop();
- }
- this.lastX = this.x; // Update lastX after movement
- };
+ return new GameObjectMovement(ufo, ufoGraphics, {
+ speed: 3.2,
+ speedRange: 0.8,
+ arcAmplitude: 4.5,
+ arcFrequency: 80,
+ isVertical: false,
+ canFlip: true,
+ moveSound: 'ufo1'
+ });
};
+;
var UFOSound = function UFOSound() {
+ ;
this.play = function () {
LK.getSound('ufo1').play();
};
};
// BackgroundMusic class to manage background music
var BackgroundMusic = function BackgroundMusic() {
+ ;
this.play = function () {
LK.playMusic('bgm1', {
loop: true,
fade: {
@@ -1413,103 +1901,94 @@
};
};
// LaserSound class to manage laser sound effects
var LaserSound = function LaserSound() {
+ ;
this.play = function () {
LK.getSound('laser1').play();
};
};
var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
- this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = this.bird.y;
- this.bird.lastX = this.bird.x;
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5;
- this.lastY = this.y;
- this.lastX = this.x;
- }.bind(this.bird);
+ return new GameObjectMovement(bird, birdGraphics, {
+ speed: 2.5,
+ speedRange: 1.2,
+ arcAmplitude: 6.5,
+ arcFrequency: 100,
+ isVertical: true,
+ canFlip: true,
+ moveSound: 'wings1'
+ });
};
-var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
+// Bird2 movement is handled by MovementConfigs.bird2
+var Bird2Effects = function Bird2Effects(bird) {
+ ;
this.bird = bird;
- this.birdGraphics = birdGraphics;
- this.bird.speed = Math.random() * 1.6 + 1;
- this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
- this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X
- this.bird.update = function () {
- this.y += this.speed;
- this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- flipImageVerticallyBasedOnDirection(birdGraphics, this.lastX, this.x); // Use flipImageVerticallyBasedOnDirection to flip on X axis
- // Check if the bird has moved off-screen
- if (this.lastY <= 2732 && this.y > 2732) {
- this.y = Math.random() * 2732; // Random initial y position within the screen height
- this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- }
- this.lastX = this.x; // Track position for next update
- this.lastY = this.y; // Update lastY after movement
+ this.applyEffects = function () {
+ // Add any specific effects or animations for Bird1 here
};
};
-var Bird2Effects = function Bird2Effects(bird) {
- this.bird = bird;
- this.applyEffects = function () {};
-};
var ReticlePulse = function ReticlePulse(reticleGraphics) {
- this.reticleGraphics = reticleGraphics;
- this.startPulsating = function () {
- function pulsate() {
- tween(this.reticleGraphics, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: function () {
- tween(this.reticleGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 1000,
- easing: tween.easeInOut,
- onFinish: pulsate.bind(this)
- });
- }.bind(this)
- });
- }
- pulsate.call(this);
- };
+ return new Pulse(reticleGraphics, {
+ minScale: 0.9,
+ maxScale: 1.3,
+ expandDuration: 800,
+ contractDuration: 1200
+ });
};
// Bird1Effects class to handle effects and animations for Bird1
var Bird1Effects = function Bird1Effects(bird) {
+ ;
this.bird = bird;
this.applyEffects = function () {
// Add any specific effects or animations for Bird1 here
};
};
+// Bird2 spawning is now handled by SpawnManager
// Add background to the BACKGROUND layer
var background = new Background();
background.x = 2048 / 2;
background.y = 2732 / 2 - 140;
game.layerManager.addToLayer(background, LAYERS.BACKGROUND);
+// Initialize bird spawning
+spawnBird2();
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
+ ;
var self = this;
var currentScore = 0;
var highScore = storage.highScore || 0;
- self.addScore = function (points) {
- if (typeof points !== 'number' || points < 0) {
- return currentScore;
+ self.scoreValues = {
+ bird1: 100,
+ bird2: 50,
+ ufo1: 250,
+ ufo2: 250
+ };
+ self.addScore = function (objectType) {
+ var points = self.scoreValues[objectType] || 0;
+ if (points > 0) {
+ currentScore += points;
+ if (currentScore > highScore) {
+ highScore = currentScore;
+ storage.highScore = highScore;
+ }
+ // Update score display
+ if (scoreDisplay && scoreDisplay.updateScore) {
+ scoreDisplay.updateScore(currentScore);
+ }
+ if (mirror && mirror.updateScore) {
+ mirror.updateScore(currentScore);
+ }
}
- currentScore += Math.floor(points);
- if (currentScore > highScore) {
- highScore = currentScore;
- storage.highScore = highScore;
- }
return currentScore;
};
self.resetScore = function () {
currentScore = 0;
+ if (scoreDisplay && scoreDisplay.updateScore) {
+ scoreDisplay.updateScore(currentScore);
+ }
+ if (mirror && mirror.updateScore) {
+ mirror.updateScore(currentScore);
+ }
return currentScore;
};
self.getScore = function () {
return currentScore;
@@ -1519,21 +1998,23 @@
};
};
var birds = [];
game.down = function (x, y, obj) {
+ if (obj && obj.event) {
+ x = obj.event.x;
+ y = obj.event.y;
+ }
if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
- if (game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(game.reticle, LAYERS.RETICLE); // Use layer manager to set reticle layer
- }
+ game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE);
}
game.reticle.x = x;
game.reticle.y = y;
- var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
- game.addChild(laser);
- if (game.children.includes(laser) && game.children.includes(game.reticle)) {
- game.layerManager.addToLayer(laser, LAYERS.LASER); // Use layer manager to set laser layer
+ if (typeof x === 'undefined' || typeof y === 'undefined') {
+ console.error('Invalid coordinates for laser');
+ return;
}
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ addEntityToLayer(laser, LAYERS.LASER);
};
var VOLUME_BGM1 = 0.02;
var VOLUME_BREEZE1 = 0.02;
var VOLUME_CRICKET1 = 0.02;
@@ -1542,13 +2023,13 @@
var VOLUME_UFO1 = 0.02;
var VOLUME_WINGS1 = 0.02;
game.move = function (x, y, obj) {
if (!game.reticle) {
- game.reticle = game.addChild(new Reticle());
+ game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE);
}
if (obj.event) {
- var x = obj.event.x;
- var y = obj.event.y;
+ x = obj.event.x;
+ y = obj.event.y;
}
game.reticle.x = x;
game.reticle.y = y;
};
@@ -1562,15 +2043,10 @@
light1.y = 1500;
game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
light1.visible = true;
// Function to add a UFO to the game
-// Initialize clouds array
-var clouds = [];
-// Initialize cloud types
-var CLOUD_TYPES = ['cloud1', 'cloud2'];
-// Add initial clouds
-// Call initializeClouds after game initialization
-initializeClouds();
+// Using existing CLOUD_TYPES definition
+// initializeClouds already called earlier
var bird1; // Define bird1 variable in the global scope
var bird; // Define bird variable in the global scope
var ufo; // Define the ufo variable in the global scope
var laser; // Define the laser variable in the global scope
@@ -1578,193 +2054,145 @@
addUFO();
// Reset the timer for the UFO to reappear between 10-20 seconds
ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000);
}, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds
-game.update = function () {
- // Update clouds
- for (var i = 0; i < clouds.length; i++) {
- clouds[i].update();
+// Helper functions for game update
+function updateEntityPositions() {
+ game.children.forEach(function (entity) {
+ if (entity.update) {
+ entity.update();
+ }
+ // Handle off-screen objects
+ if (game.layerManager.isInLayer(entity, 'birds') && entity.y > 2732) {
+ entity.y = -entity.height;
+ entity.x = Math.random() * 2048;
+ }
+ });
+}
+function handleCollisions() {
+ var projectiles = game.layerManager.getLayerEntities('projectiles');
+ projectiles.forEach(function (laser) {
+ laser.update();
+ checkLaserCollisions(laser);
+ });
+}
+function checkLaserCollisions(laser) {
+ var enemies = game.layerManager.getLayerEntities('enemies');
+ enemies.forEach(function (target) {
+ if (!laser.lastIntersecting && AABBIntersect(laser, target)) {
+ handleCollisionPoints(laser, target);
+ }
+ });
+ laser.lastIntersecting = enemies.some(function (target) {
+ return laser.intersects(target);
+ });
+}
+function handleCollisionPoints(laser, target) {
+ var points = 0;
+ var soundEffect = '';
+ if (target instanceof Bird1) {
+ points = 100;
+ soundEffect = 'dead1';
+ spawnManager.objectCounts.bird1--;
+ } else if (target instanceof Bird2) {
+ points = 50;
+ soundEffect = 'dead2';
+ spawnManager.objectCounts.bird2--;
+ } else if (target instanceof UFO1 || target instanceof UFO2) {
+ points = 250;
+ soundEffect = 'dead3';
+ spawnManager.objectCounts[target instanceof UFO1 ? 'ufo1' : 'ufo2']--;
}
- // Add a jet to the game if it doesn't exist and no jet spawn timer is active
- if (!game.jet && !game.jetSpawnTimer) {
- var jet = new Jet1();
- jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
- jet.y = Math.random() * (2732 / 2);
- game.addChild(jet);
- game.jet = jet;
- game.layerManager.addToLayer(jet, LAYERS.JET1);
- LK.getSound('jet1').play();
+ if (points > 0) {
+ game.score = (game.score || 0) + points;
+ if (scoreDisplay && scoreDisplay.updateScore) {
+ scoreDisplay.updateScore(game.score);
+ }
+ if (game.mirror && game.mirror.updateScore) {
+ game.mirror.updateScore(game.score);
+ }
+ LK.getSound(soundEffect).play();
+ target.destroy();
+ laser.destroy();
}
- // Update jet
- if (game.jet) {
- game.jet.update();
- }
- if (ufo) {
- ufo.customUpdate();
- // Cache game children to avoid repeated property access
- var gameChildren = game.children;
- // Update lasers and check collisions
- gameChildren.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- var hasIntersection = birds.some(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- score += bird instanceof Bird1 ? 5 : bird instanceof Bird2 ? 1 : 0;
- scoreDisplay.updateScore(score);
- LK.getSound('dead1').play();
- bird.destroy();
- birds.splice(birds.indexOf(bird), 1);
- child.destroy();
- return true;
- }
- return child.intersects(bird);
- });
- if (!hasIntersection && ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = hasIntersection || ufo && child.intersects(ufo);
+ game.update = function () {
+ updateEntityPositions();
+ handleCollisions();
+ if (ufo) {
+ ufo.customUpdate();
+ // Check if UFO is out of bounds
+ if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
+ ufo.destroy();
+ ufo = null;
+ ufoTimer = LK.setTimeout(function () {
+ ufo = addUFO();
+ }, Math.random() * 20000 + 30000);
}
- });
- // Check for intersections between UFO and birds
- var ufoIntersection = birds.some(function (bird) {
- if (!ufo.lastIntersecting && ufo.intersects(bird)) {
- bird.destroy();
- birds.splice(birds.indexOf(bird), 1);
- LK.getSound('dead2').play();
- return true;
+ ufo.lastX = ufo.x;
+ }
+ };
+ // Update existing birds
+ game.children.forEach(function (bird) {
+ if (game.layerManager.isInLayer(bird, 'birds')) {
+ if (bird.y > 2732) {
+ bird.y = -bird.height;
+ bird.x = Math.random() * 2048;
}
- return ufo.intersects(bird);
- });
- ufo.lastIntersecting = ufoIntersection;
- // Check if UFO is out of bounds
- if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
- ufo.destroy();
- ufo = null;
- ufoTimer = LK.setTimeout(function () {
- ufo = addUFO();
- }, Math.random() * 20000 + 30000);
}
- ufo.lastX = ufo.x;
- }
-};
-// Function to spawn a third kind of bird
-// Update the main game update function to include bird updates
-var originalUpdate = game.update;
-game.update = function () {
- // Call the original update function first
- originalUpdate.call(this);
- // Update each bird
- birds.forEach(function (bird) {
- bird.update();
- // Check if the bird has moved off-screen
- if (bird.lastY <= 2732 && bird.y > 2732) {
- bird.y = -bird.height; // Respawn the bird at the top
- bird.x = Math.random() * 2048; // Randomize the x position
- bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
- }
});
- // Update UFO and check for collisions
- if (ufo) {
- ufo.customUpdate();
- // Update each laser
- game.children.forEach(function (child) {
- if (child instanceof Laser) {
- child.update();
- // Check for intersections with birds and UFO
- birds.forEach(function (bird) {
- if (!child.lastIntersecting && AABBIntersect(child, bird)) {
- if (bird instanceof Bird1) {
- score += 5;
- } else if (bird instanceof Bird2 || bird instanceof Bird3) {
- score += 1;
- }
- scoreDisplay.updateScore(score); // Update the score display
- bird.destroy(); // Remove the bird when hit by a laser
- birds.splice(birds.indexOf(bird), 1); // Remove bird from the array
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- });
- });
- if (ufo && !child.lastIntersecting && AABBIntersect(child, ufo)) {
- score += 25;
- scoreDisplay.updateScore(score);
- child.destroy();
- }
- child.lastIntersecting = birds.some(function (bird) {
- return child.intersects(bird);
- }) || ufo && child.intersects(ufo);
- }
- });
+}
+// Update UFOs and play sounds
+game.children.forEach(function (entity) {
+ if ((game.layerManager.isInLayer(entity, LAYERS.UFO1) || game.layerManager.isInLayer(entity, LAYERS.UFO2)) && !entity.soundPlayed && entity.x > 0 && entity.x < 2048) {
+ LK.getSound('ufo1').play();
+ entity.soundPlayed = true;
}
-};
+});
+// Update each laser and check collisions
+game.children.forEach(function (laser) {
+ if (laser instanceof Laser) {
+ laser.update();
+ checkLaserCollisions(laser);
+ }
+});
// Add a tree to the game
-var tree = game.addChild(new Tree());
+var tree = addEntityToLayer(new Tree(), LAYERS.TREE);
tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
tree.y = 2500; // Position the tree on the grass
-// Ensure tree is added to the game before setting its index
-if (game.children.includes(tree) && game.children.includes(bird1)) {
- game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
+// Add tree to the proper layer
+if (game.children.includes(tree)) {
+ game.layerManager.addToLayer(tree, LAYERS.TREE); // Use layer manager to set tree layer
}
var score = 0;
// Add stack1 image to the game
-var stack1 = game.addChild(new Stack1());
+var stack1 = addEntityToLayer(new Stack1(), LAYERS.STACK);
stack1.x = 1700; // Move 700px to the right
stack1.y = 2250; // Move down by 800px
-// Ensure stack1 is added to the game before setting its index
-if (game.children.includes(stack1) && game.children.includes(tree)) {
- game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
+// Add stack1 to the proper layer
+if (game.children.includes(stack1)) {
+ game.layerManager.addToLayer(stack1, LAYERS.STACK); // Use layer manager to set stack layer
}
-// Add the grass floor to the game
-var grassBack = new GrassBack();
-grassBack.x = 1020;
-grassBack.y = 2735; // Position grassBack at the bottom
-game.addChild(grassBack);
-// Ensure grassBack is added to the game before setting its index
-if (game.children.includes(grassBack)) {
- // Make sure we don't set an index that's out of bounds
- var safeIndex = Math.min(5, game.children.length - 1);
- game.setChildIndex(grassBack, safeIndex); // Set grassBack to be rendered safely
-}
-var grassFront = new GrassFront();
-grassFront.x = 1020;
-grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
-game.addChild(grassFront);
-// Ensure grassFront is added to the game before setting its index
-if (game.children.includes(grassFront) && game.children.includes(bird2)) {
- game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
-}
var scoreDisplay = new Mirror();
scoreDisplay.x = 2048 / 2 + 400; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 390 + 30 + 50; // Move the score display up by an additional 80px and down by 30px + 50px
-game.addChild(scoreDisplay);
+addEntityToLayer(scoreDisplay, LAYERS.UI);
var mirror = new Mirror();
mirror.x = 2048 / 2 + 400; // Move the mirror 400px to the right
mirror.y = 2732 - 185 - 80 - 390 + 30; // Move the mirror up by an additional 80px and down by 30px
-game.addChild(mirror);
-// Mirror doesn't need a specific layer as it's positioned using setChildIndex
-// Ensure mirror is added to the game before setting its index
-if (game.children.includes(mirror) && game.children.includes(stack1)) {
- game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
+game.layerManager.addToLayer(mirror, LAYERS.MIRROR);
+// Add mirror to the proper layer using the layer manager
+// Add mirror to the proper layer
+if (game.children.includes(mirror)) {
+ game.layerManager.addToLayer(mirror, LAYERS.MIRROR); // Use layer manager to set mirror layer
}
-// Ensure laser is added to the game before setting mirror's index
-if (game.children.includes(laser) && game.children.includes(mirror)) {
- game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
-}
// Function to handle bgm1 end event
-;
// Add the cat to the game
-var cat = game.addChild(new Cat());
+var cat = addEntityToLayer(new Cat(), LAYERS.CAT);
cat.x = 230; // Move the cat 20px to the left
cat.y = 2732; // Position the cat at the bottom of the screen
-// Ensure cat is added to the game before setting its index
+// Add cat to the proper layer
if (game.children.includes(cat)) {
- game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
+ game.layerManager.addToLayer(cat, LAYERS.CAT); // Use layer manager to set cat layer
}
// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
LK.playMusic('bgm1', {
loop: false,
@@ -1799,21 +2227,124 @@
}, 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
+// Initialize random timers for each sound to play between 20-30 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
- currentAmbientSound.stop(); // Stop the currently playing ambient sound
+ currentAmbientSound.stop();
}
sound.play();
- currentAmbientSound = sound; // Set the current ambient sound
- // Set a timeout to reset the current ambient sound after it finishes playing
+ currentAmbientSound = sound;
LK.setTimeout(function () {
currentAmbientSound = null;
- }, sound.duration * 1000); // Convert duration from seconds to milliseconds
- // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
- ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
- }, Math.random() * 20000 + 30000);
-});
\ No newline at end of file
+ }, sound.duration * 1000);
+ ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 20000);
+ }, Math.random() * 10000 + 20000);
+});
+// Initialize EntityManager
+var entityManager = new EntityManager();
+// Initial entity spawning will be handled by the managers
+if (typeof x !== 'undefined' && typeof y !== 'undefined') {
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
+ entityManager.add(laser);
+} else {
+ console.error('Invalid coordinates for laser creation');
+}
+// Ensure timers for ambient sounds and bgm1 are set to repeat every 20-30 seconds
+function initializeAmbientSounds() {
+ var _playAmbientSounds = function playAmbientSounds() {
+ LK.getSound('songbird1').play();
+ LK.getSound('cricket1').play();
+ LK.setTimeout(_playAmbientSounds, Math.random() * 10000 + 20000); // 20-30 seconds
+ };
+ _playAmbientSounds();
+ // Set initial interval
+ LK.setInterval(_playAmbientSounds, 25000); // Average of 20-30 seconds
+}
+function initializeBGM() {
+ var playBGM = function playBGM() {
+ LK.playMusic('bgm1');
+ };
+ playBGM();
+ // Set regular interval for background music
+ LK.setInterval(playBGM, 25000); // Average of 20-30 seconds
+}
+// Fix scoring
+var scoreManager = new ScoreManager();
+var score = 0;
+game.down = function (x, y, obj) {
+ if (obj && obj.event) {
+ x = obj.event.x;
+ y = obj.event.y;
+ }
+ if (!game.reticle) {
+ game.reticle = addEntityToLayer(new Reticle(), LAYERS.RETICLE);
+ }
+ game.reticle.x = x;
+ game.reticle.y = y;
+ if (typeof x === 'undefined' || typeof y === 'undefined') {
+ console.error('Invalid coordinates for laser');
+ return;
+ }
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ addEntityToLayer(laser, LAYERS.LASER);
+};
+// Adjust layer display order
+// Ensure light1 layer is displayed after background
+if (light1) {
+ game.layerManager.addToLayer(light1, LAYERS.LIGHT1);
+}
+// Ensure jet layer is displayed before cloud2 layer
+if (jet) {
+ game.layerManager.addToLayer(jet, LAYERS.JET1);
+}
+// Ensure mirror layer is displayed behind grass-front
+if (mirror) {
+ game.layerManager.addToLayer(mirror, LAYERS.MIRROR);
+}
+// Ensure jet1 and ufo1 sounds play when on screen
+Jet1.prototype.update = function () {
+ // Fix: Use 'this' instead of 'self' since this is a prototype method
+ var jetGraphics = this.children[0];
+ flipImageVerticallyBasedOnDirection(jetGraphics, this.lastX, this.x);
+ this.x += this.speed * this.direction;
+ // Play jet sound when on screen
+ if (!this.soundPlayed && this.x > 0 && this.x < 2048) {
+ LK.getSound('jet1').play();
+ this.soundPlayed = true;
+ }
+ // Stop sound and destroy when off screen
+ if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ LK.getSound('jet1').stop();
+ this.destroy();
+ game.jet = null;
+ // Use spawn manager to handle respawn
+ if (game.spawnManager) {
+ game.spawnManager.scheduleRespawn('jet1', Jet1);
+ }
+ }
+ this.lastX = this.x;
+};
+UFOMovement.prototype.update = function () {
+ var currentX = this.x;
+ var screenWidth = 2048;
+ var halfWidth = this.width / 2;
+ var tickCos = Math.cos(LK.ticks / 60);
+ var tickSin = Math.sin(LK.ticks / 120);
+ this.x += this.speed * tickCos;
+ this.y = 100 + tickSin * 250;
+ if (this.x > 0 && this.x < screenWidth && !this.soundPlayed) {
+ LK.getSound('ufo1').play();
+ this.soundPlayed = true;
+ }
+ if (this.x < 0 || this.x > screenWidth) {
+ this.soundPlayed = false;
+ }
+ if (currentX <= screenWidth + halfWidth && this.x > screenWidth + halfWidth || currentX >= -halfWidth && this.x < -halfWidth) {
+ LK.getSound('ufo1').stop();
+ this.destroy();
+ }
+ this.lastX = this.x;
+};
\ 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