Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 48
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 168
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Level: 1 (x1.0)", {' Line Number: 148
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 140
Code edit (1 edits merged)
Please save this source code
User prompt
make label text black
User prompt
move all objects to the top right of the screen
User prompt
make the game play itself until a player clicks a start button
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 34
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 119
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 102
Code edit (1 edits merged)
Please save this source code
User prompt
change all label text colors to white
User prompt
remove unused objects
User prompt
apply images to all image obects
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var laserGraphics = new Graphics();' Line Number: 273
Code edit (1 edits merged)
Please save this source code
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
1. **Global Scope Initialization**: Ensure that all important variables, instances, arrays, and variables are initialized in the global scope of `gamecode.js`. This includes arrays for game objects like `cats`, `kittens`, `birds`, `ufos`, `clouds`, `powerUps`, and `sparkles`.
2. **Asset Classes**: Differentiate between asset classes for different behaviors, such as 'HeroBullets' and 'EnemyBullets', and ensure distinct assets are assigned to these classes.
3. **Event Listeners**: Ensure event listeners are correctly using the `obj.event` for the event object, and not assuming any standard libraries are included.
4. **Touchscreen Compatibility**: Ensure the game is touchscreen-compatible and does not rely on keyboard inputs or controls.
5. **Asset Retrieval**: Use `LK.getAsset('
User prompt
continue developing hte app
User prompt
ensure the game is initialized correctly
User prompt
continue
/****
* Classes
****/
// Cat class with enhanced features
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;
// Level indicator
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 = new LK.Text("Lvl " + self.level, {
fontFamily: "Arial",
fontSize: 16,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0.5);
levelText.y = -50;
self.addChild(levelText);
self.upgrade = function () {
self.level++;
self.productionRate *= 1.2;
levelText.text = "Lvl " + self.level;
// Update level indicator
levelText.text = "Lvl " + self.level;
levelCircleGraphics.tint = 0x000000;
// Show level up effect
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);
// 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);
levelUpEffect.alpha = 1 - elapsed;
if (elapsed >= 1) {
self.removeChild(levelUpEffect);
}
};
};
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;
};
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;
});
// Main garden area (clickable)
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);
// 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 cat to the game
// Sparkle counter display
var SparkleCounter = Container.expand(function () {
var self = Container.call(this);
var counterText = new LK.Text("Sparkles: 0", {
fontFamily: "Arial",
fontSize: 24,
fill: 0xFFFFFF
});
counterText.anchor.set(0, 0);
self.addChild(counterText);
// Add level display
var levelText = new LK.Text("Level: 1 (x1.0)", {
fontFamily: "Arial",
fontSize: 18,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
levelText.y = 30;
self.addChild(levelText);
self.update = function () {
counterText.text = "Sparkles: " + Math.floor(sparkles);
levelText.text = "Level: " + playerLevel + " (x" + levelMultiplier.toFixed(1) + ")";
};
return self;
});
// 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', {});
self.type = type;
var buttonText = new LK.Text(text, {
fontFamily: "Arial",
fontSize: 16,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
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);
} else if (self.type === "buyCat") {
buttonText.text = "Buy Cat\nCost: " + Math.floor(upgrades.catCost);
}
// Disable button if not enough sparkles
if (self.type === "clickPower" && sparkles >= upgrades.clickPower.cost) {
buttonGraphics.alpha = 1;
} else if (self.type === "autoCollect" && sparkles >= upgrades.autoCollect.cost) {
buttonGraphics.alpha = 1;
} else if (self.type === "buyCat" && sparkles >= upgrades.catCost) {
buttonGraphics.alpha = 1;
} else {
buttonGraphics.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: 0x87CEEB // Sky blue
});
/****
* Game Code
****/
// Cosmic Cat Garden - An Idle/Hypercasual Game
// Game state variables
var sparkles = 0;
var totalSparklesEarned = 0;
var sparkleRate = 1;
var autoSparkleRate = 0;
var clickMultiplier = 1;
var cats = [];
var playerLevel = 1;
var levelMultiplier = 1;
var lastSaveTime = Date.now();
var lastPlayTime = Date.now();
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
}]
};
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
};
// Object pool for sparkle effects
var sparklePool = [];
var maxSparkles = 50;
// Save game state
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
};
try {
localStorage.setItem('cosmicCatGarden', JSON.stringify(gameState));
console.log('Game saved successfully');
} catch (e) {
console.error('Failed to save game:', e);
}
}
// Load game state
function loadGame() {
try {
var savedState = localStorage.getItem('cosmicCatGarden');
if (savedState) {
var gameState = JSON.parse(savedState);
// Restore basic variables
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;
// Calculate offline progress
var currentTime = Date.now();
var offlineTime = (currentTime - gameState.lastSaveTime) / 1000; // in seconds
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);
}
// Restore cats
if (gameState.cats && gameState.cats.length > 0) {
// Remove initial cat
if (cats.length > 0) {
game.removeChild(cats[0]);
cats = [];
}
// Restore saved cats
gameState.cats.forEach(function (catData) {
var cat = new Cat();
cat.level = catData.level;
cat.productionRate = catData.productionRate;
cat.x = catData.x;
cat.y = catData.y;
game.addChild(cat);
cats.push(cat);
});
}
console.log('Game loaded successfully');
}
} catch (e) {
console.error('Failed to load game:', e);
}
}
// Show offline earnings notification
function showOfflineEarnings(amount, time) {
var notification = new Container();
var bg = notification.attachAsset('achievement-notification', {});
var titleText = new LK.Text("Welcome Back!", {
fontFamily: "Arial",
fontSize: 20,
fill: 0xFFFFFF,
fontWeight: 'bold'
});
titleText.anchor.set(0.5, 0);
titleText.y = 10;
var messageText = new LK.Text("You earned " + Math.floor(amount) + " sparkles\nwhile away for " + Math.floor(time / 60) + " minutes", {
fontFamily: "Arial",
fontSize: 16,
fill: 0xFFFFFF,
align: 'center'
});
messageText.anchor.set(0.5, 0);
messageText.y = 35;
notification.addChild(titleText);
notification.addChild(messageText);
notification.x = 1024 / 2;
notification.y = 100;
notification.alpha = 0;
game.addChild(notification);
// Animate in
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);
}
};
}
// Show achievement notification
function showAchievement(title, description, reward) {
var notification = new Container();
var bg = notification.attachAsset('achievement-notification', {});
var titleText = new LK.Text("Achievement: " + title, {
fontFamily: "Arial",
fontSize: 20,
fill: 0xFFFFFF,
fontWeight: 'bold'
});
titleText.anchor.set(0.5, 0);
titleText.y = 10;
var messageText = new LK.Text(description + "\nReward: " + reward + " sparkles", {
fontFamily: "Arial",
fontSize: 16,
fill: 0xFFFFFF,
align: 'center'
});
messageText.anchor.set(0.5, 0);
messageText.y = 35;
notification.addChild(titleText);
notification.addChild(messageText);
notification.x = 1024 / 2;
notification.y = 100;
notification.alpha = 0;
game.addChild(notification);
// Animate in
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);
}
};
}
// 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 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);
}
}
}
// Tutorial system
function showTutorial() {
if (tutorialComplete) {
return;
}
var tutorial = new Container();
var highlight = tutorial.attachAsset('tutorial-highlight', {});
var messageText = new LK.Text("", {
fontFamily: "Arial",
fontSize: 20,
fill: 0xFFFFFF,
align: 'center',
stroke: 0x000000,
strokeThickness: 4
});
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;
}
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();
}
}
};
}
// 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);
}
// Animate and remove
var startTime = LK.ticks;
sparkle.update = function () {
var elapsed = (LK.ticks - startTime) / 60;
sparkle.y -= 0.5;
sparkle.alpha = Math.max(0, 0.8 - elapsed);
if (sparkle.alpha <= 0) {
game.removeChild(sparkle);
// Return to pool if not full
if (sparklePool.length < maxSparkles) {
sparklePool.push(sparkle);
}
}
};
}
}
// 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;
garden.y = 2732;
var mainGarden = game.addChild(new MainGarden());
mainGarden.x = 1024;
mainGarden.y = 2200;
var sparkleCounter = game.addChild(new SparkleCounter());
sparkleCounter.x = 50;
sparkleCounter.y = 50;
// Add upgrade buttons
var clickUpgrade = game.addChild(new UpgradeButton("clickPower", "Click Power\nCost: 10", 150, 150));
var autoUpgrade = game.addChild(new UpgradeButton("autoCollect", "Auto Collect\nCost: 50", 150, 220));
var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 150, 290));
// Add initial cat
addCat();
// Background sounds
var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
var currentAmbientSound = null;
// Initialize random timers for ambient sounds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
currentAmbientSound.stop();
}
sound.play();
currentAmbientSound = sound;
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000);
ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000);
}, Math.random() * 20000 + 10000);
});
// Main game update loop
game.update = function () {
// Update all cats
cats.forEach(function (cat) {
cat.update();
});
// Update UI elements
sparkleCounter.update();
clickUpgrade.update();
autoUpgrade.update();
catUpgrade.update();
// Auto-collect sparkles
if (autoSparkleRate > 0) {
sparkles += autoSparkleRate / 60; // Per frame rate
}
// Random sparkle effects
if (Math.random() < 0.01 && cats.length > 0) {
var randomCat = cats[Math.floor(Math.random() * cats.length)];
createSparkleEffect(randomCat.x, randomCat.y);
}
};
// Play background music
LK.playMusic('bgm1', {
loop: true,
fade: {
start: 0,
end: 0.02,
duration: 4000
}
}); ===================================================================
--- original.js
+++ change.js
@@ -1,8 +1,8 @@
/****
* Classes
****/
-// Cat class
+// Cat class with enhanced features
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
@@ -11,20 +11,57 @@
});
self.level = 1;
self.productionRate = 0.5;
self.lastProductionTime = 0;
- var levelText = new Text2("Lvl " + self.level, {
+ // Level indicator
+ 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 = new LK.Text("Lvl " + self.level, {
fontFamily: "Arial",
fontSize: 16,
- fill: 0x000000
+ fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0.5);
levelText.y = -50;
self.addChild(levelText);
self.upgrade = function () {
self.level++;
self.productionRate *= 1.2;
levelText.text = "Lvl " + self.level;
+ // Update level indicator
+ levelText.text = "Lvl " + self.level;
+ levelCircleGraphics.tint = 0x000000;
+ // Show level up effect
+ 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);
+ // 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);
+ levelUpEffect.alpha = 1 - elapsed;
+ if (elapsed >= 1) {
+ self.removeChild(levelUpEffect);
+ }
+ };
};
self.update = function () {
var currentTime = LK.ticks / 60;
if (currentTime - self.lastProductionTime > 1) {
@@ -53,9 +90,8 @@
self.x += Math.sin(LK.ticks / 200) * 0.1;
};
return self;
});
-// Sparkle effect
// Main garden area (clickable)
var MainGarden = Container.expand(function () {
var self = Container.call(this);
var gardenGraphics = self.attachAsset('grass-front', {
@@ -79,50 +115,40 @@
// 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", {
+ var counterText = new LK.Text("Sparkles: 0", {
fontFamily: "Arial",
fontSize: 24,
- fill: 0x000000
+ fill: 0xFFFFFF
});
counterText.anchor.set(0, 0);
self.addChild(counterText);
+ // Add level display
+ var levelText = new LK.Text("Level: 1 (x1.0)", {
+ fontFamily: "Arial",
+ fontSize: 18,
+ fill: 0xFFFFFF
+ });
+ levelText.anchor.set(0, 0);
+ levelText.y = 30;
+ self.addChild(levelText);
self.update = function () {
counterText.text = "Sparkles: " + Math.floor(sparkles);
+ levelText.text = "Level: " + playerLevel + " (x" + levelMultiplier.toFixed(1) + ")";
};
return self;
});
-// Start Button class
-var StartButton = Container.expand(function () {
- var self = Container.call(this);
- var buttonGraphics = self.attachAsset('upgrade-button', {});
- var buttonText = new Text2("Start", {
- fontFamily: "Arial",
- fontSize: 16,
- fill: 0x000000
- });
- buttonText.anchor.set(0.5, 0.5);
- self.addChild(buttonText);
- self.x = 1024;
- self.y = 1366;
- self.interactive = true;
- self.buttonMode = true;
- self.on('pointerdown', function () {
- gameStarted = true;
- self.visible = false;
- });
- return self;
-});
+// 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', {});
self.type = type;
- var buttonText = new Text2(text, {
+ var buttonText = new LK.Text(text, {
fontFamily: "Arial",
fontSize: 16,
- fill: 0x000000
+ fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.x = x;
@@ -184,12 +210,61 @@
****/
// Cosmic Cat Garden - An Idle/Hypercasual Game
// Game state variables
var sparkles = 0;
+var totalSparklesEarned = 0;
var sparkleRate = 1;
var autoSparkleRate = 0;
var clickMultiplier = 1;
var cats = [];
+var playerLevel = 1;
+var levelMultiplier = 1;
+var lastSaveTime = Date.now();
+var lastPlayTime = Date.now();
+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
+ }]
+};
+var totalUpgradesPurchased = 0;
+var tutorialStep = 0;
+var tutorialComplete = false;
var upgrades = {
clickPower: {
level: 1,
cost: 10,
@@ -202,28 +277,332 @@
},
catCost: 100,
catMultiplier: 1.8
};
-// Sparkle effect
-function createSparkleEffect(x, y) {
- var sparkle = new Container();
- var sparkleGraphics = sparkle.attachAsset('sparkle', {});
- 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);
- // Animate and remove
+// Object pool for sparkle effects
+var sparklePool = [];
+var maxSparkles = 50;
+// Save game state
+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
+ };
+ try {
+ localStorage.setItem('cosmicCatGarden', JSON.stringify(gameState));
+ console.log('Game saved successfully');
+ } catch (e) {
+ console.error('Failed to save game:', e);
+ }
+}
+// Load game state
+function loadGame() {
+ try {
+ var savedState = localStorage.getItem('cosmicCatGarden');
+ if (savedState) {
+ var gameState = JSON.parse(savedState);
+ // Restore basic variables
+ 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;
+ // Calculate offline progress
+ var currentTime = Date.now();
+ var offlineTime = (currentTime - gameState.lastSaveTime) / 1000; // in seconds
+ 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);
+ }
+ // Restore cats
+ if (gameState.cats && gameState.cats.length > 0) {
+ // Remove initial cat
+ if (cats.length > 0) {
+ game.removeChild(cats[0]);
+ cats = [];
+ }
+ // Restore saved cats
+ gameState.cats.forEach(function (catData) {
+ var cat = new Cat();
+ cat.level = catData.level;
+ cat.productionRate = catData.productionRate;
+ cat.x = catData.x;
+ cat.y = catData.y;
+ game.addChild(cat);
+ cats.push(cat);
+ });
+ }
+ console.log('Game loaded successfully');
+ }
+ } catch (e) {
+ console.error('Failed to load game:', e);
+ }
+}
+// Show offline earnings notification
+function showOfflineEarnings(amount, time) {
+ var notification = new Container();
+ var bg = notification.attachAsset('achievement-notification', {});
+ var titleText = new LK.Text("Welcome Back!", {
+ fontFamily: "Arial",
+ fontSize: 20,
+ fill: 0xFFFFFF,
+ fontWeight: 'bold'
+ });
+ titleText.anchor.set(0.5, 0);
+ titleText.y = 10;
+ var messageText = new LK.Text("You earned " + Math.floor(amount) + " sparkles\nwhile away for " + Math.floor(time / 60) + " minutes", {
+ fontFamily: "Arial",
+ fontSize: 16,
+ fill: 0xFFFFFF,
+ align: 'center'
+ });
+ messageText.anchor.set(0.5, 0);
+ messageText.y = 35;
+ notification.addChild(titleText);
+ notification.addChild(messageText);
+ notification.x = 1024 / 2;
+ notification.y = 100;
+ notification.alpha = 0;
+ game.addChild(notification);
+ // Animate in
var startTime = LK.ticks;
- sparkle.update = function () {
+ notification.update = function () {
var elapsed = (LK.ticks - startTime) / 60;
- sparkle.y -= 0.5;
- sparkle.alpha = Math.max(0, 0.8 - elapsed);
- if (sparkle.alpha <= 0) {
- game.removeChild(sparkle);
+ 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);
}
};
}
+// Show achievement notification
+function showAchievement(title, description, reward) {
+ var notification = new Container();
+ var bg = notification.attachAsset('achievement-notification', {});
+ var titleText = new LK.Text("Achievement: " + title, {
+ fontFamily: "Arial",
+ fontSize: 20,
+ fill: 0xFFFFFF,
+ fontWeight: 'bold'
+ });
+ titleText.anchor.set(0.5, 0);
+ titleText.y = 10;
+ var messageText = new LK.Text(description + "\nReward: " + reward + " sparkles", {
+ fontFamily: "Arial",
+ fontSize: 16,
+ fill: 0xFFFFFF,
+ align: 'center'
+ });
+ messageText.anchor.set(0.5, 0);
+ messageText.y = 35;
+ notification.addChild(titleText);
+ notification.addChild(messageText);
+ notification.x = 1024 / 2;
+ notification.y = 100;
+ notification.alpha = 0;
+ game.addChild(notification);
+ // Animate in
+ 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);
+ }
+ };
+}
+// 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 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);
+ }
+ }
+}
+// Tutorial system
+function showTutorial() {
+ if (tutorialComplete) {
+ return;
+ }
+ var tutorial = new Container();
+ var highlight = tutorial.attachAsset('tutorial-highlight', {});
+ var messageText = new LK.Text("", {
+ fontFamily: "Arial",
+ fontSize: 20,
+ fill: 0xFFFFFF,
+ align: 'center',
+ stroke: 0x000000,
+ strokeThickness: 4
+ });
+ 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;
+ }
+ 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();
+ }
+ }
+ };
+}
+// 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);
+ }
+ // Animate and remove
+ var startTime = LK.ticks;
+ sparkle.update = function () {
+ var elapsed = (LK.ticks - startTime) / 60;
+ sparkle.y -= 0.5;
+ sparkle.alpha = Math.max(0, 0.8 - elapsed);
+ if (sparkle.alpha <= 0) {
+ game.removeChild(sparkle);
+ // Return to pool if not full
+ if (sparklePool.length < maxSparkles) {
+ sparklePool.push(sparkle);
+ }
+ }
+ };
+ }
+}
// Add a cat to the game
function addCat() {
var cat = new Cat();
cat.x = 400 + Math.random() * 800;
@@ -232,28 +611,22 @@
cats.push(cat);
}
// Initialize game elements
var garden = game.addChild(new Garden());
-garden.x = 2048;
-garden.y = 0;
+garden.x = 1024;
+garden.y = 2732;
var mainGarden = game.addChild(new MainGarden());
-mainGarden.x = 2048;
-mainGarden.y = 0;
+mainGarden.x = 1024;
+mainGarden.y = 2200;
var sparkleCounter = game.addChild(new SparkleCounter());
-sparkleCounter.x = 2048 - sparkleCounter.width;
-sparkleCounter.y = 0;
+sparkleCounter.x = 50;
+sparkleCounter.y = 50;
// Add upgrade buttons
-var clickUpgrade = game.addChild(new UpgradeButton("clickPower", "Click Power\nCost: 10", 2048 - 150, 0));
-var autoUpgrade = game.addChild(new UpgradeButton("autoCollect", "Auto Collect\nCost: 50", 2048 - 150, 70));
-var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 2048 - 150, 140));
+var clickUpgrade = game.addChild(new UpgradeButton("clickPower", "Click Power\nCost: 10", 150, 150));
+var autoUpgrade = game.addChild(new UpgradeButton("autoCollect", "Auto Collect\nCost: 50", 150, 220));
+var catUpgrade = game.addChild(new UpgradeButton("buyCat", "Buy Cat\nCost: 100", 150, 290));
// Add initial cat
addCat();
-// Add start button
-var startButton = game.addChild(new StartButton());
-startButton.x = 2048 - startButton.width / 2;
-startButton.y = 0;
-// Game start flag
-var gameStarted = false;
// Background sounds
var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
var currentAmbientSound = null;
// Initialize random timers for ambient sounds
@@ -272,28 +645,26 @@
}, Math.random() * 20000 + 10000);
});
// Main game update loop
game.update = function () {
- if (gameStarted) {
- // Update all cats
- cats.forEach(function (cat) {
- cat.update();
- });
- // Update UI elements
- sparkleCounter.update();
- clickUpgrade.update();
- autoUpgrade.update();
- catUpgrade.update();
- // Auto-collect sparkles
- if (autoSparkleRate > 0) {
- sparkles += autoSparkleRate / 60; // Per frame rate
- }
- // Random sparkle effects
- if (Math.random() < 0.01 && cats.length > 0) {
- var randomCat = cats[Math.floor(Math.random() * cats.length)];
- createSparkleEffect(randomCat.x, randomCat.y);
- }
+ // Update all cats
+ cats.forEach(function (cat) {
+ cat.update();
+ });
+ // Update UI elements
+ sparkleCounter.update();
+ clickUpgrade.update();
+ autoUpgrade.update();
+ catUpgrade.update();
+ // Auto-collect sparkles
+ if (autoSparkleRate > 0) {
+ sparkles += autoSparkleRate / 60; // Per frame rate
}
+ // Random sparkle effects
+ if (Math.random() < 0.01 && cats.length > 0) {
+ var randomCat = cats[Math.floor(Math.random() * cats.length)];
+ createSparkleEffect(randomCat.x, randomCat.y);
+ }
};
// Play background music
LK.playMusic('bgm1', {
loop: true,
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