Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'app is not defined' in or related to this line: 'app.stage.addChild(layer);' Line Number: 112
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'baseSpeed')' in or related to this line: 'self.cloud = {' Line Number: 155
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'baseSpeed is not defined' in or related to this line: 'self.cloud = {' Line Number: 153
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1931
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1496
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1465
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'cloud')' in or related to this line: 'self.cloud.update = function () {' Line Number: 1463
User prompt
Please fix the bug: 'cloudGraphics is not defined' in or related to this line: 'self.addChild(cloudGraphics);' Line Number: 185
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'sounds')' in or related to this line: 'if (config.sounds && config.sounds.move) {' Line Number: 542
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'sounds')' in or related to this line: 'if (config.sounds && config.sounds.move) {' Line Number: 540
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'direction')' in or related to this line: 'entity.direction = config.direction || (Math.random() < 0.5 ? 1 : -1);' Line Number: 539
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'attachAsset')' in or related to this line: 'var cloudGraphics = self.attachAsset('cloud', {' Line Number: 1461
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Cat class to manage cat behavior var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the cat here }; }); // Cloud container with 80% opacity var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { alpha: 0.8 }); self.cloudGraphics = cloudGraphics; self.cloud = { speed: Math.random() * 0.55 + 0.25, direction: 1, x: 0, y: 0 }; self.movement = createMovementSystem(self, cloudGraphics, { baseSpeed: self.cloud.speed, horizontalMovement: true, entityType: 'cloud' }); self.update = function () { try { // Update position based on current speed and direction this.x += this.speed * this.direction; // Handle cloud interactions for (var i = 0; i < clouds.length; i++) { if (clouds[i] !== this && this.intersects(clouds[i])) { if (!this.hasAccelerated) { this.speed *= 1.5; this.hasAccelerated = true; } break; } else if (this.hasAccelerated && !this.intersects(clouds[i])) { this.speed /= 1.5; this.hasAccelerated = false; } } // Handle sun interaction if (sun && typeof this.intersects === 'function') { if (!this.lastIntersecting && this.intersects(sun)) { this.speed *= 2; tween(this.cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } else if (this.lastIntersecting && !this.intersects(sun)) { this.speed /= 2; tween(this.cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } this.lastIntersecting = this.intersects(sun); } // Handle screen boundaries if (this.x > 2048 + this.width / 2) { this.x = -this.width / 2; } else if (this.x < -this.width / 2) { this.x = 2048 + this.width / 2; } } catch (error) { console.error('Cloud update error:', error); // Fallback to local simulation if (this.__proto__ && typeof this.__proto__.update === 'function') { this.__proto__.update.call(this); } } }; self.addChild(cloudGraphics); }); // CloudMovement class to handle cloud movement and fade effects // GrassBack class to represent the grass image var GrassBack = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1 }); self.update = function () { // Add any specific update logic for the grass here // Example: Slightly move the grass to simulate wind effect self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed }; self.addChild(grassGraphics); // Add grass graphics to the container }); // GrassFront class to represent the second grass image var GrassFront = Container.expand(function () { var self = Container.call(this); var grass2Graphics = self.attachAsset('grass-front', { anchorX: 0.5, anchorY: 1 }); self.lastX = self.x; // Initialize lastX for tracking changes on X self.addChild(grass2Graphics); // Add grass2 graphics to the container self.update = function () { updateMovement(self, { movementType: 'sinusoidal', amplitude: 0.125, frequency: 100, offset: 50 }); }; }); // Jet class to represent a jet flying across the screen var Jet = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-right', { anchorX: 0.5, anchorY: 0.5 }); // Initializes entity movement parameters createMovementSystem(self, jetGraphics, { baseSpeed: 8, speedVariation: 0, useWaveMotion: true, waveAmplitude: 100, waveFrequency: 100, horizontalMovement: true, baseY: 300, textures: { left: 'jet-left', right: 'jet-right' }, respawnPosition: 'side', sounds: { move: 'jetSound', destroy: 'jetSound' }, onDestroy: function onDestroy(entity) { handleJetReappearance(); }, entityType: 'jet' }); self.onDestroy = function () { LK.getSound('jetSound').stop(); // Ensure sound stops when jet is destroyed }; self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); var JetLeft = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-left', { anchorX: 0.5, anchorY: 0.5 }); // Initializes entity movement parameters with fixed left direction createMovementSystem(self, jetGraphics, { baseSpeed: 8, speedVariation: 0, useWaveMotion: true, waveAmplitude: 100, waveFrequency: 100, horizontalMovement: true, baseY: 300, textures: { left: 'jet-left', right: 'jet-right' }, respawnPosition: 'side', sounds: { move: 'jetSound', destroy: 'jetSound' }, onDestroy: function onDestroy(entity) { handleJetReappearance(); }, entityType: 'jet' }); self.direction = -1; // Always left self.onDestroy = function () { LK.getSound('jetSound').stop(); }; }); var JetRight = Container.expand(function () { var self = Container.call(this); var jetGraphics = self.attachAsset('jet-right', { anchorX: 0.5, anchorY: 0.5 }); // Initializes entity movement parameters with fixed right direction createMovementSystem(self, jetGraphics, { baseSpeed: 8, speedVariation: 0, useWaveMotion: true, waveAmplitude: 100, waveFrequency: 100, horizontalMovement: true, baseY: 300, textures: { left: 'jet-left', right: 'jet-right' }, respawnPosition: 'side', sounds: { move: 'jetSound', destroy: 'jetSound' }, onDestroy: function onDestroy(entity) { handleJetReappearance(); }, entityType: 'jet' }); self.direction = 1; // Always right self.onDestroy = function () { LK.getSound('jetSound').stop(); }; }); // Laser class to represent a laser shot from the cat var Laser = Container.expand(function (startX, startY, targetX, targetY) { var self = Container.call(this); var laserGraphics = self.attachAsset('laser2', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 // Increase brightness by 200% }); // Play the laser1 sound when the laser is created LK.getSound('laser1').play(); // Initializes entity movement parameters LaserMovement(self, laserGraphics, startX, startY, targetX, targetY); return self; }); // Light1 class to represent a light object var Light1 = Container.expand(function () { var self = Container.call(this); var lightGraphics = self.attachAsset('light1', { anchorX: 0.5, anchorY: 0.5, alpha: 0.2 // Set transparency to 20% }); self.x = 450, self.y = 440; self.update = function () { // Add any specific update logic for the light here }; self.pulse = new Light1Pulse(lightGraphics); self.pulse.startPulsating(); }); // Mirror class to manage score display var Mirror = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 14 // Rotate image right 15 degrees }); var scoreText = new Text2('0', { size: 175, fill: 0x800080, font: "Courier New, Courier, monospace", // Segmented clock style font stroke: 0x00FF00, strokeThickness: 15, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = 40; // Move score text up by 20px scoreText.x = -145; // Move score text left by 10px scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // Mirror1 class to represent the mirror image var Mirror1 = Container.expand(function () { var self = Container.call(this); var mirror1Graphics = self.attachAsset('mirror1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(mirror1Graphics); }); // Reticle class to manage reticle behavior var Reticle = Container.expand(function () { var self = Container.call(this); var reticleGraphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Add any specific update logic for the reticle here }; // Start the pulsating effect for the reticle startPulsating(self); }); // Reticle1 class to represent the reticle image var Reticle1 = Container.expand(function () { var self = Container.call(this); var reticle1Graphics = self.attachAsset('reticle1', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(reticle1Graphics); }); // ScoreImage class to represent the score image var ScoreImage = Container.expand(function () { var self = Container.call(this); var scoreImageGraphics = self.attachAsset('scoreImage', { anchorX: 0.5, anchorY: 0.5 }); self.addChild(scoreImageGraphics); }); // Stack1 class to represent the stack1 image var Stack1 = Container.expand(function () { var self = Container.call(this); var stackGraphics = self.attachAsset('stack1', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / -12 }); self.update = function () { // Add any specific update logic for stack1 here }; }); // ScoreManager class to manage score logic // Sun class to represent a sun in the top right corner var Sun = Container.expand(function () { var self = Container.call(this); var sunGraphics = self.attachAsset('sun', { anchorX: 0.5, anchorY: 0.5 }); self.pulse = new SunPulse(sunGraphics); self.pulse.startPulsating(); }); // Function to create a pulsating effect // Tree class to represent a tree with a 9:16 aspect ratio var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, antialias: true, // Apply antialias effect stroke: 0x000000, // Add a black stroke strokeThickness: 15 // Set stroke thickness to 15px }); self.update = function () { // Add any specific update logic for the tree here }; }); // Tree2 class to represent the second type of tree var Tree2 = Container.expand(function () { var self = Container.call(this); var tree2Graphics = self.attachAsset('tree2', { anchorX: 0.5, anchorY: 1 }); self.addChild(tree2Graphics); }); // UFO class to represent a UFO var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); // Initializes entity movement parameters UFOMovement(self, ufoGraphics); self.setChildIndex = function (index) { if (game.children.includes(self)) { game.setChildIndex(self, index); } }; }); // UFO2 class to represent the second type of UFO var UFO2 = Container.expand(function () { var self = Container.call(this); var ufo2Graphics = self.attachAsset('ufo2', { anchorX: 0.5, anchorY: 0.5 }); // Initializes entity movement parameters UFOMovement(self, ufo2Graphics); }); /**** * Initialize Game ****/ // Game instance already initialized above // Layer structure initialization with proper cleanup handling var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Sound configuration /**** * Game Configuration ****/ // Music and Sounds // Images function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) { return e; } if (void 0 !== e) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) { throw new TypeError("Super expression must either be null or a function"); } t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } var GAME_SOUND_VOLUMES = { bgm1: 0.02, breeze1: 0.02, cricket1: 0.02, frog1: 0.02, songbird1: 0.02, ufo1: 0.02, wings1: 0.02, laser1: 0.1, laser2: 0.1, jetSound: 0.3 }; /**** * Core Game Setup ****/ // Initialize game instance var gameInstance = new LK.Game({ backgroundColor: 0x000000 }); // Layer structure initialization var layers = { background: new Container(), sun: new Container(), light1: new Container(), jetLeft: new Container(), jetRight: new Container(), clouds: new Container(), ufo: new Container(), grassBack: new Container() }; var Background = /*#__PURE__*/function (_Container) { function Background() { var _this; _classCallCheck(this, Background); _this = _callSuper(this, Background); _this.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); return _this; } _inherits(Background, _Container); return _createClass(Background); }(Container); // Branch asset var Bird = /*#__PURE__*/function (_Container2) { function Bird(type) { var _this2; _classCallCheck(this, Bird); _this2 = _callSuper(this, Bird); var birdGraphics = _this2.attachAsset("".concat(type, "-right"), { anchorX: 0.5, anchorY: 0.5 }); _this2.birdGraphics = birdGraphics; BirdMovement(_this2, _this2.birdGraphics, type); return _this2; } _inherits(Bird, _Container2); return _createClass(Bird, [{ key: "setChildIndex", value: function setChildIndex(index) { if (game.children.includes(this)) { game.setChildIndex(this, index); } } }]); }(Container); var Bird1 = /*#__PURE__*/function (_Bird) { function Bird1() { _classCallCheck(this, Bird1); return _callSuper(this, Bird1, ['bird1']); } _inherits(Bird1, _Bird); return _createClass(Bird1); }(Bird); var Bird2 = /*#__PURE__*/function (_Bird2) { function Bird2() { _classCallCheck(this, Bird2); return _callSuper(this, Bird2, ['bird2']); } _inherits(Bird2, _Bird2); return _createClass(Bird2); }(Bird); // Layer z-index management is handled by the layerStructure configuration // Layer structure and initialization is already handled at the beginning of the file // Consolidated checkInteractions function is inserted below // Bird2Movement class to handle Bird2 movement // Bird2Movement class to handle Bird2 movement /** * Configures movement behavior for game entities with tween-based animations * @param {Container} entity - Target entity container * @param {Graphics} graphics - Visual representation to animate * @param {Object} config - Movement configuration: * @param {number} [config.baseSpeed=1] - Base movement speed * @param {Object} config.textures - Directional sprites {left, right} * @param {boolean} [config.useWaveMotion=false] - Enable sine-based path * @param {number} [config.waveAmplitude=0] - Vertical deviation magnitude * @param {number} [config.waveFrequency=100] - Horizontal wave cycle length */ // Consolidated movement system with state tracking and error boundaries function createMovementSystem(entity, entityGraphics, config) { if (!entity || !entityGraphics) { console.error('Entity and entityGraphics are required for movement system'); return null; } var defaults = { baseSpeed: 1, speedVariation: 0, horizontalMovement: false, useWaveMotion: false, waveAmplitude: 0, waveFrequency: 100, screenBounds: { width: 2048, height: 2732 }, respawnDelay: { min: 10000, max: 20000 }, respawnPosition: 'top', textures: { left: null, right: null }, sounds: { move: null, destroy: null }, scoreValue: 0, entityType: null, onDestroy: null, spawnInterval: { min: 2000, max: 5000 }, maxRetries: 3 }; // Enhanced state tracking entity.movementState = { isMovingDown: false, isMovingHorizontal: false, lastUpdate: Date.now(), retryCount: 0 }; var settings = Object.assign({}, defaults, config || {}); entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation; entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1; entity.lastX = entity.x || 0; entity.lastY = entity.y || 0; if (settings.sounds && settings.sounds.move) { try { var sound = LK.getSound(settings.sounds.move); if (sound && typeof sound.play === 'function') { sound.play({ loop: true }); } } catch (error) { console.error('Error playing movement sound:', error); } } entity.scoreValue = settings.scoreValue; entity.update = function () { try { if (settings.entityType === 'laser') { if (!this.vx || !this.vy) { return; } this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) { if (typeof this.destroy === 'function') { this.destroy(); } } } else if (settings.horizontalMovement) { this.x += this.speed * this.direction; if (settings.useWaveMotion && settings.baseY !== undefined) { this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude; } } else { this.y += this.speed; if (settings.useWaveMotion) { this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude; } } if (entityGraphics && settings.textures && settings.textures.left && settings.textures.right) { try { var rightAsset = LK.getAsset(settings.textures.right, {}); var leftAsset = LK.getAsset(settings.textures.left, {}); if (rightAsset && leftAsset) { entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture; } } catch (error) { console.error('Error updating entity texture:', error); } } if (settings.horizontalMovement) { if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) { if (settings.sounds && settings.sounds.destroy) { try { var sound = LK.getSound(settings.sounds.destroy); if (sound && typeof sound.stop === 'function') { sound.stop(); } } catch (error) { console.error('Error stopping destroy sound:', error); } } if (typeof this.destroy === 'function') { this.destroy(); } if (settings.onDestroy) { settings.onDestroy(this); } } } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) { switch (settings.respawnPosition) { case 'random': this.y = Math.random() * settings.screenBounds.height; this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width; break; case 'side': this.y = Math.random() * settings.screenBounds.height; this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width; break; case 'top': default: this.y = -this.height; this.x = Math.random() * settings.screenBounds.width; break; } } this.lastX = this.x; this.lastY = this.y; } catch (error) { console.error('Error in entity update:', error); } }.bind(entity); return entity; } // Game instance already initialized above // Layer structure initialization with proper cleanup handling var initializeLayers = function initializeLayers() { game.layers = { background: new Container(), sun: new Container(), light1: new Container(), jetLeft: new Container(), jetRight: new Container(), clouds: new Container(), ufo: new Container(), grassBack: new Container(), bird1: new Container(), tree: new Container(), stack1: new Container(), bird2: new Container(), mirror: new Container(), grassFront: new Container(), cat: new Container(), laser: new Container(), reticle: new Container(), enemies: new Container(), birds: new Container() }; // Add cleanup methods to each layer Object.values(game.layers).forEach(function (layer) { layer.cleanup = function () { while (this.children.length > 0) { var child = this.children[0]; if (typeof child.destroy === 'function') { child.destroy(); } this.removeChild(child); } }; }); return game.layers; }; game.layers = initializeLayers(); /**** * Game State ****/ // Add base BirdMovement class (missing) // Initialize game state as a module-level singleton var GameState = { birds: [], clouds: [], ufo: null, score: 0, scoreDisplay: null, cat: null, sounds: new Set(), reticle: null, jet: null, jetSoundPlayed: false, reset: function reset() { // Clean up birds this.birds.forEach(function (bird) { if (typeof bird.destroy === 'function') { bird.destroy(); } }); this.birds = []; // Clean up clouds this.clouds.forEach(function (cloud) { if (typeof cloud.destroy === 'function') { cloud.destroy(); } }); this.clouds = []; // Clean up UFO if (this.ufo && typeof this.ufo.destroy === 'function') { this.ufo.destroy(); this.ufo = null; } // Clean up reticle if (this.reticle && typeof this.reticle.destroy === 'function') { this.reticle.destroy(); this.reticle = null; } // Clean up jet if (this.jet && typeof this.jet.destroy === 'function') { this.jet.destroy(); this.jet = null; this.jetSoundPlayed = false; } // Stop all active sounds this.sounds.forEach(function (soundName) { try { var sound = LK.getSound(soundName); if (sound && typeof sound.stop === 'function') { sound.stop(); } } catch (error) { console.error("Error stopping sound ".concat(soundName, ":"), error); } }); this.sounds.clear(); // Reset score this.score = 0; if (this.scoreDisplay) { this.scoreDisplay.updateScore(0); } } }; // Use GameState for all game-related variables var gameState = GameState; // Initialize game layers with a single, organized structure game.layers = { background: new Container(), sun: new Container(), // z-index: 1 light1: new Container(), // z-index: 2 jetLeft: new Container(), // z-index: 3 jetRight: new Container(), // z-index: 3 clouds: new Container(), // z-index: 4 ufo: new Container(), // z-index: 5 grassBack: new Container(), // z-index: 6 bird1: new Container(), // z-index: 7 tree: new Container(), // z-index: 8 stack1: new Container(), // z-index: 9 bird2: new Container(), // z-index: 10 mirror: new Container(), // z-index: 11 grassFront: new Container(), // z-index: 12 cat: new Container(), // z-index: 13 laser: new Container(), // z-index: 14 reticle: new Container(), // z-index: 15 enemies: new Container(), // Container for collision detection birds: new Container() // Container for all birds }; // Add these layers to the game and set their z-indices var layerOrder = ['background', 'sun', 'light1', 'jetLeft', 'jetRight', 'clouds', 'ufo', 'grassBack', 'bird1', 'tree', 'stack1', 'bird2', 'mirror', 'grassFront', 'cat', 'laser', 'reticle', 'enemies', 'birds']; layerOrder.forEach(function (key, index) { if (game.layers[key]) { game.layers[key].zIndex = index; game.addChild(game.layers[key]); } }); // Duplicate game.layers initialization removed /** * Creates and adds a UFO to the game * @returns {Object} The created UFO object */ function addUFO() { if (ufo) { return ufo; } // Create new UFO instance var ufo = new UFO(); // Add to UFO layer game.layers.ufo.addChild(ufo); // Add to enemies layer for collision detection game.layers.enemies.addChild(ufo); // Set initial position (either left or right side of screen) ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; ufo.y = Math.random() * (2732 / 2 - ufo.height); // Play UFO sound LK.getSound('ufo1').play(); return ufo; } // Enhanced entity spawning system with structured intervals and error handling var EntitySpawner = { spawnIntervals: { bird1: { min: 2000, max: 5000 }, bird2: { min: 3000, max: 6000 } }, removeEntity: function removeEntity(entity) { try { if (entity.parent) { entity.parent.removeChild(entity); } if (birds.includes(entity)) { birds.splice(birds.indexOf(entity), 1); } if (typeof entity.destroy === 'function') { entity.destroy(); } } catch (error) { console.error('Error removing entity:', error); } }, spawnBird1: function spawnBird1() { try { var bird = new Bird1(); bird.x = Math.random() * 2048; bird.y = -bird.height; birds.push(bird); game.layers.birds.addChild(bird); game.layers.enemies.addChild(bird); return bird; } catch (error) { console.error('Error spawning Bird1:', error); return null; } }, spawnBird2: function spawnBird2() { try { var bird = new Bird2(); bird.x = Math.random() * 2048; bird.y = -bird.height; birds.push(bird); game.layers.birds.addChild(bird); game.layers.enemies.addChild(bird); return bird; } catch (error) { console.error('Error spawning Bird2:', error); return null; } } }; // Consolidated bird spawning functions // Consolidated bird spawning functions are inserted below // Jet timer function var jetTimer = LK.setTimeout(function spawnJet() { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2 - jet.height); // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); game.jetSoundPlayed = true; } jetTimer = LK.setTimeout(spawnJet, 5000); }, Math.random() * 5000 + 5000); // Cloud initialization for (var i = 0; i < 4; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); clouds.push(cloud); game.layers.clouds.addChild(cloud); } // Handle click/tap events with proper cleanup and error handling game.down = function (x, y, obj) { try { // Clean up old reticle if it exists if (game.reticle && typeof game.reticle.destroy === 'function') { game.reticle.destroy(); } // Create new reticle game.reticle = game.layers.reticle.addChild(new Reticle()); game.reticle.x = x; game.reticle.y = y; // Create and add laser with proper positioning if (cat) { var laser = new Laser(cat.x - 140, cat.y - 440, x, y); game.layers.laser.addChild(laser); // Clean up laser after animation setTimeout(function () { if (laser && typeof laser.destroy === 'function') { laser.destroy(); } game.layers.laser.removeChild(laser); }, 2000); } } catch (error) { console.error('Error in game.down:', error); } }; // This is a duplicate checkInteractions function that has been consolidated elsewhere // Object placements are handled in the main initialization section // This is a duplicate addUFO function that has been consolidated elsewhere // Consolidated bird spawning functions // Consolidated bird spawning functions are inserted below // Removing duplicate jetTimer code as it's already defined elsewhere for (var i = 0; i < 4; i++) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); clouds.push(cloud); game.layers.clouds.addChild(cloud); } game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.layers.reticle.addChild(new Reticle()); } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x - 140, cat.y - 440, x, y); game.layers.laser.addChild(laser); }; // This is a duplicate checkInteractions function that has been consolidated elsewhere // Layer structure and initialization is already handled at the beginning of the file // Layer z-index management is handled by the layerStructure configuration // The spawn functions for UFO, Bird1, Bird2, and Jet are already defined earlier in the code // Layer z-index management is handled by the layerStructure configuration // The game.down function is already defined earlier in the code game.addChild(game.layers.enemies); // CloudMovement class to handle cloud movement and fade effects // UFOMovement class to handle UFO movement // UFOMovement has been moved to js/movements.js // Generic Pulse class that can be used for both Sun and Light1 /** * Reusable animation controller for pulsating effects using tween * @param {Graphics} graphics - Target graphics object to animate * @param {number} [scaleMax=1.1] - Maximum scale multiplier * @param {number} [duration=1000] - Full animation cycle duration in ms */ var Pulse = function Pulse(graphics, scaleMax, duration) { this.graphics = graphics; this.scaleMax = scaleMax || 1.1; this.duration = duration || 1000; /** * Starts continuous pulsating animation using recursive tween calls * Creates smooth scale oscillation through easeInOut timing */ this.startPulsating = function () { function pulsate() { tween(this.graphics, { scaleX: this.scaleMax, scaleY: this.scaleMax }, { duration: this.duration, easing: tween.easeInOut, onFinish: function () { tween(this.graphics, { scaleX: 1.0, scaleY: 1.0 }, { duration: this.duration, easing: tween.easeInOut, onFinish: pulsate.bind(this) }); }.bind(this) }); } pulsate.call(this); }; }; // Light1Pulse now uses the generic Pulse class /** Factory for light fixture pulse (higher intensity/longer duration) */ var Light1Pulse = function Light1Pulse(lightGraphics) { return new Pulse(lightGraphics, 1.6, 1500); }; // SunPulse now uses the generic Pulse class /** Factory for subtle solar glow pulse (conservative scaling) */ var SunPulse = function SunPulse(sunGraphics) { return new Pulse(sunGraphics, 1.1, 1000); }; // Bird2Effects class to handle effects and animations for Bird2 // Consolidated function to create a pulsating effect function startPulsating(target, duration) { duration = duration || 888; function pulsate() { tween(target, { scaleX: 1.1, // Use consistent scale value scaleY: 1.1 }, { duration: duration, easing: tween.easeInOut, onFinish: function onFinish() { tween(target, { scaleX: 1.0, scaleY: 1.0 }, { duration: duration, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); } var UFOSound = function UFOSound() { this.play = function () { LK.getSound('ufo1').play(); }; }; // BackgroundMusic class to manage background music function playSoundEffect(soundName, action) { var volume = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; try { var sound = LK.getSound(soundName); if (!sound) { console.warn("Sound '".concat(soundName, "' not found")); return; } switch (action) { case 'play': if (typeof sound.play === 'function') { sound.play({ volume: volume, loops: loops }); } break; case 'stop': if (typeof sound.stop === 'function') { sound.stop(); } break; case 'pause': if (typeof sound.pause === 'function') { sound.pause(); } break; default: console.warn("Unknown sound action: ".concat(action)); } } catch (error) { console.error("Error playing sound '".concat(soundName, "':"), error); } } var BackgroundMusic = function BackgroundMusic() { this.play = function () { LK.playMusic('bgm1', { loop: false, fade: { start: 0, end: 1, duration: 4000 } }); }; }; // LaserSound class to manage laser sound effects var LaserSound = function LaserSound() { this.play = function () { LK.getSound('laser1').play(); }; }; // Unified movement system for all entities /** * Bird1 movement configuration */ function BirdMovement(bird, birdGraphics, birdType) { var config = { baseSpeed: birdType === 'bird1' ? 1 : 1.5, speedVariation: birdType === 'bird1' ? 0.5 : 1.6, useWaveMotion: true, waveAmplitude: birdType === 'bird1' ? 4.5 : 6.5, waveFrequency: birdType === 'bird1' ? 120 : 100, horizontalMovement: false, textures: { left: "".concat(birdType, "-left"), right: "".concat(birdType, "-right") }, respawnPosition: birdType === 'bird1' ? 'top' : 'random', sounds: { move: 'wings1', destroy: null }, scoreValue: birdType === 'bird1' ? 5 : 10, entityType: birdType, onDestroy: function onDestroy(entity) { var index = birds.indexOf(entity); if (index > -1) { birds.splice(index, 1); LK.setTimeout(function () { if (birdType === 'bird1') { spawnBird1(); } else { spawnBird2(); } }, Math.random() * 2000 + 1000); } } }; createMovementSystem(bird, birdGraphics, config); } function UFOMovement(ufo, ufoGraphics) { var config = { baseSpeed: 3, speedVariation: 1, useWaveMotion: true, waveAmplitude: 50, waveFrequency: 100, horizontalMovement: true, baseY: Math.random() * 300 + 100, textures: null, sounds: { move: 'ufo1', destroy: null }, onDestroy: function onDestroy(entity) { if (entity.sounds && entity.sounds.move) { LK.getSound(entity.sounds.move).stop(); } entity.destroy(); ufo = null; handleUFOReappearance(); }, scoreValue: 20, entityType: 'ufo', handleLaserCollision: function handleLaserCollision(laser) { var angle = Math.atan2(laser.vy, laser.vx) + Math.PI; laser.vx = Math.cos(angle) * laser.speed; laser.vy = Math.sin(angle) * laser.speed; return false; } }; createMovementSystem(ufo, ufoGraphics, config); } /** * Jet movement configuration */ /** * Laser movement configuration */ function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) { // Calculate direction and speed var dx = targetX - startX; var dy = targetY - startY; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 60; // Speed of the laser laser.vx = dx / distance * speed; laser.vy = dy / distance * speed; // Set initial position laser.x = startX; laser.y = startY; // Initializes entity movement parameters with laser-specific configuration createMovementSystem(laser, laserGraphics, { entityType: 'laser', sounds: { move: 'laser2', destroy: null }, scoreValue: 0, screenBounds: { width: 2048, height: 2732 } }); return laser; } // CloudMovement class is already defined earlier in the file var Bird2Effects = function Bird2Effects(bird) { this.bird = bird; this.applyEffects = function () { // Apply swooping animation effect tween(this.bird, { rotation: Math.sin(this.bird.y / 100) * 0.2 }, { duration: 1000, easing: tween.easeInOut }); // Apply scale pulsing effect when moving fast if (Math.abs(this.bird.x - this.bird.lastX) > 5) { tween(this.bird, { scaleX: 1.1, scaleY: 1.1 }, { duration: 500, easing: tween.easeOut, onFinish: function () { tween(this.bird, { scaleX: 1.0, scaleY: 1.0 }, { duration: 500, easing: tween.easeIn }); }.bind(this) }); } }; }; var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2 - 100; game.layers.background.addChild(background); game.addChild(background); // ScoreManager class to manage score logic var ScoreManager = function ScoreManager() { var self = this; self.score = 0; self.addScore = function (points) { self.score += points; return self.score; }; self.resetScore = function () { self.score = 0; }; self.getScore = function () { return self.score; }; }; // Removed duplicate gameState declaration as it's now handled by GameState game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = new Reticle(); game.layers.reticle.addChild(game.reticle); } if (GameState.cat) { game.reticle.x = x; game.reticle.y = y; var laser = new Laser(GameState.cat.x - 140, GameState.cat.y - 440, x, y); game.layers.laser.addChild(laser); } }; game.move = function (x, y, obj) { if (!game.reticle) { game.reticle = new Reticle(); game.layers.reticle.addChild(game.reticle); } var eventX = obj && obj.event ? obj.event.x : x; var eventY = obj && obj.event ? obj.event.y : y; if (game.reticle) { game.reticle.x = eventX; game.reticle.y = eventY; } }; // Initialize sun and light1 var sun = game.layers.background.addChild(new Sun()); sun.x = 1800; sun.y = 300; var light1 = game.layers.background.addChild(new Light1()); light1.x = 450; light1.y = 440; // Add a sun to the game in the top left corner // Duplicate sun placement removed // Duplicate light1 placement removed // Move light1 down by 210px // Ensure light1 is added to the game before setting its index if (game.children.includes(light1)) { game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun // Add score display var scoreDisplay = game.addChild(new Mirror()); scoreDisplay.x = 1700; scoreDisplay.y = 300; } // Function to add a UFO to the game // Initialize clouds array GameState.clouds = []; GameState.birds = []; GameState.score = 0; for (var i = 0; i < 4; i++) { // Add 3 clouds for variety var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen clouds.push(cloud); game.layers.clouds.addChild(cloud); // No need to add cloud directly to game since it's already in the clouds layer } // Initialize birds spawnBird1(); spawnBird2(); spawnBird2(); // Start UFO 3 seconds after game loads var ufoTimer = LK.setTimeout(function () { GameState.ufo = addUFO(); game.layers.enemies.addChild(GameState.ufo); }, 3000); // Function to handle UFO reappearance logic function handleUFOReappearance() { if (!ufo) { LK.setTimeout(function () { ufo = addUFO(); }, Math.random() * 10000 + 20000); } } // Function to handle jet reappearance logic function handleJetReappearance() { try { jetTimer = LK.setTimeout(function () { var jet = new Jet(); jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2; jet.y = Math.random() * (2732 / 2 - jet.height); // Add to appropriate layer based on direction if (jet.x < 1024) { game.layers.jetLeft.addChild(jet); } else { game.layers.jetRight.addChild(jet); } game.jet = jet; if (!game.jetSoundPlayed) { playSoundEffect('jetSound', 'play', 0.3, true); game.jetSoundPlayed = true; } }, Math.random() * 5000 + 5000); } catch (error) { console.error('Error in handleJetReappearance:', error); } } // Initialize a timer to add a Jet at a random time between 5 and 10 seconds // Initial interval for Jet appearances 5-10 seconds after page load // Initialize enemy movement systems function initEnemyMovement(enemy) { if (enemy instanceof Bird1) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1'); } if (enemy instanceof Bird2) { enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2'); } if (enemy instanceof UFO) { enemy.movementSystem = new UFOMovement(enemy, enemy.graphics); } } // Main game loop function gameTick() { game.layers.enemies.children.forEach(function (enemy) { var _enemy$movementSystem; (_enemy$movementSystem = enemy.movementSystem) === null || _enemy$movementSystem === void 0 || _enemy$movementSystem.update(); }); checkInteractions(); requestAnimationFrame(gameTick); } /** * Main game update function * Uses the unified movement system for all entities */ game.update = function () { // Update all clouds for (var i = 0; i < clouds.length; i++) { clouds[i].update(); } // Ensure at least 3 clouds are visible while (clouds.length < 3) { var cloud = new Cloud(); cloud.x = Math.random() * 2048; cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen clouds.push(cloud); game.layers.clouds.addChild(cloud); } // Update all birds birds.forEach(function (bird) { bird.update(); }); // Ensure we have enough birds while (birds.length < 3) { if (birds.length % 2 === 0) { spawnBird1(); } else { spawnBird2(); } } // Update all lasers game.layers.laser.children.forEach(function (laser) { laser.update(); }); // Update UFO if it exists if (GameState.ufo) { GameState.ufo.update(); } // Check for all interactions between game entities checkInteractions(); }; // Function to spawn a third kind of bird // Consolidated bird spawning functions are inserted below // Ensure there are always 3 birds on screen // Initialize enemy movement systems game.update = function () { // Update each bird birds.forEach(function (bird, index) { bird.update(); // Check for intersections with other birds birds.forEach(function (otherBird, otherIndex) { if (index !== otherIndex && !bird.lastIntersecting && bird.intersects(otherBird)) { // Calculate bounce direction var dx = bird.x - otherBird.x; var dy = bird.y - otherBird.y; var distance = Math.sqrt(dx * dx + dy * dy); var bounceFactor = 5; // Adjust bounce factor for desired effect // Apply bounce with acceleration bird.x += dx / distance * bounceFactor; bird.y += dy / distance * bounceFactor; otherBird.x -= dx / distance * bounceFactor; otherBird.y -= dy / distance * bounceFactor; // Mark as intersecting bird.lastIntersecting = true; otherBird.lastIntersecting = true; } }); // Reset intersection state bird.lastIntersecting = birds.some(function (otherBird, otherIndex) { return index !== otherIndex && bird.intersects(otherBird); }); // Check if the bird has moved off-screen if (bird.lastY <= 2732 && bird.y > 2732) { bird.y = -bird.height; // Respawn the bird at the top bird.x = Math.random() * 2048; // Randomize the x position bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird } }); }; // Note: Tree and stack1 are already added to their respective layers earlier in the code // This section is redundant and can be removed // Add the grass floor to the game var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer grassBack.x = 1020; grassBack.y = 2735; // Position grassBack at the bottom // Note: grassFront and mirror are already added to their respective layers earlier in the code // This section is redundant and can be removed as it causes duplicate rendering // Function to handle bgm1 end event // Initialize cat instance GameState.cat = new Cat(); GameState.cat.x = 2048 / 2; GameState.cat.y = 2732 - 100; game.layers.cat.addChild(GameState.cat); function initBackgroundMusic() { try { LK.playMusic('bgm1', { loop: false, volume: SOUND_VOLUMES.bgm1, fade: { start: 0, end: 1, duration: 4000 }, onEnd: function onEnd() { LK.setTimeout(function () { initBackgroundMusic(); }, Math.random() * 30000 + 20000); } }); } catch (error) { console.error('Error initializing background music:', error); } } // Initialize background music initBackgroundMusic(); // Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds var wingsTimer = LK.setTimeout(function () { LK.getSound('wings1').play(); wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000); }, Math.random() * 20000 + 10000); // Create an array for all sounds except ufo1, including all birdsong sounds var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1']; var currentAmbientSound = null; // Initialize random timers for each sound to play between 30-50 seconds sounds.forEach(function (soundId) { var sound = LK.getSound(soundId); var ambientSoundTimer = LK.setTimeout(function () { if (currentAmbientSound) { currentAmbientSound.stop(); // Stop the currently playing ambient sound } sound.play(); currentAmbientSound = sound; // Set the current ambient sound // Set a timeout to reset the current ambient sound after it finishes playing LK.setTimeout(function () { currentAmbientSound = null; }, sound.duration * 1000); // Convert duration from seconds to milliseconds // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000); }, Math.random() * 20000 + 30000); }); /** * Check for interactions between game entities */ function checkInteractions() { try { // Lasers vs Enemies if (game.layers.laser && game.layers.enemies) { game.layers.laser.children.forEach(function (laser) { if (!laser || !laser.intersects) { return; } game.layers.enemies.children.forEach(function (enemy) { if (!enemy || !enemy.intersects) { return; } if (laser.intersects(enemy)) { try { // Use the handleLaserCollision method if available if (typeof enemy.handleLaserCollision === 'function') { var destroyed = enemy.handleLaserCollision(laser); if (destroyed && typeof enemy.getScoreValue === 'function') { score += enemy.getScoreValue(); if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') { scoreDisplay.updateScore(score); } } } else { enemy.destroy(); laser.destroy(); if (typeof enemy.getScoreValue === 'function') { score += enemy.getScoreValue(); if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') { scoreDisplay.updateScore(score); } } else { // Default score increment if getScoreValue is not available score += 5; if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') { scoreDisplay.updateScore(score); } } } } catch (error) { console.error('Error handling laser collision:', error); } } }); }); } // UFO vs Enemies if (game.layers.enemies) { var ufo = game.layers.enemies.children.find(function (child) { return child instanceof UFO; }); if (ufo && typeof ufo.intersects === 'function') { game.layers.enemies.children.forEach(function (enemy) { if (!enemy || !enemy.intersects || enemy === ufo) { return; } if (ufo.intersects(enemy)) { try { enemy.destroy(); var sound = LK.getSound('electro'); if (sound && typeof sound.play === 'function') { sound.play(); } } catch (error) { console.error('Error handling UFO collision:', error); } } }); } } } catch (error) { console.error('Error in checkInteractions:', error); } } /**** * Utility Functions ****/ /** * Simple movement update function that works with the consolidated movement system * This is kept for backward compatibility with existing code that uses it */ function updateMovement(obj, params) { // If the object already has a movement system applied, use that if (typeof obj.update === 'function' && obj.speed !== undefined) { obj.speed = params.speed || obj.speed; obj.direction = params.direction || obj.direction; return; } // Otherwise apply simple movement obj.x += params.speed * params.direction; if (params.boundaryCheck) { handleScreenBoundaries(obj, params.boundaryWidth); } } function updateDirection(obj, graphics, rightAsset, leftAsset) { graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture; } function handleScreenBoundaries(obj, screenWidth) { if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) { obj.x = -obj.width / 2; } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) { obj.x = screenWidth + obj.width / 2; } } function handleCollisions(obj, others, collisionHandler) { others.forEach(function (other) { if (other !== obj && obj.intersects(other)) { collisionHandler(obj, other); } }); } function handleSunInteraction(obj, sun, enterHandler, exitHandler) { var intersecting = obj.intersects(sun); if (!obj.lastIntersecting && intersecting) { enterHandler(obj); } else if (obj.lastIntersecting && !intersecting) { exitHandler(obj); } obj.lastIntersecting = intersecting; } function handleDestruction(obj, sounds) { if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) { sounds.forEach(function (sound) { return LK.getSound(sound).stop(); }); obj.destroy(); } } // Updated Cloud update method self.cloud.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction, boundaryCheck: true, boundaryWidth: 2048 }); handleCollisions(this, clouds, function (cloud, other) { if (!cloud.hasAccelerated) { cloud.speed *= 1.5; cloud.hasAccelerated = true; } }); handleSunInteraction(this, sun, function (cloud) { cloud.speed *= 2; tween(cloud.cloudGraphics, { alpha: 0.5 }, { duration: 3000 }); }, function (cloud) { cloud.speed /= 2; tween(cloud.cloudGraphics, { alpha: 1.0 }, { duration: 3000 }); }); this.lastX = this.x; }; // Updated Jet update method self.update = function () { updateMovement(this, { speed: this.speed, direction: this.direction }); updateDirection(this, jetGraphics, 'jet-right', 'jet-left'); handleDestruction(this, ['jetSound']); }; // Note: Tree and stack1 are already added to their respective layers earlier in the code // This section is redundant and can be removed // Add the grass floor to the game
===================================================================
--- original.js
+++ change.js
@@ -1,33 +1,434 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Cat class to manage cat behavior
+var Cat = Container.expand(function () {
+ var self = Container.call(this);
+ var catGraphics = self.attachAsset('cat', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.update = function () {
+ // Add any specific update logic for the cat here
+ };
+});
+// Cloud container with 80% opacity
+var Cloud = Container.expand(function () {
+ var self = Container.call(this);
+ var cloudGraphics = self.attachAsset('cloud', {
+ alpha: 0.8
+ });
+ self.cloudGraphics = cloudGraphics;
+ self.cloud = {
+ speed: Math.random() * 0.55 + 0.25,
+ direction: 1,
+ x: 0,
+ y: 0
+ };
+ self.movement = createMovementSystem(self, cloudGraphics, {
+ baseSpeed: self.cloud.speed,
+ horizontalMovement: true,
+ entityType: 'cloud'
+ });
+ self.update = function () {
+ try {
+ // Update position based on current speed and direction
+ this.x += this.speed * this.direction;
+ // Handle cloud interactions
+ for (var i = 0; i < clouds.length; i++) {
+ if (clouds[i] !== this && this.intersects(clouds[i])) {
+ if (!this.hasAccelerated) {
+ this.speed *= 1.5;
+ this.hasAccelerated = true;
+ }
+ break;
+ } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
+ this.speed /= 1.5;
+ this.hasAccelerated = false;
+ }
+ }
+ // Handle sun interaction
+ if (sun && typeof this.intersects === 'function') {
+ if (!this.lastIntersecting && this.intersects(sun)) {
+ this.speed *= 2;
+ tween(this.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
+ } else if (this.lastIntersecting && !this.intersects(sun)) {
+ this.speed /= 2;
+ tween(this.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000,
+ easing: tween.linear
+ });
+ }
+ this.lastIntersecting = this.intersects(sun);
+ }
+ // Handle screen boundaries
+ if (this.x > 2048 + this.width / 2) {
+ this.x = -this.width / 2;
+ } else if (this.x < -this.width / 2) {
+ this.x = 2048 + this.width / 2;
+ }
+ } catch (error) {
+ console.error('Cloud update error:', error);
+ // Fallback to local simulation
+ if (this.__proto__ && typeof this.__proto__.update === 'function') {
+ this.__proto__.update.call(this);
+ }
+ }
+ };
+ self.addChild(cloudGraphics);
+});
+// CloudMovement class to handle cloud movement and fade effects
+// GrassBack class to represent the grass image
+var GrassBack = Container.expand(function () {
+ var self = Container.call(this);
+ var grassGraphics = self.attachAsset('grass-back', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.update = function () {
+ // Add any specific update logic for the grass here
+ // Example: Slightly move the grass to simulate wind effect
+ self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
+ };
+ self.addChild(grassGraphics); // Add grass graphics to the container
+});
+// GrassFront class to represent the second grass image
+var GrassFront = Container.expand(function () {
+ var self = Container.call(this);
+ var grass2Graphics = self.attachAsset('grass-front', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.lastX = self.x; // Initialize lastX for tracking changes on X
+ self.addChild(grass2Graphics); // Add grass2 graphics to the container
+ self.update = function () {
+ updateMovement(self, {
+ movementType: 'sinusoidal',
+ amplitude: 0.125,
+ frequency: 100,
+ offset: 50
+ });
+ };
+});
+// Jet class to represent a jet flying across the screen
+var Jet = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-right', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initializes entity movement parameters
+ createMovementSystem(self, jetGraphics, {
+ baseSpeed: 8,
+ speedVariation: 0,
+ useWaveMotion: true,
+ waveAmplitude: 100,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: 300,
+ textures: {
+ left: 'jet-left',
+ right: 'jet-right'
+ },
+ respawnPosition: 'side',
+ sounds: {
+ move: 'jetSound',
+ destroy: 'jetSound'
+ },
+ onDestroy: function onDestroy(entity) {
+ handleJetReappearance();
+ },
+ entityType: 'jet'
+ });
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop(); // Ensure sound stops when jet is destroyed
+ };
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
+ }
+ };
+});
+var JetLeft = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-left', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initializes entity movement parameters with fixed left direction
+ createMovementSystem(self, jetGraphics, {
+ baseSpeed: 8,
+ speedVariation: 0,
+ useWaveMotion: true,
+ waveAmplitude: 100,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: 300,
+ textures: {
+ left: 'jet-left',
+ right: 'jet-right'
+ },
+ respawnPosition: 'side',
+ sounds: {
+ move: 'jetSound',
+ destroy: 'jetSound'
+ },
+ onDestroy: function onDestroy(entity) {
+ handleJetReappearance();
+ },
+ entityType: 'jet'
+ });
+ self.direction = -1; // Always left
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop();
+ };
+});
+var JetRight = Container.expand(function () {
+ var self = Container.call(this);
+ var jetGraphics = self.attachAsset('jet-right', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initializes entity movement parameters with fixed right direction
+ createMovementSystem(self, jetGraphics, {
+ baseSpeed: 8,
+ speedVariation: 0,
+ useWaveMotion: true,
+ waveAmplitude: 100,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: 300,
+ textures: {
+ left: 'jet-left',
+ right: 'jet-right'
+ },
+ respawnPosition: 'side',
+ sounds: {
+ move: 'jetSound',
+ destroy: 'jetSound'
+ },
+ onDestroy: function onDestroy(entity) {
+ handleJetReappearance();
+ },
+ entityType: 'jet'
+ });
+ self.direction = 1; // Always right
+ self.onDestroy = function () {
+ LK.getSound('jetSound').stop();
+ };
+});
+// Laser class to represent a laser shot from the cat
+var Laser = Container.expand(function (startX, startY, targetX, targetY) {
+ var self = Container.call(this);
+ var laserGraphics = self.attachAsset('laser2', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ brightness: 2.0 // Increase brightness by 200%
+ });
+ // Play the laser1 sound when the laser is created
+ LK.getSound('laser1').play();
+ // Initializes entity movement parameters
+ LaserMovement(self, laserGraphics, startX, startY, targetX, targetY);
+ return self;
+});
+// Light1 class to represent a light object
+var Light1 = Container.expand(function () {
+ var self = Container.call(this);
+ var lightGraphics = self.attachAsset('light1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.2 // Set transparency to 20%
+ });
+ self.x = 450, self.y = 440;
+ self.update = function () {
+ // Add any specific update logic for the light here
+ };
+ self.pulse = new Light1Pulse(lightGraphics);
+ self.pulse.startPulsating();
+});
+// Mirror class to manage score display
+var Mirror = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreGraphics = self.attachAsset('mirror1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / 14 // Rotate image right 15 degrees
+ });
+ var scoreText = new Text2('0', {
+ size: 175,
+ fill: 0x800080,
+ font: "Courier New, Courier, monospace",
+ // Segmented clock style font
+ stroke: 0x00FF00,
+ strokeThickness: 15,
+ dropShadow: true,
+ dropShadowColor: 0x000000,
+ dropShadowBlur: 5,
+ dropShadowAngle: Math.PI / 6,
+ dropShadowDistance: 6
+ });
+ scoreText.y = 40; // Move score text up by 20px
+ scoreText.x = -145; // Move score text left by 10px
+ scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees
+ self.addChild(scoreText);
+ self.updateScore = function (newScore) {
+ scoreText.setText(newScore);
+ };
+});
+// Mirror1 class to represent the mirror image
+var Mirror1 = Container.expand(function () {
+ var self = Container.call(this);
+ var mirror1Graphics = self.attachAsset('mirror1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(mirror1Graphics);
+});
+// Reticle class to manage reticle behavior
+var Reticle = Container.expand(function () {
+ var self = Container.call(this);
+ var reticleGraphics = self.attachAsset('reticle1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Add any specific update logic for the reticle here
+ };
+ // Start the pulsating effect for the reticle
+ startPulsating(self);
+});
+// Reticle1 class to represent the reticle image
+var Reticle1 = Container.expand(function () {
+ var self = Container.call(this);
+ var reticle1Graphics = self.attachAsset('reticle1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(reticle1Graphics);
+});
+// ScoreImage class to represent the score image
+var ScoreImage = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreImageGraphics = self.attachAsset('scoreImage', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(scoreImageGraphics);
+});
+// Stack1 class to represent the stack1 image
+var Stack1 = Container.expand(function () {
+ var self = Container.call(this);
+ var stackGraphics = self.attachAsset('stack1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / -12
+ });
+ self.update = function () {
+ // Add any specific update logic for stack1 here
+ };
+});
+// ScoreManager class to manage score logic
+// Sun class to represent a sun in the top right corner
+var Sun = Container.expand(function () {
+ var self = Container.call(this);
+ var sunGraphics = self.attachAsset('sun', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.pulse = new SunPulse(sunGraphics);
+ self.pulse.startPulsating();
+});
+// Function to create a pulsating effect
+// Tree class to represent a tree with a 9:16 aspect ratio
+var Tree = Container.expand(function () {
+ var self = Container.call(this);
+ var treeGraphics = self.attachAsset('tree', {
+ anchorX: 0.5,
+ anchorY: 1,
+ antialias: true,
+ // Apply antialias effect
+ stroke: 0x000000,
+ // Add a black stroke
+ strokeThickness: 15 // Set stroke thickness to 15px
+ });
+ self.update = function () {
+ // Add any specific update logic for the tree here
+ };
+});
+// Tree2 class to represent the second type of tree
+var Tree2 = Container.expand(function () {
+ var self = Container.call(this);
+ var tree2Graphics = self.attachAsset('tree2', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.addChild(tree2Graphics);
+});
+// UFO class to represent a UFO
+var UFO = Container.expand(function () {
+ var self = Container.call(this);
+ var ufoGraphics = self.attachAsset('ufo2', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initializes entity movement parameters
+ UFOMovement(self, ufoGraphics);
+ self.setChildIndex = function (index) {
+ if (game.children.includes(self)) {
+ game.setChildIndex(self, index);
+ }
+ };
+});
+// UFO2 class to represent the second type of UFO
+var UFO2 = Container.expand(function () {
+ var self = Container.call(this);
+ var ufo2Graphics = self.attachAsset('ufo2', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initializes entity movement parameters
+ UFOMovement(self, ufo2Graphics);
+});
+
+/****
* Initialize Game
****/
+// Game instance already initialized above
+// Layer structure initialization with proper cleanup handling
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
-var app = new Application({
- width: 2048,
- height: 2732,
- backgroundColor: 0x000000
-});
-document.body.appendChild(app.view);
+// Sound configuration
+/****
+* Game Configuration
+****/
+// Music and Sounds
+// Images
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
-function _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);
@@ -55,409 +456,1344 @@
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
-var Game = /*#__PURE__*/function () {
- function Game() {
- _classCallCheck(this, Game);
- // Core game properties
- this.score = 0;
- this.isGameOver = false;
- // Game entities
- this.birds = [];
- this.clouds = [];
- this.ufo = null;
- this.background = null;
- this.scoreText = null;
- this.gameOverText = null;
- // Movement state
- this.isMovingDown = false;
- // Layer management
- this.layers = {
- background: new Container(),
- game: new Container(),
- ui: new Container()
- };
- this.layerOrder = ['background', 'game', 'ui'];
- this.activeLayer = 'game';
- // Sound management
- this.sounds = {};
- // Entity spawn intervals
- this.spawnIntervals = {
- bird: {
- min: 1000,
- max: 2000
- },
- ufo: 10000
- };
- this.initializeGame();
+function _classCallCheck(a, n) {
+ if (!(a instanceof n)) {
+ throw new TypeError("Cannot call a class as a function");
}
- // Initialization Methods
- return _createClass(Game, [{
- key: "initializeGame",
- value: function initializeGame() {
- var _this = this;
- // Initialize game containers with proper z-index
- this.layerOrder.forEach(function (layerName, index) {
- var layer = _this.layers[layerName];
- layer.zIndex = index;
- app.stage.addChild(layer);
- });
- app.stage.sortChildren();
- // Add layer management methods
- this.initializeLayerManagement();
- // Initialize background
- this.background = new Background();
- this.layers.background.addChild(this.background);
- // Initialize sounds
- this.initializeSounds();
- // Start game loop
- this.gameLoop = this.gameLoop.bind(this);
- app.ticker.add(this.gameLoop);
- // Initialize event listeners
- this.initializeEventListeners();
- // Start spawning entities
- this.startEntitySpawning();
+}
+function _callSuper(t, o, e) {
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
+}
+function _possibleConstructorReturn(t, e) {
+ if (e && ("object" == _typeof(e) || "function" == typeof e)) {
+ return e;
+ }
+ if (void 0 !== e) {
+ throw new TypeError("Derived constructors may only return object or undefined");
+ }
+ return _assertThisInitialized(t);
+}
+function _assertThisInitialized(e) {
+ if (void 0 === e) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
+ return e;
+}
+function _isNativeReflectConstruct() {
+ try {
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
+ } catch (t) {}
+ return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
+ return !!t;
+ })();
+}
+function _getPrototypeOf(t) {
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
+ return t.__proto__ || Object.getPrototypeOf(t);
+ }, _getPrototypeOf(t);
+}
+function _inherits(t, e) {
+ if ("function" != typeof e && null !== e) {
+ throw new TypeError("Super expression must either be null or a function");
+ }
+ t.prototype = Object.create(e && e.prototype, {
+ constructor: {
+ value: t,
+ writable: !0,
+ configurable: !0
}
- }, {
- key: "initializeSounds",
- value: function initializeSounds() {
- this.sounds = {
- jet: new Howl({
- src: ['sounds/jet.mp3'],
+ }), Object.defineProperty(t, "prototype", {
+ writable: !1
+ }), e && _setPrototypeOf(t, e);
+}
+function _setPrototypeOf(t, e) {
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
+ return t.__proto__ = e, t;
+ }, _setPrototypeOf(t, e);
+}
+var GAME_SOUND_VOLUMES = {
+ bgm1: 0.02,
+ breeze1: 0.02,
+ cricket1: 0.02,
+ frog1: 0.02,
+ songbird1: 0.02,
+ ufo1: 0.02,
+ wings1: 0.02,
+ laser1: 0.1,
+ laser2: 0.1,
+ jetSound: 0.3
+};
+/****
+* Core Game Setup
+****/
+// Initialize game instance
+var gameInstance = new LK.Game({
+ backgroundColor: 0x000000
+});
+// Layer structure initialization
+var layers = {
+ background: new Container(),
+ sun: new Container(),
+ light1: new Container(),
+ jetLeft: new Container(),
+ jetRight: new Container(),
+ clouds: new Container(),
+ ufo: new Container(),
+ grassBack: new Container()
+};
+var Background = /*#__PURE__*/function (_Container) {
+ function Background() {
+ var _this;
+ _classCallCheck(this, Background);
+ _this = _callSuper(this, Background);
+ _this.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return _this;
+ }
+ _inherits(Background, _Container);
+ return _createClass(Background);
+}(Container); // Branch asset
+var Bird = /*#__PURE__*/function (_Container2) {
+ function Bird(type) {
+ var _this2;
+ _classCallCheck(this, Bird);
+ _this2 = _callSuper(this, Bird);
+ var birdGraphics = _this2.attachAsset("".concat(type, "-right"), {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ _this2.birdGraphics = birdGraphics;
+ BirdMovement(_this2, _this2.birdGraphics, type);
+ return _this2;
+ }
+ _inherits(Bird, _Container2);
+ return _createClass(Bird, [{
+ key: "setChildIndex",
+ value: function setChildIndex(index) {
+ if (game.children.includes(this)) {
+ game.setChildIndex(this, index);
+ }
+ }
+ }]);
+}(Container);
+var Bird1 = /*#__PURE__*/function (_Bird) {
+ function Bird1() {
+ _classCallCheck(this, Bird1);
+ return _callSuper(this, Bird1, ['bird1']);
+ }
+ _inherits(Bird1, _Bird);
+ return _createClass(Bird1);
+}(Bird);
+var Bird2 = /*#__PURE__*/function (_Bird2) {
+ function Bird2() {
+ _classCallCheck(this, Bird2);
+ return _callSuper(this, Bird2, ['bird2']);
+ }
+ _inherits(Bird2, _Bird2);
+ return _createClass(Bird2);
+}(Bird); // Layer z-index management is handled by the layerStructure configuration
+// Layer structure and initialization is already handled at the beginning of the file
+// Consolidated checkInteractions function is inserted below
+// Bird2Movement class to handle Bird2 movement
+// Bird2Movement class to handle Bird2 movement
+/**
+* Configures movement behavior for game entities with tween-based animations
+* @param {Container} entity - Target entity container
+* @param {Graphics} graphics - Visual representation to animate
+* @param {Object} config - Movement configuration:
+* @param {number} [config.baseSpeed=1] - Base movement speed
+* @param {Object} config.textures - Directional sprites {left, right}
+* @param {boolean} [config.useWaveMotion=false] - Enable sine-based path
+* @param {number} [config.waveAmplitude=0] - Vertical deviation magnitude
+* @param {number} [config.waveFrequency=100] - Horizontal wave cycle length
+*/
+// Consolidated movement system with state tracking and error boundaries
+function createMovementSystem(entity, entityGraphics, config) {
+ if (!entity || !entityGraphics) {
+ console.error('Entity and entityGraphics are required for movement system');
+ return null;
+ }
+ var defaults = {
+ baseSpeed: 1,
+ speedVariation: 0,
+ horizontalMovement: false,
+ useWaveMotion: false,
+ waveAmplitude: 0,
+ waveFrequency: 100,
+ screenBounds: {
+ width: 2048,
+ height: 2732
+ },
+ respawnDelay: {
+ min: 10000,
+ max: 20000
+ },
+ respawnPosition: 'top',
+ textures: {
+ left: null,
+ right: null
+ },
+ sounds: {
+ move: null,
+ destroy: null
+ },
+ scoreValue: 0,
+ entityType: null,
+ onDestroy: null,
+ spawnInterval: {
+ min: 2000,
+ max: 5000
+ },
+ maxRetries: 3
+ };
+ // Enhanced state tracking
+ entity.movementState = {
+ isMovingDown: false,
+ isMovingHorizontal: false,
+ lastUpdate: Date.now(),
+ retryCount: 0
+ };
+ var settings = Object.assign({}, defaults, config || {});
+ entity.speed = settings.baseSpeed + Math.random() * settings.speedVariation;
+ entity.direction = settings.horizontalMovement ? Math.random() < 0.5 ? 1 : -1 : 1;
+ entity.lastX = entity.x || 0;
+ entity.lastY = entity.y || 0;
+ if (settings.sounds && settings.sounds.move) {
+ try {
+ var sound = LK.getSound(settings.sounds.move);
+ if (sound && typeof sound.play === 'function') {
+ sound.play({
loop: true
- }),
- explosion: new Howl({
- src: ['sounds/explosion.mp3']
- }),
- point: new Howl({
- src: ['sounds/point.mp3']
- })
- };
+ });
+ }
+ } catch (error) {
+ console.error('Error playing movement sound:', error);
}
- }, {
- key: "initializeEventListeners",
- value: function initializeEventListeners() {
- window.addEventListener('keydown', this.handleKeyDown.bind(this));
- window.addEventListener('keyup', this.handleKeyUp.bind(this));
- }
- }, {
- key: "initializeLayerManagement",
- value: function initializeLayerManagement() {
- var _this2 = this;
- // Layer visibility control
- this.showLayer = function (layerName) {
- if (_this2.layers[layerName]) {
- _this2.layers[layerName].visible = true;
- }
- };
- this.hideLayer = function (layerName) {
- if (_this2.layers[layerName]) {
- _this2.layers[layerName].visible = false;
- }
- };
- // Layer order management
- this.setLayerIndex = function (layerName, newIndex) {
- if (!_this2.layers[layerName] || newIndex < 0 || newIndex >= _this2.layerOrder.length) {
+ }
+ entity.scoreValue = settings.scoreValue;
+ entity.update = function () {
+ try {
+ if (settings.entityType === 'laser') {
+ if (!this.vx || !this.vy) {
return;
}
- var oldIndex = _this2.layerOrder.indexOf(layerName);
- _this2.layerOrder.splice(oldIndex, 1);
- _this2.layerOrder.splice(newIndex, 0, layerName);
- // Update z-index for all layers
- _this2.layerOrder.forEach(function (name, index) {
- _this2.layers[name].zIndex = index;
- });
- app.stage.sortChildren();
- };
- // Active layer management
- this.setActiveLayer = function (layerName) {
- if (_this2.layers[layerName]) {
- _this2.activeLayer = layerName;
+ this.x += this.vx;
+ this.y += this.vy;
+ if (this.x < 0 || this.x > settings.screenBounds.width || this.y < 0 || this.y > settings.screenBounds.height) {
+ if (typeof this.destroy === 'function') {
+ this.destroy();
+ }
}
- };
- // Add content to specific layer
- this.addToLayer = function (layerName, displayObject) {
- if (_this2.layers[layerName] && displayObject) {
- _this2.layers[layerName].addChild(displayObject);
+ } else if (settings.horizontalMovement) {
+ this.x += this.speed * this.direction;
+ if (settings.useWaveMotion && settings.baseY !== undefined) {
+ this.y = settings.baseY + Math.sin(this.x / settings.waveFrequency) * settings.waveAmplitude;
}
- };
- // Remove content from specific layer
- this.removeFromLayer = function (layerName, displayObject) {
- if (_this2.layers[layerName] && displayObject) {
- _this2.layers[layerName].removeChild(displayObject);
+ } else {
+ this.y += this.speed;
+ if (settings.useWaveMotion) {
+ this.x += Math.sin(this.y / settings.waveFrequency) * settings.waveAmplitude;
}
- };
- }
- // Event Handlers
- }, {
- key: "handleKeyDown",
- value: function handleKeyDown(event) {
- if (event.key === 'ArrowDown' && !this.isGameOver) {
- this.down();
}
- }
- }, {
- key: "handleKeyUp",
- value: function handleKeyUp(event) {
- if (event.key === 'ArrowDown' && !this.isGameOver) {
- this.up();
+ if (entityGraphics && settings.textures && settings.textures.left && settings.textures.right) {
+ try {
+ var rightAsset = LK.getAsset(settings.textures.right, {});
+ var leftAsset = LK.getAsset(settings.textures.left, {});
+ if (rightAsset && leftAsset) {
+ entityGraphics.texture = this.lastX <= this.x ? rightAsset.texture : leftAsset.texture;
+ }
+ } catch (error) {
+ console.error('Error updating entity texture:', error);
+ }
}
- }
- }, {
- key: "down",
- value: function down() {
- if (this.background) {
- var _this$background$twee;
- (_this$background$twee = this.background.tween) === null || _this$background$twee === void 0 || _this$background$twee.kill();
- this.background.tween = gsap.to(this.background, {
- y: 100,
- duration: 0.5,
- ease: 'power2.out'
- });
+ if (settings.horizontalMovement) {
+ if (this.lastX <= settings.screenBounds.width + this.width / 2 && this.x > settings.screenBounds.width + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
+ if (settings.sounds && settings.sounds.destroy) {
+ try {
+ var sound = LK.getSound(settings.sounds.destroy);
+ if (sound && typeof sound.stop === 'function') {
+ sound.stop();
+ }
+ } catch (error) {
+ console.error('Error stopping destroy sound:', error);
+ }
+ }
+ if (typeof this.destroy === 'function') {
+ this.destroy();
+ }
+ if (settings.onDestroy) {
+ settings.onDestroy(this);
+ }
+ }
+ } else if (this.lastY <= settings.screenBounds.height && this.y > settings.screenBounds.height) {
+ switch (settings.respawnPosition) {
+ case 'random':
+ this.y = Math.random() * settings.screenBounds.height;
+ this.x = Math.random() < 0.5 ? 0 : settings.screenBounds.width;
+ break;
+ case 'side':
+ this.y = Math.random() * settings.screenBounds.height;
+ this.x = this.direction > 0 ? -this.width : settings.screenBounds.width + this.width;
+ break;
+ case 'top':
+ default:
+ this.y = -this.height;
+ this.x = Math.random() * settings.screenBounds.width;
+ break;
+ }
}
- this.sounds.jet.play();
+ this.lastX = this.x;
+ this.lastY = this.y;
+ } catch (error) {
+ console.error('Error in entity update:', error);
}
- }, {
- key: "up",
- value: function up() {
- if (this.background) {
- var _this$background$twee2;
- (_this$background$twee2 = this.background.tween) === null || _this$background$twee2 === void 0 || _this$background$twee2.kill();
- this.background.tween = gsap.to(this.background, {
- y: 0,
- duration: 0.5,
- ease: 'power2.out'
- });
+ }.bind(entity);
+ return entity;
+}
+// Game instance already initialized above
+// Layer structure initialization with proper cleanup handling
+var initializeLayers = function initializeLayers() {
+ game.layers = {
+ background: new Container(),
+ sun: new Container(),
+ light1: new Container(),
+ jetLeft: new Container(),
+ jetRight: new Container(),
+ clouds: new Container(),
+ ufo: new Container(),
+ grassBack: new Container(),
+ bird1: new Container(),
+ tree: new Container(),
+ stack1: new Container(),
+ bird2: new Container(),
+ mirror: new Container(),
+ grassFront: new Container(),
+ cat: new Container(),
+ laser: new Container(),
+ reticle: new Container(),
+ enemies: new Container(),
+ birds: new Container()
+ };
+ // Add cleanup methods to each layer
+ Object.values(game.layers).forEach(function (layer) {
+ layer.cleanup = function () {
+ while (this.children.length > 0) {
+ var child = this.children[0];
+ if (typeof child.destroy === 'function') {
+ child.destroy();
+ }
+ this.removeChild(child);
}
- this.sounds.jet.stop();
- }
- // Entity Management
- }, {
- key: "startEntitySpawning",
- value: function startEntitySpawning() {
- // Spawn initial clouds
- var INITIAL_CLOUDS = 3;
- for (var i = 0; i < INITIAL_CLOUDS; i++) {
- this.spawnCloud();
+ };
+ });
+ return game.layers;
+};
+game.layers = initializeLayers();
+/****
+* Game State
+****/
+// Add base BirdMovement class (missing)
+// Initialize game state as a module-level singleton
+var GameState = {
+ birds: [],
+ clouds: [],
+ ufo: null,
+ score: 0,
+ scoreDisplay: null,
+ cat: null,
+ sounds: new Set(),
+ reticle: null,
+ jet: null,
+ jetSoundPlayed: false,
+ reset: function reset() {
+ // Clean up birds
+ this.birds.forEach(function (bird) {
+ if (typeof bird.destroy === 'function') {
+ bird.destroy();
}
- // Start bird spawning
- this.spawnBird();
- // Start UFO spawning with delay
- this.spawnUFOWithDelay();
- }
- }, {
- key: "spawnCloud",
- value: function spawnCloud() {
- try {
- var cloud = new Cloud();
- this.clouds.push(cloud);
- this.addToLayer('game', cloud);
- } catch (error) {
- console.error('Error spawning cloud:', error);
+ });
+ this.birds = [];
+ // Clean up clouds
+ this.clouds.forEach(function (cloud) {
+ if (typeof cloud.destroy === 'function') {
+ cloud.destroy();
}
+ });
+ this.clouds = [];
+ // Clean up UFO
+ if (this.ufo && typeof this.ufo.destroy === 'function') {
+ this.ufo.destroy();
+ this.ufo = null;
}
- }, {
- key: "spawnBird",
- value: function spawnBird() {
- var _this3 = this;
- if (this.isGameOver) {
- return;
- }
- try {
- var bird = new Bird();
- this.birds.push(bird);
- this.addToLayer('game', bird);
- // Schedule next bird spawn with random interval
- var nextSpawnDelay = Math.random() * (this.spawnIntervals.bird.max - this.spawnIntervals.bird.min) + this.spawnIntervals.bird.min;
- setTimeout(function () {
- return _this3.spawnBird();
- }, nextSpawnDelay);
- } catch (error) {
- console.error('Error spawning bird:', error);
- // Retry spawning after a delay if failed
- setTimeout(function () {
- return _this3.spawnBird();
- }, this.spawnIntervals.bird.max);
- }
+ // Clean up reticle
+ if (this.reticle && typeof this.reticle.destroy === 'function') {
+ this.reticle.destroy();
+ this.reticle = null;
}
- }, {
- key: "spawnUFOWithDelay",
- value: function spawnUFOWithDelay() {
- var _this4 = this;
- setTimeout(function () {
- if (!_this4.isGameOver) {
- _this4.spawnUFO();
- }
- }, this.spawnIntervals.ufo);
+ // Clean up jet
+ if (this.jet && typeof this.jet.destroy === 'function') {
+ this.jet.destroy();
+ this.jet = null;
+ this.jetSoundPlayed = false;
}
- }, {
- key: "spawnUFO",
- value: function spawnUFO() {
+ // Stop all active sounds
+ this.sounds.forEach(function (soundName) {
try {
- if (!this.ufo && !this.isGameOver) {
- this.ufo = new UFO();
- this.addToLayer('game', this.ufo);
+ var sound = LK.getSound(soundName);
+ if (sound && typeof sound.stop === 'function') {
+ sound.stop();
}
} catch (error) {
- console.error('Error spawning UFO:', error);
- // Retry UFO spawn after a delay
- this.spawnUFOWithDelay();
+ console.error("Error stopping sound ".concat(soundName, ":"), error);
}
+ });
+ this.sounds.clear();
+ // Reset score
+ this.score = 0;
+ if (this.scoreDisplay) {
+ this.scoreDisplay.updateScore(0);
}
- }, {
- key: "removeEntity",
- value: function removeEntity(entity, collection, index) {
- if (!entity) {
- return;
+ }
+};
+// Use GameState for all game-related variables
+var gameState = GameState;
+// Initialize game layers with a single, organized structure
+game.layers = {
+ background: new Container(),
+ sun: new Container(),
+ // z-index: 1
+ light1: new Container(),
+ // z-index: 2
+ jetLeft: new Container(),
+ // z-index: 3
+ jetRight: new Container(),
+ // z-index: 3
+ clouds: new Container(),
+ // z-index: 4
+ ufo: new Container(),
+ // z-index: 5
+ grassBack: new Container(),
+ // z-index: 6
+ bird1: new Container(),
+ // z-index: 7
+ tree: new Container(),
+ // z-index: 8
+ stack1: new Container(),
+ // z-index: 9
+ bird2: new Container(),
+ // z-index: 10
+ mirror: new Container(),
+ // z-index: 11
+ grassFront: new Container(),
+ // z-index: 12
+ cat: new Container(),
+ // z-index: 13
+ laser: new Container(),
+ // z-index: 14
+ reticle: new Container(),
+ // z-index: 15
+ enemies: new Container(),
+ // Container for collision detection
+ birds: new Container() // Container for all birds
+};
+// Add these layers to the game and set their z-indices
+var layerOrder = ['background', 'sun', 'light1', 'jetLeft', 'jetRight', 'clouds', 'ufo', 'grassBack', 'bird1', 'tree', 'stack1', 'bird2', 'mirror', 'grassFront', 'cat', 'laser', 'reticle', 'enemies', 'birds'];
+layerOrder.forEach(function (key, index) {
+ if (game.layers[key]) {
+ game.layers[key].zIndex = index;
+ game.addChild(game.layers[key]);
+ }
+});
+// Duplicate game.layers initialization removed
+/**
+* Creates and adds a UFO to the game
+* @returns {Object} The created UFO object
+*/
+function addUFO() {
+ if (ufo) {
+ return ufo;
+ }
+ // Create new UFO instance
+ var ufo = new UFO();
+ // Add to UFO layer
+ game.layers.ufo.addChild(ufo);
+ // Add to enemies layer for collision detection
+ game.layers.enemies.addChild(ufo);
+ // Set initial position (either left or right side of screen)
+ ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2;
+ ufo.y = Math.random() * (2732 / 2 - ufo.height);
+ // Play UFO sound
+ LK.getSound('ufo1').play();
+ return ufo;
+}
+// Enhanced entity spawning system with structured intervals and error handling
+var EntitySpawner = {
+ spawnIntervals: {
+ bird1: {
+ min: 2000,
+ max: 5000
+ },
+ bird2: {
+ min: 3000,
+ max: 6000
+ }
+ },
+ removeEntity: function removeEntity(entity) {
+ try {
+ if (entity.parent) {
+ entity.parent.removeChild(entity);
}
- try {
- this.removeFromLayer('game', entity);
+ if (birds.includes(entity)) {
+ birds.splice(birds.indexOf(entity), 1);
+ }
+ if (typeof entity.destroy === 'function') {
entity.destroy();
- if (collection && index >= 0) {
- collection.splice(index, 1);
- }
- } catch (error) {
- console.error('Error removing entity:', error);
}
+ } catch (error) {
+ console.error('Error removing entity:', error);
}
- }, {
- key: "removeCloud",
- value: function removeCloud(index) {
- if (index >= 0 && index < this.clouds.length) {
- this.removeEntity(this.clouds[index], this.clouds, index);
- this.spawnCloud();
- this.incrementScore();
- }
+ },
+ spawnBird1: function spawnBird1() {
+ try {
+ var bird = new Bird1();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ birds.push(bird);
+ game.layers.birds.addChild(bird);
+ game.layers.enemies.addChild(bird);
+ return bird;
+ } catch (error) {
+ console.error('Error spawning Bird1:', error);
+ return null;
}
- }, {
- key: "removeBird",
- value: function removeBird(index) {
- if (index >= 0 && index < this.birds.length) {
- this.removeEntity(this.birds[index], this.birds, index);
- }
+ },
+ spawnBird2: function spawnBird2() {
+ try {
+ var bird = new Bird2();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ birds.push(bird);
+ game.layers.birds.addChild(bird);
+ game.layers.enemies.addChild(bird);
+ return bird;
+ } catch (error) {
+ console.error('Error spawning Bird2:', error);
+ return null;
}
- }, {
- key: "removeUFO",
- value: function removeUFO() {
- if (this.ufo) {
- this.removeEntity(this.ufo);
- this.ufo = null;
- this.spawnUFOWithDelay();
- }
+ }
+};
+// Consolidated bird spawning functions
+// Consolidated bird spawning functions are inserted below
+// Jet timer function
+var jetTimer = LK.setTimeout(function spawnJet() {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2 - jet.height);
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
+ }
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true);
+ game.jetSoundPlayed = true;
+ }
+ jetTimer = LK.setTimeout(spawnJet, 5000);
+}, Math.random() * 5000 + 5000);
+// Cloud initialization
+for (var i = 0; i < 4; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2);
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+}
+// Handle click/tap events with proper cleanup and error handling
+game.down = function (x, y, obj) {
+ try {
+ // Clean up old reticle if it exists
+ if (game.reticle && typeof game.reticle.destroy === 'function') {
+ game.reticle.destroy();
}
- // Sound Management
- }, {
- key: "playSoundSafely",
- value: function playSoundSafely(soundKey) {
- try {
- var sound = this.sounds[soundKey];
- if (sound !== null && sound !== void 0 && sound.play) {
- sound.play();
+ // Create new reticle
+ game.reticle = game.layers.reticle.addChild(new Reticle());
+ game.reticle.x = x;
+ game.reticle.y = y;
+ // Create and add laser with proper positioning
+ if (cat) {
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ game.layers.laser.addChild(laser);
+ // Clean up laser after animation
+ setTimeout(function () {
+ if (laser && typeof laser.destroy === 'function') {
+ laser.destroy();
}
- } catch (error) {
- console.error("Error playing sound ".concat(soundKey, ":"), error);
+ game.layers.laser.removeChild(laser);
+ }, 2000);
+ }
+ } catch (error) {
+ console.error('Error in game.down:', error);
+ }
+};
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Object placements are handled in the main initialization section
+// This is a duplicate addUFO function that has been consolidated elsewhere
+// Consolidated bird spawning functions
+// Consolidated bird spawning functions are inserted below
+// Removing duplicate jetTimer code as it's already defined elsewhere
+for (var i = 0; i < 4; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2);
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+}
+game.down = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = game.layers.reticle.addChild(new Reticle());
+ }
+ game.reticle.x = x;
+ game.reticle.y = y;
+ var laser = new Laser(cat.x - 140, cat.y - 440, x, y);
+ game.layers.laser.addChild(laser);
+};
+// This is a duplicate checkInteractions function that has been consolidated elsewhere
+// Layer structure and initialization is already handled at the beginning of the file
+// Layer z-index management is handled by the layerStructure configuration
+// The spawn functions for UFO, Bird1, Bird2, and Jet are already defined earlier in the code
+// Layer z-index management is handled by the layerStructure configuration
+// The game.down function is already defined earlier in the code
+game.addChild(game.layers.enemies);
+// CloudMovement class to handle cloud movement and fade effects
+// UFOMovement class to handle UFO movement
+// UFOMovement has been moved to js/movements.js
+// Generic Pulse class that can be used for both Sun and Light1
+/**
+* Reusable animation controller for pulsating effects using tween
+* @param {Graphics} graphics - Target graphics object to animate
+* @param {number} [scaleMax=1.1] - Maximum scale multiplier
+* @param {number} [duration=1000] - Full animation cycle duration in ms
+*/
+var Pulse = function Pulse(graphics, scaleMax, duration) {
+ this.graphics = graphics;
+ this.scaleMax = scaleMax || 1.1;
+ this.duration = duration || 1000;
+ /**
+ * Starts continuous pulsating animation using recursive tween calls
+ * Creates smooth scale oscillation through easeInOut timing
+ */
+ this.startPulsating = function () {
+ function pulsate() {
+ tween(this.graphics, {
+ scaleX: this.scaleMax,
+ scaleY: this.scaleMax
+ }, {
+ duration: this.duration,
+ easing: tween.easeInOut,
+ onFinish: function () {
+ tween(this.graphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: this.duration,
+ easing: tween.easeInOut,
+ onFinish: pulsate.bind(this)
+ });
+ }.bind(this)
+ });
+ }
+ pulsate.call(this);
+ };
+};
+// Light1Pulse now uses the generic Pulse class
+/** Factory for light fixture pulse (higher intensity/longer duration) */
+var Light1Pulse = function Light1Pulse(lightGraphics) {
+ return new Pulse(lightGraphics, 1.6, 1500);
+};
+// SunPulse now uses the generic Pulse class
+/** Factory for subtle solar glow pulse (conservative scaling) */
+var SunPulse = function SunPulse(sunGraphics) {
+ return new Pulse(sunGraphics, 1.1, 1000);
+};
+// Bird2Effects class to handle effects and animations for Bird2
+// Consolidated function to create a pulsating effect
+function startPulsating(target, duration) {
+ duration = duration || 888;
+ function pulsate() {
+ tween(target, {
+ scaleX: 1.1,
+ // Use consistent scale value
+ scaleY: 1.1
+ }, {
+ duration: duration,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(target, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: duration,
+ easing: tween.easeInOut,
+ onFinish: pulsate
+ });
}
+ });
+ }
+ pulsate();
+}
+var UFOSound = function UFOSound() {
+ this.play = function () {
+ LK.getSound('ufo1').play();
+ };
+};
+// BackgroundMusic class to manage background music
+function playSoundEffect(soundName, action) {
+ var volume = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
+ var loops = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
+ try {
+ var sound = LK.getSound(soundName);
+ if (!sound) {
+ console.warn("Sound '".concat(soundName, "' not found"));
+ return;
}
- }, {
- key: "stopSoundSafely",
- value: function stopSoundSafely(soundKey) {
- try {
- var sound = this.sounds[soundKey];
- if (sound !== null && sound !== void 0 && sound.stop) {
+ switch (action) {
+ case 'play':
+ if (typeof sound.play === 'function') {
+ sound.play({
+ volume: volume,
+ loops: loops
+ });
+ }
+ break;
+ case 'stop':
+ if (typeof sound.stop === 'function') {
sound.stop();
}
- } catch (error) {
- console.error("Error stopping sound ".concat(soundKey, ":"), error);
+ break;
+ case 'pause':
+ if (typeof sound.pause === 'function') {
+ sound.pause();
+ }
+ break;
+ default:
+ console.warn("Unknown sound action: ".concat(action));
+ }
+ } catch (error) {
+ console.error("Error playing sound '".concat(soundName, "':"), error);
+ }
+}
+var BackgroundMusic = function BackgroundMusic() {
+ this.play = function () {
+ LK.playMusic('bgm1', {
+ loop: false,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
}
+ });
+ };
+};
+// LaserSound class to manage laser sound effects
+var LaserSound = function LaserSound() {
+ this.play = function () {
+ LK.getSound('laser1').play();
+ };
+};
+// Unified movement system for all entities
+/**
+* Bird1 movement configuration
+*/
+function BirdMovement(bird, birdGraphics, birdType) {
+ var config = {
+ baseSpeed: birdType === 'bird1' ? 1 : 1.5,
+ speedVariation: birdType === 'bird1' ? 0.5 : 1.6,
+ useWaveMotion: true,
+ waveAmplitude: birdType === 'bird1' ? 4.5 : 6.5,
+ waveFrequency: birdType === 'bird1' ? 120 : 100,
+ horizontalMovement: false,
+ textures: {
+ left: "".concat(birdType, "-left"),
+ right: "".concat(birdType, "-right")
+ },
+ respawnPosition: birdType === 'bird1' ? 'top' : 'random',
+ sounds: {
+ move: 'wings1',
+ destroy: null
+ },
+ scoreValue: birdType === 'bird1' ? 5 : 10,
+ entityType: birdType,
+ onDestroy: function onDestroy(entity) {
+ var index = birds.indexOf(entity);
+ if (index > -1) {
+ birds.splice(index, 1);
+ LK.setTimeout(function () {
+ if (birdType === 'bird1') {
+ spawnBird1();
+ } else {
+ spawnBird2();
+ }
+ }, Math.random() * 2000 + 1000);
+ }
}
- }, {
- key: "incrementScore",
- value: function incrementScore() {
- this.score++;
- this.playSoundSafely('point');
- this.updateScoreDisplay();
- }
- }, {
- key: "updateScoreDisplay",
- value: function updateScoreDisplay() {
- if (!this.scoreText) {
- this.scoreText = new Text('Score: 0', {
- fontFamily: 'Arial',
- fontSize: 24,
- fill: 0xFFFFFF,
- align: 'center'
- });
- this.scoreText.position.set(10, 10);
- this.addToLayer('ui', this.scoreText);
+ };
+ createMovementSystem(bird, birdGraphics, config);
+}
+function UFOMovement(ufo, ufoGraphics) {
+ var config = {
+ baseSpeed: 3,
+ speedVariation: 1,
+ useWaveMotion: true,
+ waveAmplitude: 50,
+ waveFrequency: 100,
+ horizontalMovement: true,
+ baseY: Math.random() * 300 + 100,
+ textures: null,
+ sounds: {
+ move: 'ufo1',
+ destroy: null
+ },
+ onDestroy: function onDestroy(entity) {
+ if (entity.sounds && entity.sounds.move) {
+ LK.getSound(entity.sounds.move).stop();
}
- this.scoreText.text = "Score: ".concat(this.score);
+ entity.destroy();
+ ufo = null;
+ handleUFOReappearance();
+ },
+ scoreValue: 20,
+ entityType: 'ufo',
+ handleLaserCollision: function handleLaserCollision(laser) {
+ var angle = Math.atan2(laser.vy, laser.vx) + Math.PI;
+ laser.vx = Math.cos(angle) * laser.speed;
+ laser.vy = Math.sin(angle) * laser.speed;
+ return false;
}
- }, {
- key: "gameOver",
- value: function gameOver() {
- this.isGameOver = true;
- this.playSoundSafely('explosion');
- this.stopSoundSafely('jet');
- // Clean up all entities
- this.cleanup();
- // Show game over screen
- this.showGameOverScreen();
+ };
+ createMovementSystem(ufo, ufoGraphics, config);
+}
+/**
+* Jet movement configuration
+*/
+/**
+* Laser movement configuration
+*/
+function LaserMovement(laser, laserGraphics, startX, startY, targetX, targetY) {
+ // Calculate direction and speed
+ var dx = targetX - startX;
+ var dy = targetY - startY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var speed = 60; // Speed of the laser
+ laser.vx = dx / distance * speed;
+ laser.vy = dy / distance * speed;
+ // Set initial position
+ laser.x = startX;
+ laser.y = startY;
+ // Initializes entity movement parameters with laser-specific configuration
+ createMovementSystem(laser, laserGraphics, {
+ entityType: 'laser',
+ sounds: {
+ move: 'laser2',
+ destroy: null
+ },
+ scoreValue: 0,
+ screenBounds: {
+ width: 2048,
+ height: 2732
}
- }, {
- key: "cleanup",
- value: function cleanup() {
- // Clean up birds
- while (this.birds.length > 0) {
- this.removeBird(0);
+ });
+ return laser;
+}
+// CloudMovement class is already defined earlier in the file
+var Bird2Effects = function Bird2Effects(bird) {
+ this.bird = bird;
+ this.applyEffects = function () {
+ // Apply swooping animation effect
+ tween(this.bird, {
+ rotation: Math.sin(this.bird.y / 100) * 0.2
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ // Apply scale pulsing effect when moving fast
+ if (Math.abs(this.bird.x - this.bird.lastX) > 5) {
+ tween(this.bird, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function () {
+ tween(this.bird, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ }.bind(this)
+ });
+ }
+ };
+};
+var background = LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+background.x = 2048 / 2;
+background.y = 2732 / 2 - 100;
+game.layers.background.addChild(background);
+game.addChild(background);
+// ScoreManager class to manage score logic
+var ScoreManager = function ScoreManager() {
+ var self = this;
+ self.score = 0;
+ self.addScore = function (points) {
+ self.score += points;
+ return self.score;
+ };
+ self.resetScore = function () {
+ self.score = 0;
+ };
+ self.getScore = function () {
+ return self.score;
+ };
+};
+// Removed duplicate gameState declaration as it's now handled by GameState
+game.down = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = new Reticle();
+ game.layers.reticle.addChild(game.reticle);
+ }
+ if (GameState.cat) {
+ game.reticle.x = x;
+ game.reticle.y = y;
+ var laser = new Laser(GameState.cat.x - 140, GameState.cat.y - 440, x, y);
+ game.layers.laser.addChild(laser);
+ }
+};
+game.move = function (x, y, obj) {
+ if (!game.reticle) {
+ game.reticle = new Reticle();
+ game.layers.reticle.addChild(game.reticle);
+ }
+ var eventX = obj && obj.event ? obj.event.x : x;
+ var eventY = obj && obj.event ? obj.event.y : y;
+ if (game.reticle) {
+ game.reticle.x = eventX;
+ game.reticle.y = eventY;
+ }
+};
+// Initialize sun and light1
+var sun = game.layers.background.addChild(new Sun());
+sun.x = 1800;
+sun.y = 300;
+var light1 = game.layers.background.addChild(new Light1());
+light1.x = 450;
+light1.y = 440;
+// Add a sun to the game in the top left corner
+// Duplicate sun placement removed
+// Duplicate light1 placement removed // Move light1 down by 210px
+// Ensure light1 is added to the game before setting its index
+if (game.children.includes(light1)) {
+ game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun
+ // Add score display
+ var scoreDisplay = game.addChild(new Mirror());
+ scoreDisplay.x = 1700;
+ scoreDisplay.y = 300;
+}
+// Function to add a UFO to the game
+// Initialize clouds array
+GameState.clouds = [];
+GameState.birds = [];
+GameState.score = 0;
+for (var i = 0; i < 4; i++) {
+ // Add 3 clouds for variety
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+ // No need to add cloud directly to game since it's already in the clouds layer
+}
+// Initialize birds
+spawnBird1();
+spawnBird2();
+spawnBird2();
+// Start UFO 3 seconds after game loads
+var ufoTimer = LK.setTimeout(function () {
+ GameState.ufo = addUFO();
+ game.layers.enemies.addChild(GameState.ufo);
+}, 3000);
+// Function to handle UFO reappearance logic
+function handleUFOReappearance() {
+ if (!ufo) {
+ LK.setTimeout(function () {
+ ufo = addUFO();
+ }, Math.random() * 10000 + 20000);
+ }
+}
+// Function to handle jet reappearance logic
+function handleJetReappearance() {
+ try {
+ jetTimer = LK.setTimeout(function () {
+ var jet = new Jet();
+ jet.x = Math.random() < 0.5 ? 2048 + jet.width / 2 : -jet.width / 2;
+ jet.y = Math.random() * (2732 / 2 - jet.height);
+ // Add to appropriate layer based on direction
+ if (jet.x < 1024) {
+ game.layers.jetLeft.addChild(jet);
+ } else {
+ game.layers.jetRight.addChild(jet);
}
- // Clean up clouds
- while (this.clouds.length > 0) {
- this.removeCloud(0);
+ game.jet = jet;
+ if (!game.jetSoundPlayed) {
+ playSoundEffect('jetSound', 'play', 0.3, true);
+ game.jetSoundPlayed = true;
}
- // Clean up UFO
- if (this.ufo) {
- this.removeUFO();
+ }, Math.random() * 5000 + 5000);
+ } catch (error) {
+ console.error('Error in handleJetReappearance:', error);
+ }
+}
+// Initialize a timer to add a Jet at a random time between 5 and 10 seconds
+// Initial interval for Jet appearances 5-10 seconds after page load
+// Initialize enemy movement systems
+function initEnemyMovement(enemy) {
+ if (enemy instanceof Bird1) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird1');
+ }
+ if (enemy instanceof Bird2) {
+ enemy.movementSystem = new BirdMovement(enemy, enemy.graphics, 'bird2');
+ }
+ if (enemy instanceof UFO) {
+ enemy.movementSystem = new UFOMovement(enemy, enemy.graphics);
+ }
+}
+// Main game loop
+function gameTick() {
+ game.layers.enemies.children.forEach(function (enemy) {
+ var _enemy$movementSystem;
+ (_enemy$movementSystem = enemy.movementSystem) === null || _enemy$movementSystem === void 0 || _enemy$movementSystem.update();
+ });
+ checkInteractions();
+ requestAnimationFrame(gameTick);
+}
+/**
+* Main game update function
+* Uses the unified movement system for all entities
+*/
+game.update = function () {
+ // Update all clouds
+ for (var i = 0; i < clouds.length; i++) {
+ clouds[i].update();
+ }
+ // Ensure at least 3 clouds are visible
+ while (clouds.length < 3) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
+ clouds.push(cloud);
+ game.layers.clouds.addChild(cloud);
+ }
+ // Update all birds
+ birds.forEach(function (bird) {
+ bird.update();
+ });
+ // Ensure we have enough birds
+ while (birds.length < 3) {
+ if (birds.length % 2 === 0) {
+ spawnBird1();
+ } else {
+ spawnBird2();
+ }
+ }
+ // Update all lasers
+ game.layers.laser.children.forEach(function (laser) {
+ laser.update();
+ });
+ // Update UFO if it exists
+ if (GameState.ufo) {
+ GameState.ufo.update();
+ }
+ // Check for all interactions between game entities
+ checkInteractions();
+};
+// Function to spawn a third kind of bird
+// Consolidated bird spawning functions are inserted below
+// Ensure there are always 3 birds on screen
+// Initialize enemy movement systems
+game.update = function () {
+ // Update each bird
+ birds.forEach(function (bird, index) {
+ bird.update();
+ // Check for intersections with other birds
+ birds.forEach(function (otherBird, otherIndex) {
+ if (index !== otherIndex && !bird.lastIntersecting && bird.intersects(otherBird)) {
+ // Calculate bounce direction
+ var dx = bird.x - otherBird.x;
+ var dy = bird.y - otherBird.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ var bounceFactor = 5; // Adjust bounce factor for desired effect
+ // Apply bounce with acceleration
+ bird.x += dx / distance * bounceFactor;
+ bird.y += dy / distance * bounceFactor;
+ otherBird.x -= dx / distance * bounceFactor;
+ otherBird.y -= dy / distance * bounceFactor;
+ // Mark as intersecting
+ bird.lastIntersecting = true;
+ otherBird.lastIntersecting = true;
}
+ });
+ // Reset intersection state
+ bird.lastIntersecting = birds.some(function (otherBird, otherIndex) {
+ return index !== otherIndex && bird.intersects(otherBird);
+ });
+ // Check if the bird has moved off-screen
+ if (bird.lastY <= 2732 && bird.y > 2732) {
+ bird.y = -bird.height; // Respawn the bird at the top
+ bird.x = Math.random() * 2048; // Randomize the x position
+ bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
}
- }, {
- key: "showGameOverScreen",
- value: function showGameOverScreen() {
- this.gameOverText = new Text('Game Over\nScore: ' + this.score + '\nPress R to Restart', {
- fontFamily: 'Arial',
- fontSize: 36,
- fill: 0xFFFFFF,
- align: 'center'
+ });
+};
+// Note: Tree and stack1 are already added to their respective layers earlier in the code
+// This section is redundant and can be removed
+// Add the grass floor to the game
+var grassBack = game.layers.grassBack.addChild(new GrassBack()); // grassBack layer
+grassBack.x = 1020;
+grassBack.y = 2735; // Position grassBack at the bottom
+// Note: grassFront and mirror are already added to their respective layers earlier in the code
+// This section is redundant and can be removed as it causes duplicate rendering
+// Function to handle bgm1 end event
+// Initialize cat instance
+GameState.cat = new Cat();
+GameState.cat.x = 2048 / 2;
+GameState.cat.y = 2732 - 100;
+game.layers.cat.addChild(GameState.cat);
+function initBackgroundMusic() {
+ try {
+ LK.playMusic('bgm1', {
+ loop: false,
+ volume: SOUND_VOLUMES.bgm1,
+ fade: {
+ start: 0,
+ end: 1,
+ duration: 4000
+ },
+ onEnd: function onEnd() {
+ LK.setTimeout(function () {
+ initBackgroundMusic();
+ }, Math.random() * 30000 + 20000);
+ }
+ });
+ } catch (error) {
+ console.error('Error initializing background music:', error);
+ }
+}
+// Initialize background music
+initBackgroundMusic();
+// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
+var wingsTimer = LK.setTimeout(function () {
+ LK.getSound('wings1').play();
+ wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
+}, Math.random() * 20000 + 10000);
+// Create an array for all sounds except ufo1, including all birdsong sounds
+var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
+var currentAmbientSound = null;
+// Initialize random timers for each sound to play between 30-50 seconds
+sounds.forEach(function (soundId) {
+ var sound = LK.getSound(soundId);
+ var ambientSoundTimer = LK.setTimeout(function () {
+ if (currentAmbientSound) {
+ currentAmbientSound.stop(); // Stop the currently playing ambient sound
+ }
+ sound.play();
+ currentAmbientSound = sound; // Set the current ambient sound
+ // Set a timeout to reset the current ambient sound after it finishes playing
+ LK.setTimeout(function () {
+ currentAmbientSound = null;
+ }, sound.duration * 1000); // Convert duration from seconds to milliseconds
+ // Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
+ ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
+ }, Math.random() * 20000 + 30000);
+});
+/**
+* Check for interactions between game entities
+*/
+function checkInteractions() {
+ try {
+ // Lasers vs Enemies
+ if (game.layers.laser && game.layers.enemies) {
+ game.layers.laser.children.forEach(function (laser) {
+ if (!laser || !laser.intersects) {
+ return;
+ }
+ game.layers.enemies.children.forEach(function (enemy) {
+ if (!enemy || !enemy.intersects) {
+ return;
+ }
+ if (laser.intersects(enemy)) {
+ try {
+ // Use the handleLaserCollision method if available
+ if (typeof enemy.handleLaserCollision === 'function') {
+ var destroyed = enemy.handleLaserCollision(laser);
+ if (destroyed && typeof enemy.getScoreValue === 'function') {
+ score += enemy.getScoreValue();
+ if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
+ scoreDisplay.updateScore(score);
+ }
+ }
+ } else {
+ enemy.destroy();
+ laser.destroy();
+ if (typeof enemy.getScoreValue === 'function') {
+ score += enemy.getScoreValue();
+ if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
+ scoreDisplay.updateScore(score);
+ }
+ } else {
+ // Default score increment if getScoreValue is not available
+ score += 5;
+ if (scoreDisplay && typeof scoreDisplay.updateScore === 'function') {
+ scoreDisplay.updateScore(score);
+ }
+ }
+ }
+ } catch (error) {
+ console.error('Error handling laser collision:', error);
+ }
+ }
+ });
});
- this.gameOverText.anchor.set(0.5);
- this.gameOverText.position.set(app.screen.width / 2, app.screen.height / 2);
- this.addToLayer('ui', this.gameOverText);
- // Add restart listener
- window.addEventListener('keydown', this.handleRestart.bind(this));
}
- }, {
- key: "handleRestart",
- value: function handleRestart(event) {
- if (event.key === 'r' || event.key === 'R') {
- window.removeEventListener('keydown', this.handleRestart.bind(this));
- this.resetGame();
+ // UFO vs Enemies
+ if (game.layers.enemies) {
+ var ufo = game.layers.enemies.children.find(function (child) {
+ return child instanceof UFO;
+ });
+ if (ufo && typeof ufo.intersects === 'function') {
+ game.layers.enemies.children.forEach(function (enemy) {
+ if (!enemy || !enemy.intersects || enemy === ufo) {
+ return;
+ }
+ if (ufo.intersects(enemy)) {
+ try {
+ enemy.destroy();
+ var sound = LK.getSound('electro');
+ if (sound && typeof sound.play === 'function') {
+ sound.play();
+ }
+ } catch (error) {
+ console.error('Error handling UFO collision:', error);
+ }
+ }
+ });
}
}
- }, {
- key: "resetGame",
- value: function resetGame() {
- // Reset game properties
- this.score = 0;
- this.isGameOver = false;
- // Remove game over text
- if (this.gameOverText) {
- this.removeFromLayer('ui', this.gameOverText);
- this.gameOverText = null;
- }
- // Reset score display
- this.updateScoreDisplay();
- // Restart entity spawning
- this.startEntitySpawning();
+ } catch (error) {
+ console.error('Error in checkInteractions:', error);
+ }
+}
+/****
+* Utility Functions
+****/
+/**
+* Simple movement update function that works with the consolidated movement system
+* This is kept for backward compatibility with existing code that uses it
+*/
+function updateMovement(obj, params) {
+ // If the object already has a movement system applied, use that
+ if (typeof obj.update === 'function' && obj.speed !== undefined) {
+ obj.speed = params.speed || obj.speed;
+ obj.direction = params.direction || obj.direction;
+ return;
+ }
+ // Otherwise apply simple movement
+ obj.x += params.speed * params.direction;
+ if (params.boundaryCheck) {
+ handleScreenBoundaries(obj, params.boundaryWidth);
+ }
+}
+function updateDirection(obj, graphics, rightAsset, leftAsset) {
+ graphics.texture = LK.getAsset(obj.lastX < obj.x ? rightAsset : leftAsset, {}).texture;
+}
+function handleScreenBoundaries(obj, screenWidth) {
+ if (obj.lastX <= screenWidth + obj.width / 2 && obj.x > screenWidth + obj.width / 2) {
+ obj.x = -obj.width / 2;
+ } else if (obj.lastX >= -obj.width / 2 && obj.x < -obj.width / 2) {
+ obj.x = screenWidth + obj.width / 2;
+ }
+}
+function handleCollisions(obj, others, collisionHandler) {
+ others.forEach(function (other) {
+ if (other !== obj && obj.intersects(other)) {
+ collisionHandler(obj, other);
}
- }]);
-}(); // Initialize game
-var game = new Game();
\ No newline at end of file
+ });
+}
+function handleSunInteraction(obj, sun, enterHandler, exitHandler) {
+ var intersecting = obj.intersects(sun);
+ if (!obj.lastIntersecting && intersecting) {
+ enterHandler(obj);
+ } else if (obj.lastIntersecting && !intersecting) {
+ exitHandler(obj);
+ }
+ obj.lastIntersecting = intersecting;
+}
+function handleDestruction(obj, sounds) {
+ if (obj.x > 2048 + obj.width / 2 || obj.x < -obj.width / 2) {
+ sounds.forEach(function (sound) {
+ return LK.getSound(sound).stop();
+ });
+ obj.destroy();
+ }
+}
+// Updated Cloud update method
+self.cloud.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction,
+ boundaryCheck: true,
+ boundaryWidth: 2048
+ });
+ handleCollisions(this, clouds, function (cloud, other) {
+ if (!cloud.hasAccelerated) {
+ cloud.speed *= 1.5;
+ cloud.hasAccelerated = true;
+ }
+ });
+ handleSunInteraction(this, sun, function (cloud) {
+ cloud.speed *= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 0.5
+ }, {
+ duration: 3000
+ });
+ }, function (cloud) {
+ cloud.speed /= 2;
+ tween(cloud.cloudGraphics, {
+ alpha: 1.0
+ }, {
+ duration: 3000
+ });
+ });
+ this.lastX = this.x;
+};
+// Updated Jet update method
+self.update = function () {
+ updateMovement(this, {
+ speed: this.speed,
+ direction: this.direction
+ });
+ updateDirection(this, jetGraphics, 'jet-right', 'jet-left');
+ handleDestruction(this, ['jetSound']);
+};
+// Note: Tree and stack1 are already added to their respective layers earlier in the code
+// This section is redundant and can be removed
+// Add the grass floor to the game
\ No newline at end of file
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