User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, LK.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, game.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, LK.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, game.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, LK.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, game.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, LK.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, game.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, game.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'cats.push(new Cat(100, LK.canvas.height / 2));' Line Number: 1103
User prompt
Please fix the bug: 'LK.setBackgroundColor is not a function' in or related to this line: 'LK.setBackgroundColor('#87CEEB'); // Sky blue' Line Number: 1101
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'cat is not defined' in or related to this line: 'cats = [{' Line Number: 177
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'id')' in or related to this line: 'branches = [{' Line Number: 113
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'id')' in or related to this line: 'branches = [{' Line Number: 114
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'id')' in or related to this line: 'branches = [{' Line Number: 113
User prompt
Please fix the bug: 'branch is not defined' in or related to this line: 'branches = [{' Line Number: 113
User prompt
add labels to all objects
User prompt
increase font for all text 200%
User prompt
assign images to objects
User prompt
assign images to objects that need one
User prompt
Please fix the bug: 'requestAnimationFrame is not a function' in or related to this line: 'requestAnimationFrame(gameLoop);' Line Number: 167
User prompt
Please fix the bug: 'LK.gameLoop is not a function' in or related to this line: 'LK.gameLoop(gameLoop);' Line Number: 167
User prompt
Please fix the bug: 'LK.gameLoop is not a function' in or related to this line: 'LK.gameLoop(gameLoop);' Line Number: 167
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'createElement')' in or related to this line: 'var btn = document.createElement('button');' Line Number: 184
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * 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 _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 _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 _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 _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 _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 _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 _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); } var cats = []; var kittens = []; var birds = []; var ufos = []; var clouds = []; 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 = 10; 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; var CLOUD_SPAWN_INTERVAL = 5000; // ms var MAX_CLOUDS = 8; // Timers var birdSpawnTimer = 0; var ufoSpawnTimer = 0; var cloudSpawnTimer = 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 */ 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; } 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; } }]); }(); /** * 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; } _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); } } } }, { key: "findTarget", value: function findTarget() { // Find closest enemy var closestDist = Infinity; var closest = null; // Check birds first var _iterator = _createForOfIteratorHelper(birds), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var bird = _step.value; 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) } catch (err) { _iterator.e(err); } finally { _iterator.f(); } if ((!closest || this instanceof Kitten) && ufos.length > 0) { var _iterator2 = _createForOfIteratorHelper(ufos), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var ufo = _step2.value; 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; } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } } this.target = closest; } }, { key: "moveTowardsTarget", value: function moveTowardsTarget(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; } } }, { 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); /** * 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); /** * 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); /** * 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; } _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); /** * Bird Class - Standard 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); /** * UFO Class - Rare, stronger 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); /** * PowerUp Class - Temporary boosts for defenders */ 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; } _inherits(PowerUp, _GameObject3); return _createClass(PowerUp, [{ key: "update", value: function update(deltaTime) { if (!this.active) { return; } // Decrease lifespan this.lifespan -= deltaTime; if (this.lifespan <= 0) { this.active = false; return; } // Check for collision with defenders for (var _i = 0, _cats = cats; _i < _cats.length; _i++) { var cat = _cats[_i]; if (this.isColliding(cat)) { this.applyEffect(cat); this.active = false; return; } } for (var _i2 = 0, _kittens = kittens; _i2 < _kittens.length; _i2++) { var kitten = _kittens[_i2]; if (this.isColliding(kitten)) { this.applyEffect(kitten); this.active = false; return; } } // 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 _i3 = 0, _arr = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i3 < _arr.length; _i3++) { var enemy = _arr[_i3]; 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 _i4 = 0, _arr2 = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i4 < _arr2.length; _i4++) { var enemy = _arr2[_i4]; 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 _i5 = 0, _cats2 = cats; _i5 < _cats2.length; _i5++) { var cat = _cats2[_i5]; } // Cats don't have health in this game, but could add temporary invincibility for (var _i6 = 0, _kittens2 = kittens; _i6 < _kittens2.length; _i6++) { var kitten = _kittens2[_i6]; } // Kittens don't have health in this game, but could add temporary invincibility break; case 'time': // Slow down all enemies var _iterator3 = _createForOfIteratorHelper(birds), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var bird = _step3.value; if (bird.active) { bird.speed *= this.effects.time.multiplier; } } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } var _iterator4 = _createForOfIteratorHelper(ufos), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var ufo = _step4.value; if (ufo.active) { ufo.speed *= this.effects.time.multiplier; } } } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } setTimeout(function () { var _iterator5 = _createForOfIteratorHelper(birds), _step5; try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { var bird = _step5.value; if (bird.active) { bird.speed /= _this4.effects.time.multiplier; } } } catch (err) { _iterator5.e(err); } finally { _iterator5.f(); } var _iterator6 = _createForOfIteratorHelper(ufos), _step6; try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { var ufo = _step6.value; if (ufo.active) { ufo.speed /= _this4.effects.time.multiplier; } } } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } }, this.effects.time.duration * 1000); break; } // 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 _i7 = 0, _points = points; _i7 < _points.length; _i7++) { var point = _points[_i7]; 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); /** * 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; } _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); // --- Cloud Class --- var Cloud = /*#__PURE__*/function (_GameObject5) { function Cloud() { var _this6; _classCallCheck(this, Cloud); var size = 32 + Math.floor(Math.random() * 96); // Random size between 32x32 and 128x128 var y = Math.random() * (LK.canvas.height - size); _this6 = _callSuper(this, Cloud, [LK.canvas.width + size, y, size, size, 'cloud']); _this6.speed = 10 + Math.random() * 20; // Random speed _this6.parallaxLayer = Math.random(); // Random depth effect return _this6; } _inherits(Cloud, _GameObject5); return _createClass(Cloud, [{ key: "update", value: function update(deltaTime) { if (!this.active) { return; } // Move cloud from right to left this.x -= this.speed * this.parallaxLayer * deltaTime; // Remove if off screen if (this.x + this.width < 0) { this.active = false; } } }]); }(GameObject); // --- Game Functions --- // Create a sparkle effect function createSparkle(x, y, type) { var sparkle = new Sparkle(x, y, type); sparkles.push(sparkle); return sparkle; } // Spawn a power-up function spawnPowerUp(x, y) { var powerUp = new PowerUp(x, y); powerUps.push(powerUp); return powerUp; } // Level up function function levelUp() { level++; multiplier = 1 + (level - 1) * 0.1; // Increase multiplier by 0.1 per level enemiesDefeated = 0; // Create level up effect for (var i = 0; i < 20; i++) { createSparkle(LK.canvas.width / 2 + (Math.random() - 0.5) * 200, LK.canvas.height / 2 + (Math.random() - 0.5) * 200, 'levelup'); } } // --- Main Game Functions --- // Initialize game function initialize() { // Set background color LK.setBackgroundColor('#87CEEB'); // Sky blue // Create initial cat cats.push(new Cat(100, LK.canvas.height / 2)); // Initialize timers lastUpdateTime = Date.now(); idlePointsLastCalculated = Date.now(); // Create initial clouds for (var i = 0; i < 5; i++) { var cloud = new Cloud(); cloud.x = Math.random() * LK.canvas.width; // Position randomly across screen clouds.push(cloud); } } // Update game state function update(deltaTime) { // Update timers var currentTime = Date.now(); deltaTime = (currentTime - lastUpdateTime) / 1000; // Convert to seconds lastUpdateTime = currentTime; // Calculate idle points calculateIdlePoints(); // Spawn enemies based on timers birdSpawnTimer += deltaTime * 1000; if (birdSpawnTimer >= BIRD_SPAWN_INTERVAL / (1 + (level - 1) * 0.1) && birds.length < MAX_BIRDS) { birds.push(new Bird()); birdSpawnTimer = 0; } ufoSpawnTimer += deltaTime * 1000; if (ufoSpawnTimer >= UFO_SPAWN_INTERVAL && ufos.length < MAX_UFOS && level % 5 === 0) { ufos.push(new UFO()); ufoSpawnTimer = 0; } // Spawn clouds cloudSpawnTimer += deltaTime * 1000; if (cloudSpawnTimer >= CLOUD_SPAWN_INTERVAL && clouds.length < MAX_CLOUDS) { spawnCloud(); cloudSpawnTimer = 0; } // Update all game objects updateGameObjects(cats, deltaTime); updateGameObjects(kittens, deltaTime); updateGameObjects(birds, deltaTime); updateGameObjects(ufos, deltaTime); updateGameObjects(powerUps, deltaTime); updateGameObjects(sparkles, deltaTime); updateGameObjects(clouds, deltaTime); // Clean up inactive objects cleanupInactiveObjects(); } // Update array of game objects function updateGameObjects(objects, deltaTime) { for (var i = 0; i < objects.length; i++) { if (objects[i].active) { objects[i].update(deltaTime); } } } // Clean up inactive objects function cleanupInactiveObjects() { birds = birds.filter(function (obj) { return obj.active; }); ufos = ufos.filter(function (obj) { return obj.active; }); powerUps = powerUps.filter(function (obj) { return obj.active; }); sparkles = sparkles.filter(function (obj) { return obj.active; }); clouds = clouds.filter(function (obj) { return obj.active; }); } // Render game function render() { // Clear canvas LK.clear(); // Render clouds (background) renderGameObjects(clouds); // Render game objects renderGameObjects(cats); renderGameObjects(kittens); renderGameObjects(birds); renderGameObjects(ufos); renderGameObjects(powerUps); renderGameObjects(sparkles); // Render UI renderUI(); } // Render array of game objects function renderGameObjects(objects) { for (var i = 0; i < objects.length; i++) { if (objects[i].active) { objects[i].render(); } } } // Render UI elements function renderUI() { // Score display LK.setFillStyle('white'); LK.setFont('24px Arial'); LK.fillText("Score: ".concat(Math.floor(score)), LK.canvas.width / 2, 30, 'center'); // Level and multiplier LK.setFont('18px Arial'); LK.fillText("Level: ".concat(level), LK.canvas.width - 80, 30, 'right'); LK.fillText("Multiplier: ".concat(multiplier.toFixed(1), "x"), LK.canvas.width / 2, 60, 'center'); // Enemies defeated counter LK.fillText("Enemies: ".concat(enemiesDefeated, "/").concat(ENEMIES_PER_LEVEL), 80, 30, 'left'); // Idle points counter LK.fillText("Idle Points: ".concat(Math.floor(idlePoints)), LK.canvas.width - 20, LK.canvas.height - 20, 'right'); } // Handle input events function handleInput(obj) { var x = obj.x; var y = obj.y; // Check if clicked on a power-up var _iterator7 = _createForOfIteratorHelper(powerUps), _step7; try { for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { var powerUp = _step7.value; if (powerUp.active && x >= powerUp.x && x <= powerUp.x + powerUp.width && y >= powerUp.y && y <= powerUp.y + powerUp.height) { // Collect power-up powerUp.active = false; // Apply to nearest defender var closestDist = Infinity; var closest = null; var _iterator8 = _createForOfIteratorHelper(cats), _step8; try { for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { var cat = _step8.value; var dist = distance(powerUp.x, powerUp.y, cat.x, cat.y); if (dist < closestDist) { closestDist = dist; closest = cat; } } } catch (err) { _iterator8.e(err); } finally { _iterator8.f(); } var _iterator9 = _createForOfIteratorHelper(kittens), _step9; try { for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { var kitten = _step9.value; var dist = distance(powerUp.x, powerUp.y, kitten.x, kitten.y); if (dist < closestDist) { closestDist = dist; closest = kitten; } } } catch (err) { _iterator9.e(err); } finally { _iterator9.f(); } if (closest) { powerUp.applyEffect(closest); } return; } } // Place a new cat at the clicked position } catch (err) { _iterator7.e(err); } finally { _iterator7.f(); } if (idlePoints >= 50) { idlePoints -= 50; cats.push(new Cat(x, y)); } } // Main game loop function gameLoop() { update(1 / 60); // 60 FPS render(); } // Start the game initialize(); LK.on('pointerdown', handleInput); multiplier = 1.0 + (level - 1) * 0.1;
===================================================================
--- original.js
+++ change.js
@@ -7,45 +7,191 @@
/****
* Game Code
****/
-// Game state
+// --- 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 _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 _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 _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 _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 _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 _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 _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 ownKeys(e, r) {
- var t = Object.keys(e);
- if (Object.getOwnPropertySymbols) {
- var o = Object.getOwnPropertySymbols(e);
- r && (o = o.filter(function (r) {
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
- })), t.push.apply(t, o);
+function _classCallCheck(a, n) {
+ if (!(a instanceof n)) {
+ throw new TypeError("Cannot call a class as a function");
}
- return t;
}
-function _objectSpread(e) {
- for (var r = 1; r < arguments.length; r++) {
- var t = null != arguments[r] ? arguments[r] : {};
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
- _defineProperty(e, r, t[r]);
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
- });
+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);
}
- return e;
}
-function _defineProperty(e, r, t) {
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
- value: t,
- enumerable: !0,
- configurable: !0,
- writable: !0
- }) : e[r] = t, e;
+function _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 + "";
@@ -63,297 +209,1065 @@
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
-var sparkleCount = 500;
-var cat = {
- id: 'cat-1'
-};
var cats = [];
-var branches = [];
-var notifications = [];
-var sparkleInterval = null;
-// Helper functions
-var isoX = function isoX(x, y) {
- return (x - y) * 0.866;
-};
-var isoY = function isoY(x, y, z) {
- return (x + y) * 0.5 - z;
-};
-// Initialize game
-function startGame() {
- initializeGame();
+var kittens = [];
+var birds = [];
+var ufos = [];
+var clouds = [];
+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 = 10;
+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;
+var CLOUD_SPAWN_INTERVAL = 5000; // ms
+var MAX_CLOUDS = 8;
+// Timers
+var birdSpawnTimer = 0;
+var ufoSpawnTimer = 0;
+var cloudSpawnTimer = 0;
+// --- Utility Functions ---
+function distance(x1, y1, x2, y2) {
+ var dx = x1 - x2;
+ var dy = y1 - y2;
+ return Math.sqrt(dx * dx + dy * dy);
}
-// Initialize game
-function initializeGame() {
- var sparkleCountEl = new Text2("Sparkles: ".concat(sparkleCount), {
- size: 60,
- fill: "gold",
- fontFamily: "Arial, sans-serif",
- background: 'rgba(0,0,0,0.7)',
- padding: 10,
- borderRadius: 5
- });
- sparkleCountEl.position.set(10, 10);
- LK.gui.topLeft.addChild(sparkleCountEl);
- // Initialize branches
- branches = [{
- id: 0,
- level: 1,
- catCapacity: 1,
- upgradeCost: 100,
- position: {
- x: 0,
- y: -50,
- z: 80
- },
- image: LK.getAsset('branchImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }),
- // Assign image to branch
- label: new Text2("Branch ".concat(0), {
- size: 30,
- fill: 0xFFFFFF,
- fontFamily: "Arial, sans-serif"
- })
+// --- 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;
+ }
+ return _createClass(GameObject, [{
+ key: "update",
+ value: function update(deltaTime) {
+ // Override in subclasses
+ }
}, {
- id: 1,
- level: 1,
- catCapacity: 1,
- upgradeCost: 100,
- position: {
- x: 50,
- y: 0,
- z: 80
- },
- image: LK.getAsset('branchImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }) // Assign image to branch
+ key: "render",
+ value: function render() {
+ if (!this.active) {
+ return;
+ }
+ // Draw the sprite
+ LK.drawImage(this.assetId, this.x, this.y, this.width, this.height);
+ }
}, {
- id: 2,
- level: 1,
- catCapacity: 1,
- upgradeCost: 100,
- position: {
- x: 0,
- y: 50,
- z: 80
- },
- image: LK.getAsset('branchImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }) // Assign image to branch
+ 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;
+ }
+ }]);
+}();
+/**
+* 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;
+ }
+ _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);
+ }
+ }
+ }
}, {
- id: 3,
- level: 1,
- catCapacity: 1,
- upgradeCost: 100,
- position: {
- x: -50,
- y: 0,
- z: 80
- },
- image: LK.getAsset('branchImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }) // Assign image to branch
- }];
- // Initialize starter cat
- cats = [{
- id: 'cat-1',
- level: 1,
- sparkleRate: 1,
- upgradeCost: 50,
- position: {
- x: 0,
- y: -70,
- z: 20
- },
- image: LK.getAsset('catImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }),
- // Assign image to cat
- label: new Text2("Cat ".concat(cat.id), {
- size: 30,
- fill: 0xFFFFFF,
- fontFamily: "Arial, sans-serif"
- })
- }];
- // Create UI buttons
- createButtons();
- // Start game loop
- game.update = gameLoop;
-}
-// Create game buttons
-function createButtons() {
- var buyCatBtn = new Text2('Buy Cat (50)', {
- size: 60,
- fill: 0xFFFFFF,
- fontFamily: "Arial, sans-serif",
- background: 'rgba(0,0,0,0.7)',
- padding: 10,
- borderRadius: 5
- });
- buyCatBtn.interactive = true;
- buyCatBtn.buttonMode = true;
- buyCatBtn.on('pointerdown', buyCat);
- LK.gui.topLeft.addChild(buyCatBtn);
- branches.forEach(function (branch) {
- var btn = new Text2("Upgrade Branch ".concat(branch.id, " (").concat(branch.upgradeCost, ")"), {
- size: 60,
- fill: 0xFFFFFF,
- fontFamily: "Arial, sans-serif",
- background: 'rgba(0,0,0,0.7)',
- padding: 10,
- borderRadius: 5
- });
- btn.interactive = true;
- btn.buttonMode = true;
- btn.on('pointerdown', function () {
- return upgradeBranch(branch.id);
- });
- LK.gui.topLeft.addChild(btn);
- });
-}
-// Game mechanics
-function generateSparkles() {
- var newSparkles = cats.map(function (cat) {
- return {
- id: "sparkle-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9)),
- position: {
- x: cat.position.x + (Math.random() * 20 - 10),
- y: cat.position.y + (Math.random() * 20 - 10),
- z: cat.position.z
+ key: "findTarget",
+ value: function findTarget() {
+ // Find closest enemy
+ var closestDist = Infinity;
+ var closest = null;
+ // Check birds first
+ var _iterator = _createForOfIteratorHelper(birds),
+ _step;
+ try {
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
+ var bird = _step.value;
+ 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)
+ } catch (err) {
+ _iterator.e(err);
+ } finally {
+ _iterator.f();
+ }
+ if ((!closest || this instanceof Kitten) && ufos.length > 0) {
+ var _iterator2 = _createForOfIteratorHelper(ufos),
+ _step2;
+ try {
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
+ var ufo = _step2.value;
+ 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;
+ }
+ }
+ } catch (err) {
+ _iterator2.e(err);
+ } finally {
+ _iterator2.f();
+ }
+ }
+ this.target = closest;
+ }
+ }, {
+ key: "moveTowardsTarget",
+ value: function moveTowardsTarget(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;
+ }
+ }
+ }, {
+ 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);
+/**
+* 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);
+/**
+* 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);
+/**
+* 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;
+ }
+ _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);
+/**
+* Bird Class - Standard 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);
+/**
+* UFO Class - Rare, stronger 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);
+/**
+* PowerUp Class - Temporary boosts for defenders
+*/
+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
},
- value: cat.level * cat.sparkleRate
+ 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
+ }
};
- });
- sparkleCount += newSparkles.reduce(function (sum, s) {
- return sum + s.value;
- }, 0);
- LK.play.sound('chitter');
- updateUI();
+ // 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;
+ }
+ _inherits(PowerUp, _GameObject3);
+ return _createClass(PowerUp, [{
+ key: "update",
+ value: function update(deltaTime) {
+ if (!this.active) {
+ return;
+ }
+ // Decrease lifespan
+ this.lifespan -= deltaTime;
+ if (this.lifespan <= 0) {
+ this.active = false;
+ return;
+ }
+ // Check for collision with defenders
+ for (var _i = 0, _cats = cats; _i < _cats.length; _i++) {
+ var cat = _cats[_i];
+ if (this.isColliding(cat)) {
+ this.applyEffect(cat);
+ this.active = false;
+ return;
+ }
+ }
+ for (var _i2 = 0, _kittens = kittens; _i2 < _kittens.length; _i2++) {
+ var kitten = _kittens[_i2];
+ if (this.isColliding(kitten)) {
+ this.applyEffect(kitten);
+ this.active = false;
+ return;
+ }
+ }
+ // 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 _i3 = 0, _arr = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i3 < _arr.length; _i3++) {
+ var enemy = _arr[_i3];
+ 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 _i4 = 0, _arr2 = [].concat(_toConsumableArray(birds), _toConsumableArray(ufos)); _i4 < _arr2.length; _i4++) {
+ var enemy = _arr2[_i4];
+ 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 _i5 = 0, _cats2 = cats; _i5 < _cats2.length; _i5++) {
+ var cat = _cats2[_i5];
+ } // Cats don't have health in this game, but could add temporary invincibility
+ for (var _i6 = 0, _kittens2 = kittens; _i6 < _kittens2.length; _i6++) {
+ var kitten = _kittens2[_i6];
+ } // Kittens don't have health in this game, but could add temporary invincibility
+ break;
+ case 'time':
+ // Slow down all enemies
+ var _iterator3 = _createForOfIteratorHelper(birds),
+ _step3;
+ try {
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
+ var bird = _step3.value;
+ if (bird.active) {
+ bird.speed *= this.effects.time.multiplier;
+ }
+ }
+ } catch (err) {
+ _iterator3.e(err);
+ } finally {
+ _iterator3.f();
+ }
+ var _iterator4 = _createForOfIteratorHelper(ufos),
+ _step4;
+ try {
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
+ var ufo = _step4.value;
+ if (ufo.active) {
+ ufo.speed *= this.effects.time.multiplier;
+ }
+ }
+ } catch (err) {
+ _iterator4.e(err);
+ } finally {
+ _iterator4.f();
+ }
+ setTimeout(function () {
+ var _iterator5 = _createForOfIteratorHelper(birds),
+ _step5;
+ try {
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
+ var bird = _step5.value;
+ if (bird.active) {
+ bird.speed /= _this4.effects.time.multiplier;
+ }
+ }
+ } catch (err) {
+ _iterator5.e(err);
+ } finally {
+ _iterator5.f();
+ }
+ var _iterator6 = _createForOfIteratorHelper(ufos),
+ _step6;
+ try {
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
+ var ufo = _step6.value;
+ if (ufo.active) {
+ ufo.speed /= _this4.effects.time.multiplier;
+ }
+ }
+ } catch (err) {
+ _iterator6.e(err);
+ } finally {
+ _iterator6.f();
+ }
+ }, this.effects.time.duration * 1000);
+ break;
+ }
+ // 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 _i7 = 0, _points = points; _i7 < _points.length; _i7++) {
+ var point = _points[_i7];
+ 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);
+/**
+* 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;
+ }
+ _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); // --- Cloud Class ---
+var Cloud = /*#__PURE__*/function (_GameObject5) {
+ function Cloud() {
+ var _this6;
+ _classCallCheck(this, Cloud);
+ var size = 32 + Math.floor(Math.random() * 96); // Random size between 32x32 and 128x128
+ var y = Math.random() * (LK.canvas.height - size);
+ _this6 = _callSuper(this, Cloud, [LK.canvas.width + size, y, size, size, 'cloud']);
+ _this6.speed = 10 + Math.random() * 20; // Random speed
+ _this6.parallaxLayer = Math.random(); // Random depth effect
+ return _this6;
+ }
+ _inherits(Cloud, _GameObject5);
+ return _createClass(Cloud, [{
+ key: "update",
+ value: function update(deltaTime) {
+ if (!this.active) {
+ return;
+ }
+ // Move cloud from right to left
+ this.x -= this.speed * this.parallaxLayer * deltaTime;
+ // Remove if off screen
+ if (this.x + this.width < 0) {
+ this.active = false;
+ }
+ }
+ }]);
+}(GameObject); // --- Game Functions ---
+// Create a sparkle effect
+function createSparkle(x, y, type) {
+ var sparkle = new Sparkle(x, y, type);
+ sparkles.push(sparkle);
+ return sparkle;
}
-function buyCat() {
- if (sparkleCount < 50) {
- addNotification('Not enough sparkles! Need 50');
- LK.play.sound('laser1');
- return;
+// Spawn a power-up
+function spawnPowerUp(x, y) {
+ var powerUp = new PowerUp(x, y);
+ powerUps.push(powerUp);
+ return powerUp;
+}
+// Level up function
+function levelUp() {
+ level++;
+ multiplier = 1 + (level - 1) * 0.1; // Increase multiplier by 0.1 per level
+ enemiesDefeated = 0;
+ // Create level up effect
+ for (var i = 0; i < 20; i++) {
+ createSparkle(LK.canvas.width / 2 + (Math.random() - 0.5) * 200, LK.canvas.height / 2 + (Math.random() - 0.5) * 200, 'levelup');
}
- sparkleCount -= 50;
- var newCat = {
- id: "cat-".concat(Date.now()),
- level: 1,
- sparkleRate: 1,
- upgradeCost: 50,
- position: {
- x: 0,
- y: 0,
- z: 0
- },
- image: LK.getAsset('catImage', {
- anchorX: 0.5,
- anchorY: 0.5
- }),
- // Assign image to cat
- label: new Text2("Cat ".concat(newCat.id), {
- size: 30,
- fill: 0xFFFFFF,
- fontFamily: "Arial, sans-serif"
- })
- };
- cats.push(newCat);
- LK.play.sound('songbird1');
- updateUI();
}
-function upgradeBranch(branchId) {
- var branch = branches.find(function (b) {
- return b.id === branchId;
- });
- if (!branch) {
- return;
+// --- Main Game Functions ---
+// Initialize game
+function initialize() {
+ // Set background color
+ LK.setBackgroundColor('#87CEEB'); // Sky blue
+ // Create initial cat
+ cats.push(new Cat(100, LK.canvas.height / 2));
+ // Initialize timers
+ lastUpdateTime = Date.now();
+ idlePointsLastCalculated = Date.now();
+ // Create initial clouds
+ for (var i = 0; i < 5; i++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * LK.canvas.width; // Position randomly across screen
+ clouds.push(cloud);
}
- if (sparkleCount < branch.upgradeCost) {
- addNotification("Not enough sparkles! Need ".concat(branch.upgradeCost));
- LK.play.sound('laser1');
- return;
+}
+// Update game state
+function update(deltaTime) {
+ // Update timers
+ var currentTime = Date.now();
+ deltaTime = (currentTime - lastUpdateTime) / 1000; // Convert to seconds
+ lastUpdateTime = currentTime;
+ // Calculate idle points
+ calculateIdlePoints();
+ // Spawn enemies based on timers
+ birdSpawnTimer += deltaTime * 1000;
+ if (birdSpawnTimer >= BIRD_SPAWN_INTERVAL / (1 + (level - 1) * 0.1) && birds.length < MAX_BIRDS) {
+ birds.push(new Bird());
+ birdSpawnTimer = 0;
}
- sparkleCount -= branch.upgradeCost;
- branches = branches.map(function (b) {
- if (b.id === branchId) {
- return _objectSpread(_objectSpread({}, b), {}, {
- level: b.level + 1,
- catCapacity: b.catCapacity + 1,
- upgradeCost: Math.floor(b.upgradeCost * 1.5)
- });
+ ufoSpawnTimer += deltaTime * 1000;
+ if (ufoSpawnTimer >= UFO_SPAWN_INTERVAL && ufos.length < MAX_UFOS && level % 5 === 0) {
+ ufos.push(new UFO());
+ ufoSpawnTimer = 0;
+ }
+ // Spawn clouds
+ cloudSpawnTimer += deltaTime * 1000;
+ if (cloudSpawnTimer >= CLOUD_SPAWN_INTERVAL && clouds.length < MAX_CLOUDS) {
+ spawnCloud();
+ cloudSpawnTimer = 0;
+ }
+ // Update all game objects
+ updateGameObjects(cats, deltaTime);
+ updateGameObjects(kittens, deltaTime);
+ updateGameObjects(birds, deltaTime);
+ updateGameObjects(ufos, deltaTime);
+ updateGameObjects(powerUps, deltaTime);
+ updateGameObjects(sparkles, deltaTime);
+ updateGameObjects(clouds, deltaTime);
+ // Clean up inactive objects
+ cleanupInactiveObjects();
+}
+// Update array of game objects
+function updateGameObjects(objects, deltaTime) {
+ for (var i = 0; i < objects.length; i++) {
+ if (objects[i].active) {
+ objects[i].update(deltaTime);
}
- return b;
+ }
+}
+// Clean up inactive objects
+function cleanupInactiveObjects() {
+ birds = birds.filter(function (obj) {
+ return obj.active;
});
- LK.play.sound('teslacoil');
- updateUI();
+ ufos = ufos.filter(function (obj) {
+ return obj.active;
+ });
+ powerUps = powerUps.filter(function (obj) {
+ return obj.active;
+ });
+ sparkles = sparkles.filter(function (obj) {
+ return obj.active;
+ });
+ clouds = clouds.filter(function (obj) {
+ return obj.active;
+ });
}
-function addNotification(message) {
- var newNotification = {
- id: Date.now(),
- message: message
- };
- notifications.push(newNotification);
- showNotification(message);
- // Auto-remove notification
- setTimeout(function () {
- notifications = notifications.filter(function (n) {
- return n.id !== newNotification.id;
- });
- }, 3000);
+// Render game
+function render() {
+ // Clear canvas
+ LK.clear();
+ // Render clouds (background)
+ renderGameObjects(clouds);
+ // Render game objects
+ renderGameObjects(cats);
+ renderGameObjects(kittens);
+ renderGameObjects(birds);
+ renderGameObjects(ufos);
+ renderGameObjects(powerUps);
+ renderGameObjects(sparkles);
+ // Render UI
+ renderUI();
}
-function showNotification(message) {
- var notificationEl = document.createElement('div');
- notificationEl.className = 'notification';
- notificationEl.textContent = message;
- notificationEl.style.position = 'fixed';
- notificationEl.style.bottom = '20px';
- notificationEl.style.left = '50%';
- notificationEl.style.transform = 'translateX(-50%)';
- notificationEl.style.padding = '10px 20px';
- notificationEl.style.background = 'rgba(255,0,0,0.7)';
- notificationEl.style.color = 'white';
- notificationEl.style.fontFamily = 'Arial, sans-serif';
- notificationEl.style.borderRadius = '5px';
- notificationEl.style.zIndex = '1000';
- notificationEl.style.opacity = '0';
- notificationEl.style.transition = 'opacity 0.3s';
- document.body.appendChild(notificationEl);
- // Fade in animation
- setTimeout(function () {
- notificationEl.style.opacity = '1';
- }, 10);
- // Fade out and remove after delay
- setTimeout(function () {
- notificationEl.style.opacity = '0';
- setTimeout(function () {
- notificationEl.remove();
- }, 300);
- }, 2700);
+// Render array of game objects
+function renderGameObjects(objects) {
+ for (var i = 0; i < objects.length; i++) {
+ if (objects[i].active) {
+ objects[i].render();
+ }
+ }
}
-function updateUI() {
- sparkleCountEl.textContent = "Sparkles: ".concat(sparkleCount);
+// Render UI elements
+function renderUI() {
+ // Score display
+ LK.setFillStyle('white');
+ LK.setFont('24px Arial');
+ LK.fillText("Score: ".concat(Math.floor(score)), LK.canvas.width / 2, 30, 'center');
+ // Level and multiplier
+ LK.setFont('18px Arial');
+ LK.fillText("Level: ".concat(level), LK.canvas.width - 80, 30, 'right');
+ LK.fillText("Multiplier: ".concat(multiplier.toFixed(1), "x"), LK.canvas.width / 2, 60, 'center');
+ // Enemies defeated counter
+ LK.fillText("Enemies: ".concat(enemiesDefeated, "/").concat(ENEMIES_PER_LEVEL), 80, 30, 'left');
+ // Idle points counter
+ LK.fillText("Idle Points: ".concat(Math.floor(idlePoints)), LK.canvas.width - 20, LK.canvas.height - 20, 'right');
}
-// Game loop
-var lastTime = 0;
-function gameLoop(timestamp) {
- var deltaTime = timestamp - lastTime;
- lastTime = timestamp;
- // Generate sparkles every 3 seconds
- if (deltaTime >= 3000) {
- generateSparkles();
- lastTime = timestamp;
+// Handle input events
+function handleInput(obj) {
+ var x = obj.x;
+ var y = obj.y;
+ // Check if clicked on a power-up
+ var _iterator7 = _createForOfIteratorHelper(powerUps),
+ _step7;
+ try {
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
+ var powerUp = _step7.value;
+ if (powerUp.active && x >= powerUp.x && x <= powerUp.x + powerUp.width && y >= powerUp.y && y <= powerUp.y + powerUp.height) {
+ // Collect power-up
+ powerUp.active = false;
+ // Apply to nearest defender
+ var closestDist = Infinity;
+ var closest = null;
+ var _iterator8 = _createForOfIteratorHelper(cats),
+ _step8;
+ try {
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
+ var cat = _step8.value;
+ var dist = distance(powerUp.x, powerUp.y, cat.x, cat.y);
+ if (dist < closestDist) {
+ closestDist = dist;
+ closest = cat;
+ }
+ }
+ } catch (err) {
+ _iterator8.e(err);
+ } finally {
+ _iterator8.f();
+ }
+ var _iterator9 = _createForOfIteratorHelper(kittens),
+ _step9;
+ try {
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
+ var kitten = _step9.value;
+ var dist = distance(powerUp.x, powerUp.y, kitten.x, kitten.y);
+ if (dist < closestDist) {
+ closestDist = dist;
+ closest = kitten;
+ }
+ }
+ } catch (err) {
+ _iterator9.e(err);
+ } finally {
+ _iterator9.f();
+ }
+ if (closest) {
+ powerUp.applyEffect(closest);
+ }
+ return;
+ }
+ }
+ // Place a new cat at the clicked position
+ } catch (err) {
+ _iterator7.e(err);
+ } finally {
+ _iterator7.f();
}
+ if (idlePoints >= 50) {
+ idlePoints -= 50;
+ cats.push(new Cat(x, y));
+ }
}
-// Cleanup
-function cleanup() {
- // Cleanup logic if needed
+// Main game loop
+function gameLoop() {
+ update(1 / 60); // 60 FPS
+ render();
}
// Start the game
-startGame();
\ No newline at end of file
+initialize();
+LK.on('pointerdown', handleInput);
+multiplier = 1.0 + (level - 1) * 0.1;
\ No newline at end of file
an orange and white cat facing away from the camera. the cat is sitting straight up and looking up, ready to pounce. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
remove black box
fluffy translucent cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bright sun with wincing cartoon face and a black eye. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a goofy ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red gaming reticle. Minimal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sunny day, hilly landscape. there is an alien invasion taking place in the distance. cities burning.
large AUTUMN SHADES tree with sparse bunches of leaves. branches are exposed, but the tree is tough and old.. true-color, realistic, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
glowing orange sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sideway view of a fighter jet. . . In-Game 2d asset. transparent background. horizontal. No shadows.
shiny purple and black attack ufo.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows