User prompt
Please fix the bug: 'levelProgressBar is not defined' in or related to this line: 'if (levelProgressBar && typeof levelProgressBar.update === 'function') {' Line Number: 1489
User prompt
Please fix the bug: 'statsPanel is not defined' in or related to this line: 'if (statsPanel && typeof statsPanel.update === 'function') {' Line Number: 1477
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1464
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1460
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1460
User prompt
refactor all font related code.
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1468
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1468
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1468
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1467
User prompt
Please fix the bug: 'checkSpecialEvents is not defined' in or related to this line: 'checkSpecialEvents();' Line Number: 1464
User prompt
Please fix the bug: 'fontSizeBase is not defined' in or related to this line: 'var buttonText = new Text2(text, {' Line Number: 652
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'for (var i = 0; i < messages.length; i++) {' Line Number: 359
User prompt
i can't play it. it is not playable.
User prompt
do that for all buttons
User prompt
anchor buttontext to the button image.
User prompt
continue
User prompt
contiunue
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'for (var i = 0; i < messages.length; i++) {' Line Number: 361 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'for (var i = 0; i < messages.length; i++) {' Line Number: 359 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'for (var i = 0; i < messages.length; i++) {' Line Number: 359 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5, scale: 0.6 }); birdGraphics.tint = 0xFF0000; self.health = 20; self.speed = 1 + Math.random(); self.value = 10; self.update = function () { if (cats.length > 0) { var nearestCat = cats[0]; var minDist = 10000; cats.forEach(function (cat) { var dist = Math.sqrt(Math.pow(cat.x - self.x, 2) + Math.pow(cat.y - self.y, 2)); if (dist < minDist) { minDist = dist; nearestCat = cat; } }); var dx = nearestCat.x - self.x; var dy = nearestCat.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 10) { self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; } if (dist < 50) { self.health -= nearestCat.level; createSparkleEffect(self.x, self.y, 0xFF0000, 2); if (self.health <= 0) { handleEnemyDefeat(self, self.value); game.removeChild(self); birds.splice(birds.indexOf(self), 1); } } } }; return self; }); var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5, scale: 0.8 }); self.level = 1; self.productionRate = 0.5; self.lastProductionTime = 0; self.speed = 2; self.attackPower = 10; self.attackRange = 150; self.type = 'cat'; var levelCircle = new Container(); var levelCircleGraphics = levelCircle.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 0.5 }); levelCircleGraphics.tint = 0x000000; levelCircle.x = 0; levelCircle.y = -catGraphics.height / 2 - 10; levelCircle.alpha = 0.7; self.addChild(levelCircle); var levelText = createGameText("Lvl " + self.level, { sizeFactor: 0.8, anchorX: 0.5, anchorY: 0.5, fill: 0xFFFFFF }); levelCircle.addChild(levelText); var powerUpIndicator = new Container(); var powerUpGraphics = powerUpIndicator.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 0.4 }); powerUpGraphics.tint = 0xFFFFFF; powerUpIndicator.x = 0; powerUpIndicator.y = catGraphics.height / 2 + 5; powerUpIndicator.alpha = 0; self.addChild(powerUpIndicator); self.updateLevel = function (newLevel) { self.level = newLevel; updateTextProperties(levelText, { text: "Lvl " + self.level }); }; self.upgrade = function () { self.level++; self.productionRate *= 1.2; self.speed *= 1.1; self.attackPower *= 1.2; self.attackRange *= 1.05; self.updateLevel(self.level); levelCircleGraphics.tint = 0x000000; var levelUpEffect = new Container(); var levelUpGraphics = levelUpEffect.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 1.5 }); levelUpGraphics.tint = 0xFFFFFF; levelUpEffect.x = 0; levelUpEffect.y = -catGraphics.height / 2 - 10; levelUpEffect.alpha = 1; self.addChild(levelUpEffect); var startTime = LK.ticks; levelUpEffect.update = function () { var elapsed = (LK.ticks - startTime) / 60; levelUpEffect.scale.set(1.5 - elapsed * 0.5); levelUpEffect.alpha = 1 - elapsed; if (elapsed >= 1) { self.removeChild(levelUpEffect); } }; }; self.applyPowerUp = function (type, duration) { self.powerUps = self.powerUps || {}; self.powerUps[type] = LK.ticks + duration * 60; if (type === "speed") { self.speed *= 2; powerUpGraphics.tint = 0x00FFFF; } else if (type === "attack") { self.attackPower *= 2; powerUpGraphics.tint = 0xFF0000; } powerUpIndicator.alpha = 0.8; createSparkleEffect(self.x, self.y, powerUpGraphics.tint, 10); }; self.update = function () { var currentTime = LK.ticks / 60; if (currentTime - self.lastProductionTime > 1) { sparkles += self.productionRate * self.level; self.lastProductionTime = currentTime; if (Math.random() < 0.3) { createSparkleEffect(self.x, self.y); } } self.rotation = Math.sin(LK.ticks / 120) * 0.03; if (self.powerUps) { var hasPowerUp = false; for (var type in self.powerUps) { if (self.powerUps[type] < LK.ticks) { if (type === "speed") { self.speed /= 2; } else if (type === "attack") { self.attackPower /= 2; } delete self.powerUps[type]; } else { hasPowerUp = true; var color = type === "speed" ? 0x00FFFF : 0xFF0000; if (Math.random() < 0.1) { createSparkleEffect(self.x, self.y, color, 1); } } } powerUpIndicator.alpha = hasPowerUp ? 0.8 : 0; } }; return self; }); var CatStatusDisplay = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 3 }); bg.tint = 0x663300; bg.alpha = 0.7; var titleText = createGameText("Cat Status", { sizeFactor: 0.9, fontWeight: 'bold' }); titleText.anchor.set(0.5, 0); titleText.y = -fontSizeBase * 1.5; self.addChild(titleText); var countText = createGameText("Count: 0", { sizeFactor: 0.8 }); countText.anchor.set(0.5, 0); countText.y = -fontSizeBase * 0.5; self.addChild(countText); var powerText = createGameText("Power: 1.0", { sizeFactor: 0.8 }); powerText.anchor.set(0.5, 0); powerText.y = fontSizeBase * 0.5; self.addChild(powerText); self.update = function () { countText.text = "Count: " + cats.length; var totalPower = 0; cats.forEach(function (cat) { totalPower += cat.level || 1; }); var avgPower = cats.length > 0 ? (totalPower / cats.length).toFixed(1) : "0.0"; powerText.text = "Avg Power: " + avgPower; }; return self; }); var Garden = Container.expand(function () { var self = Container.call(this); var gardenGraphics = self.attachAsset('grass-back', { anchorX: 0.5, anchorY: 1, scale: 1.2 }); self.update = function () { self.x += Math.sin(LK.ticks / 200) * 0.1; }; return self; }); var Kitten = Container.expand(function () { var self = Container.call(this); var kittenGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5, scale: 0.6 }); kittenGraphics.tint = 0xFFCC99; self.level = 1; self.productionRate = 0.3; self.lastProductionTime = 0; self.speed = 3; self.attackPower = 5; self.attackRange = 100; self.type = 'kitten'; var levelCircle = new Container(); var levelCircleGraphics = levelCircle.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 0.4 }); levelCircleGraphics.tint = 0x000000; levelCircle.x = 0; levelCircle.y = -kittenGraphics.height / 2 - 8; levelCircle.alpha = 0.7; self.addChild(levelCircle); var levelText = createGameText("Lvl " + self.level, { sizeFactor: 0.7, anchorX: 0.5, anchorY: 0.5, fill: 0xFFFFFF }); levelCircle.addChild(levelText); var powerUpIndicator = new Container(); var powerUpGraphics = powerUpIndicator.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 0.3 }); powerUpGraphics.tint = 0xFFFFFF; powerUpIndicator.x = 0; powerUpIndicator.y = kittenGraphics.height / 2 + 4; powerUpIndicator.alpha = 0; self.addChild(powerUpIndicator); self.updateLevel = function (newLevel) { self.level = newLevel; updateTextProperties(levelText, { text: "Lvl " + self.level }); }; self.upgrade = function () { self.level++; self.productionRate *= 1.2; self.speed *= 1.15; self.attackPower *= 1.15; self.attackRange *= 1.03; self.updateLevel(self.level); levelCircleGraphics.tint = 0x000000; var levelUpEffect = new Container(); var levelUpGraphics = levelUpEffect.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 1.2 }); levelUpGraphics.tint = 0xFFFFFF; levelUpEffect.x = 0; levelUpEffect.y = -kittenGraphics.height / 2 - 8; levelUpEffect.alpha = 1; self.addChild(levelUpEffect); var startTime = LK.ticks; levelUpEffect.update = function () { var elapsed = (LK.ticks - startTime) / 60; levelUpEffect.scale.set(1.2 - elapsed * 0.4); levelUpEffect.alpha = 1 - elapsed; if (elapsed >= 1) { self.removeChild(levelUpEffect); } }; }; self.applyPowerUp = function (type, duration) { self.powerUps = self.powerUps || {}; self.powerUps[type] = LK.ticks + duration * 60; if (type === "speed") { self.speed *= 2; powerUpGraphics.tint = 0x00FFFF; } else if (type === "attack") { self.attackPower *= 2; powerUpGraphics.tint = 0xFF0000; } powerUpIndicator.alpha = 0.8; createSparkleEffect(self.x, self.y, powerUpGraphics.tint, 8); }; self.update = function () { var currentTime = LK.ticks / 60; if (currentTime - self.lastProductionTime > 1) { sparkles += self.productionRate * self.level; self.lastProductionTime = currentTime; if (Math.random() < 0.3) { createSparkleEffect(self.x, self.y); } } self.rotation = Math.sin(LK.ticks / 90) * 0.05; if (self.powerUps) { var hasPowerUp = false; for (var type in self.powerUps) { if (self.powerUps[type] < LK.ticks) { if (type === "speed") { self.speed /= 2; } else if (type === "attack") { self.attackPower /= 2; } delete self.powerUps[type]; } else { hasPowerUp = true; var color = type === "speed" ? 0x00FFFF : 0xFF0000; if (Math.random() < 0.1) { createSparkleEffect(self.x, self.y, color, 1); } } } powerUpIndicator.alpha = hasPowerUp ? 0.8 : 0; } }; return self; }); var LevelIndicator = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 3 }); bg.tint = 0x000000; bg.alpha = 0.7; var levelText = new Text2("Level " + playerLevel, { fontFamily: "Arial", fontSize: fontSizeBase, fill: 0xFFFFFF }); levelText.anchor.set(0.5, 0); levelText.y = 10; self.addChild(levelText); var multiplierText = new Text2("x" + levelMultiplier.toFixed(1), { fontFamily: "Arial", fontSize: fontSizeBase * 0.8, fill: 0xFFD700 }); multiplierText.anchor.set(0.5, 0); multiplierText.y = fontSizeBase * 2; self.addChild(multiplierText); self.update = function () { updateTextProperties(levelText, { text: "Level " + playerLevel }); updateTextProperties(multiplierText, { text: "x" + levelMultiplier.toFixed(1) }); }; return self; }); var LevelProgressBar = Container.expand(function () { var self = Container.call(this); var bgBar = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 0.1 }); bgBar.tint = 0x333333; self.addChild(bgBar); var progressBar = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 0.1 }); progressBar.tint = 0x00FF00; self.progressBar = progressBar; self.addChild(progressBar); var labelText = createGameText("Next Level", { sizeFactor: 0.7 }); labelText.anchor.set(0.5, 1); labelText.y = -5; self.addChild(labelText); self.update = function () { var enemiesForNextLevel = playerLevel * 10; var currentLevelEnemies = enemiesDefeated % enemiesForNextLevel; var progress = currentLevelEnemies / enemiesForNextLevel; progressBar.scale.x = progress * 2; updateTextProperties(labelText, { text: "Next Level: " + currentLevelEnemies + "/" + enemiesForNextLevel }); }; return self; }); var MainGarden = Container.expand(function () { var self = Container.call(this); var gardenGraphics = self.attachAsset('grass-front', { anchorX: 0.5, anchorY: 0.5, scale: 1.5 }); self.interactive = true; self.buttonMode = true; self.on('pointerdown', function (event) { sparkles += clickMultiplier; createSparkleEffect(event.data.global.x, event.data.global.y); if (Math.random() < 0.2) { var soundIndex = Math.floor(Math.random() * sounds.length); LK.getSound(sounds[soundIndex]).play(); } }); return self; }); var NotificationArea = Container.expand(function () { var self = Container.call(this); var messages = []; var maxMessages = 3; self.addMessage = function (message) { var messageText = createGameText(message, { sizeFactor: 0.7, fill: 0xFFFFFF }); messageText.anchor.set(0, 0); messageText.alpha = 1; self.addChild(messageText); messages.push({ text: messageText, creationTime: LK.ticks }); self.repositionMessages(); if (messages.length > maxMessages) { var oldest = messages.shift(); self.removeChild(oldest.text); } }; self.repositionMessages = function () { for (var i = 0; i < messages.length; i++) { messages[i].text.y = i * fontSizeBase; } }; self.update = function () { var messagesToRemove = []; messages.forEach(function (message) { var age = (LK.ticks - message.creationTime) / 60; if (age > 5) { messagesToRemove.push(message); } else if (age > 3) { message.text.alpha = 1 - (age - 3) / 2; } }); messagesToRemove.forEach(function (message) { var index = messages.indexOf(message); if (index !== -1) { messages.splice(index, 1); self.removeChild(message.text); } }); self.repositionMessages(); }; return self; }); var PowerUpIndicator = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 2 }); bg.tint = 0x0000FF; bg.alpha = 0.5; var titleText = createGameText("Power-ups", { sizeFactor: 0.9, fontWeight: 'bold' }); titleText.anchor.set(0.5, 0); titleText.y = -fontSizeBase; self.addChild(titleText); var activeText = createGameText("None Active", { sizeFactor: 0.8 }); activeText.anchor.set(0.5, 0); activeText.y = 0; self.addChild(activeText); self.update = function () { if (powerUps && powerUps.length > 0) { activeText.text = powerUps.length + " Active"; } else { activeText.text = "None Active"; } }; return self; }); var SparkleCounter = Container.expand(function () { var self = Container.call(this); var counterText = new Text2("Sparkles: 0", { fontFamily: "Arial", fontSize: fontSizeBase, fill: 0xFFFFFF }); counterText.anchor.set(0, 0); self.addChild(counterText); var levelText = new Text2("Level: 1 (x1.0)", { fontFamily: "Arial", fontSize: fontSizeBase * 0.9, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); levelText.y = fontSizeBase * 1.5; self.addChild(levelText); self.update = function () { updateTextProperties(counterText, { text: "Sparkles: " + Math.floor(sparkles) }); updateTextProperties(levelText, { text: "Level: " + playerLevel + " (x" + levelMultiplier.toFixed(1) + ")" }); }; return self; }); var StatsPanel = Container.expand(function () { var self = Container.call(this); var bg = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 4 }); bg.tint = 0x000000; bg.alpha = 0.7; var titleText = createGameText("Game Stats", { sizeFactor: 1, fontWeight: 'bold' }); titleText.anchor.set(0.5, 0); titleText.y = -fontSizeBase * 2; self.addChild(titleText); var enemiesText = createGameText("Enemies Defeated: 0", { sizeFactor: 0.8 }); enemiesText.anchor.set(0.5, 0); enemiesText.y = -fontSizeBase; self.addChild(enemiesText); var catsText = createGameText("Cats: 0", { sizeFactor: 0.8 }); catsText.anchor.set(0.5, 0); catsText.y = 0; self.addChild(catsText); var totalSparklesText = createGameText("Total Sparkles: 0", { sizeFactor: 0.8 }); totalSparklesText.anchor.set(0.5, 0); totalSparklesText.y = fontSizeBase; self.addChild(totalSparklesText); self.update = function () { if (typeof enemiesDefeated !== 'undefined') { enemiesText.text = "Enemies Defeated: " + enemiesDefeated; } if (typeof cats !== 'undefined') { catsText.text = "Cats: " + (cats ? cats.length : 0); } if (typeof totalSparklesEarned !== 'undefined') { totalSparklesText.text = "Total Sparkles: " + Math.floor(totalSparklesEarned || 0); } }; return self; }); var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5, scale: 0.7 }); ufoGraphics.tint = 0x00FFFF; self.health = 40; self.speed = 0.7 + Math.random() * 0.5; self.value = 20; self.update = function () { self.x += Math.sin(LK.ticks / 30) * self.speed; self.y += Math.cos(LK.ticks / 20) * self.speed; cats.forEach(function (cat) { var dist = Math.sqrt(Math.pow(cat.x - self.x, 2) + Math.pow(cat.y - self.y, 2)); if (dist < 60) { self.health -= cat.level; createSparkleEffect(self.x, self.y, 0x00FFFF, 1); if (self.health <= 0) { handleEnemyDefeat(self, self.value); game.removeChild(self); ufos.splice(ufos.indexOf(self), 1); } } }); }; return self; }); var UpgradeButton = Container.expand(function (type, text, x, y) { var self = Container.call(this); var buttonGraphics = self.attachAsset('upgrade-button', { anchorX: 0.5, anchorY: 0.5 }); self.type = type; var buttonText = new Text2(text, { fontFamily: "Arial", fontSize: fontSizeBase * 1.2, fill: 0xFFFFFF, align: 'center' }); buttonText.anchor.set(0.5, 0.5); buttonText.x = 0; buttonText.y = 0; self.addChild(buttonText); self.x = x; self.y = y; self.update = function () { if (self.type === "clickPower") { buttonText.text = "Click Power\nCost: " + Math.floor(upgrades.clickPower.cost); } else if (self.type === "autoCollect") { buttonText.text = "Auto Collect\nCost: " + Math.floor(upgrades.autoCollect.cost); } else if (self.type === "buyCat") { buttonText.text = "Buy Cat\nCost: " + Math.floor(upgrades.catCost); } else if (self.type === "upgradeCat") { var upgradeCost = 200 * playerLevel; buttonText.text = "Upgrade Cat\nCost: " + Math.floor(upgradeCost); if (cats.length > 0) { if (sparkles >= upgradeCost) { self.alpha = 1.0; } else { self.alpha = 0.7; } } else { if (self.buttonText) { self.buttonText.text = "No Cats"; } self.alpha = 0.5; } } }; self.interactive = true; self.buttonMode = true; self.on('pointerdown', function () { if (self.type === "clickPower" && sparkles >= upgrades.clickPower.cost) { sparkles -= upgrades.clickPower.cost; upgrades.clickPower.level++; clickMultiplier *= 1.2; upgrades.clickPower.cost *= upgrades.clickPower.multiplier; LK.getSound('songbird1').play(); } else if (self.type === "autoCollect" && sparkles >= upgrades.autoCollect.cost) { sparkles -= upgrades.autoCollect.cost; upgrades.autoCollect.level++; autoSparkleRate += 0.5; upgrades.autoCollect.cost *= upgrades.autoCollect.multiplier; LK.getSound('songbird1').play(); } else if (self.type === "buyCat" && sparkles >= upgrades.catCost) { sparkles -= upgrades.catCost; addCat(); upgrades.catCost *= upgrades.catMultiplier; LK.getSound('wings1').play(); } }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var gameStorage = { save: function save(key, data) { try { storage.set(key, JSON.stringify(data)); return true; } catch (e) { console.error("Error saving data:", e); return false; } }, load: function load(key) { try { var data = storage.get(key); return data ? JSON.parse(data) : null; } catch (e) { console.error("Error loading data:", e); return null; } }, clear: function clear(key) { try { storage.remove(key); return true; } catch (e) { console.error("Error clearing data:", e); return false; } } }; 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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var startButton = game.addChild(new UpgradeButton("start", "Start", 2048 - 150, 2732 - 100)); startButton.on('pointerdown', function () { sparkles = 0; totalSparklesEarned = 0; playerLevel = 1; levelMultiplier = 1; cats = []; kittens = []; birds = []; ufos = []; enemiesDefeated = 0; powerUps = []; totalUpgradesPurchased = 0; addCat(); addKitten(); game.update = function () { updateGameElements(); updateGameMechanics(); updateUIElements(); }; function updateGameElements() { cats.forEach(function (cat) { if (cat && typeof cat.update === 'function') { cat.update(); } }); if (birds && Array.isArray(birds)) { birds.forEach(function (bird) { if (bird && typeof bird.update === 'function') { bird.update(); } }); } if (ufos && Array.isArray(ufos)) { ufos.forEach(function (ufo) { if (ufo && typeof ufo.update === 'function') { ufo.update(); } }); } if (powerUps && Array.isArray(powerUps)) { powerUps.forEach(function (powerUp) { if (powerUp && typeof powerUp.update === 'function') { powerUp.update(); } }); } if (Math.random() < 0.01 * (1 + playerLevel * 0.1)) { var bird = new Bird(); bird.x = 2048 + 100; bird.y = 1500 + Math.random() * 800; game.addChild(bird); birds.push(bird); } if (playerLevel % 5 === 0 && Math.random() < 0.005) { var ufo = new UFO(); ufo.x = 2048 + 100; ufo.y = 1200 + Math.random() * 1000; game.addChild(ufo); ufos.push(ufo); } if (Math.random() < 0.002 * (1 + playerLevel * 0.05)) { spawnPowerUp(); } } function updateGameMechanics() { checkSpecialEvents(); if (typeof checkAchievements === 'function') { checkAchievements(); } if (typeof checkLevelUp === 'function') { checkLevelUp(); } if (typeof checkDailyBonus === 'function') { checkDailyBonus(); } if (typeof catDefenseSystem === 'function') { catDefenseSystem(); } } function updateUIElements() { if (sparkleCounter && typeof sparkleCounter.update === 'function') { sparkleCounter.update(); } if (levelIndicator && typeof levelIndicator.update === 'function') { levelIndicator.update(); } if (ensureInBounds) { [statsPanel, powerUpIndicator, catStatusDisplay, notificationArea, levelProgressBar].forEach(function (element) { if (element) { ensureInBounds(element); } }); } [clickUpgrade, autoUpgrade, catUpgrade, autoClickUpgrade, catSpeedUpgrade, catPowerUpgrade].forEach(function (button) { if (button && typeof button.update === 'function') { button.update(); } }); } ; }); var fontSizeBase = 24; // Define a base font size var sparkles = 0; var totalSparklesEarned = 0; var sparkleRate = 1; var autoSparkleRate = 0; var clickMultiplier = 1; var cats = []; var kittens = []; var birds = []; var ufos = []; var powerUps = []; var playerLevel = 1; var levelMultiplier = 1; var lastSaveTime = Date.now(); var lastPlayTime = Date.now(); var enemiesDefeated = 0; var achievements = { sparklesCollected: [{ threshold: 100, achieved: false, reward: 10 }, { threshold: 1000, achieved: false, reward: 50 }, { threshold: 10000, achieved: false, reward: 200 }], catsOwned: [{ threshold: 5, achieved: false, reward: 20 }, { threshold: 10, achieved: false, reward: 100 }, { threshold: 20, achieved: false, reward: 500 }], upgradesPurchased: [{ threshold: 5, achieved: false, reward: 30 }, { threshold: 15, achieved: false, reward: 150 }, { threshold: 30, achieved: false, reward: 600 }], catLevels: [{ threshold: 5, reward: 500, achieved: false }, { threshold: 10, reward: 1000, achieved: false }, { threshold: 20, reward: 2000, achieved: false }] }; var totalUpgradesPurchased = 0; var tutorialStep = 0; var tutorialComplete = false; var upgrades = { clickPower: { level: 1, cost: 10, multiplier: 1.5 }, autoCollect: { level: 0, cost: 50, multiplier: 2 }, catCost: 100, catMultiplier: 1.8 }; var sparklePool = []; var maxSparkles = 50; function saveGame() { var gameState = { sparkles: sparkles, totalSparklesEarned: totalSparklesEarned, sparkleRate: sparkleRate, autoSparkleRate: autoSparkleRate, clickMultiplier: clickMultiplier, cats: cats.map(function (cat) { return { level: cat.level, productionRate: cat.productionRate, x: cat.x, y: cat.y }; }), playerLevel: playerLevel, levelMultiplier: levelMultiplier, lastSaveTime: Date.now(), achievements: achievements, totalUpgradesPurchased: totalUpgradesPurchased, tutorialComplete: tutorialComplete, upgrades: upgrades }; return gameStorage.save('cosmicCatGarden', gameState); } function loadGame() { var gameState = gameStorage.load('cosmicCatGarden'); if (gameState) { sparkles = gameState.sparkles || 0; totalSparklesEarned = gameState.totalSparklesEarned || 0; sparkleRate = gameState.sparkleRate || 1; autoSparkleRate = gameState.autoSparkleRate || 0; clickMultiplier = gameState.clickMultiplier || 1; playerLevel = gameState.playerLevel || 1; levelMultiplier = gameState.levelMultiplier || 1; achievements = gameState.achievements || achievements; totalUpgradesPurchased = gameState.totalUpgradesPurchased || 0; tutorialComplete = gameState.tutorialComplete || false; upgrades = gameState.upgrades || upgrades; var currentTime = Date.now(); var offlineTime = (currentTime - gameState.lastSaveTime) / 1000; var offlineSparkles = 0; if (offlineTime > 0 && gameState.cats && gameState.cats.length > 0) { var totalCatProduction = gameState.cats.reduce(function (total, cat) { return total + cat.productionRate * cat.level; }, 0); offlineSparkles = totalCatProduction * offlineTime; offlineSparkles += gameState.autoSparkleRate * offlineTime; offlineSparkles *= gameState.levelMultiplier; sparkles += offlineSparkles; totalSparklesEarned += offlineSparkles; showOfflineEarnings(offlineSparkles, offlineTime); } if (gameState.cats && gameState.cats.length > 0) { cats.forEach(function (cat) { game.removeChild(cat); }); cats = []; gameState.cats.forEach(function (catData) { var cat = addCat(catData.x, catData.y); cat.level = catData.level || 1; cat.productionRate = catData.productionRate || 0.5; }); } return true; } return false; } function resetGame() { gameStorage.clear('cosmicCatGarden'); sparkles = 0; totalSparklesEarned = 0; sparkleRate = 1; autoSparkleRate = 0; clickMultiplier = 1; playerLevel = 1; levelMultiplier = 1; cats.forEach(function (cat) { game.removeChild(cat); }); cats = []; birds.forEach(function (bird) { game.removeChild(bird); }); birds = []; ufos.forEach(function (ufo) { game.removeChild(ufo); }); ufos = []; achievements = []; totalUpgradesPurchased = 0; tutorialComplete = false; upgrades = []; addCat(); return true; } var lastAutoSaveTime = Date.now(); var saveIndicator = null; function createSaveIndicator() { if (!saveIndicator) { saveIndicator = new Container(); var saveText = createGameText("Saving...", { sizeFactor: 0.7, fill: 0xFFFFFF, align: 'right' }); saveText.anchor.set(1, 0); saveIndicator.addChild(saveText); saveIndicator.alpha = 0; saveIndicator.x = 1024 - 20; saveIndicator.y = 20; game.addChild(saveIndicator); } return saveIndicator; } function checkAutoSave() { var currentTime = Date.now(); if (currentTime - lastAutoSaveTime > 30000) { var indicator = createSaveIndicator(); indicator.alpha = 1; saveGame(); lastAutoSaveTime = currentTime; setTimeout(function () { var fadeInterval = setInterval(function () { indicator.alpha -= 0.05; if (indicator.alpha <= 0) { clearInterval(fadeInterval); } }, 50); }, 1000); } } function showOfflineEarnings(amount, time) { var notification = new Container(); var bg = notification.attachAsset('achievement-notification', {}); var titleText = new Text2("Welcome Back!", { fontFamily: "Arial", fontSize: fontSizeBase, fill: 0xFFFFFF, fontWeight: 'bold' }); titleText.anchor.set(0.5, 0); titleText.y = 10; var messageText = new Text2("You earned " + Math.floor(amount) + " sparkles\nwhile away for " + Math.floor(time / 60) + " minutes", { fontFamily: "Arial", fontSize: fontSizeBase * 0.8, fill: 0xFFFFFF, align: 'center' }); messageText.anchor.set(0.5, 0); messageText.y = 35; notification.addChild(titleText); notification.addChild(messageText); notification.x = 2048 / 2; notification.y = 2732 / 2; notification.alpha = 0; game.addChild(notification); var startTime = LK.ticks; notification.update = function () { var elapsed = (LK.ticks - startTime) / 60; if (elapsed < 1) { notification.alpha = elapsed; } else if (elapsed < 5) { notification.alpha = 1; } else if (elapsed < 6) { notification.alpha = 6 - elapsed; } else { game.removeChild(notification); } }; } function showAchievement(title, description, reward) { var notification = new Container(); var bg = notification.attachAsset('achievement-notification', {}); var titleText = new Text2("Achievement: " + title, { fontFamily: "Arial", fontSize: fontSizeBase, fill: 0xFFFFFF, fontWeight: 'bold' }); titleText.anchor.set(0.5, 0); titleText.y = 10; notification.addChild(titleText); var messageText = new Text2(description + "\nReward: " + reward + " sparkles", { fontFamily: "Arial", fontSize: fontSizeBase * 0.8, fill: 0xFFFFFF, align: 'center' }); messageText.anchor.set(0.5, 0); messageText.y = fontSizeBase * 2; notification.addChild(messageText); notification.x = 1024 / 2; notification.y = 2732 / 2 - bg.height / 2; game.addChild(notification); var startTime = LK.ticks; notification.update = function () { var elapsed = (LK.ticks - startTime) / 60; if (elapsed < 1) { notification.alpha = elapsed; } else if (elapsed < 5) { notification.alpha = 1; } else if (elapsed < 6) { notification.alpha = 6 - elapsed; } else { game.removeChild(notification); } }; } function checkAchievements() { achievements.sparklesCollected.forEach(function (achievement) { if (!achievement.achieved && totalSparklesEarned >= achievement.threshold) { achievement.achieved = true; sparkles += achievement.reward; totalSparklesEarned += achievement.reward; showAchievement("Sparkle Collector", "Collected " + achievement.threshold + " sparkles", achievement.reward); } }); achievements.catsOwned.forEach(function (achievement) { if (!achievement.achieved && cats.length >= achievement.threshold) { achievement.achieved = true; sparkles += achievement.reward; totalSparklesEarned += achievement.reward; showAchievement("Cat Collector", "Owned " + achievement.threshold + " cats", achievement.reward); } }); achievements.upgradesPurchased.forEach(function (achievement) { if (!achievement.achieved && totalUpgradesPurchased >= achievement.threshold) { achievement.achieved = true; sparkles += achievement.reward; totalSparklesEarned += achievement.reward; showAchievement("Upgrade Master", "Purchased " + achievement.threshold + " upgrades", achievement.reward); } }); var totalCatLevels = cats.reduce(function (sum, cat) { return sum + cat.level; }, 0); achievements.catLevels.forEach(function (achievement) { if (!achievement.achieved && totalCatLevels >= achievement.threshold) { achievement.achieved = true; sparkles += achievement.reward; totalSparklesEarned += achievement.reward; showAchievement("Cat Master", "Reached total cat level " + achievement.threshold, achievement.reward); } }); } function checkLevelUp() { var newLevel = Math.floor(Math.log(totalSparklesEarned / 100 + 1) / Math.log(1.5)) + 1; if (newLevel > playerLevel) { var oldLevel = playerLevel; playerLevel = newLevel; levelMultiplier = 1 + (playerLevel - 1) * 0.1; showAchievement("Level Up!", "You reached level " + playerLevel, playerLevel * 50); sparkles += playerLevel * 50; totalSparklesEarned += playerLevel * 50; if (LK.getSound('chime1')) { LK.getSound('chime1').play(); } } } var sparkles = 0; var totalSparklesEarned = 0; var sparkleRate = 1; var autoSparkleRate = 0; var clickMultiplier = 1; var cats = []; var kittens = []; var birds = []; var ufos = []; var powerUps = []; var enemiesDefeated = 0; var playerLevel = 1; var levelMultiplier = 1; var lastSaveTime = Date.now(); var lastPlayTime = Date.now(); var totalUpgradesPurchased = 0; var tutorialComplete = false; var sparklePool = []; var maxSparkles = 50; function initSparklePool() { for (var i = 0; i < maxSparkles; i++) { var sparkle = new Container(); sparkle.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scale: 0.5 }); sparkle.visible = false; sparklePool.push(sparkle); game.addChild(sparkle); } } function initializeGame() { console.log("Initializing game..."); sparkles = 0; totalSparklesEarned = 0; sparkleRate = 1; autoSparkleRate = 0; clickMultiplier = 1; playerLevel = 1; levelMultiplier = 1; enemiesDefeated = 0; totalUpgradesPurchased = 0; tutorialComplete = false; clearGameObjects(); initSparklePool(); addCat(); addKitten(); setupUI(); if (LK.getMusic('bgm1')) { LK.getMusic('bgm1').play({ loop: true, volume: 0.5 }); } game.update = function () { updateGameElements(); updateGameMechanics(); updateUIElements(); if (Date.now() - lastSaveTime > 30000) { saveGame(); lastSaveTime = Date.now(); } }; console.log("Game initialized successfully"); } function clearGameObjects() { cats.forEach(function (cat) { if (cat && game.children.includes(cat)) { game.removeChild(cat); } }); cats = []; kittens.forEach(function (kitten) { if (kitten && game.children.includes(kitten)) { game.removeChild(kitten); } }); kittens = []; birds.forEach(function (bird) { if (bird && game.children.includes(bird)) { game.removeChild(bird); } }); birds = []; ufos.forEach(function (ufo) { if (ufo && game.children.includes(ufo)) { game.removeChild(ufo); } }); ufos = []; powerUps.forEach(function (powerUp) { if (powerUp && game.children.includes(powerUp)) { game.removeChild(powerUp); } }); powerUps = []; } function setupUI() { if (!game.children.includes(sparkleCounter)) { sparkleCounter = game.addChild(new SparkleCounter()); sparkleCounter.x = 1024 - 150; sparkleCounter.y = 30; } if (!game.children.includes(levelIndicator)) { levelIndicator = game.addChild(new LevelIndicator()); levelIndicator.x = 1024 - 150; levelIndicator.y = 80; } if (!game.children.includes(levelProgressBar)) { levelProgressBar = game.addChild(new LevelProgressBar()); levelProgressBar.x = 1024 - 150; levelProgressBar.y = 130; } updateUIElements(); } function updateGameElements() { cats.forEach(function (cat, index) { if (cat && typeof cat.update === 'function') { cat.update(); } }); kittens.forEach(function (kitten, index) { if (kitten && typeof kitten.update === 'function') { kitten.update(); } }); for (var i = birds.length - 1; i >= 0; i--) { var bird = birds[i]; if (bird && typeof bird.update === 'function') { bird.update(); } if (bird && bird.markedForRemoval) { game.removeChild(bird); birds.splice(i, 1); } } for (var i = ufos.length - 1; i >= 0; i--) { var ufo = ufos[i]; if (ufo && typeof ufo.update === 'function') { ufo.update(); } if (ufo && ufo.markedForRemoval) { game.removeChild(ufo); ufos.splice(i, 1); } } for (var i = powerUps.length - 1; i >= 0; i--) { var powerUp = powerUps[i]; if (powerUp && typeof powerUp.update === 'function') { powerUp.update(); } if (powerUp && powerUp.expired) { game.removeChild(powerUp); powerUps.splice(i, 1); } } if (Math.random() < 0.01 * (1 + playerLevel * 0.05)) { spawnBird(); } if (Math.random() < 0.001 * (1 + playerLevel * 0.02)) { spawnUFO(); } if (autoSparkleRate > 0) { sparkles += autoSparkleRate * levelMultiplier / 60; totalSparklesEarned += autoSparkleRate * levelMultiplier / 60; } } function updateGameMechanics() { if (enemiesDefeated >= playerLevel * 10) { levelUp(); } checkAchievements(); processCollisions(); } function updateUIElements() { if (sparkleCounter && typeof sparkleCounter.update === 'function') { sparkleCounter.update(); } if (levelIndicator && typeof levelIndicator.update === 'function') { levelIndicator.update(); } if (levelProgressBar && typeof levelProgressBar.update === 'function') { levelProgressBar.update(); } } cats.forEach(function (cat) { if (cat && typeof cat.update === 'function') { cat.update(); } }); if (birds && Array.isArray(birds)) { birds.forEach(function (bird) { if (bird && typeof bird.update === 'function') { bird.update(); } }); } if (ufos && Array.isArray(ufos)) { ufos.forEach(function (ufo) { if (ufo && typeof ufo.update === 'function') { ufo.update(); } }); } checkSpecialEvents(); if (typeof checkAchievements === 'function') { checkAchievements(); } if (typeof checkLevelUp === 'function') { checkLevelUp(); } if (statsPanel && typeof statsPanel.update === 'function') { statsPanel.update(); } if (powerUpIndicator && typeof powerUpIndicator.update === 'function') { powerUpIndicator.update(); } if (catStatusDisplay && typeof catStatusDisplay.update === 'function') { catStatusDisplay.update(); } if (notificationArea && typeof notificationArea.update === 'function') { notificationArea.update(); } if (levelProgressBar && typeof levelProgressBar.update === 'function') { levelProgressBar.update(); } if (ensureInBounds) { if (statsPanel) { ensureInBounds(statsPanel); } if (powerUpIndicator) { ensureInBounds(powerUpIndicator); } if (catStatusDisplay) { ensureInBounds(catStatusDisplay); } if (notificationArea) { ensureInBounds(notificationArea); } if (levelProgressBar) { ensureInBounds(levelProgressBar); } } if (clickUpgrade && typeof clickUpgrade.update === 'function') { clickUpgrade.update(); } if (autoUpgrade && typeof autoUpgrade.update === 'function') { autoUpgrade.update(); } if (catUpgrade && typeof catUpgrade.update === 'function') { catUpgrade.update(); } if (autoClickUpgrade && typeof autoClickUpgrade.update === 'function') { autoClickUpgrade.update(); } if (catSpeedUpgrade && typeof catSpeedUpgrade.update === 'function') { catSpeedUpgrade.update(); } if (catPowerUpgrade && typeof catPowerUpgrade.update === 'function') { catPowerUpgrade.update(); } if (typeof ensureInBounds === 'function') { [statsPanel, powerUpIndicator, catStatusDisplay, notificationArea, levelProgressBar].forEach(function (element) { if (element) { ensureInBounds(element); } }); } [clickUpgrade, autoUpgrade, catUpgrade, autoClickUpgrade, catSpeedUpgrade, catPowerUpgrade].forEach(function (button) { if (button && typeof button.update === 'function') { button.update(); } }); var powerUpIndicator = game.addChild(new PowerUpIndicator()); powerUpIndicator.x = 2048 - 150; powerUpIndicator.y = 250; var catStatusDisplay = game.addChild(new CatStatusDisplay()); catStatusDisplay.x = 2048 - 150; catStatusDisplay.y = 350; var notificationArea = game.addChild(new NotificationArea()); notificationArea.x = 20; notificationArea.y = 550; var buttonGap = 120; clickUpgrade.x = 150; clickUpgrade.y = 2732 - 150; var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 0, 2732 - 290)); if (catUpgrade) { catUpgrade.x = clickUpgrade.x + buttonGap; catUpgrade.y = clickUpgrade.y; } var autoClickUpgrade = game.addChild(new UpgradeButton("autoClick", "Auto Click\nCost: 50", 0, 2732 - 220)); autoClickUpgrade.x = clickUpgrade.x + buttonGap * 2; autoClickUpgrade.y = clickUpgrade.y; var catSpeedUpgrade = game.addChild(new UpgradeButton("catSpeed", "Cat Speed\nCost: 150", 0, 2732 - 360)); catSpeedUpgrade.x = clickUpgrade.x; catSpeedUpgrade.y = clickUpgrade.y - buttonGap; var catPowerUpgrade = game.addChild(new UpgradeButton("catPower", "Cat Power\nCost: 200", 0, 2732 - 430)); catPowerUpgrade.x = clickUpgrade.x + buttonGap; catPowerUpgrade.y = clickUpgrade.y - buttonGap; statsPanel.update(); powerUpIndicator.update(); catStatusDisplay.update(); levelProgressBar.update(); notificationArea.update(); ensureInBounds(statsPanel); ensureInBounds(powerUpIndicator); ensureInBounds(catStatusDisplay); ensureInBounds(levelProgressBar); ensureInBounds(notificationArea); function addSparkles(amount) { if (typeof amount !== 'number' || isNaN(amount)) { console.error("Invalid sparkle amount:", amount); return; } var multipliedAmount = amount; if (typeof levelMultiplier === 'number' && !isNaN(levelMultiplier)) { multipliedAmount *= levelMultiplier; } sparkles += multipliedAmount; totalSparklesEarned += multipliedAmount; if (typeof sparkleCounter !== 'undefined' && sparkleCounter && typeof sparkleCounter.update === 'function') { sparkleCounter.update(); } if (typeof checkAchievements === 'function') { checkAchievements(); } return multipliedAmount; }
===================================================================
--- original.js
+++ change.js
@@ -5,22 +5,20 @@
/****
* Classes
****/
-// Add bird enemies to the game
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 0.5,
scale: 0.6
});
- birdGraphics.tint = 0xFF0000; // Red tint for birds
+ birdGraphics.tint = 0xFF0000;
self.health = 20;
self.speed = 1 + Math.random();
self.value = 10;
self.update = function () {
- // Move toward nearest cat
if (cats.length > 0) {
var nearestCat = cats[0];
var minDist = 10000;
cats.forEach(function (cat) {
@@ -29,24 +27,19 @@
minDist = dist;
nearestCat = cat;
}
});
- // Move toward cat
var dx = nearestCat.x - self.x;
var dy = nearestCat.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 10) {
- // Stop when close enough
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
- // Check collision with cats
if (dist < 50) {
- // Cat attacks bird
self.health -= nearestCat.level;
createSparkleEffect(self.x, self.y, 0xFF0000, 2);
if (self.health <= 0) {
- // Bird defeated
handleEnemyDefeat(self, self.value);
game.removeChild(self);
birds.splice(birds.indexOf(self), 1);
}
@@ -54,9 +47,8 @@
}
};
return self;
});
-// Cat class with enhanced features
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
@@ -65,9 +57,12 @@
});
self.level = 1;
self.productionRate = 0.5;
self.lastProductionTime = 0;
- // Level indicator
+ self.speed = 2;
+ self.attackPower = 10;
+ self.attackRange = 150;
+ self.type = 'cat';
var levelCircle = new Container();
var levelCircleGraphics = levelCircle.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
@@ -84,8 +79,19 @@
anchorY: 0.5,
fill: 0xFFFFFF
});
levelCircle.addChild(levelText);
+ var powerUpIndicator = new Container();
+ var powerUpGraphics = powerUpIndicator.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 0.4
+ });
+ powerUpGraphics.tint = 0xFFFFFF;
+ powerUpIndicator.x = 0;
+ powerUpIndicator.y = catGraphics.height / 2 + 5;
+ powerUpIndicator.alpha = 0;
+ self.addChild(powerUpIndicator);
self.updateLevel = function (newLevel) {
self.level = newLevel;
updateTextProperties(levelText, {
text: "Lvl " + self.level
@@ -93,12 +99,13 @@
};
self.upgrade = function () {
self.level++;
self.productionRate *= 1.2;
+ self.speed *= 1.1;
+ self.attackPower *= 1.2;
+ self.attackRange *= 1.05;
self.updateLevel(self.level);
- // Update level indicator
levelCircleGraphics.tint = 0x000000;
- // Show level up effect
var levelUpEffect = new Container();
var levelUpGraphics = levelUpEffect.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
@@ -108,9 +115,8 @@
levelUpEffect.x = 0;
levelUpEffect.y = -catGraphics.height / 2 - 10;
levelUpEffect.alpha = 1;
self.addChild(levelUpEffect);
- // Animate level up effect
var startTime = LK.ticks;
levelUpEffect.update = function () {
var elapsed = (LK.ticks - startTime) / 60;
levelUpEffect.scale.set(1.5 - elapsed * 0.5);
@@ -119,42 +125,54 @@
self.removeChild(levelUpEffect);
}
};
};
+ self.applyPowerUp = function (type, duration) {
+ self.powerUps = self.powerUps || {};
+ self.powerUps[type] = LK.ticks + duration * 60;
+ if (type === "speed") {
+ self.speed *= 2;
+ powerUpGraphics.tint = 0x00FFFF;
+ } else if (type === "attack") {
+ self.attackPower *= 2;
+ powerUpGraphics.tint = 0xFF0000;
+ }
+ powerUpIndicator.alpha = 0.8;
+ createSparkleEffect(self.x, self.y, powerUpGraphics.tint, 10);
+ };
self.update = function () {
var currentTime = LK.ticks / 60;
if (currentTime - self.lastProductionTime > 1) {
sparkles += self.productionRate * self.level;
self.lastProductionTime = currentTime;
- // Create sparkle effect
if (Math.random() < 0.3) {
createSparkleEffect(self.x, self.y);
}
}
- // Idle animation
self.rotation = Math.sin(LK.ticks / 120) * 0.03;
- // Handle power-ups
if (self.powerUps) {
+ var hasPowerUp = false;
for (var type in self.powerUps) {
if (self.powerUps[type] < LK.ticks) {
- // Power-up expired
if (type === "speed") {
self.speed /= 2;
} else if (type === "attack") {
- self.level /= 2;
+ self.attackPower /= 2;
}
delete self.powerUps[type];
} else {
- // Show power-up indicator
+ hasPowerUp = true;
var color = type === "speed" ? 0x00FFFF : 0xFF0000;
- createSparkleEffect(self.x, self.y, color, 1);
+ if (Math.random() < 0.1) {
+ createSparkleEffect(self.x, self.y, color, 1);
+ }
}
}
+ powerUpIndicator.alpha = hasPowerUp ? 0.8 : 0;
}
};
return self;
});
-// Add a cat status display
var CatStatusDisplay = Container.expand(function () {
var self = Container.call(this);
var bg = self.attachAsset('sparkle', {
anchorX: 0.5,
@@ -183,9 +201,8 @@
powerText.y = fontSizeBase * 0.5;
self.addChild(powerText);
self.update = function () {
countText.text = "Count: " + cats.length;
- // Calculate average cat power
var totalPower = 0;
cats.forEach(function (cat) {
totalPower += cat.level || 1;
});
@@ -193,23 +210,145 @@
powerText.text = "Avg Power: " + avgPower;
};
return self;
});
-// Garden background
var Garden = Container.expand(function () {
var self = Container.call(this);
var gardenGraphics = self.attachAsset('grass-back', {
anchorX: 0.5,
anchorY: 1,
scale: 1.2
});
self.update = function () {
- // Subtle movement
self.x += Math.sin(LK.ticks / 200) * 0.1;
};
return self;
});
-// Add level indicator to the UI
+var Kitten = Container.expand(function () {
+ var self = Container.call(this);
+ var kittenGraphics = self.attachAsset('cat', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 0.6
+ });
+ kittenGraphics.tint = 0xFFCC99;
+ self.level = 1;
+ self.productionRate = 0.3;
+ self.lastProductionTime = 0;
+ self.speed = 3;
+ self.attackPower = 5;
+ self.attackRange = 100;
+ self.type = 'kitten';
+ var levelCircle = new Container();
+ var levelCircleGraphics = levelCircle.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 0.4
+ });
+ levelCircleGraphics.tint = 0x000000;
+ levelCircle.x = 0;
+ levelCircle.y = -kittenGraphics.height / 2 - 8;
+ levelCircle.alpha = 0.7;
+ self.addChild(levelCircle);
+ var levelText = createGameText("Lvl " + self.level, {
+ sizeFactor: 0.7,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ fill: 0xFFFFFF
+ });
+ levelCircle.addChild(levelText);
+ var powerUpIndicator = new Container();
+ var powerUpGraphics = powerUpIndicator.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 0.3
+ });
+ powerUpGraphics.tint = 0xFFFFFF;
+ powerUpIndicator.x = 0;
+ powerUpIndicator.y = kittenGraphics.height / 2 + 4;
+ powerUpIndicator.alpha = 0;
+ self.addChild(powerUpIndicator);
+ self.updateLevel = function (newLevel) {
+ self.level = newLevel;
+ updateTextProperties(levelText, {
+ text: "Lvl " + self.level
+ });
+ };
+ self.upgrade = function () {
+ self.level++;
+ self.productionRate *= 1.2;
+ self.speed *= 1.15;
+ self.attackPower *= 1.15;
+ self.attackRange *= 1.03;
+ self.updateLevel(self.level);
+ levelCircleGraphics.tint = 0x000000;
+ var levelUpEffect = new Container();
+ var levelUpGraphics = levelUpEffect.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 1.2
+ });
+ levelUpGraphics.tint = 0xFFFFFF;
+ levelUpEffect.x = 0;
+ levelUpEffect.y = -kittenGraphics.height / 2 - 8;
+ levelUpEffect.alpha = 1;
+ self.addChild(levelUpEffect);
+ var startTime = LK.ticks;
+ levelUpEffect.update = function () {
+ var elapsed = (LK.ticks - startTime) / 60;
+ levelUpEffect.scale.set(1.2 - elapsed * 0.4);
+ levelUpEffect.alpha = 1 - elapsed;
+ if (elapsed >= 1) {
+ self.removeChild(levelUpEffect);
+ }
+ };
+ };
+ self.applyPowerUp = function (type, duration) {
+ self.powerUps = self.powerUps || {};
+ self.powerUps[type] = LK.ticks + duration * 60;
+ if (type === "speed") {
+ self.speed *= 2;
+ powerUpGraphics.tint = 0x00FFFF;
+ } else if (type === "attack") {
+ self.attackPower *= 2;
+ powerUpGraphics.tint = 0xFF0000;
+ }
+ powerUpIndicator.alpha = 0.8;
+ createSparkleEffect(self.x, self.y, powerUpGraphics.tint, 8);
+ };
+ self.update = function () {
+ var currentTime = LK.ticks / 60;
+ if (currentTime - self.lastProductionTime > 1) {
+ sparkles += self.productionRate * self.level;
+ self.lastProductionTime = currentTime;
+ if (Math.random() < 0.3) {
+ createSparkleEffect(self.x, self.y);
+ }
+ }
+ self.rotation = Math.sin(LK.ticks / 90) * 0.05;
+ if (self.powerUps) {
+ var hasPowerUp = false;
+ for (var type in self.powerUps) {
+ if (self.powerUps[type] < LK.ticks) {
+ if (type === "speed") {
+ self.speed /= 2;
+ } else if (type === "attack") {
+ self.attackPower /= 2;
+ }
+ delete self.powerUps[type];
+ } else {
+ hasPowerUp = true;
+ var color = type === "speed" ? 0x00FFFF : 0xFF0000;
+ if (Math.random() < 0.1) {
+ createSparkleEffect(self.x, self.y, color, 1);
+ }
+ }
+ }
+ powerUpIndicator.alpha = hasPowerUp ? 0.8 : 0;
+ }
+ };
+ return self;
+});
var LevelIndicator = Container.expand(function () {
var self = Container.call(this);
var bg = self.attachAsset('sparkle', {
anchorX: 0.5,
@@ -243,21 +382,18 @@
});
};
return self;
});
-// Add a progress bar for the next level
var LevelProgressBar = Container.expand(function () {
var self = Container.call(this);
- // Background bar
var bgBar = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 0.1
});
bgBar.tint = 0x333333;
self.addChild(bgBar);
- // Progress bar
var progressBar = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
@@ -272,22 +408,18 @@
labelText.anchor.set(0.5, 1);
labelText.y = -5;
self.addChild(labelText);
self.update = function () {
- // Calculate progress to next level (assuming 10 enemies per level)
var enemiesForNextLevel = playerLevel * 10;
var currentLevelEnemies = enemiesDefeated % enemiesForNextLevel;
var progress = currentLevelEnemies / enemiesForNextLevel;
- // Update progress bar
- progressBar.scale.x = progress * 2; // Scale the progress bar based on progress
+ progressBar.scale.x = progress * 2;
updateTextProperties(labelText, {
text: "Next Level: " + currentLevelEnemies + "/" + enemiesForNextLevel
});
};
return self;
});
-// Add level indicator to the game
-// Main garden area (clickable)
var MainGarden = Container.expand(function () {
var self = Container.call(this);
var gardenGraphics = self.attachAsset('grass-front', {
anchorX: 0.5,
@@ -298,38 +430,32 @@
self.buttonMode = true;
self.on('pointerdown', function (event) {
sparkles += clickMultiplier;
createSparkleEffect(event.data.global.x, event.data.global.y);
- // Play random sound on click
if (Math.random() < 0.2) {
var soundIndex = Math.floor(Math.random() * sounds.length);
LK.getSound(sounds[soundIndex]).play();
}
});
return self;
});
-// Add a notification area for game events
var NotificationArea = Container.expand(function () {
var self = Container.call(this);
var messages = [];
var maxMessages = 3;
self.addMessage = function (message) {
- // Create new message text
var messageText = createGameText(message, {
sizeFactor: 0.7,
fill: 0xFFFFFF
});
messageText.anchor.set(0, 0);
messageText.alpha = 1;
self.addChild(messageText);
- // Add to messages array with creation time
messages.push({
text: messageText,
creationTime: LK.ticks
});
- // Position messages
self.repositionMessages();
- // Remove oldest if we exceed max
if (messages.length > maxMessages) {
var oldest = messages.shift();
self.removeChild(oldest.text);
}
@@ -339,35 +465,28 @@
messages[i].text.y = i * fontSizeBase;
}
};
self.update = function () {
- // Fade out messages over time
var messagesToRemove = [];
messages.forEach(function (message) {
- var age = (LK.ticks - message.creationTime) / 60; // in seconds
+ var age = (LK.ticks - message.creationTime) / 60;
if (age > 5) {
- // Mark for removal if older than 5 seconds
messagesToRemove.push(message);
} else if (age > 3) {
- // Start fading after 3 seconds
message.text.alpha = 1 - (age - 3) / 2;
}
});
- // Remove old messages
messagesToRemove.forEach(function (message) {
var index = messages.indexOf(message);
if (index !== -1) {
messages.splice(index, 1);
self.removeChild(message.text);
}
});
- // Reposition remaining messages
self.repositionMessages();
};
return self;
});
-// Add these new UI elements to the game
-// Add a power-up indicator
var PowerUpIndicator = Container.expand(function () {
var self = Container.call(this);
var bg = self.attachAsset('sparkle', {
anchorX: 0.5,
@@ -397,10 +516,8 @@
}
};
return self;
});
-// Add a cat to the game
-// Sparkle counter display
var SparkleCounter = Container.expand(function () {
var self = Container.call(this);
var counterText = new Text2("Sparkles: 0", {
fontFamily: "Arial",
@@ -426,9 +543,8 @@
});
};
return self;
});
-// Add a stats panel to display game statistics
var StatsPanel = Container.expand(function () {
var self = Container.call(this);
var bg = self.attachAsset('sparkle', {
anchorX: 0.5,
@@ -462,40 +578,40 @@
totalSparklesText.anchor.set(0.5, 0);
totalSparklesText.y = fontSizeBase;
self.addChild(totalSparklesText);
self.update = function () {
- enemiesText.text = "Enemies Defeated: " + enemiesDefeated;
- catsText.text = "Cats: " + cats.length;
- totalSparklesText.text = "Total Sparkles: " + Math.floor(totalSparklesEarned);
+ if (typeof enemiesDefeated !== 'undefined') {
+ enemiesText.text = "Enemies Defeated: " + enemiesDefeated;
+ }
+ if (typeof cats !== 'undefined') {
+ catsText.text = "Cats: " + (cats ? cats.length : 0);
+ }
+ if (typeof totalSparklesEarned !== 'undefined') {
+ totalSparklesText.text = "Total Sparkles: " + Math.floor(totalSparklesEarned || 0);
+ }
};
return self;
});
-// Add UFO enemies
var UFO = Container.expand(function () {
var self = Container.call(this);
var ufoGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 0.5,
scale: 0.7
});
- ufoGraphics.tint = 0x00FFFF; // Cyan tint for UFOs
+ ufoGraphics.tint = 0x00FFFF;
self.health = 40;
self.speed = 0.7 + Math.random() * 0.5;
self.value = 20;
self.update = function () {
- // Similar to bird but with different behavior
- // Move in a more erratic pattern
self.x += Math.sin(LK.ticks / 30) * self.speed;
self.y += Math.cos(LK.ticks / 20) * self.speed;
- // Check collision with cats
cats.forEach(function (cat) {
var dist = Math.sqrt(Math.pow(cat.x - self.x, 2) + Math.pow(cat.y - self.y, 2));
if (dist < 60) {
- // Cat attacks UFO
self.health -= cat.level;
createSparkleEffect(self.x, self.y, 0x00FFFF, 1);
if (self.health <= 0) {
- // UFO defeated
handleEnemyDefeat(self, self.value);
game.removeChild(self);
ufos.splice(ufos.indexOf(self), 1);
}
@@ -503,11 +619,8 @@
});
};
return self;
});
-// Add these variables to the game state
-// Enhanced sparkle effect with color options
-// Upgrade Button class
var UpgradeButton = Container.expand(function (type, text, x, y) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('upgrade-button', {
anchorX: 0.5,
@@ -526,9 +639,8 @@
self.addChild(buttonText);
self.x = x;
self.y = y;
self.update = function () {
- // Update button text based on type
if (self.type === "clickPower") {
buttonText.text = "Click Power\nCost: " + Math.floor(upgrades.clickPower.cost);
} else if (self.type === "autoCollect") {
buttonText.text = "Auto Collect\nCost: " + Math.floor(upgrades.autoCollect.cost);
@@ -536,9 +648,8 @@
buttonText.text = "Buy Cat\nCost: " + Math.floor(upgrades.catCost);
} else if (self.type === "upgradeCat") {
var upgradeCost = 200 * playerLevel;
buttonText.text = "Upgrade Cat\nCost: " + Math.floor(upgradeCost);
- // Update button appearance based on affordability
if (cats.length > 0) {
if (sparkles >= upgradeCost) {
self.alpha = 1.0;
} else {
@@ -580,17 +691,14 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- // No title, no description
- // Always backgroundColor is black
backgroundColor: 0x000000
});
/****
* Game Code
****/
-// Create a wrapper for storage operations with fallback
var gameStorage = {
save: function save(key, data) {
try {
storage.set(key, JSON.stringify(data));
@@ -675,109 +783,124 @@
return ("string" === r ? String : Number)(t);
}
var startButton = game.addChild(new UpgradeButton("start", "Start", 2048 - 150, 2732 - 100));
startButton.on('pointerdown', function () {
- // Reset game state
sparkles = 0;
totalSparklesEarned = 0;
playerLevel = 1;
levelMultiplier = 1;
cats = [];
+ kittens = [];
birds = [];
ufos = [];
enemiesDefeated = 0;
powerUps = [];
- // Add initial cat
+ totalUpgradesPurchased = 0;
addCat();
- // Start game logic
+ addKitten();
game.update = function () {
- // Update game elements
+ updateGameElements();
+ updateGameMechanics();
+ updateUIElements();
+ };
+ function updateGameElements() {
cats.forEach(function (cat) {
- return cat.update();
+ if (cat && typeof cat.update === 'function') {
+ cat.update();
+ }
});
- birds.forEach(function (bird) {
- return bird.update();
- });
- ufos.forEach(function (ufo) {
- return ufo.update();
- });
- // Check for special events
- checkSpecialEvents();
- // Check for achievements
- checkAchievements();
- // Check for level up
- checkLevelUp();
- // Check for daily bonus
- checkDailyBonus();
- // Check tutorials
- checkTutorials();
- // Update UI elements
- if (statsPanel && statsPanel.update) {
- statsPanel.update();
+ if (birds && Array.isArray(birds)) {
+ birds.forEach(function (bird) {
+ if (bird && typeof bird.update === 'function') {
+ bird.update();
+ }
+ });
}
- if (powerUpIndicator && powerUpIndicator.update) {
- powerUpIndicator.update();
+ if (ufos && Array.isArray(ufos)) {
+ ufos.forEach(function (ufo) {
+ if (ufo && typeof ufo.update === 'function') {
+ ufo.update();
+ }
+ });
}
- if (catStatusDisplay && catStatusDisplay.update) {
- catStatusDisplay.update();
+ if (powerUps && Array.isArray(powerUps)) {
+ powerUps.forEach(function (powerUp) {
+ if (powerUp && typeof powerUp.update === 'function') {
+ powerUp.update();
+ }
+ });
}
- if (notificationArea && notificationArea.update) {
- notificationArea.update();
+ if (Math.random() < 0.01 * (1 + playerLevel * 0.1)) {
+ var bird = new Bird();
+ bird.x = 2048 + 100;
+ bird.y = 1500 + Math.random() * 800;
+ game.addChild(bird);
+ birds.push(bird);
}
- if (levelProgressBar && levelProgressBar.update) {
- levelProgressBar.update();
+ if (playerLevel % 5 === 0 && Math.random() < 0.005) {
+ var ufo = new UFO();
+ ufo.x = 2048 + 100;
+ ufo.y = 1200 + Math.random() * 1000;
+ game.addChild(ufo);
+ ufos.push(ufo);
}
- // Ensure all UI elements are within bounds
- if (ensureInBounds) {
- if (statsPanel) {
- ensureInBounds(statsPanel);
- }
- if (powerUpIndicator) {
- ensureInBounds(powerUpIndicator);
- }
- if (catStatusDisplay) {
- ensureInBounds(catStatusDisplay);
- }
- if (notificationArea) {
- ensureInBounds(notificationArea);
- }
- if (levelProgressBar) {
- ensureInBounds(levelProgressBar);
- }
+ if (Math.random() < 0.002 * (1 + playerLevel * 0.05)) {
+ spawnPowerUp();
}
- // Update buttons if they exist and have update methods
- if (clickUpgrade && clickUpgrade.update) {
- clickUpgrade.update();
+ }
+ function updateGameMechanics() {
+ checkSpecialEvents();
+ if (typeof checkAchievements === 'function') {
+ checkAchievements();
}
- if (autoUpgrade && autoUpgrade.update) {
- autoUpgrade.update();
+ if (typeof checkLevelUp === 'function') {
+ checkLevelUp();
}
- if (catUpgrade && catUpgrade.update) {
- catUpgrade.update();
+ if (typeof checkDailyBonus === 'function') {
+ checkDailyBonus();
}
- if (autoClickUpgrade && autoClickUpgrade.update) {
- autoClickUpgrade.update();
+ if (typeof catDefenseSystem === 'function') {
+ catDefenseSystem();
}
- if (catSpeedUpgrade && catSpeedUpgrade.update) {
- catSpeedUpgrade.update();
+ }
+ function updateUIElements() {
+ if (sparkleCounter && typeof sparkleCounter.update === 'function') {
+ sparkleCounter.update();
}
- if (catPowerUpgrade && catPowerUpgrade.update) {
- catPowerUpgrade.update();
+ if (levelIndicator && typeof levelIndicator.update === 'function') {
+ levelIndicator.update();
}
- };
+ if (ensureInBounds) {
+ [statsPanel, powerUpIndicator, catStatusDisplay, notificationArea, levelProgressBar].forEach(function (element) {
+ if (element) {
+ ensureInBounds(element);
+ }
+ });
+ }
+ [clickUpgrade, autoUpgrade, catUpgrade, autoClickUpgrade, catSpeedUpgrade, catPowerUpgrade].forEach(function (button) {
+ if (button && typeof button.update === 'function') {
+ button.update();
+ }
+ });
+ }
+ ;
});
-// Add a cat to the game
-// Game state variables
+var fontSizeBase = 24; // Define a base font size
var sparkles = 0;
var totalSparklesEarned = 0;
var sparkleRate = 1;
var autoSparkleRate = 0;
var clickMultiplier = 1;
var cats = [];
+var kittens = [];
+var birds = [];
+var ufos = [];
+var powerUps = [];
var playerLevel = 1;
var levelMultiplier = 1;
var lastSaveTime = Date.now();
var lastPlayTime = Date.now();
+var enemiesDefeated = 0;
var achievements = {
sparklesCollected: [{
threshold: 100,
achieved: false,
@@ -847,12 +970,10 @@
},
catCost: 100,
catMultiplier: 1.8
};
-// Object pool for sparkle effects
var sparklePool = [];
var maxSparkles = 50;
-// Save game state
function saveGame() {
var gameState = {
sparkles: sparkles,
totalSparklesEarned: totalSparklesEarned,
@@ -874,16 +995,13 @@
totalUpgradesPurchased: totalUpgradesPurchased,
tutorialComplete: tutorialComplete,
upgrades: upgrades
};
- // Use the storage wrapper
return gameStorage.save('cosmicCatGarden', gameState);
}
-// Load game state
function loadGame() {
var gameState = gameStorage.load('cosmicCatGarden');
if (gameState) {
- // Restore basic variables
sparkles = gameState.sparkles || 0;
totalSparklesEarned = gameState.totalSparklesEarned || 0;
sparkleRate = gameState.sparkleRate || 1;
autoSparkleRate = gameState.autoSparkleRate || 0;
@@ -893,35 +1011,27 @@
achievements = gameState.achievements || achievements;
totalUpgradesPurchased = gameState.totalUpgradesPurchased || 0;
tutorialComplete = gameState.tutorialComplete || false;
upgrades = gameState.upgrades || upgrades;
- // Calculate offline progress
var currentTime = Date.now();
- var offlineTime = (currentTime - gameState.lastSaveTime) / 1000; // in seconds
+ var offlineTime = (currentTime - gameState.lastSaveTime) / 1000;
var offlineSparkles = 0;
if (offlineTime > 0 && gameState.cats && gameState.cats.length > 0) {
- // Calculate sparkles earned while away
var totalCatProduction = gameState.cats.reduce(function (total, cat) {
return total + cat.productionRate * cat.level;
}, 0);
offlineSparkles = totalCatProduction * offlineTime;
offlineSparkles += gameState.autoSparkleRate * offlineTime;
- // Apply level multiplier
offlineSparkles *= gameState.levelMultiplier;
- // Add offline sparkles
sparkles += offlineSparkles;
totalSparklesEarned += offlineSparkles;
- // Show offline earnings notification
showOfflineEarnings(offlineSparkles, offlineTime);
}
- // Recreate cats from saved data
if (gameState.cats && gameState.cats.length > 0) {
- // Clear existing cats
cats.forEach(function (cat) {
game.removeChild(cat);
});
cats = [];
- // Recreate cats from saved data
gameState.cats.forEach(function (catData) {
var cat = addCat(catData.x, catData.y);
cat.level = catData.level || 1;
cat.productionRate = catData.productionRate || 0.5;
@@ -930,43 +1040,36 @@
return true;
}
return false;
}
-// Add a reset game function for testing or player resets
function resetGame() {
gameStorage.clear('cosmicCatGarden');
- // Reset all game variables to initial values
sparkles = 0;
totalSparklesEarned = 0;
sparkleRate = 1;
autoSparkleRate = 0;
clickMultiplier = 1;
playerLevel = 1;
levelMultiplier = 1;
- // Clear existing cats
cats.forEach(function (cat) {
game.removeChild(cat);
});
cats = [];
- // Reset other game elements
birds.forEach(function (bird) {
game.removeChild(bird);
});
birds = [];
ufos.forEach(function (ufo) {
game.removeChild(ufo);
});
ufos = [];
- // Reset achievements and upgrades
achievements = [];
totalUpgradesPurchased = 0;
tutorialComplete = false;
upgrades = [];
- // Add initial cat
addCat();
return true;
}
-// Improve the auto-save function with status indicator
var lastAutoSaveTime = Date.now();
var saveIndicator = null;
function createSaveIndicator() {
if (!saveIndicator) {
@@ -978,25 +1081,21 @@
});
saveText.anchor.set(1, 0);
saveIndicator.addChild(saveText);
saveIndicator.alpha = 0;
- saveIndicator.x = 1024 - 20; // Right side of screen
- saveIndicator.y = 20; // Top of screen
+ saveIndicator.x = 1024 - 20;
+ saveIndicator.y = 20;
game.addChild(saveIndicator);
}
return saveIndicator;
}
function checkAutoSave() {
var currentTime = Date.now();
- // Save every 30 seconds
if (currentTime - lastAutoSaveTime > 30000) {
- // Show save indicator
var indicator = createSaveIndicator();
indicator.alpha = 1;
- // Perform save
saveGame();
lastAutoSaveTime = currentTime;
- // Fade out indicator
setTimeout(function () {
var fadeInterval = setInterval(function () {
indicator.alpha -= 0.05;
if (indicator.alpha <= 0) {
@@ -1005,9 +1104,8 @@
}, 50);
}, 1000);
}
}
-// Show offline earnings notification
function showOfflineEarnings(amount, time) {
var notification = new Container();
var bg = notification.attachAsset('achievement-notification', {});
var titleText = new Text2("Welcome Back!", {
@@ -1031,9 +1129,8 @@
notification.x = 2048 / 2;
notification.y = 2732 / 2;
notification.alpha = 0;
game.addChild(notification);
- // Animate in
var startTime = LK.ticks;
notification.update = function () {
var elapsed = (LK.ticks - startTime) / 60;
if (elapsed < 1) {
@@ -1046,9 +1143,8 @@
game.removeChild(notification);
}
};
}
-// Show achievement notification
function showAchievement(title, description, reward) {
var notification = new Container();
var bg = notification.attachAsset('achievement-notification', {});
var titleText = new Text2("Achievement: " + title, {
@@ -1068,13 +1164,11 @@
});
messageText.anchor.set(0.5, 0);
messageText.y = fontSizeBase * 2;
notification.addChild(messageText);
- // Position the notification in the center of the screen
notification.x = 1024 / 2;
notification.y = 2732 / 2 - bg.height / 2;
game.addChild(notification);
- // Add animation and removal logic
var startTime = LK.ticks;
notification.update = function () {
var elapsed = (LK.ticks - startTime) / 60;
if (elapsed < 1) {
@@ -1087,38 +1181,33 @@
game.removeChild(notification);
}
};
}
-// Check achievements
function checkAchievements() {
- // Check sparkles collected achievements
achievements.sparklesCollected.forEach(function (achievement) {
if (!achievement.achieved && totalSparklesEarned >= achievement.threshold) {
achievement.achieved = true;
sparkles += achievement.reward;
totalSparklesEarned += achievement.reward;
showAchievement("Sparkle Collector", "Collected " + achievement.threshold + " sparkles", achievement.reward);
}
});
- // Check cats owned achievements
achievements.catsOwned.forEach(function (achievement) {
if (!achievement.achieved && cats.length >= achievement.threshold) {
achievement.achieved = true;
sparkles += achievement.reward;
totalSparklesEarned += achievement.reward;
showAchievement("Cat Collector", "Owned " + achievement.threshold + " cats", achievement.reward);
}
});
- // Check upgrades purchased achievements
achievements.upgradesPurchased.forEach(function (achievement) {
if (!achievement.achieved && totalUpgradesPurchased >= achievement.threshold) {
achievement.achieved = true;
sparkles += achievement.reward;
totalSparklesEarned += achievement.reward;
showAchievement("Upgrade Master", "Purchased " + achievement.threshold + " upgrades", achievement.reward);
}
});
- // Check cat level achievements
var totalCatLevels = cats.reduce(function (sum, cat) {
return sum + cat.level;
}, 0);
achievements.catLevels.forEach(function (achievement) {
@@ -1129,757 +1218,347 @@
showAchievement("Cat Master", "Reached total cat level " + achievement.threshold, achievement.reward);
}
});
}
-// Check for level up
function checkLevelUp() {
var newLevel = Math.floor(Math.log(totalSparklesEarned / 100 + 1) / Math.log(1.5)) + 1;
if (newLevel > playerLevel) {
var oldLevel = playerLevel;
playerLevel = newLevel;
levelMultiplier = 1 + (playerLevel - 1) * 0.1;
- // Show level up notification
- showAchievement("Level Up!", "You reached level " + playerLevel, 0);
- // Random chance to upgrade a cat
- if (cats.length > 0 && Math.random() < 0.5) {
- var randomCat = cats[Math.floor(Math.random() * cats.length)];
- randomCat.upgrade();
- createSparkleEffect(randomCat.x, randomCat.y, 0xFFFFFF, 20);
+ showAchievement("Level Up!", "You reached level " + playerLevel, playerLevel * 50);
+ sparkles += playerLevel * 50;
+ totalSparklesEarned += playerLevel * 50;
+ if (LK.getSound('chime1')) {
+ LK.getSound('chime1').play();
}
}
}
-// Tutorial system
-function showTutorial() {
- if (tutorialComplete) {
- return;
+var sparkles = 0;
+var totalSparklesEarned = 0;
+var sparkleRate = 1;
+var autoSparkleRate = 0;
+var clickMultiplier = 1;
+var cats = [];
+var kittens = [];
+var birds = [];
+var ufos = [];
+var powerUps = [];
+var enemiesDefeated = 0;
+var playerLevel = 1;
+var levelMultiplier = 1;
+var lastSaveTime = Date.now();
+var lastPlayTime = Date.now();
+var totalUpgradesPurchased = 0;
+var tutorialComplete = false;
+var sparklePool = [];
+var maxSparkles = 50;
+function initSparklePool() {
+ for (var i = 0; i < maxSparkles; i++) {
+ var sparkle = new Container();
+ sparkle.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scale: 0.5
+ });
+ sparkle.visible = false;
+ sparklePool.push(sparkle);
+ game.addChild(sparkle);
}
- var tutorial = new Container();
- var highlight = tutorial.attachAsset('tutorial-highlight', {});
- var messageText = new Text2("", {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.8,
- fill: 0xFFFFFF,
- align: 'center',
- stroke: 0x000000,
- strokeThickness: 2
- });
- messageText.anchor.set(0.5, 0.5);
- tutorial.addChild(messageText);
- // Position based on tutorial step
- switch (tutorialStep) {
- case 0:
- // Click garden
- messageText.text = "Click on the garden\nto collect sparkles!";
- tutorial.x = mainGarden.x;
- tutorial.y = mainGarden.y - 100;
- break;
- case 1:
- // Upgrade click power
- messageText.text = "Upgrade your click power\nto get more sparkles!";
- tutorial.x = clickUpgrade.x;
- tutorial.y = clickUpgrade.y;
- break;
- case 2:
- // Buy a cat
- messageText.text = "Buy a cat to automatically\ngenerate sparkles!";
- tutorial.x = catUpgrade.x;
- tutorial.y = catUpgrade.y;
- break;
- case 3:
- // Tutorial complete
- messageText.text = "Great job! Now keep\ncollecting sparkles!";
- tutorial.x = 1024 / 2;
- tutorial.y = 300;
- tutorialComplete = true;
- break;
+}
+function initializeGame() {
+ console.log("Initializing game...");
+ sparkles = 0;
+ totalSparklesEarned = 0;
+ sparkleRate = 1;
+ autoSparkleRate = 0;
+ clickMultiplier = 1;
+ playerLevel = 1;
+ levelMultiplier = 1;
+ enemiesDefeated = 0;
+ totalUpgradesPurchased = 0;
+ tutorialComplete = false;
+ clearGameObjects();
+ initSparklePool();
+ addCat();
+ addKitten();
+ setupUI();
+ if (LK.getMusic('bgm1')) {
+ LK.getMusic('bgm1').play({
+ loop: true,
+ volume: 0.5
+ });
}
- game.addChild(tutorial);
- // Animate
- var startTime = LK.ticks;
- tutorial.update = function () {
- var elapsed = (LK.ticks - startTime) / 60;
- highlight.scale.x = 1 + Math.sin(elapsed * 2) * 0.1;
- highlight.scale.y = 1 + Math.sin(elapsed * 2) * 0.1;
- if (elapsed > 10 || tutorialStep === 3 && elapsed > 5) {
- game.removeChild(tutorial);
- if (tutorialStep === 3) {
- saveGame();
- }
+ game.update = function () {
+ updateGameElements();
+ updateGameMechanics();
+ updateUIElements();
+ if (Date.now() - lastSaveTime > 30000) {
+ saveGame();
+ lastSaveTime = Date.now();
}
};
+ console.log("Game initialized successfully");
}
-// Enhanced sparkle effect with color options
-function createSparkleEffect(x, y, color, count) {
- color = color || 0xFFD700;
- count = count || 1;
- for (var i = 0; i < count; i++) {
- var sparkle;
- // Use object pool if available
- if (sparklePool.length > 0) {
- sparkle = sparklePool.pop();
- sparkle.x = x + (Math.random() * 60 - 30);
- sparkle.y = y + (Math.random() * 60 - 30);
- sparkle.alpha = 0.8;
- sparkle.scale.set(0.5 + Math.random() * 0.5);
- game.addChild(sparkle);
- } else {
- sparkle = new Container();
- var sparkleGraphics = sparkle.attachAsset('sparkle', {});
- sparkleGraphics.tint = color;
- sparkle.x = x + (Math.random() * 60 - 30);
- sparkle.y = y + (Math.random() * 60 - 30);
- sparkle.alpha = 0.8;
- sparkle.scale.set(0.5 + Math.random() * 0.5);
- game.addChild(sparkle);
+function clearGameObjects() {
+ cats.forEach(function (cat) {
+ if (cat && game.children.includes(cat)) {
+ game.removeChild(cat);
}
- // Add fade out animation without triggering save
- sparkle.update = function () {
- this.alpha -= 0.01;
- if (this.alpha <= 0) {
- game.removeChild(this);
- sparklePool.push(this);
- // Don't save game here - this was likely causing the error
- }
- };
- }
+ });
+ cats = [];
+ kittens.forEach(function (kitten) {
+ if (kitten && game.children.includes(kitten)) {
+ game.removeChild(kitten);
+ }
+ });
+ kittens = [];
+ birds.forEach(function (bird) {
+ if (bird && game.children.includes(bird)) {
+ game.removeChild(bird);
+ }
+ });
+ birds = [];
+ ufos.forEach(function (ufo) {
+ if (ufo && game.children.includes(ufo)) {
+ game.removeChild(ufo);
+ }
+ });
+ ufos = [];
+ powerUps.forEach(function (powerUp) {
+ if (powerUp && game.children.includes(powerUp)) {
+ game.removeChild(powerUp);
+ }
+ });
+ powerUps = [];
}
-// Add a cat to the game
-function addCat() {
- var cat = new Cat();
- cat.x = 400 + Math.random() * 800;
- cat.y = 1800 + Math.random() * 500;
- game.addChild(cat);
- cats.push(cat);
-}
-// Initialize game elements
-var garden = game.addChild(new Garden());
-garden.x = 1024 / 2;
-garden.y = 0;
-var mainGarden = game.addChild(new MainGarden());
-mainGarden.x = 1024 / 2;
-mainGarden.y = 2732 / 2;
-var sparkleCounter = game.addChild(new SparkleCounter());
-sparkleCounter.x = 1024 - 150; // Position in the right half of the screen
-sparkleCounter.y = 30; // Position 30 pixels from the top edge
-// Add level indicator to the game
-var levelIndicator = game.addChild(new LevelIndicator());
-levelIndicator.x = 1024 - 150; // Position in the right half of the screen
-levelIndicator.y = 80; // Position below the SparkleCounter
-// Add level progress bar to the game
-var levelProgressBar = game.addChild(new LevelProgressBar());
-levelProgressBar.x = 1024 / 2; // Center horizontally
-levelProgressBar.y = 130; // Position below level indicator
-// Add upgrade buttons
-var clickUpgrade = game.addChild(new UpgradeButton("clickPower", "Click Power\nCost: 10", 0, 2732 - 150));
-var autoUpgrade = game.addChild(new UpgradeButton("autoCollect", "Auto Collect\nCost: 50", 0, 2732 - 220));
-var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 0, 2732 - 290));
-if (catUpgrade) {
- catUpgrade.x = clickUpgrade.x + buttonGap;
- catUpgrade.y = clickUpgrade.y;
- // Ensure the update method is properly defined for this instance
- if (!catUpgrade.update) {
- catUpgrade.update = function () {
- // Update button text based on type
- if (this.type === "buyCat") {
- this.text.text = "Buy Cat\nCost: " + Math.floor(upgrades.catCost);
- // Update button appearance based on affordability
- if (sparkles >= upgrades.catCost) {
- this.alpha = 1.0;
- } else {
- this.alpha = 0.7;
- }
- }
- };
+function setupUI() {
+ if (!game.children.includes(sparkleCounter)) {
+ sparkleCounter = game.addChild(new SparkleCounter());
+ sparkleCounter.x = 1024 - 150;
+ sparkleCounter.y = 30;
}
-}
-var autoClickUpgrade = game.addChild(new UpgradeButton("autoClick", "Auto Click\nCost: 50", 0, 2732 - 220));
-autoClickUpgrade.x = clickUpgrade.x + buttonGap * 2;
-autoClickUpgrade.y = clickUpgrade.y;
-// Update any other buttons that might exist
-var catSpeedUpgrade = game.addChild(new UpgradeButton("catSpeed", "Cat Speed\nCost: 150", 0, 2732 - 360));
-catSpeedUpgrade.x = clickUpgrade.x;
-catSpeedUpgrade.y = clickUpgrade.y - buttonGap;
-var catPowerUpgrade = game.addChild(new UpgradeButton("catPower", "Cat Power\nCost: 200", 0, 2732 - 430));
-catPowerUpgrade.x = clickUpgrade.x + buttonGap;
-catPowerUpgrade.y = clickUpgrade.y - buttonGap;
-// Update the ensureInBounds function to account for the new positions
-function ensureInBounds(uiElement) {
- // Get canvas dimensions
- var canvasWidth = 2048; // Updated based on code context
- var canvasHeight = 2732; // Based on code context
- // Add padding
- var padding = 20;
- // Ensure x position is within bounds
- if (uiElement.x < padding) {
- uiElement.x = padding;
- } else if (uiElement.x > canvasWidth - padding) {
- uiElement.x = canvasWidth - padding;
+ if (!game.children.includes(levelIndicator)) {
+ levelIndicator = game.addChild(new LevelIndicator());
+ levelIndicator.x = 1024 - 150;
+ levelIndicator.y = 80;
}
- // Ensure y position is within bounds
- if (uiElement.y < padding) {
- uiElement.y = padding;
- } else if (uiElement.y > canvasHeight - padding) {
- uiElement.y = canvasHeight - padding;
+ if (!game.children.includes(levelProgressBar)) {
+ levelProgressBar = game.addChild(new LevelProgressBar());
+ levelProgressBar.x = 1024 - 150;
+ levelProgressBar.y = 130;
}
+ updateUIElements();
}
-// Update game update function to check bounds
-// Update UI elements
-if (statsPanel && typeof statsPanel.update === 'function') {
- statsPanel.update();
-}
-if (powerUpIndicator && typeof powerUpIndicator.update === 'function') {
- powerUpIndicator.update();
-}
-if (catStatusDisplay && typeof catStatusDisplay.update === 'function') {
- catStatusDisplay.update();
-}
-if (levelProgressBar && typeof levelProgressBar.update === 'function') {
- levelProgressBar.update();
-}
-if (notificationArea && typeof notificationArea.update === 'function') {
- notificationArea.update();
-}
-// Ensure all UI elements are within bounds
-if (statsPanel) {
- ensureInBounds(statsPanel);
-}
-if (powerUpIndicator) {
- ensureInBounds(powerUpIndicator);
-}
-if (catStatusDisplay) {
- ensureInBounds(catStatusDisplay);
-}
-if (levelProgressBar) {
- ensureInBounds(levelProgressBar);
-}
-if (notificationArea) {
- ensureInBounds(notificationArea);
-}
-// Add cat defense system
-function catDefenseSystem() {
- // Check for nearby enemies and defend
- cats.forEach(function (cat) {
- // Only cats level 2+ can defend
- if (cat.level >= 2) {
- // Check for nearby birds
- birds.forEach(function (bird) {
- var dist = Math.sqrt(Math.pow(cat.x - bird.x, 2) + Math.pow(cat.y - bird.y, 2));
- if (dist < 150) {
- // Defense range
- // Attack bird based on cat level
- bird.health -= 0.1 * cat.level;
- // Visual effect
- createSparkleEffect(bird.x, bird.y, 0xFF0000, 3);
- // Sound effect
- if (Math.random() < 0.1) {
- LK.getSound('songbird1').play();
- }
- }
- });
- // Check for nearby UFOs
- ufos.forEach(function (ufo) {
- var dist = Math.sqrt(Math.pow(cat.x - ufo.x, 2) + Math.pow(cat.y - ufo.y, 2));
- if (dist < 200) {
- // UFOs have larger detection range
- // Attack UFO based on cat level
- ufo.health -= 0.05 * cat.level; // UFOs are tougher
- // Visual effect
- createSparkleEffect(ufo.x, ufo.y, 0xFF0000, 3);
- }
- });
+function updateGameElements() {
+ cats.forEach(function (cat, index) {
+ if (cat && typeof cat.update === 'function') {
+ cat.update();
}
});
-}
-// Add daily bonus system
-var lastDailyBonusTime = 0;
-function checkDailyBonus() {
- var now = Date.now();
- // Check if 24 hours have passed since last bonus
- if (now - lastDailyBonusTime > 24 * 60 * 60 * 1000) {
- // Calculate bonus based on player level
- var bonus = 100 * playerLevel;
- sparkles += bonus;
- totalSparklesEarned += bonus;
- // Show achievement notification
- showAchievement("Daily Bonus!", "You received " + bonus + " sparkles", bonus);
- // Update last bonus time
- lastDailyBonusTime = now;
- // Save this to game state
- saveGame();
- }
-}
-// Add special event system
-var specialEvents = [{
- name: "Sparkle Shower",
- chance: 0.0005,
- // Rare chance per update
- effect: function effect() {
- // Create lots of sparkles
- for (var i = 0; i < 50; i++) {
- createSparkleEffect(Math.random() * 1024, Math.random() * 2732, 0xFFD700, 5);
+ kittens.forEach(function (kitten, index) {
+ if (kitten && typeof kitten.update === 'function') {
+ kitten.update();
}
- // Add bonus sparkles
- var bonus = 50 * playerLevel;
- sparkles += bonus;
- totalSparklesEarned += bonus;
- showAchievement("Sparkle Shower!", "You received " + bonus + " sparkles", bonus);
- }
-}, {
- name: "Cat Party",
- chance: 0.0003,
- // Very rare chance per update
- effect: function effect() {
- // All cats get temporary level boost
- cats.forEach(function (cat) {
- cat.powerUps = cat.powerUps || {};
- cat.powerUps["party"] = LK.ticks + 600; // 10 seconds
- cat.oldLevel = cat.level;
- cat.level *= 2;
- createSparkleEffect(cat.x, cat.y, 0xFF00FF, 10);
- });
- showAchievement("Cat Party!", "All cats are twice as productive", 0);
- }
-}];
-function checkSpecialEvents() {
- specialEvents.forEach(function (event) {
- if (Math.random() < event.chance) {
- event.effect();
- }
});
-}
-// Add cat upgrade button
-var catUpgradeButton = game.addChild(new UpgradeButton("upgradeCat", "Upgrade Cat\nCost: 200", 0, 2732 - 360));
-// Store the buttonText reference on the button itself
-catUpgradeButton.buttonText = new Text2("Upgrade Cat\nCost: 200", {
- fontFamily: "Arial",
- fontSize: 16,
- fill: 0xFFFFFF
-});
-catUpgradeButton.buttonText.anchor.set(0.5, 0.5);
-catUpgradeButton.addChild(catUpgradeButton.buttonText);
-catUpgradeButton.update = function () {
- if (cats.length > 0) {
- var upgradeCost = 200 * playerLevel;
- this.buttonText.text = "Upgrade Cat\nCost: " + Math.floor(upgradeCost);
- // Update button appearance based on affordability
- if (sparkles >= upgradeCost) {
- this.alpha = 1.0;
- } else {
- this.alpha = 0.7;
+ for (var i = birds.length - 1; i >= 0; i--) {
+ var bird = birds[i];
+ if (bird && typeof bird.update === 'function') {
+ bird.update();
}
- } else {
- this.buttonText.text = "No Cats";
- this.alpha = 0.5;
- }
-};
-// Add event handler for cat upgrade button
-catUpgradeButton.interactive = true;
-catUpgradeButton.buttonMode = true;
-catUpgradeButton.on('pointerdown', function () {
- if (cats.length > 0) {
- var upgradeCost = 200 * playerLevel;
- if (sparkles >= upgradeCost) {
- sparkles -= upgradeCost;
- // Find lowest level cat to upgrade
- var lowestCat = cats[0];
- cats.forEach(function (cat) {
- if (cat.level < lowestCat.level) {
- lowestCat = cat;
- }
- });
- // Upgrade the cat
- lowestCat.upgrade();
- createSparkleEffect(lowestCat.x, lowestCat.y, 0xFFFFFF, 20);
- LK.getSound('songbird1').play();
+ if (bird && bird.markedForRemoval) {
+ game.removeChild(bird);
+ birds.splice(i, 1);
}
}
-});
-// Add tutorial system
-var tutorialSteps = [{
- message: "Welcome to Cat Garden! Click the garden to collect sparkles.",
- shown: false,
- condition: function condition() {
- return true;
- } // Show immediately
-}, {
- message: "Buy a cat to automatically collect sparkles for you!",
- shown: false,
- condition: function condition() {
- return sparkles >= 50;
- } // Show when player has 50 sparkles
-}, {
- message: "Cats will defend your garden from birds and UFOs!",
- shown: false,
- condition: function condition() {
- return cats.length >= 2;
- } // Show when player has 2 cats
-}, {
- message: "Upgrade cats to make them more powerful!",
- shown: false,
- condition: function condition() {
- return playerLevel >= 3;
- } // Show at player level 3
-}];
-function checkTutorials() {
- tutorialSteps.forEach(function (step) {
- if (!step.shown && step.condition()) {
- showAchievement("Tip", step.message, 0);
- step.shown = true;
+ for (var i = ufos.length - 1; i >= 0; i--) {
+ var ufo = ufos[i];
+ if (ufo && typeof ufo.update === 'function') {
+ ufo.update();
}
- });
-}
-// Update font sizes to be 2% of screen height
-var fontSizeBase = Math.floor(2732 * 0.02); // 2% of screen height
-// Update existing text elements to use the new font size
-function updateFontSizes() {
- // Update SparkleCounter
- SparkleCounter = Container.expand(function () {
- var self = Container.call(this);
- var counterText = new Text2("Sparkles: 0", {
- fontFamily: "Arial",
- fontSize: fontSizeBase,
- fill: 0xFFFFFF
- });
- counterText.anchor.set(0, 0);
- self.addChild(counterText);
- var levelText = new Text2("Level: 1 (x1.0)", {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.9,
- fill: 0xFFFFFF
- });
- levelText.anchor.set(0, 0);
- levelText.y = fontSizeBase * 1.5;
- self.addChild(levelText);
- self.update = function () {
- counterText.text = "Sparkles: " + Math.floor(sparkles);
- levelText.text = "Level: " + playerLevel + " (x" + levelMultiplier.toFixed(1) + ")";
- };
- return self;
- });
- // Update LevelIndicator
- LevelIndicator = Container.expand(function () {
- var self = Container.call(this);
- var bg = self.attachAsset('sparkle', {
- anchorX: 0.5,
- anchorY: 0.5,
- scale: 3
- });
- bg.tint = 0x000000;
- bg.alpha = 0.7;
- var levelText = new Text2("Level " + playerLevel, {
- fontFamily: "Arial",
- fontSize: fontSizeBase,
- fill: 0xFFFFFF
- });
- levelText.x = -fontSizeBase * 2;
- levelText.y = -fontSizeBase / 2;
- self.addChild(levelText);
- var multiplierText = new Text2("x" + levelMultiplier.toFixed(1), {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.8,
- fill: 0xFFD700
- });
- multiplierText.x = -fontSizeBase;
- multiplierText.y = fontSizeBase / 2;
- self.addChild(multiplierText);
- self.update = function () {
- levelText.text = "Level " + playerLevel;
- multiplierText.text = "x" + levelMultiplier.toFixed(1);
- };
- return self;
- });
- // Update UpgradeButton
- UpgradeButton = Container.expand(function (type, text, x, y) {
- var self = Container.call(this);
- var buttonGraphics = self.attachAsset('upgrade-button', {});
- self.type = type;
- var buttonText = new Text2(text, {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.8,
- fill: 0xFFFFFF
- });
- // Rest of the UpgradeButton code remains the same
- });
- // Update showAchievement function
- showAchievement = function showAchievement(title, description, reward) {
- var notification = new Container();
- var bg = notification.attachAsset('achievement-notification', {});
- var titleText = new Text2("Achievement: " + title, {
- fontFamily: "Arial",
- fontSize: fontSizeBase,
- fill: 0xFFFFFF,
- fontWeight: 'bold'
- });
- titleText.anchor.set(0.5, 0);
- titleText.y = 10;
- var messageText = new Text2(description + "\nReward: " + reward + " sparkles", {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.8,
- fill: 0xFFFFFF,
- align: 'center'
- });
- // Rest of the showAchievement function remains the same
- };
- // Update showOfflineEarnings function
- showOfflineEarnings = function showOfflineEarnings(amount, time) {
- var notification = new Container();
- var bg = notification.attachAsset('achievement-notification', {});
- var titleText = new Text2("Welcome Back!", {
- fontFamily: "Arial",
- fontSize: fontSizeBase,
- fill: 0xFFFFFF,
- fontWeight: 'bold'
- });
- // Rest of the showOfflineEarnings function remains the same
- };
- // Update showTutorial function
- showTutorial = function showTutorial() {
- if (tutorialComplete) {
- return;
+ if (ufo && ufo.markedForRemoval) {
+ game.removeChild(ufo);
+ ufos.splice(i, 1);
}
- var tutorial = new Container();
- var highlight = tutorial.attachAsset('tutorial-highlight', {});
- var messageText = new Text2("", {
- fontFamily: "Arial",
- fontSize: fontSizeBase * 0.8,
- fill: 0xFFFFFF,
- align: 'center',
- stroke: 0x000000,
- strokeThickness: 2
- });
- // Rest of the showTutorial function remains the same
- };
-}
-// Call this function to update all font sizes
-updateFontSizes();
-// Create a reusable function for creating text with consistent styling
-function createGameText(content) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var defaultOptions = {
- fontFamily: "Arial",
- fontSize: fontSizeBase * (options.sizeFactor || 1),
- fill: 0xFFFFFF,
- align: options.align || 'left',
- fontWeight: options.fontWeight || 'normal'
- };
- return new Text2(content, _objectSpread(_objectSpread({}, defaultOptions), options));
-}
-// Create a reusable function for attaching assets with common properties
-function attachGameAsset(container, assetName) {
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
- return container.attachAsset(assetName, {});
-}
-// Create a reusable function for playing sounds with randomization
-function playGameSound(soundId) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var sound = LK.getSound(soundId);
- if (sound) {
- if (options.volume !== undefined) {
- sound.volume = options.volume;
+ }
+ for (var i = powerUps.length - 1; i >= 0; i--) {
+ var powerUp = powerUps[i];
+ if (powerUp && typeof powerUp.update === 'function') {
+ powerUp.update();
}
- sound.play();
+ if (powerUp && powerUp.expired) {
+ game.removeChild(powerUp);
+ powerUps.splice(i, 1);
+ }
}
-}
-// Create a reusable function for enemy spawning logic
-function spawnEnemy(type) {
- if (type === 'bird') {
+ if (Math.random() < 0.01 * (1 + playerLevel * 0.05)) {
spawnBird();
- } else if (type === 'ufo') {
+ }
+ if (Math.random() < 0.001 * (1 + playerLevel * 0.02)) {
spawnUFO();
}
+ if (autoSparkleRate > 0) {
+ sparkles += autoSparkleRate * levelMultiplier / 60;
+ totalSparklesEarned += autoSparkleRate * levelMultiplier / 60;
+ }
}
-// Create a reusable function for checking conditions
-function checkCondition(condition, action) {
- if (condition()) {
- action();
+function updateGameMechanics() {
+ if (enemiesDefeated >= playerLevel * 10) {
+ levelUp();
}
+ checkAchievements();
+ processCollisions();
}
-// Enhanced text creation function with better positioning and sizing
-// Function to update text properties consistently
-function updateTextProperties(textObject) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- if (options.text !== undefined) {
- textObject.text = options.text;
+function updateUIElements() {
+ if (sparkleCounter && typeof sparkleCounter.update === 'function') {
+ sparkleCounter.update();
}
- if (options.fill !== undefined) {
- textObject.style.fill = options.fill;
+ if (levelIndicator && typeof levelIndicator.update === 'function') {
+ levelIndicator.update();
}
- if (options.fontSize !== undefined) {
- textObject.style.fontSize = options.fontSize;
+ if (levelProgressBar && typeof levelProgressBar.update === 'function') {
+ levelProgressBar.update();
}
- if (options.alpha !== undefined) {
- textObject.alpha = options.alpha;
- }
}
-// Add these new UI elements to the game with safe positioning
-var statsPanel = game.addChild(new StatsPanel());
-statsPanel.x = 2048 - 150; // Move to right side of screen
-statsPanel.y = 150; // Position below other top-right elements
-// Reposition sparkle counter and level indicator to create a consolidated UI group
-sparkleCounter.x = 2048 - 150; // Right side positioning
-sparkleCounter.y = 30; // Top position
-levelIndicator.x = 2048 - 150; // Right side positioning
-levelIndicator.y = 80; // Position below sparkle counter
-// Reposition other UI elements that were previously on the left
-// Add missing global variables
-var powerUpIndicator;
-var catStatusDisplay;
-var notificationArea;
-var statsPanel;
-var enemiesDefeated = 0;
-var powerUps = [];
-// Initialize UI elements
-powerUpIndicator = game.addChild(new PowerUpIndicator());
-powerUpIndicator.x = 2048 - 150; // Move to right side
-powerUpIndicator.y = 250; // Position below level indicator
-catStatusDisplay = game.addChild(new CatStatusDisplay());
-catStatusDisplay.x = 2048 - 150; // Move to right side
-catStatusDisplay.y = 350; // Position below power-up indicator
-notificationArea = game.addChild(new NotificationArea());
-notificationArea.x = 150; // Left edge with small margin
-notificationArea.y = 550; // Below other UI elements
-// Define statsPanel if it doesn't exist
-if (!statsPanel) {
- statsPanel = Container.expand(function () {
- var self = Container.call(this);
- var bg = self.attachAsset('sparkle', {
- anchorX: 0.5,
- anchorY: 0.5,
- scale: 2.5
- });
- bg.tint = 0xFFFFFF;
- bg.alpha = 0.3;
- var statsText = createGameText("Game Stats", {
- sizeFactor: 0.9,
- fontWeight: 'bold'
- });
- statsText.anchor.set(0.5, 0);
- statsText.y = -fontSizeBase;
- self.addChild(statsText);
- var detailsText = createGameText("Sparkles: 0", {
- sizeFactor: 0.8
- });
- detailsText.anchor.set(0.5, 0);
- detailsText.y = 0;
- self.addChild(detailsText);
- self.update = function () {
- detailsText.text = "Sparkles: " + Math.floor(sparkles) + "\nLevel: " + playerLevel + "\nEnemies: " + enemiesDefeated;
- };
- return self;
- });
- statsPanel = game.addChild(statsPanel);
- statsPanel.x = 150;
- statsPanel.y = 150;
-}
-// Fix the getChildByName references
-// Replace with direct references to the existing buttons
-// Make sure the update methods are properly defined for all buttons
-// Update the game update function to safely check for UI elements before updating
-var originalGameUpdate = game.update;
-game.update = function () {
- // Call the original update function if it exists
- if (originalGameUpdate) {
- originalGameUpdate.call(game);
+cats.forEach(function (cat) {
+ if (cat && typeof cat.update === 'function') {
+ cat.update();
}
- // Update game elements
- cats.forEach(function (cat) {
- if (cat && typeof cat.update === 'function') {
- cat.update();
- }
- });
+});
+if (birds && Array.isArray(birds)) {
birds.forEach(function (bird) {
if (bird && typeof bird.update === 'function') {
bird.update();
}
});
+}
+if (ufos && Array.isArray(ufos)) {
ufos.forEach(function (ufo) {
if (ufo && typeof ufo.update === 'function') {
ufo.update();
}
});
- // Check for special events
- checkSpecialEvents();
- // Check for achievements
- if (typeof checkAchievements === 'function') {
- checkAchievements();
+}
+checkSpecialEvents();
+if (typeof checkAchievements === 'function') {
+ checkAchievements();
+}
+if (typeof checkLevelUp === 'function') {
+ checkLevelUp();
+}
+if (statsPanel && typeof statsPanel.update === 'function') {
+ statsPanel.update();
+}
+if (powerUpIndicator && typeof powerUpIndicator.update === 'function') {
+ powerUpIndicator.update();
+}
+if (catStatusDisplay && typeof catStatusDisplay.update === 'function') {
+ catStatusDisplay.update();
+}
+if (notificationArea && typeof notificationArea.update === 'function') {
+ notificationArea.update();
+}
+if (levelProgressBar && typeof levelProgressBar.update === 'function') {
+ levelProgressBar.update();
+}
+if (ensureInBounds) {
+ if (statsPanel) {
+ ensureInBounds(statsPanel);
}
- // Check for level up
- if (typeof checkLevelUp === 'function') {
- checkLevelUp();
+ if (powerUpIndicator) {
+ ensureInBounds(powerUpIndicator);
}
- // Safely update UI elements
- if (statsPanel && typeof statsPanel.update === 'function') {
- statsPanel.update();
+ if (catStatusDisplay) {
+ ensureInBounds(catStatusDisplay);
}
- if (powerUpIndicator && typeof powerUpIndicator.update === 'function') {
- powerUpIndicator.update();
+ if (notificationArea) {
+ ensureInBounds(notificationArea);
}
- if (catStatusDisplay && typeof catStatusDisplay.update === 'function') {
- catStatusDisplay.update();
+ if (levelProgressBar) {
+ ensureInBounds(levelProgressBar);
}
- if (notificationArea && typeof notificationArea.update === 'function') {
- notificationArea.update();
- }
- if (levelProgressBar && typeof levelProgressBar.update === 'function') {
- levelProgressBar.update();
- }
- // Ensure all UI elements are within bounds
- if (typeof ensureInBounds === 'function') {
- [statsPanel, powerUpIndicator, catStatusDisplay, notificationArea, levelProgressBar].forEach(function (element) {
- if (element) {
- ensureInBounds(element);
- }
- });
- }
- // Update buttons
- [clickUpgrade, autoUpgrade, catUpgrade, autoClickUpgrade, catSpeedUpgrade, catPowerUpgrade].forEach(function (button) {
- if (button && typeof button.update === 'function') {
- button.update();
+}
+if (clickUpgrade && typeof clickUpgrade.update === 'function') {
+ clickUpgrade.update();
+}
+if (autoUpgrade && typeof autoUpgrade.update === 'function') {
+ autoUpgrade.update();
+}
+if (catUpgrade && typeof catUpgrade.update === 'function') {
+ catUpgrade.update();
+}
+if (autoClickUpgrade && typeof autoClickUpgrade.update === 'function') {
+ autoClickUpgrade.update();
+}
+if (catSpeedUpgrade && typeof catSpeedUpgrade.update === 'function') {
+ catSpeedUpgrade.update();
+}
+if (catPowerUpgrade && typeof catPowerUpgrade.update === 'function') {
+ catPowerUpgrade.update();
+}
+if (typeof ensureInBounds === 'function') {
+ [statsPanel, powerUpIndicator, catStatusDisplay, notificationArea, levelProgressBar].forEach(function (element) {
+ if (element) {
+ ensureInBounds(element);
}
});
-};
+}
+[clickUpgrade, autoUpgrade, catUpgrade, autoClickUpgrade, catSpeedUpgrade, catPowerUpgrade].forEach(function (button) {
+ if (button && typeof button.update === 'function') {
+ button.update();
+ }
+});
var powerUpIndicator = game.addChild(new PowerUpIndicator());
-powerUpIndicator.x = 2048 - 150; // Move to right side
-powerUpIndicator.y = 250; // Position below stats panel
+powerUpIndicator.x = 2048 - 150;
+powerUpIndicator.y = 250;
var catStatusDisplay = game.addChild(new CatStatusDisplay());
-catStatusDisplay.x = 2048 - 150; // Move to right side
-catStatusDisplay.y = 350; // Position below power-up indicator
-// Keep notification area on the left but adjust position
+catStatusDisplay.x = 2048 - 150;
+catStatusDisplay.y = 350;
var notificationArea = game.addChild(new NotificationArea());
-notificationArea.x = 20; // Left edge with small margin
-notificationArea.y = 550; // Below other UI elements
-// Increase gap between buttons at bottom left
-// Assuming buttons are positioned sequentially
-var buttonGap = 120; // Increased gap between buttons (was likely around 80-100)
-// Reposition upgrade buttons with increased gaps
-clickUpgrade.x = 150; // First button position
+notificationArea.x = 20;
+notificationArea.y = 550;
+var buttonGap = 120;
+clickUpgrade.x = 150;
clickUpgrade.y = 2732 - 150;
-// Position other buttons with the new gap
var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 0, 2732 - 290));
if (catUpgrade) {
catUpgrade.x = clickUpgrade.x + buttonGap;
catUpgrade.y = clickUpgrade.y;
}
var autoClickUpgrade = game.addChild(new UpgradeButton("autoClick", "Auto Click\nCost: 50", 0, 2732 - 220));
autoClickUpgrade.x = clickUpgrade.x + buttonGap * 2;
autoClickUpgrade.y = clickUpgrade.y;
-// Update any other buttons that might exist
var catSpeedUpgrade = game.addChild(new UpgradeButton("catSpeed", "Cat Speed\nCost: 150", 0, 2732 - 360));
catSpeedUpgrade.x = clickUpgrade.x;
catSpeedUpgrade.y = clickUpgrade.y - buttonGap;
var catPowerUpgrade = game.addChild(new UpgradeButton("catPower", "Cat Power\nCost: 200", 0, 2732 - 430));
catPowerUpgrade.x = clickUpgrade.x + buttonGap;
catPowerUpgrade.y = clickUpgrade.y - buttonGap;
-// Update the ensureInBounds function to account for the new positions
-// Update game update function to check bounds
-// Update UI elements
statsPanel.update();
powerUpIndicator.update();
catStatusDisplay.update();
levelProgressBar.update();
notificationArea.update();
-// Ensure all UI elements are within bounds
ensureInBounds(statsPanel);
ensureInBounds(powerUpIndicator);
ensureInBounds(catStatusDisplay);
ensureInBounds(levelProgressBar);
-ensureInBounds(notificationArea);
\ No newline at end of file
+ensureInBounds(notificationArea);
+function addSparkles(amount) {
+ if (typeof amount !== 'number' || isNaN(amount)) {
+ console.error("Invalid sparkle amount:", amount);
+ return;
+ }
+ var multipliedAmount = amount;
+ if (typeof levelMultiplier === 'number' && !isNaN(levelMultiplier)) {
+ multipliedAmount *= levelMultiplier;
+ }
+ sparkles += multipliedAmount;
+ totalSparklesEarned += multipliedAmount;
+ if (typeof sparkleCounter !== 'undefined' && sparkleCounter && typeof sparkleCounter.update === 'function') {
+ sparkleCounter.update();
+ }
+ if (typeof checkAchievements === 'function') {
+ checkAchievements();
+ }
+ return multipliedAmount;
+}
\ 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