Code edit (2 edits merged)
Please save this source code
User prompt
ensure all objects are initialized, as well s the game itself
Code edit (2 edits merged)
Please save this source code
User prompt
add shapes for all images, etc.
User prompt
ensure all objects are visible, initialized, etc.
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Text is not a constructor' in or related to this line: 'var buttonText = new Text(text, {' Line Number: 771
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Text is not a constructor' in or related to this line: 'var buttonText = new Text(text, {' Line Number: 771
Code edit (3 edits merged)
Please save this source code
User prompt
continue
Code edit (1 edits merged)
Please save this source code
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: '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: '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: '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: '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: '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
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ /** * Cat Defender - Idle Game * * A game where cats automatically defend against incoming birds and UFOs. * Features idle point accumulation, upgrades, and progressive difficulty. */ // --- Global Variables --- var cats = []; var kittens = []; var birds = []; var ufos = []; var powerUps = []; var sparkles = []; // Game State Variables var score = 0; var level = 1; var multiplier = 1.0; // Starts at 1.0, increases by 0.1 per level var idlePoints = 0; var enemiesDefeated = 0; var lastUpdateTime = Date.now(); var idlePointsLastCalculated = Date.now(); // Game Constants var ENEMIES_PER_LEVEL = 11; var BASE_IDLE_POINTS_RATE = 0.5; // Points per cat per second var BIRD_POINTS = 10; var UFO_POINTS = 20; var BIRD_SPAWN_INTERVAL = 2000; // ms var UFO_SPAWN_INTERVAL = 15000; // ms var MAX_BIRDS = 10; var MAX_UFOS = 3; // Timers var birdSpawnTimer = 0; var ufoSpawnTimer = 0; // --- Utility Functions --- function distance(x1, y1, x2, y2) { var dx = x1 - x2; var dy = y1 - y2; return Math.sqrt(dx * dx + dy * dy); } // --- Game Classes --- /** * Base class for game entities */ function GameObject(x, y, width, height, assetId) { this.x = x; this.y = y; this.width = width; this.height = height; this.assetId = assetId; this.active = true; } GameObject.prototype.update = function (deltaTime) { // Override in subclasses }; GameObject.prototype.render = function () { if (!this.active) { return; } // Draw the sprite LK.drawImage(this.assetId, this.x, this.y, this.width, this.height); }; GameObject.prototype.isColliding = function (other) { return this.x < other.x + other.width && this.x + this.width > other.x && this.y < other.y + other.height && this.y + this.height > other.y; }; /** * Base class for defenders (Cats and Kittens) */ function Defender(x, y, width, height, assetId, attackRange, attackCooldown, attackDamage, moveSpeed) { GameObject.call(this, x, y, width, height, assetId); this.attackRange = attackRange; this.attackCooldown = attackCooldown; this.attackDamage = attackDamage; this.moveSpeed = moveSpeed; this.attackTimer = 0; this.target = null; } Defender.prototype = Object.create(GameObject.prototype); Defender.prototype.constructor = Defender; Defender.prototype.update = function (deltaTime) { if (!this.active) { return; } // Handle attack cooldown if (this.attackTimer > 0) { this.attackTimer -= deltaTime; } // Find target if none exists if (!this.target || !this.target.active) { this.findTarget(); } // Move towards target or attack if (this.target) { var dist = distance(this.x + this.width / 2, this.y + this.height / 2, this.target.x + this.target.width / 2, this.target.y + this.target.height / 2); if (dist <= this.attackRange) { this.attack(); } else { this.moveTowardsTarget(deltaTime); } } }; Defender.prototype.findTarget = function () { // Find closest enemy var closestDist = Infinity; var closest = null; // Check birds first for (var i = 0; i < birds.length; i++) { var bird = birds[i]; if (!bird.active) { continue; } var dist = distance(this.x + this.width / 2, this.y + this.height / 2, bird.x + bird.width / 2, bird.y + bird.height / 2); if (dist < closestDist) { closestDist = dist; closest = bird; } } // Check UFOs if no birds found or if this is a kitten (kittens prefer UFOs) if ((!closest || this instanceof Kitten) && ufos.length > 0) { for (var i = 0; i < ufos.length; i++) { var ufo = ufos[i]; if (!ufo.active) { continue; } var dist = distance(this.x + this.width / 2, this.y + this.height / 2, ufo.x + ufo.width / 2, ufo.y + ufo.height / 2); if (dist < closestDist) { closestDist = dist; closest = ufo; } } } this.target = closest; }; Defender.prototype.moveTowardsTarget = function (deltaTime) { if (!this.target) { return; } var targetX = this.target.x + this.target.width / 2; var targetY = this.target.y + this.target.height / 2; var dx = targetX - (this.x + this.width / 2); var dy = targetY - (this.y + this.height / 2); var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0) { var moveX = dx / dist * this.moveSpeed * deltaTime; var moveY = dy / dist * this.moveSpeed * deltaTime; this.x += moveX; this.y += moveY; } }; Defender.prototype.attack = function () { if (this.attackTimer <= 0 && this.target && this.target.active) { this.target.takeDamage(this.attackDamage); this.attackTimer = this.attackCooldown; // Create attack effect createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack'); } }; /** * Cat Class - Standard defender */ function Cat(x, y) { Defender.call(this, x, y, 64, 64, 'cat', 100, 1.0, 2, 2); } Cat.prototype = Object.create(Defender.prototype); Cat.prototype.constructor = Cat; /** * Kitten Class - Faster but weaker defender */ function Kitten(x, y) { Defender.call(this, x, y, 48, 48, 'kitten', 60, 0.5, 1, 3); } Kitten.prototype = Object.create(Defender.prototype); Kitten.prototype.constructor = Kitten; /** * Enemy base class */ function Enemy(x, y, width, height, assetId, health, speed, pointValue) { GameObject.call(this, x, y, width, height, assetId); this.health = health; this.maxHealth = health; this.speed = speed; this.pointValue = pointValue; this.targetX = LK.canvas.width / 2; this.targetY = LK.canvas.height / 2; } Enemy.prototype = Object.create(GameObject.prototype); Enemy.prototype.constructor = Enemy; Enemy.prototype.update = function (deltaTime) { if (!this.active) { return; } // Move towards center var dx = this.targetX - (this.x + this.width / 2); var dy = this.targetY - (this.y + this.height / 2); var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 10) { // Not too close to center var moveX = dx / dist * this.speed * deltaTime; var moveY = dy / dist * this.speed * deltaTime; this.x += moveX; this.y += moveY; } else { // Reached center, remove this.active = false; } }; Enemy.prototype.takeDamage = function (amount) { this.health -= amount; if (this.health <= 0) { this.defeat(); } }; Enemy.prototype.defeat = function () { this.active = false; // Add points var pointsEarned = this.pointValue * multiplier; score += pointsEarned; enemiesDefeated++; // Check for level up if (enemiesDefeated >= ENEMIES_PER_LEVEL) { levelUp(); } // Create sparkles for (var i = 0; i < 5; i++) { createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'defeat'); } // Chance to spawn power-up if (Math.random() < 0.2) { // 20% chance spawnPowerUp(this.x, this.y); } }; /** * Bird Class - Basic enemy */ function Bird(x, y) { Enemy.call(this, x, y, 32, 32, 'bird', 3, 30, BIRD_POINTS); } Bird.prototype = Object.create(Enemy.prototype); Bird.prototype.constructor = Bird; /** * UFO Class - Advanced enemy */ function UFO(x, y) { Enemy.call(this, x, y, 64, 32, 'ufo', 10, 15, UFO_POINTS); } UFO.prototype = Object.create(Enemy.prototype); UFO.prototype.constructor = UFO; /** * PowerUp Class */ function PowerUp(x, y, type) { GameObject.call(this, x, y, 32, 32, 'powerup_' + type); this.type = type; this.duration = 10; // seconds this.targetX = LK.canvas.width / 2; this.targetY = LK.canvas.height / 2; } PowerUp.prototype = Object.create(GameObject.prototype); PowerUp.prototype.constructor = PowerUp; PowerUp.prototype.update = function (deltaTime) { if (!this.active) { return; } // Move towards center var dx = this.targetX - (this.x + this.width / 2); var dy = this.targetY - (this.y + this.height / 2); var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 10) { // Not too close to center var moveX = dx / dist * 50 * deltaTime; var moveY = dy / dist * 50 * deltaTime; this.x += moveX; this.y += moveY; } else { // Reached center, apply effect this.applyEffect(); this.active = false; } }; PowerUp.prototype.applyEffect = function () { switch (this.type) { case 'speed': // Increase all cats' speed by 50% for duration for (var i = 0; i < cats.length; i++) { cats[i].moveSpeed *= 1.5; } for (var i = 0; i < kittens.length; i++) { kittens[i].moveSpeed *= 1.5; } setTimeout(function () { for (var i = 0; i < cats.length; i++) { cats[i].moveSpeed /= 1.5; } for (var i = 0; i < kittens.length; i++) { kittens[i].moveSpeed /= 1.5; } }, this.duration * 1000); break; case 'damage': // Increase all cats' damage by 50% for duration for (var i = 0; i < cats.length; i++) { cats[i].attackDamage *= 1.5; } for (var i = 0; i < kittens.length; i++) { kittens[i].attackDamage *= 1.5; } setTimeout(function () { for (var i = 0; i < cats.length; i++) { cats[i].attackDamage /= 1.5; } for (var i = 0; i < kittens.length; i++) { kittens[i].attackDamage /= 1.5; } }, this.duration * 1000); break; case 'points': // Double points for duration var oldMultiplier = multiplier; multiplier *= 2; setTimeout(function () { multiplier = oldMultiplier; }, this.duration * 1000); break; } // Create effect for (var i = 0; i < 10; i++) { createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'powerup'); } }; /** * Sparkle Class - Visual effects */ function Sparkle(x, y, type) { this.x = x; this.y = y; this.type = type; this.size = Math.random() * 5 + 5; this.lifespan = 0.5; // seconds this.maxLifespan = this.lifespan; this.active = true; // Set color based on type switch (type) { case 'attack': this.color = '#ffff00'; // Yellow break; case 'defeat': this.color = '#ff0000'; // Red break; case 'powerup': this.color = '#00ffff'; // Cyan break; case 'chain': this.color = '#ff00ff'; // Magenta break; default: this.color = '#ffffff'; // White } // Random velocity var angle = Math.random() * Math.PI * 2; var speed = Math.random() * 100 + 50; this.vx = Math.cos(angle) * speed; this.vy = Math.sin(angle) * speed; } Sparkle.prototype.update = function (deltaTime) { if (!this.active) { return; } // Update position this.x += this.vx * deltaTime; this.y += this.vy * deltaTime; // Update lifespan this.lifespan -= deltaTime; if (this.lifespan <= 0) { this.active = false; } }; Sparkle.prototype.render = function () { if (!this.active) { return; } // Calculate alpha based on remaining lifespan var alpha = this.lifespan / this.maxLifespan; // Draw sparkle LK.setFillStyle(this.color); LK.setGlobalAlpha(alpha); LK.fillCircle(this.x, this.y, this.size * alpha); LK.setGlobalAlpha(1.0); }; // --- Game Functions --- // Spawn a bird at a random edge position function spawnBird() { if (birds.length >= MAX_BIRDS) { return; } var x, y; var side = Math.floor(Math.random() * 4); switch (side) { case 0: // Top x = Math.random() * LK.canvas.width; y = -32; break; case 1: // Right x = LK.canvas.width + 32; y = Math.random() * LK.canvas.height; break; case 2: // Bottom x = Math.random() * LK.canvas.width; y = LK.canvas.height + 32; break; case 3: // Left x = -32; y = Math.random() * LK.canvas.height; break; } var bird = new Bird(x, y); birds.push(bird); return bird; } // Spawn a UFO at a random edge position function spawnUFO() { if (ufos.length >= MAX_UFOS) { return; } var x, y; var side = Math.floor(Math.random() * 4); switch (side) { case 0: // Top x = Math.random() * LK.canvas.width; y = -32; break; case 1: // Right x = LK.canvas.width + 64; y = Math.random() * LK.canvas.height; break; case 2: // Bottom x = Math.random() * LK.canvas.width; y = LK.canvas.height + 32; break; case 3: // Left x = -64; y = Math.random() * LK.canvas.height; break; } var ufo = new UFO(x, y); ufos.push(ufo); return ufo; } // Spawn a power-up function spawnPowerUp(x, y, type) { // If type not specified, choose random if (!type) { var types = ['speed', 'damage', 'range', 'multi', 'chain', 'time']; type = types[Math.floor(Math.random() * types.length)]; } var powerUp = new PowerUp(x, y, type); powerUps.push(powerUp); return powerUp; } // Level up function function levelUp() { level++; multiplier = 1.0 + (level - 1) * 0.1; // Create level up effect var centerX = LK.canvas.width / 2; var centerY = LK.canvas.height / 2; // Create sparkles for level up effect for (var i = 0; i < 20; i++) { createSparkle(centerX + (Math.random() - 0.5) * 200, centerY + (Math.random() - 0.5) * 200, 'powerup'); } // Reset enemy counter enemiesDefeated = 0; // Play level up sound LK.playSound('teslacoil'); } // Calculate idle points function calculateIdlePoints() { var currentTime = Date.now(); var elapsedSeconds = (currentTime - idlePointsLastCalculated) / 1000; // Calculate points based on cats and kittens var pointsPerSecond = cats.length * BASE_IDLE_POINTS_RATE; pointsPerSecond += kittens.length * (BASE_IDLE_POINTS_RATE * 0.6); // Kittens generate 60% of cat rate // Apply level multiplier pointsPerSecond *= multiplier; // Add points var pointsEarned = pointsPerSecond * elapsedSeconds; idlePoints += pointsEarned; score += pointsEarned; // Update last calculation time idlePointsLastCalculated = currentTime; return pointsEarned; } // Update game state function updateGame(deltaTime) { // Calculate idle points calculateIdlePoints(); // Update all game objects // Update cats for (var i = cats.length - 1; i >= 0; i--) { var cat = cats[i]; cat.update(deltaTime); } // Update kittens for (var i = kittens.length - 1; i >= 0; i--) { var kitten = kittens[i]; kitten.update(deltaTime); } // Update birds and remove inactive ones for (var i = birds.length - 1; i >= 0; i--) { var bird = birds[i]; bird.update(deltaTime); if (!bird.active) { birds.splice(i, 1); } } // Update UFOs and remove inactive ones for (var i = ufos.length - 1; i >= 0; i--) { var ufo = ufos[i]; ufo.update(deltaTime); if (!ufo.active) { ufos.splice(i, 1); } } // Update power-ups and remove inactive ones for (var i = powerUps.length - 1; i >= 0; i--) { var powerUp = powerUps[i]; powerUp.update(deltaTime); if (!powerUp.active) { powerUps.splice(i, 1); } } // Update sparkles and remove inactive ones for (var i = sparkles.length - 1; i >= 0; i--) { var sparkle = sparkles[i]; sparkle.update(deltaTime); if (!sparkle.active) { sparkles.splice(i, 1); } } // Update kittens for (var i = kittens.length - 1; i >= 0; i--) { var kitten = kittens[i]; kitten.update(deltaTime); } // Update birds and remove inactive ones for (var i = birds.length - 1; i >= 0; i--) { var bird = birds[i]; bird.update(deltaTime); if (!bird.active) { birds.splice(i, 1); } } // Update UFOs and remove inactive ones for (var i = ufos.length - 1; i >= 0; i--) { var ufo = ufos[i]; ufo.update(deltaTime); if (!ufo.active) { ufos.splice(i, 1); } } // Update power-ups and remove inactive ones for (var i = powerUps.length - 1; i >= 0; i--) { var powerUp = powerUps[i]; powerUp.update(deltaTime); if (!powerUp.active) { powerUps.splice(i, 1); } } // Update sparkles and remove inactive ones for (var i = sparkles.length - 1; i >= 0; i--) { var sparkle = sparkles[i]; sparkle.update(deltaTime); if (!sparkle.active) { sparkles.splice(i, 1); } } // Spawn birds birdSpawnTimer += deltaTime * 1000; // Convert to milliseconds if (birds.length < MAX_BIRDS && birdSpawnTimer >= BIRD_SPAWN_INTERVAL) { spawnBird(); birdSpawnTimer = 0; LK.playSound('wings1', { volume: 0.2 }); } // Spawn UFOs ufoSpawnTimer += deltaTime * 1000; // Convert to milliseconds if (ufos.length < MAX_UFOS && ufoSpawnTimer >= UFO_SPAWN_INTERVAL && level >= 3) { spawnUFO(); ufoSpawnTimer = 0; LK.playSound('ufo1'); } } // Render game function renderGame() { // Clear canvas LK.clear(); // Draw background LK.setFillStyle('#1a1a2e'); LK.fillRect(0, 0, LK.canvas.width, LK.canvas.height); // Render all game objects // Render sparkles first (background layer) for (var i = 0; i < sparkles.length; i++) { var sparkle = sparkles[i]; sparkle.render(); } // Render power-ups for (var i = 0; i < powerUps.length; i++) { var powerUp = powerUps[i]; powerUp.render(); } // Render birds for (var i = 0; i < birds.length; i++) { var bird = birds[i]; bird.render(); } // Render UFOs for (var i = 0; i < ufos.length; i++) { var ufo = ufos[i]; ufo.render(); } // Render cats for (var i = 0; i < cats.length; i++) { var cat = cats[i]; cat.render(); } // Render kittens for (var i = 0; i < kittens.length; i++) { var kitten = kittens[i]; kitten.render(); } // Render power-ups for (var i = 0; i < powerUps.length; i++) { var powerUp = powerUps[i]; powerUp.render(); } // Render birds for (var i = 0; i < birds.length; i++) { var bird = birds[i]; bird.render(); } // Render UFOs for (var i = 0; i < ufos.length; i++) { var ufo = ufos[i]; ufo.render(); } // Render cats for (var i = 0; i < cats.length; i++) { var cat = cats[i]; cat.render(); } // Render kittens for (var i = 0; i < kittens.length; i++) { var kitten = kittens[i]; kitten.render(); } // Render UI renderUI(); } // Render UI elements function renderUI() { // Score LK.setFillStyle('#FFFFFF'); LK.setFont('24px Arial'); LK.fillText("Score: ".concat(Math.floor(score)), LK.canvas.width / 2, 30, { align: 'center' }); // Level LK.setFont('18px Arial'); LK.fillText("Level: ".concat(level), LK.canvas.width - 20, 30, { align: 'right' }); // Multiplier LK.fillText("Multiplier: x".concat(multiplier.toFixed(1)), LK.canvas.width - 20, 60, { align: 'right' }); // Idle Points LK.fillText("Idle Points: ".concat(Math.floor(idlePoints)), LK.canvas.width - 20, LK.canvas.height - 20, { align: 'right' }); // Enemies Defeated LK.fillText("Enemies: ".concat(enemiesDefeated, "/").concat(ENEMIES_PER_LEVEL), 20, 30, { align: 'left' }); // Cat Count LK.fillText("Cats: ".concat(cats.length), 20, 60, { align: 'left' }); // Kitten Count LK.fillText("Kittens: ".concat(kittens.length), 20, 90, { align: 'left' }); // Spawn buttons renderButton("Add Cat (50)", 20, LK.canvas.height - 60, 120, 40, idlePoints >= 50); renderButton("Add Kitten (30)", 150, LK.canvas.height - 60, 120, 40, idlePoints >= 30); } // Render a button function renderButton(text, x, y, width, height, enabled) { // Button background LK.setFillStyle(enabled ? '#33aa33' : '#666666'); LK.fillRect(x, y, width, height); // Button border LK.setStrokeStyle('#FFFFFF'); LK.strokeRect(x, y, width, height); // Button text LK.setFillStyle('#FFFFFF'); LK.setFont('14px Arial'); LK.fillText(text, x + width / 2, y + height / 2, { align: 'center', baseline: 'middle' }); } // Handle mouse click function handleMouseClick(x, y) { // Check if cat spawn button clicked if (x >= 20 && x <= 140 && y >= LK.canvas.height - 60 && y <= LK.canvas.height - 20) { if (idlePoints >= 50) { var cat = spawnCat(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height); if (cat) { LK.playSound('chitter'); } } } // Check if kitten spawn button clicked if (x >= 150 && x <= 270 && y >= LK.canvas.height - 60 && y <= LK.canvas.height - 20) { if (idlePoints >= 30) { var kitten = spawnKitten(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height); if (kitten) { LK.playSound('chitter', { pitch: 1.5 }); } } } } // Initialize game function initGame() { // Reset game state cats = []; kittens = []; birds = []; ufos = []; powerUps = []; sparkles = []; score = 0; level = 1; multiplier = 1.0; idlePoints = 100; // Start with enough for 2 cats or 3 kittens enemiesDefeated = 0; lastUpdateTime = Date.now(); idlePointsLastCalculated = Date.now(); birdSpawnTimer = 0; ufoSpawnTimer = 0; // Create initial cats spawnCat(LK.canvas.width / 2, LK.canvas.height / 2); // Create initial kittens spawnKitten(LK.canvas.width / 2 + 100, LK.canvas.height / 2 + 100); // Create initial birds spawnBird(); // Create initial UFOs spawnUFO(); // Create initial power-ups spawnPowerUp(LK.canvas.width / 2, LK.canvas.height / 2, 'speed'); // Setup mouse click handler LK.onMouseDown = function (event) { handleMouseClick(event.x, event.y); }; // Play background music LK.playMusic('bgm1', { volume: 0.3, loop: true }); // Occasionally play ambient sounds setInterval(function () { if (Math.random() < 0.3) { var sounds = ['breeze1', 'cricket1', 'frog1', 'songbird1']; var sound = sounds[Math.floor(Math.random() * sounds.length)]; LK.playSound(sound, { volume: 0.1 + Math.random() * 0.1 }); } }, 10000); // Start game loop startGameLoop(); } // Game loop var lastFrameTime = 0; function gameLoop(timestamp) { // Calculate delta time var deltaTime = (timestamp - lastFrameTime) / 1000; // Convert to seconds lastFrameTime = timestamp; // Cap delta time to prevent large jumps if (deltaTime > 0.1) { deltaTime = 0.1; } // Update game state updateGame(deltaTime); // Render game renderGame(); // Request next frame requestAnimationFrame(gameLoop); } // Start game loop function startGameLoop() { lastFrameTime = performance.now(); requestAnimationFrame(gameLoop); } // Initialize game when page loads window.onload = function () { initGame(); };
===================================================================
--- original.js
+++ change.js
@@ -7,210 +7,15 @@
/****
* Game Code
****/
-// --- Global Variables ---
/**
* Cat Defender - Idle Game
*
* A game where cats automatically defend against incoming birds and UFOs.
* Features idle point accumulation, upgrades, and progressive difficulty.
*/
-function _createForOfIteratorHelper(r, e) {
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
- if (!t) {
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
- t && (r = t);
- var _n = 0,
- F = function F() {};
- return {
- s: F,
- n: function n() {
- return _n >= r.length ? {
- done: !0
- } : {
- done: !1,
- value: r[_n++]
- };
- },
- e: function e(r) {
- throw r;
- },
- f: F
- };
- }
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
- var o,
- a = !0,
- u = !1;
- return {
- s: function s() {
- t = t.call(r);
- },
- n: function n() {
- var r = t.next();
- return a = r.done, r;
- },
- e: function e(r) {
- u = !0, o = r;
- },
- f: function f() {
- try {
- a || null == t["return"] || t["return"]();
- } finally {
- if (u) {
- throw o;
- }
- }
- }
- };
-}
-function _toConsumableArray(r) {
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
-}
-function _nonIterableSpread() {
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
-}
-function _unsupportedIterableToArray(r, a) {
- if (r) {
- if ("string" == typeof r) {
- return _arrayLikeToArray(r, a);
- }
- var t = {}.toString.call(r).slice(8, -1);
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
- }
-}
-function _iterableToArray(r) {
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
- return Array.from(r);
- }
-}
-function _arrayWithoutHoles(r) {
- if (Array.isArray(r)) {
- return _arrayLikeToArray(r);
- }
-}
-function _arrayLikeToArray(r, a) {
- (null == a || a > r.length) && (a = r.length);
- for (var e = 0, n = Array(a); e < a; e++) {
- n[e] = r[e];
- }
- return n;
-}
-function _superPropGet(t, o, e, r) {
- var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e);
- return 2 & r && "function" == typeof p ? function (t) {
- return p.apply(e, t);
- } : p;
-}
-function _get() {
- return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
- var p = _superPropBase(e, t);
- if (p) {
- var n = Object.getOwnPropertyDescriptor(p, t);
- return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
- }
- }, _get.apply(null, arguments);
-}
-function _superPropBase(t, o) {
- for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));) {
- ;
- }
- return t;
-}
-function _callSuper(t, o, e) {
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
-}
-function _possibleConstructorReturn(t, e) {
- if (e && ("object" == _typeof(e) || "function" == typeof e)) {
- return e;
- }
- if (void 0 !== e) {
- throw new TypeError("Derived constructors may only return object or undefined");
- }
- return _assertThisInitialized(t);
-}
-function _assertThisInitialized(e) {
- if (void 0 === e) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return e;
-}
-function _isNativeReflectConstruct() {
- try {
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
- } catch (t) {}
- return (_isNativeReflectConstruct = function _isNativeReflectConstruct() {
- return !!t;
- })();
-}
-function _getPrototypeOf(t) {
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
- return t.__proto__ || Object.getPrototypeOf(t);
- }, _getPrototypeOf(t);
-}
-function _inherits(t, e) {
- if ("function" != typeof e && null !== e) {
- throw new TypeError("Super expression must either be null or a function");
- }
- t.prototype = Object.create(e && e.prototype, {
- constructor: {
- value: t,
- writable: !0,
- configurable: !0
- }
- }), Object.defineProperty(t, "prototype", {
- writable: !1
- }), e && _setPrototypeOf(t, e);
-}
-function _setPrototypeOf(t, e) {
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
- return t.__proto__ = e, t;
- }, _setPrototypeOf(t, e);
-}
-function _typeof(o) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
- return typeof o;
- } : function (o) {
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
- }, _typeof(o);
-}
-function _classCallCheck(a, n) {
- if (!(a instanceof n)) {
- throw new TypeError("Cannot call a class as a function");
- }
-}
-function _defineProperties(e, r) {
- for (var t = 0; t < r.length; t++) {
- var o = r[t];
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
- }
-}
-function _createClass(e, r, t) {
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
- writable: !1
- }), e;
-}
-function _toPropertyKey(t) {
- var i = _toPrimitive(t, "string");
- return "symbol" == _typeof(i) ? i : i + "";
-}
-function _toPrimitive(t, r) {
- if ("object" != _typeof(t) || !t) {
- return t;
- }
- var e = t[Symbol.toPrimitive];
- if (void 0 !== e) {
- var i = e.call(t, r || "default");
- if ("object" != _typeof(i)) {
- return i;
- }
- throw new TypeError("@@toPrimitive must return a primitive value.");
- }
- return ("string" === r ? String : Number)(t);
-}
+// --- Global Variables ---
var cats = [];
var kittens = [];
var birds = [];
var ufos = [];
@@ -224,9 +29,9 @@
var enemiesDefeated = 0;
var lastUpdateTime = Date.now();
var idlePointsLastCalculated = Date.now();
// Game Constants
-var ENEMIES_PER_LEVEL = 10;
+var ENEMIES_PER_LEVEL = 11;
var BASE_IDLE_POINTS_RATE = 0.5; // Points per cat per second
var BIRD_POINTS = 10;
var UFO_POINTS = 20;
var BIRD_SPAWN_INTERVAL = 2000; // ms
@@ -245,749 +50,429 @@
// --- Game Classes ---
/**
* Base class for game entities
*/
-var GameObject = /*#__PURE__*/function () {
- function GameObject(x, y, width, height, assetId) {
- _classCallCheck(this, GameObject);
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- this.assetId = assetId;
- this.active = true;
+function GameObject(x, y, width, height, assetId) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.assetId = assetId;
+ this.active = true;
+}
+GameObject.prototype.update = function (deltaTime) {
+ // Override in subclasses
+};
+GameObject.prototype.render = function () {
+ if (!this.active) {
+ return;
}
- return _createClass(GameObject, [{
- key: "update",
- value: function update(deltaTime) {
- // Override in subclasses
- }
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
- }
- // Draw the sprite
- LK.drawImage(this.assetId, this.x, this.y, this.width, this.height);
- }
- }, {
- key: "isColliding",
- value: function isColliding(other) {
- return this.x < other.x + other.width && this.x + this.width > other.x && this.y < other.y + other.height && this.y + this.height > other.y;
- }
- }]);
-}();
+ // Draw the sprite
+ LK.drawImage(this.assetId, this.x, this.y, this.width, this.height);
+};
+GameObject.prototype.isColliding = function (other) {
+ return this.x < other.x + other.width && this.x + this.width > other.x && this.y < other.y + other.height && this.y + this.height > other.y;
+};
/**
* Base class for defenders (Cats and Kittens)
*/
-var Defender = /*#__PURE__*/function (_GameObject) {
- function Defender(x, y, width, height, assetId, attackRange, attackCooldown, attackDamage, moveSpeed) {
- var _this;
- _classCallCheck(this, Defender);
- _this = _callSuper(this, Defender, [x, y, width, height, assetId]);
- _this.attackRange = attackRange;
- _this.attackCooldown = attackCooldown;
- _this.attackDamage = attackDamage;
- _this.moveSpeed = moveSpeed;
- _this.attackTimer = 0;
- _this.target = null;
- return _this;
+function Defender(x, y, width, height, assetId, attackRange, attackCooldown, attackDamage, moveSpeed) {
+ GameObject.call(this, x, y, width, height, assetId);
+ this.attackRange = attackRange;
+ this.attackCooldown = attackCooldown;
+ this.attackDamage = attackDamage;
+ this.moveSpeed = moveSpeed;
+ this.attackTimer = 0;
+ this.target = null;
+}
+Defender.prototype = Object.create(GameObject.prototype);
+Defender.prototype.constructor = Defender;
+Defender.prototype.update = function (deltaTime) {
+ if (!this.active) {
+ return;
}
- _inherits(Defender, _GameObject);
- return _createClass(Defender, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Handle attack cooldown
- if (this.attackTimer > 0) {
- this.attackTimer -= deltaTime;
- }
- // Find target if none exists
- if (!this.target || !this.target.active) {
- this.findTarget();
- }
- // Move towards target or attack
- if (this.target) {
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, this.target.x + this.target.width / 2, this.target.y + this.target.height / 2);
- if (dist <= this.attackRange) {
- this.attack();
- } else {
- this.moveTowardsTarget(deltaTime);
- }
- }
+ // Handle attack cooldown
+ if (this.attackTimer > 0) {
+ this.attackTimer -= deltaTime;
+ }
+ // Find target if none exists
+ if (!this.target || !this.target.active) {
+ this.findTarget();
+ }
+ // Move towards target or attack
+ if (this.target) {
+ var dist = distance(this.x + this.width / 2, this.y + this.height / 2, this.target.x + this.target.width / 2, this.target.y + this.target.height / 2);
+ if (dist <= this.attackRange) {
+ this.attack();
+ } else {
+ this.moveTowardsTarget(deltaTime);
}
- }, {
- key: "findTarget",
- value: function findTarget() {
- // Find closest enemy
- var closestDist = Infinity;
- var closest = null;
- // Check birds first
- for (var _i = 0, _birds = birds; _i < _birds.length; _i++) {
- var bird = _birds[_i];
- if (!bird.active) {
- continue;
- }
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, bird.x + bird.width / 2, bird.y + bird.height / 2);
- if (dist < closestDist) {
- closestDist = dist;
- closest = bird;
- }
- }
- // Check UFOs if no birds found or if this is a kitten (kittens prefer UFOs)
- if ((!closest || this instanceof Kitten) && ufos.length > 0) {
- for (var _i2 = 0, _ufos = ufos; _i2 < _ufos.length; _i2++) {
- var ufo = _ufos[_i2];
- if (!ufo.active) {
- continue;
- }
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, ufo.x + ufo.width / 2, ufo.y + ufo.height / 2);
- if (dist < closestDist) {
- closestDist = dist;
- closest = ufo;
- }
- }
- }
- this.target = closest;
+ }
+};
+Defender.prototype.findTarget = function () {
+ // Find closest enemy
+ var closestDist = Infinity;
+ var closest = null;
+ // Check birds first
+ for (var i = 0; i < birds.length; i++) {
+ var bird = birds[i];
+ if (!bird.active) {
+ continue;
}
- }, {
- key: "moveTowardsTarget",
- value: function moveTowardsTarget(deltaTime) {
- if (!this.target) {
- return;
+ var dist = distance(this.x + this.width / 2, this.y + this.height / 2, bird.x + bird.width / 2, bird.y + bird.height / 2);
+ if (dist < closestDist) {
+ closestDist = dist;
+ closest = bird;
+ }
+ }
+ // Check UFOs if no birds found or if this is a kitten (kittens prefer UFOs)
+ if ((!closest || this instanceof Kitten) && ufos.length > 0) {
+ for (var i = 0; i < ufos.length; i++) {
+ var ufo = ufos[i];
+ if (!ufo.active) {
+ continue;
}
- var targetX = this.target.x + this.target.width / 2;
- var targetY = this.target.y + this.target.height / 2;
- var dx = targetX - (this.x + this.width / 2);
- var dy = targetY - (this.y + this.height / 2);
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist > 0) {
- var moveX = dx / dist * this.moveSpeed * deltaTime;
- var moveY = dy / dist * this.moveSpeed * deltaTime;
- this.x += moveX;
- this.y += moveY;
+ var dist = distance(this.x + this.width / 2, this.y + this.height / 2, ufo.x + ufo.width / 2, ufo.y + ufo.height / 2);
+ if (dist < closestDist) {
+ closestDist = dist;
+ closest = ufo;
}
}
- }, {
- key: "attack",
- value: function attack() {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- this.target.takeDamage(this.attackDamage);
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
- }
- }]);
-}(GameObject);
+ }
+ this.target = closest;
+};
+Defender.prototype.moveTowardsTarget = function (deltaTime) {
+ if (!this.target) {
+ return;
+ }
+ var targetX = this.target.x + this.target.width / 2;
+ var targetY = this.target.y + this.target.height / 2;
+ var dx = targetX - (this.x + this.width / 2);
+ var dy = targetY - (this.y + this.height / 2);
+ var dist = Math.sqrt(dx * dx + dy * dy);
+ if (dist > 0) {
+ var moveX = dx / dist * this.moveSpeed * deltaTime;
+ var moveY = dy / dist * this.moveSpeed * deltaTime;
+ this.x += moveX;
+ this.y += moveY;
+ }
+};
+Defender.prototype.attack = function () {
+ if (this.attackTimer <= 0 && this.target && this.target.active) {
+ this.target.takeDamage(this.attackDamage);
+ this.attackTimer = this.attackCooldown;
+ // Create attack effect
+ createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
+ }
+};
/**
* Cat Class - Standard defender
*/
-var Cat = /*#__PURE__*/function (_Defender) {
- function Cat(x, y) {
- _classCallCheck(this, Cat);
- return _callSuper(this, Cat, [x, y, 64, 64, 'cat', 100, 1.0, 2, 2]);
- }
- _inherits(Cat, _Defender);
- return _createClass(Cat);
-}(Defender);
+function Cat(x, y) {
+ Defender.call(this, x, y, 64, 64, 'cat', 100, 1.0, 2, 2);
+}
+Cat.prototype = Object.create(Defender.prototype);
+Cat.prototype.constructor = Cat;
/**
* Kitten Class - Faster but weaker defender
*/
-var Kitten = /*#__PURE__*/function (_Defender2) {
- function Kitten(x, y) {
- _classCallCheck(this, Kitten);
- return _callSuper(this, Kitten, [x, y, 48, 48, 'kitten', 60, 0.5, 1, 3]);
- }
- _inherits(Kitten, _Defender2);
- return _createClass(Kitten);
-}(Defender);
+function Kitten(x, y) {
+ Defender.call(this, x, y, 48, 48, 'kitten', 60, 0.5, 1, 3);
+}
+Kitten.prototype = Object.create(Defender.prototype);
+Kitten.prototype.constructor = Kitten;
/**
* Enemy base class
*/
-var Enemy = /*#__PURE__*/function (_GameObject2) {
- function Enemy(x, y, width, height, assetId, health, speed, pointValue) {
- var _this2;
- _classCallCheck(this, Enemy);
- _this2 = _callSuper(this, Enemy, [x, y, width, height, assetId]);
- _this2.health = health;
- _this2.maxHealth = health;
- _this2.speed = speed;
- _this2.pointValue = pointValue;
- _this2.targetX = LK.canvas.width / 2;
- _this2.targetY = LK.canvas.height / 2;
- return _this2;
+function Enemy(x, y, width, height, assetId, health, speed, pointValue) {
+ GameObject.call(this, x, y, width, height, assetId);
+ this.health = health;
+ this.maxHealth = health;
+ this.speed = speed;
+ this.pointValue = pointValue;
+ this.targetX = LK.canvas.width / 2;
+ this.targetY = LK.canvas.height / 2;
+}
+Enemy.prototype = Object.create(GameObject.prototype);
+Enemy.prototype.constructor = Enemy;
+Enemy.prototype.update = function (deltaTime) {
+ if (!this.active) {
+ return;
}
- _inherits(Enemy, _GameObject2);
- return _createClass(Enemy, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Move towards center
- var dx = this.targetX - (this.x + this.width / 2);
- var dy = this.targetY - (this.y + this.height / 2);
- var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist > 10) {
- // Not too close to center
- var moveX = dx / dist * this.speed * deltaTime;
- var moveY = dy / dist * this.speed * deltaTime;
- this.x += moveX;
- this.y += moveY;
- } else {
- // Reached center, remove
- this.active = false;
- }
- }
- }, {
- key: "takeDamage",
- value: function takeDamage(amount) {
- this.health -= amount;
- if (this.health <= 0) {
- this.defeat();
- }
- }
- }, {
- key: "defeat",
- value: function defeat() {
- this.active = false;
- // Add points
- var pointsEarned = this.pointValue * multiplier;
- score += pointsEarned;
- enemiesDefeated++;
- // Check for level up
- if (enemiesDefeated >= ENEMIES_PER_LEVEL) {
- levelUp();
- }
- // Create sparkles
- for (var i = 0; i < 5; i++) {
- createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'defeat');
- }
- // Chance to spawn power-up
- if (Math.random() < 0.2) {
- // 20% chance
- spawnPowerUp(this.x, this.y);
- }
- }
- }, {
- key: "render",
- value: function render() {
- _superPropGet(Enemy, "render", this, 3)([]);
- // Draw health bar
- var healthPercent = this.health / this.maxHealth;
- var barWidth = this.width * 0.8;
- var barHeight = 5;
- var barX = this.x + (this.width - barWidth) / 2;
- var barY = this.y - 10;
- // Background
- LK.setFillStyle('rgba(0,0,0,0.5)');
- LK.fillRect(barX, barY, barWidth, barHeight);
- // Health
- LK.setFillStyle('rgba(255,50,50,0.8)');
- LK.fillRect(barX, barY, barWidth * healthPercent, barHeight);
- }
- }]);
-}(GameObject);
+ // Move towards center
+ var dx = this.targetX - (this.x + this.width / 2);
+ var dy = this.targetY - (this.y + this.height / 2);
+ var dist = Math.sqrt(dx * dx + dy * dy);
+ if (dist > 10) {
+ // Not too close to center
+ var moveX = dx / dist * this.speed * deltaTime;
+ var moveY = dy / dist * this.speed * deltaTime;
+ this.x += moveX;
+ this.y += moveY;
+ } else {
+ // Reached center, remove
+ this.active = false;
+ }
+};
+Enemy.prototype.takeDamage = function (amount) {
+ this.health -= amount;
+ if (this.health <= 0) {
+ this.defeat();
+ }
+};
+Enemy.prototype.defeat = function () {
+ this.active = false;
+ // Add points
+ var pointsEarned = this.pointValue * multiplier;
+ score += pointsEarned;
+ enemiesDefeated++;
+ // Check for level up
+ if (enemiesDefeated >= ENEMIES_PER_LEVEL) {
+ levelUp();
+ }
+ // Create sparkles
+ for (var i = 0; i < 5; i++) {
+ createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'defeat');
+ }
+ // Chance to spawn power-up
+ if (Math.random() < 0.2) {
+ // 20% chance
+ spawnPowerUp(this.x, this.y);
+ }
+};
/**
-* Bird Class - Standard enemy
+* Bird Class - Basic enemy
*/
-var Bird = /*#__PURE__*/function (_Enemy) {
- function Bird() {
- _classCallCheck(this, Bird);
- // Random position at edge of screen
- var side = Math.floor(Math.random() * 4);
- var x, y;
- switch (side) {
- case 0:
- // Top
- x = Math.random() * LK.canvas.width;
- y = -50;
- break;
- case 1:
- // Right
- x = LK.canvas.width + 50;
- y = Math.random() * LK.canvas.height;
- break;
- case 2:
- // Bottom
- x = Math.random() * LK.canvas.width;
- y = LK.canvas.height + 50;
- break;
- case 3:
- // Left
- x = -50;
- y = Math.random() * LK.canvas.height;
- break;
- }
- return _callSuper(this, Bird, [x, y, 32, 32, 'bird', 3, 50, BIRD_POINTS]);
- }
- _inherits(Bird, _Enemy);
- return _createClass(Bird);
-}(Enemy);
+function Bird(x, y) {
+ Enemy.call(this, x, y, 32, 32, 'bird', 3, 30, BIRD_POINTS);
+}
+Bird.prototype = Object.create(Enemy.prototype);
+Bird.prototype.constructor = Bird;
/**
-* UFO Class - Rare, stronger enemy
+* UFO Class - Advanced enemy
*/
-var UFO = /*#__PURE__*/function (_Enemy2) {
- function UFO() {
- _classCallCheck(this, UFO);
- // Random position at edge of screen
- var side = Math.floor(Math.random() * 4);
- var x, y;
- switch (side) {
- case 0:
- // Top
- x = Math.random() * LK.canvas.width;
- y = -50;
- break;
- case 1:
- // Right
- x = LK.canvas.width + 50;
- y = Math.random() * LK.canvas.height;
- break;
- case 2:
- // Bottom
- x = Math.random() * LK.canvas.width;
- y = LK.canvas.height + 50;
- break;
- case 3:
- // Left
- x = -50;
- y = Math.random() * LK.canvas.height;
- break;
- }
- return _callSuper(this, UFO, [x, y, 64, 32, 'ufo', 10, 30, UFO_POINTS]);
- }
- _inherits(UFO, _Enemy2);
- return _createClass(UFO);
-}(Enemy);
+function UFO(x, y) {
+ Enemy.call(this, x, y, 64, 32, 'ufo', 10, 15, UFO_POINTS);
+}
+UFO.prototype = Object.create(Enemy.prototype);
+UFO.prototype.constructor = UFO;
/**
-* PowerUp Class - Temporary boosts for defenders
+* PowerUp Class
*/
-var PowerUp = /*#__PURE__*/function (_GameObject3) {
- function PowerUp(x, y) {
- var _this3;
- _classCallCheck(this, PowerUp);
- _this3 = _callSuper(this, PowerUp, [x, y, 30, 30, 'powerup']);
- // Define possible power-up types and their effects
- _this3.effects = {
- damage: {
- color: '#ff5555',
- duration: 10,
- multiplier: 2
- },
- speed: {
- color: '#55ff55',
- duration: 15,
- multiplier: 1.5
- },
- range: {
- color: '#5555ff',
- duration: 12,
- multiplier: 1.5
- },
- multi: {
- color: '#ffaa55',
- duration: 8,
- multiplier: 1
- },
- chain: {
- color: '#55ffff',
- duration: 10,
- multiplier: 1
- },
- shield: {
- color: '#aaaaff',
- duration: 20,
- multiplier: 1
- },
- heal: {
- color: '#ff55ff',
- duration: 0,
- multiplier: 1
- },
- time: {
- color: '#ffff55',
- duration: 5,
- multiplier: 0.5
- }
- };
- // Select random type
- var types = Object.keys(_this3.effects);
- _this3.type = types[Math.floor(Math.random() * types.length)];
- // Set duration
- _this3.duration = 10; // seconds
- _this3.lifespan = 10; // seconds before disappearing if not collected
- return _this3;
+function PowerUp(x, y, type) {
+ GameObject.call(this, x, y, 32, 32, 'powerup_' + type);
+ this.type = type;
+ this.duration = 10; // seconds
+ this.targetX = LK.canvas.width / 2;
+ this.targetY = LK.canvas.height / 2;
+}
+PowerUp.prototype = Object.create(GameObject.prototype);
+PowerUp.prototype.constructor = PowerUp;
+PowerUp.prototype.update = function (deltaTime) {
+ if (!this.active) {
+ return;
}
- _inherits(PowerUp, _GameObject3);
- return _createClass(PowerUp, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
+ // Move towards center
+ var dx = this.targetX - (this.x + this.width / 2);
+ var dy = this.targetY - (this.y + this.height / 2);
+ var dist = Math.sqrt(dx * dx + dy * dy);
+ if (dist > 10) {
+ // Not too close to center
+ var moveX = dx / dist * 50 * deltaTime;
+ var moveY = dy / dist * 50 * deltaTime;
+ this.x += moveX;
+ this.y += moveY;
+ } else {
+ // Reached center, apply effect
+ this.applyEffect();
+ this.active = false;
+ }
+};
+PowerUp.prototype.applyEffect = function () {
+ switch (this.type) {
+ case 'speed':
+ // Increase all cats' speed by 50% for duration
+ for (var i = 0; i < cats.length; i++) {
+ cats[i].moveSpeed *= 1.5;
}
- // Decrease lifespan
- this.lifespan -= deltaTime;
- if (this.lifespan <= 0) {
- this.active = false;
- return;
+ for (var i = 0; i < kittens.length; i++) {
+ kittens[i].moveSpeed *= 1.5;
}
- // Check for collision with defenders
- for (var _i3 = 0, _cats = cats; _i3 < _cats.length; _i3++) {
- var cat = _cats[_i3];
- if (this.isColliding(cat)) {
- this.applyEffect(cat);
- this.active = false;
- return;
+ setTimeout(function () {
+ for (var i = 0; i < cats.length; i++) {
+ cats[i].moveSpeed /= 1.5;
}
- }
- for (var _i4 = 0, _kittens = kittens; _i4 < _kittens.length; _i4++) {
- var kitten = _kittens[_i4];
- if (this.isColliding(kitten)) {
- this.applyEffect(kitten);
- this.active = false;
- return;
+ for (var i = 0; i < kittens.length; i++) {
+ kittens[i].moveSpeed /= 1.5;
}
+ }, this.duration * 1000);
+ break;
+ case 'damage':
+ // Increase all cats' damage by 50% for duration
+ for (var i = 0; i < cats.length; i++) {
+ cats[i].attackDamage *= 1.5;
}
- // Floating animation
- this.y += Math.sin(Date.now() / 200) * 0.5;
- }
- }, {
- key: "applyEffect",
- value: function applyEffect(defender) {
- var _this4 = this;
- // Apply effect based on type
- switch (this.type) {
- case 'damage':
- defender.attackDamage *= this.effects.damage.multiplier;
- setTimeout(function () {
- defender.attackDamage /= _this4.effects.damage.multiplier;
- }, this.effects.damage.duration * 1000);
- break;
- case 'speed':
- defender.moveSpeed *= this.effects.speed.multiplier;
- setTimeout(function () {
- defender.moveSpeed /= _this4.effects.speed.multiplier;
- }, this.effects.speed.duration * 1000);
- break;
- case 'range':
- defender.attackRange *= this.effects.range.multiplier;
- setTimeout(function () {
- defender.attackRange /= _this4.effects.range.multiplier;
- }, this.effects.range.duration * 1000);
- break;
- case 'multi':
- // Create temporary multi-attack effect
- var originalAttack = defender.attack;
- defender.attack = function () {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- this.target.takeDamage(this.attackDamage);
- // Attack additional enemies
- var count = 0;
- for (var _i5 = 0, _arr = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i5 < _arr.length; _i5++) {
- var enemy = _arr[_i5];
- if (enemy !== this.target && enemy.active && count < 2) {
- var dist = distance(this.x + this.width / 2, this.y + this.height / 2, enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
- if (dist <= this.attackRange * 1.5) {
- enemy.takeDamage(this.attackDamage / 2);
- count++;
- // Create attack effect
- createSparkle(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, 'attack');
- }
- }
- }
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
- };
- setTimeout(function () {
- defender.attack = originalAttack;
- }, this.effects.multi.duration * 1000);
- break;
- case 'chain':
- // Create chain attack effect
- var chainAttack = defender.attack;
- defender.attack = function () {
- if (this.attackTimer <= 0 && this.target && this.target.active) {
- // Initial attack
- this.target.takeDamage(this.attackDamage);
- // Chain to nearby enemies
- var lastEnemy = this.target;
- var chainCount = 0;
- for (var _i6 = 0, _arr2 = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i6 < _arr2.length; _i6++) {
- var enemy = _arr2[_i6];
- if (enemy !== lastEnemy && enemy.active && chainCount < 3) {
- var dist = distance(lastEnemy.x + lastEnemy.width / 2, lastEnemy.y + lastEnemy.height / 2, enemy.x + enemy.width / 2, enemy.y + enemy.height / 2);
- if (dist <= 100) {
- enemy.takeDamage(this.attackDamage * 0.7);
- chainCount++;
- lastEnemy = enemy;
- // Create chain effect
- createSparkle(enemy.x + enemy.width / 2, enemy.y + enemy.height / 2, 'chain');
- }
- }
- }
- this.attackTimer = this.attackCooldown;
- // Create attack effect
- createSparkle(this.target.x + this.target.width / 2, this.target.y + this.target.height / 2, 'attack');
- }
- };
- setTimeout(function () {
- defender.attack = chainAttack;
- }, this.effects.chain.duration * 1000);
- break;
- case 'shield':
- // Create shield effect
- defender.shielded = true;
- setTimeout(function () {
- defender.shielded = false;
- }, this.effects.shield.duration * 1000);
- break;
- case 'heal':
- // Heal all defenders
- for (var _i7 = 0, _cats2 = cats; _i7 < _cats2.length; _i7++) {
- var cat = _cats2[_i7];
- } // Cats don't have health in this game, but could add temporary invincibility
- for (var _i8 = 0, _kittens2 = kittens; _i8 < _kittens2.length; _i8++) {
- var kitten = _kittens2[_i8];
- } // Kittens don't have health in this game, but could add temporary invincibility
- break;
- case 'time':
- // Slow down all enemies
- for (var _i9 = 0, _birds2 = birds; _i9 < _birds2.length; _i9++) {
- var bird = _birds2[_i9];
- if (bird.active) {
- bird.speed *= this.effects.time.multiplier;
- }
- }
- for (var _i10 = 0, _ufos2 = ufos; _i10 < _ufos2.length; _i10++) {
- var ufo = _ufos2[_i10];
- if (ufo.active) {
- ufo.speed *= this.effects.time.multiplier;
- }
- }
- setTimeout(function () {
- for (var _i11 = 0, _birds3 = birds; _i11 < _birds3.length; _i11++) {
- var bird = _birds3[_i11];
- if (bird.active) {
- bird.speed /= _this4.effects.time.multiplier;
- }
- }
- for (var _i12 = 0, _ufos3 = ufos; _i12 < _ufos3.length; _i12++) {
- var ufo = _ufos3[_i12];
- if (ufo.active) {
- ufo.speed /= _this4.effects.time.multiplier;
- }
- }
- }, this.effects.time.duration * 1000);
- break;
+ for (var i = 0; i < kittens.length; i++) {
+ kittens[i].attackDamage *= 1.5;
}
- // Create collection effect
- for (var i = 0; i < 10; i++) {
- createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'powerup');
- }
- }
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
- }
- // Draw power-up background
- LK.setFillStyle(this.effects[this.type].color);
- LK.fillRect(this.x, this.y, this.width, this.height);
- // Draw icon
- this.drawPowerUpIcon();
- // Pulsing effect based on remaining lifespan
- if (this.lifespan < 3) {
- var alpha = 0.5 + 0.5 * Math.sin(Date.now() / 100);
- LK.setFillStyle("rgba(255,255,255,".concat(alpha, ")"));
- LK.fillRect(this.x, this.y, this.width, this.height);
- }
- }
- // Helper method to convert hex color to RGB format
- }, {
- key: "hexToRgb",
- value: function hexToRgb(hex) {
- // Remove # if present
- hex = hex.replace('#', '');
- // Parse the hex values
- var r = parseInt(hex.substring(0, 2), 16);
- var g = parseInt(hex.substring(2, 4), 16);
- var b = parseInt(hex.substring(4, 6), 16);
- return "".concat(r, ",").concat(g, ",").concat(b);
- }
- // Draw an icon representing the power-up type
- }, {
- key: "drawPowerUpIcon",
- value: function drawPowerUpIcon() {
- var centerX = this.x + this.width / 2;
- var centerY = this.y + this.height / 2;
- var iconSize = this.width / 6;
- LK.setFillStyle('white');
- switch (this.type) {
- case 'damage':
- // Draw a plus symbol
- LK.fillRect(centerX - iconSize, centerY - iconSize / 3, iconSize * 2, iconSize * 2 / 3);
- LK.fillRect(centerX - iconSize / 3, centerY - iconSize, iconSize * 2 / 3, iconSize * 2);
- break;
- case 'speed':
- // Draw a lightning bolt
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX - iconSize, centerY - iconSize);
- LK.lineTo(centerX + iconSize / 2, centerY);
- LK.lineTo(centerX - iconSize / 2, centerY);
- LK.lineTo(centerX + iconSize, centerY + iconSize);
- LK.stroke();
- break;
- case 'range':
- // Draw a circle
- LK.drawCircle(centerX, centerY, iconSize);
- LK.setFillStyle(this.effects[this.type].color);
- LK.drawCircle(centerX, centerY, iconSize / 2);
- break;
- case 'multi':
- // Draw multiple dots
- for (var i = 0; i < 3; i++) {
- var angle = i / 3 * Math.PI * 2;
- LK.drawCircle(centerX + Math.cos(angle) * iconSize, centerY + Math.sin(angle) * iconSize, iconSize / 2);
- }
- break;
- case 'chain':
- // Draw connected dots
- var points = [{
- x: centerX - iconSize,
- y: centerY - iconSize
- }, {
- x: centerX,
- y: centerY
- }, {
- x: centerX + iconSize,
- y: centerY + iconSize
- }];
- // Draw lines connecting points
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(points[0].x, points[0].y);
- LK.lineTo(points[1].x, points[1].y);
- LK.lineTo(points[2].x, points[2].y);
- LK.stroke();
- // Draw points
- for (var _i13 = 0, _points = points; _i13 < _points.length; _i13++) {
- var point = _points[_i13];
- LK.drawCircle(point.x, point.y, iconSize / 3);
- }
- break;
- case 'shield':
- // Draw shield shape
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX, centerY - iconSize);
- LK.lineTo(centerX + iconSize, centerY - iconSize / 2);
- LK.lineTo(centerX + iconSize, centerY + iconSize / 2);
- LK.lineTo(centerX, centerY + iconSize);
- LK.lineTo(centerX - iconSize, centerY + iconSize / 2);
- LK.lineTo(centerX - iconSize, centerY - iconSize / 2);
- LK.lineTo(centerX, centerY - iconSize);
- LK.stroke();
- break;
- case 'heal':
- // Draw plus symbol
- LK.fillRect(centerX - iconSize, centerY - iconSize / 4, iconSize * 2, iconSize / 2);
- LK.fillRect(centerX - iconSize / 4, centerY - iconSize, iconSize / 2, iconSize * 2);
- break;
- case 'time':
- // Draw clock symbol
- LK.drawCircle(centerX, centerY, iconSize);
- LK.setStrokeStyle('white');
- LK.beginPath();
- LK.moveTo(centerX, centerY);
- LK.lineTo(centerX, centerY - iconSize * 0.7);
- LK.moveTo(centerX, centerY);
- LK.lineTo(centerX + iconSize * 0.5, centerY);
- LK.stroke();
- break;
- }
- }
- }]);
-}(GameObject);
+ setTimeout(function () {
+ for (var i = 0; i < cats.length; i++) {
+ cats[i].attackDamage /= 1.5;
+ }
+ for (var i = 0; i < kittens.length; i++) {
+ kittens[i].attackDamage /= 1.5;
+ }
+ }, this.duration * 1000);
+ break;
+ case 'points':
+ // Double points for duration
+ var oldMultiplier = multiplier;
+ multiplier *= 2;
+ setTimeout(function () {
+ multiplier = oldMultiplier;
+ }, this.duration * 1000);
+ break;
+ }
+ // Create effect
+ for (var i = 0; i < 10; i++) {
+ createSparkle(this.x + Math.random() * this.width, this.y + Math.random() * this.height, 'powerup');
+ }
+};
/**
* Sparkle Class - Visual effects
*/
-var Sparkle = /*#__PURE__*/function (_GameObject4) {
- function Sparkle(x, y, type) {
- var _this5;
- _classCallCheck(this, Sparkle);
- _this5 = _callSuper(this, Sparkle, [x, y, 10, 10, 'sparkle']);
- _this5.type = type || 'defeat'; // defeat, attack, powerup
- _this5.lifespan = 0.5; // seconds
- _this5.velocity = {
- x: (Math.random() - 0.5) * 100,
- y: (Math.random() - 0.5) * 100
- };
- // Set color based on type
- switch (_this5.type) {
- case 'defeat':
- _this5.color = "rgba(255,255,".concat(Math.floor(Math.random() * 100) + 155, ",0.8)");
- break;
- case 'attack':
- _this5.color = "rgba(255,".concat(Math.floor(Math.random() * 100) + 100, ",100,0.8)");
- break;
- case 'powerup':
- _this5.color = "rgba(".concat(Math.floor(Math.random() * 155) + 100, ",").concat(Math.floor(Math.random() * 155) + 100, ",255,0.8)");
- break;
- case 'chain':
- _this5.color = "rgba(100,255,".concat(Math.floor(Math.random() * 155) + 100, ",0.8)");
- break;
- default:
- _this5.color = "rgba(255,255,255,0.8)";
- }
- return _this5;
+function Sparkle(x, y, type) {
+ this.x = x;
+ this.y = y;
+ this.type = type;
+ this.size = Math.random() * 5 + 5;
+ this.lifespan = 0.5; // seconds
+ this.maxLifespan = this.lifespan;
+ this.active = true;
+ // Set color based on type
+ switch (type) {
+ case 'attack':
+ this.color = '#ffff00'; // Yellow
+ break;
+ case 'defeat':
+ this.color = '#ff0000'; // Red
+ break;
+ case 'powerup':
+ this.color = '#00ffff'; // Cyan
+ break;
+ case 'chain':
+ this.color = '#ff00ff'; // Magenta
+ break;
+ default:
+ this.color = '#ffffff';
+ // White
}
- _inherits(Sparkle, _GameObject4);
- return _createClass(Sparkle, [{
- key: "update",
- value: function update(deltaTime) {
- if (!this.active) {
- return;
- }
- // Update position
- this.x += this.velocity.x * deltaTime;
- this.y += this.velocity.y * deltaTime;
- // Decrease lifespan
- this.lifespan -= deltaTime;
- if (this.lifespan <= 0) {
- this.active = false;
- }
- }
- }, {
- key: "render",
- value: function render() {
- if (!this.active) {
- return;
- }
- // Draw sparkle
- var alpha = this.lifespan * 2; // Fade out
- LK.setFillStyle(this.color.replace('0.8', alpha));
- LK.fillRect(this.x, this.y, this.width, this.height);
- }
- }]);
-}(GameObject); // --- Game Functions ---
-// Create a sparkle effect
-function createSparkle(x, y, type) {
- var sparkle = new Sparkle(x, y, type);
- sparkles.push(sparkle);
- return sparkle;
+ // Random velocity
+ var angle = Math.random() * Math.PI * 2;
+ var speed = Math.random() * 100 + 50;
+ this.vx = Math.cos(angle) * speed;
+ this.vy = Math.sin(angle) * speed;
}
+Sparkle.prototype.update = function (deltaTime) {
+ if (!this.active) {
+ return;
+ }
+ // Update position
+ this.x += this.vx * deltaTime;
+ this.y += this.vy * deltaTime;
+ // Update lifespan
+ this.lifespan -= deltaTime;
+ if (this.lifespan <= 0) {
+ this.active = false;
+ }
+};
+Sparkle.prototype.render = function () {
+ if (!this.active) {
+ return;
+ }
+ // Calculate alpha based on remaining lifespan
+ var alpha = this.lifespan / this.maxLifespan;
+ // Draw sparkle
+ LK.setFillStyle(this.color);
+ LK.setGlobalAlpha(alpha);
+ LK.fillCircle(this.x, this.y, this.size * alpha);
+ LK.setGlobalAlpha(1.0);
+};
+// --- Game Functions ---
+// Spawn a bird at a random edge position
+function spawnBird() {
+ if (birds.length >= MAX_BIRDS) {
+ return;
+ }
+ var x, y;
+ var side = Math.floor(Math.random() * 4);
+ switch (side) {
+ case 0:
+ // Top
+ x = Math.random() * LK.canvas.width;
+ y = -32;
+ break;
+ case 1:
+ // Right
+ x = LK.canvas.width + 32;
+ y = Math.random() * LK.canvas.height;
+ break;
+ case 2:
+ // Bottom
+ x = Math.random() * LK.canvas.width;
+ y = LK.canvas.height + 32;
+ break;
+ case 3:
+ // Left
+ x = -32;
+ y = Math.random() * LK.canvas.height;
+ break;
+ }
+ var bird = new Bird(x, y);
+ birds.push(bird);
+ return bird;
+}
+// Spawn a UFO at a random edge position
+function spawnUFO() {
+ if (ufos.length >= MAX_UFOS) {
+ return;
+ }
+ var x, y;
+ var side = Math.floor(Math.random() * 4);
+ switch (side) {
+ case 0:
+ // Top
+ x = Math.random() * LK.canvas.width;
+ y = -32;
+ break;
+ case 1:
+ // Right
+ x = LK.canvas.width + 64;
+ y = Math.random() * LK.canvas.height;
+ break;
+ case 2:
+ // Bottom
+ x = Math.random() * LK.canvas.width;
+ y = LK.canvas.height + 32;
+ break;
+ case 3:
+ // Left
+ x = -64;
+ y = Math.random() * LK.canvas.height;
+ break;
+ }
+ var ufo = new UFO(x, y);
+ ufos.push(ufo);
+ return ufo;
+}
// Spawn a power-up
-function spawnPowerUp(x, y) {
- var powerUp = new PowerUp(x, y);
+function spawnPowerUp(x, y, type) {
+ // If type not specified, choose random
+ if (!type) {
+ var types = ['speed', 'damage', 'range', 'multi', 'chain', 'time'];
+ type = types[Math.floor(Math.random() * types.length)];
+ }
+ var powerUp = new PowerUp(x, y, type);
powerUps.push(powerUp);
return powerUp;
}
// Level up function
@@ -1002,8 +487,10 @@
createSparkle(centerX + (Math.random() - 0.5) * 200, centerY + (Math.random() - 0.5) * 200, 'powerup');
}
// Reset enemy counter
enemiesDefeated = 0;
+ // Play level up sound
+ LK.playSound('teslacoil');
}
// Calculate idle points
function calculateIdlePoints() {
var currentTime = Date.now();
@@ -1020,30 +507,8 @@
// Update last calculation time
idlePointsLastCalculated = currentTime;
return pointsEarned;
}
-// Spawn a new cat
-function spawnCat(x, y) {
- if (idlePoints >= 50) {
- // Cost to spawn a cat
- idlePoints -= 50;
- var cat = new Cat(x, y);
- cats.push(cat);
- return cat;
- }
- return null;
-}
-// Spawn a new kitten
-function spawnKitten(x, y) {
- if (idlePoints >= 30) {
- // Cost to spawn a kitten
- idlePoints -= 30;
- var kitten = new Kitten(x, y);
- kittens.push(kitten);
- return kitten;
- }
- return null;
-}
// Update game state
function updateGame(deltaTime) {
// Calculate idle points
calculateIdlePoints();
@@ -1089,21 +554,60 @@
if (!sparkle.active) {
sparkles.splice(i, 1);
}
}
+ // Update kittens
+ for (var i = kittens.length - 1; i >= 0; i--) {
+ var kitten = kittens[i];
+ kitten.update(deltaTime);
+ }
+ // Update birds and remove inactive ones
+ for (var i = birds.length - 1; i >= 0; i--) {
+ var bird = birds[i];
+ bird.update(deltaTime);
+ if (!bird.active) {
+ birds.splice(i, 1);
+ }
+ }
+ // Update UFOs and remove inactive ones
+ for (var i = ufos.length - 1; i >= 0; i--) {
+ var ufo = ufos[i];
+ ufo.update(deltaTime);
+ if (!ufo.active) {
+ ufos.splice(i, 1);
+ }
+ }
+ // Update power-ups and remove inactive ones
+ for (var i = powerUps.length - 1; i >= 0; i--) {
+ var powerUp = powerUps[i];
+ powerUp.update(deltaTime);
+ if (!powerUp.active) {
+ powerUps.splice(i, 1);
+ }
+ }
+ // Update sparkles and remove inactive ones
+ for (var i = sparkles.length - 1; i >= 0; i--) {
+ var sparkle = sparkles[i];
+ sparkle.update(deltaTime);
+ if (!sparkle.active) {
+ sparkles.splice(i, 1);
+ }
+ }
// Spawn birds
birdSpawnTimer += deltaTime * 1000; // Convert to milliseconds
if (birds.length < MAX_BIRDS && birdSpawnTimer >= BIRD_SPAWN_INTERVAL) {
- var bird = new Bird();
- birds.push(bird);
+ spawnBird();
birdSpawnTimer = 0;
+ LK.playSound('wings1', {
+ volume: 0.2
+ });
}
// Spawn UFOs
ufoSpawnTimer += deltaTime * 1000; // Convert to milliseconds
if (ufos.length < MAX_UFOS && ufoSpawnTimer >= UFO_SPAWN_INTERVAL && level >= 3) {
- var ufo = new UFO();
- ufos.push(ufo);
+ spawnUFO();
ufoSpawnTimer = 0;
+ LK.playSound('ufo1');
}
}
// Render game
function renderGame() {
@@ -1113,86 +617,63 @@
LK.setFillStyle('#1a1a2e');
LK.fillRect(0, 0, LK.canvas.width, LK.canvas.height);
// Render all game objects
// Render sparkles first (background layer)
- var _iterator = _createForOfIteratorHelper(sparkles),
- _step;
- try {
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
- var sparkle = _step.value;
- sparkle.render();
- }
- // Render power-ups
- } catch (err) {
- _iterator.e(err);
- } finally {
- _iterator.f();
+ for (var i = 0; i < sparkles.length; i++) {
+ var sparkle = sparkles[i];
+ sparkle.render();
}
- var _iterator2 = _createForOfIteratorHelper(powerUps),
- _step2;
- try {
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
- var powerUp = _step2.value;
- powerUp.render();
- }
- // Render birds
- } catch (err) {
- _iterator2.e(err);
- } finally {
- _iterator2.f();
+ // Render power-ups
+ for (var i = 0; i < powerUps.length; i++) {
+ var powerUp = powerUps[i];
+ powerUp.render();
}
- var _iterator3 = _createForOfIteratorHelper(birds),
- _step3;
- try {
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
- var bird = _step3.value;
- bird.render();
- }
- // Render UFOs
- } catch (err) {
- _iterator3.e(err);
- } finally {
- _iterator3.f();
+ // Render birds
+ for (var i = 0; i < birds.length; i++) {
+ var bird = birds[i];
+ bird.render();
}
- var _iterator4 = _createForOfIteratorHelper(ufos),
- _step4;
- try {
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
- var ufo = _step4.value;
- ufo.render();
- }
- // Render cats
- } catch (err) {
- _iterator4.e(err);
- } finally {
- _iterator4.f();
+ // Render UFOs
+ for (var i = 0; i < ufos.length; i++) {
+ var ufo = ufos[i];
+ ufo.render();
}
- var _iterator5 = _createForOfIteratorHelper(cats),
- _step5;
- try {
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
- var cat = _step5.value;
- cat.render();
- }
- // Render kittens
- } catch (err) {
- _iterator5.e(err);
- } finally {
- _iterator5.f();
+ // Render cats
+ for (var i = 0; i < cats.length; i++) {
+ var cat = cats[i];
+ cat.render();
}
- var _iterator6 = _createForOfIteratorHelper(kittens),
- _step6;
- try {
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
- var kitten = _step6.value;
- kitten.render();
- }
- // Render UI
- } catch (err) {
- _iterator6.e(err);
- } finally {
- _iterator6.f();
+ // Render kittens
+ for (var i = 0; i < kittens.length; i++) {
+ var kitten = kittens[i];
+ kitten.render();
}
+ // Render power-ups
+ for (var i = 0; i < powerUps.length; i++) {
+ var powerUp = powerUps[i];
+ powerUp.render();
+ }
+ // Render birds
+ for (var i = 0; i < birds.length; i++) {
+ var bird = birds[i];
+ bird.render();
+ }
+ // Render UFOs
+ for (var i = 0; i < ufos.length; i++) {
+ var ufo = ufos[i];
+ ufo.render();
+ }
+ // Render cats
+ for (var i = 0; i < cats.length; i++) {
+ var cat = cats[i];
+ cat.render();
+ }
+ // Render kittens
+ for (var i = 0; i < kittens.length; i++) {
+ var kitten = kittens[i];
+ kitten.render();
+ }
+ // Render UI
renderUI();
}
// Render UI elements
function renderUI() {
@@ -1250,13 +731,25 @@
// Handle mouse click
function handleMouseClick(x, y) {
// Check if cat spawn button clicked
if (x >= 20 && x <= 140 && y >= LK.canvas.height - 60 && y <= LK.canvas.height - 20) {
- spawnCat(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height);
+ if (idlePoints >= 50) {
+ var cat = spawnCat(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height);
+ if (cat) {
+ LK.playSound('chitter');
+ }
+ }
}
// Check if kitten spawn button clicked
if (x >= 150 && x <= 270 && y >= LK.canvas.height - 60 && y <= LK.canvas.height - 20) {
- spawnKitten(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height);
+ if (idlePoints >= 30) {
+ var kitten = spawnKitten(Math.random() * LK.canvas.width, Math.random() * LK.canvas.height);
+ if (kitten) {
+ LK.playSound('chitter', {
+ pitch: 1.5
+ });
+ }
+ }
}
}
// Initialize game
function initGame() {
@@ -1277,12 +770,35 @@
birdSpawnTimer = 0;
ufoSpawnTimer = 0;
// Create initial cats
spawnCat(LK.canvas.width / 2, LK.canvas.height / 2);
+ // Create initial kittens
+ spawnKitten(LK.canvas.width / 2 + 100, LK.canvas.height / 2 + 100);
+ // Create initial birds
+ spawnBird();
+ // Create initial UFOs
+ spawnUFO();
+ // Create initial power-ups
+ spawnPowerUp(LK.canvas.width / 2, LK.canvas.height / 2, 'speed');
// Setup mouse click handler
LK.onMouseDown = function (event) {
handleMouseClick(event.x, event.y);
};
+ // Play background music
+ LK.playMusic('bgm1', {
+ volume: 0.3,
+ loop: true
+ });
+ // Occasionally play ambient sounds
+ setInterval(function () {
+ if (Math.random() < 0.3) {
+ var sounds = ['breeze1', 'cricket1', 'frog1', 'songbird1'];
+ var sound = sounds[Math.floor(Math.random() * sounds.length)];
+ LK.playSound(sound, {
+ volume: 0.1 + Math.random() * 0.1
+ });
+ }
+ }, 10000);
// Start game loop
startGameLoop();
}
// Game loop
@@ -1290,8 +806,12 @@
function gameLoop(timestamp) {
// Calculate delta time
var deltaTime = (timestamp - lastFrameTime) / 1000; // Convert to seconds
lastFrameTime = timestamp;
+ // Cap delta time to prevent large jumps
+ if (deltaTime > 0.1) {
+ deltaTime = 0.1;
+ }
// Update game state
updateGame(deltaTime);
// Render game
renderGame();
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