User prompt
# Cosmic Cat Tree Game Implementation Plan ## 1. Core Game Logic & Mechanics - Implement Bird movement patterns and spawning system - Complete Cat and Kitten charm mechanics with cooldowns - Add UFO collection behavior and automation - Create sparkle generation and collection system - Implement idle progression mechanics - Add tap interaction for tree sparkle burst
User prompt
# Cosmic Cat Tree Game Implementation Plan ## 1. Core Game Logic & Mechanics - Implement Bird movement patterns and spawning system - Complete Cat and Kitten charm mechanics with cooldowns - Add UFO collection behavior and automation - Create sparkle generation and collection system - Implement idle progression mechanics - Add tap interaction for tree sparkle burst ## 2. Animation System ### Particle Effects - Sparkle Dust generation and floating - Collection beam effects for UFOs - Charm effect particles - Tree tap burst effect - Sleeping cat Zzz particles ### Character Animations - Cat/Kitten idle animations (tail swish, ear twitch) - Bird flight and perching animations - UFO hovering and collection movements - Tree leaf shimmer effect ## 3. Game Object Methods ### Cat & Kitten - tryCharmBird(): Check nearby birds and attempt to charm them - getCharmRadius(): Define interaction range - handleCharmCooldown(): Manage charm timing - playIdleAnimation(): Handle random idle animations ### Bird - setRandomPosition(): Set starting position and target - update(): Handle movement towards tree - handleCharmed(): Manage charmed state and rewards - playFlightAnimation(): Control flight animations ### UFO - findNearestSparkle(): Locate closest collectible sparkle - moveToSparkle(): Navigate to target sparkle - collectSparkle(): Handle collection and rewards - playBeamEffect(): Show collection beam ### Sparkle - update(): Handle floating animation - handleCollection(): Manage collection state ## 4. Game Class Methods - spawnBirds(): Manage bird population - updateSparkles(): Handle sparkle lifecycle - createSparkle(): Generate new sparkles - handlePurchases(): Manage resource spending - updateUI(): Keep display current - saveGameState(): Store progress to localStorage - loadGameState(): Restore saved progress - initializeSoundSystem(): Set up audio management ## 5. Asset Management ### Visual Assets - Tree background with branch positions - Cat and kitten sprites with animation frames - Bird variants with flight animations - UFO design with beam effects - Sparkle and particle effect sprites - UI elements and upgrade icons ### Audio Assets - Background music - Bird chirp sounds - UFO hover and collection sounds - Sparkle collection effects - UI interaction sounds - Cat purring and meowing ## 6. Implementation Order 1. Set up basic game structure and asset loading 2. Implement core movement and positioning 3. Add basic animations and particle system 4. Implement charm mechanics and sparkle generation 5. Add UFO collection system 6. Integrate purchase and upgrade system 7. Implement save/load functionality 8. Add sound effects and background music 9. Polish animations and visual feedback 10. Balance gameplay mechanics and economy 11. Optimize performance and memory usage 12. Final testing and bug fixes
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {' Line Number: 158 āŖš” Consider importing and using the following plugins: @upit/storage.v1
User prompt
improve the ui
User prompt
continue
User prompt
refactor
User prompt
continue
User prompt
fill in any missing code.
User prompt
create classes for all assets that do not have one
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Maximum call stack size exceeded' in or related to this line: 'return false;' Line Number: 50
User prompt
Please fix the bug: 'Maximum call stack size exceeded' in or related to this line: 'return isLocalStorageAccessible() ? false : undefined;' Line Number: 50
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return false;' Line Number: 50
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return false;' Line Number: 50
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return typeof o;' Line Number: 135
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return typeof o;' Line Number: 131
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;' Line Number: 128
User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;' Line Number: 118
User prompt
ensure all shapes are initialized and used correctly.
User prompt
improve the ui layout
Code edit (1 edits merged)
Please save this source code
User prompt
improve the code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'createPlaceholderAsset(TREE_ASSET_ID, 0x8b4513, 5, LK.canvas.height * 0.6); // Brown Tree Trunk (adjust height as needed);' Line Number: 847
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'createPlaceholderAsset(TREE_ASSET_ID, 0x8b4513, 5, LK.canvas.height * 0.6); // Brown Tree Trunk (adjust height as needed);' Line Number: 845
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game objects in global scope function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _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 sparkles = []; var tree; var sparkleDust = 0; // Game parameters var GAME_CONFIG = { catCost: 10, kittenCost: 50, ufoCost: 200, catCharmPower: 1, kittenCharmPower: 3, catCharmInterval: 5000, kittenCharmInterval: 3000, ufoCollectSpeed: 150, ufoCollectRange: 100, birdSpawnInterval: 3000, maxBirds: 10 }; var Cat = /*#__PURE__*/function () { function Cat(x, y) { _classCallCheck(this, Cat); this.sprite = LK.getAsset('cat', { anchorX: 0.5, anchorY: 0.5 }); this.sprite.x = x; this.sprite.y = y; this.charmingCooldown = false; } return _createClass(Cat, [{ key: "getCharmRadius", value: function getCharmRadius() { return 100; } }, { key: "tryCharmBird", value: function tryCharmBird() { if (this.charmingCooldown) { return; } for (var _i = 0, _birds = birds; _i < _birds.length; _i++) { var bird = _birds[_i]; if (bird.charmed) { continue; } var dx = bird.sprite.x - this.sprite.x; var dy = bird.sprite.y - this.sprite.y; var distSq = dx * dx + dy * dy; if (distSq <= this.getCharmRadius() * this.getCharmRadius()) { var sparkleValue = bird.handleCharmed(); this.handleCharmCooldown(); // Create visual feedback for successful charm var charm = LK.getAsset('sparkle', { anchorX: 0.5, anchorY: 0.5 }); charm.x = bird.sprite.x; charm.y = bird.sprite.y; charm.alpha = 0.7; // Animate and remove the charm effect setTimeout(function () { charm.alpha = 0; setTimeout(function () { return LK.remove(charm); }, 500); }, 500); return sparkleValue; } } return 0; } }, { key: "handleCharmCooldown", value: function handleCharmCooldown() { var _this = this; this.charmingCooldown = true; setTimeout(function () { _this.charmingCooldown = false; }, GAME_CONFIG.catCharmInterval); } }, { key: "update", value: function update() { var sparkleValue = this.tryCharmBird(); if (sparkleValue > 0) { Game.instance.createSparkle(this.sprite.x, this.sprite.y, sparkleValue); } } }]); }(); var Kitten = /*#__PURE__*/function (_Cat) { function Kitten(x, y) { var _this2; _classCallCheck(this, Kitten); _this2 = _callSuper(this, Kitten, [x, y]); _this2.sprite = LK.getAsset('kitten', { anchorX: 0.5, anchorY: 0.5 }); return _this2; } _inherits(Kitten, _Cat); return _createClass(Kitten); }(Cat); var Bird = /*#__PURE__*/function () { function Bird() { _classCallCheck(this, Bird); this.sprite = LK.getAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); this.charmed = false; this.setRandomPosition(); } return _createClass(Bird, [{ key: "setRandomPosition", value: function setRandomPosition() { // Start from either side of screen this.sprite.x = Math.random() < 0.5 ? -50 : LK.width + 50; this.sprite.y = Math.random() * (LK.height * 0.6); // Target position near tree with more varied positions this.targetX = tree.x + (Math.random() * 400 - 200); this.targetY = tree.y - (Math.random() * 400 + 50); // Set random movement speed this.moveSpeed = 0.01 + Math.random() * 0.02; // Set random wobble for natural movement this.wobbleOffset = Math.random() * Math.PI * 2; this.wobbleSpeed = 1 + Math.random(); } }, { key: "update", value: function update() { if (this.charmed) { // Charmed birds slowly float upward with spiral motion this.sprite.y -= 0.5; this.sprite.x += Math.sin(Date.now() / 500) * 0.5; this.sprite.rotation += 0.02; this.sprite.alpha = Math.max(0.2, this.sprite.alpha - 0.001); // Remove bird when it's nearly invisible if (this.sprite.alpha <= 0.2) { var index = birds.indexOf(this); if (index > -1) { birds.splice(index, 1); LK.remove(this.sprite); } } return; } // Move towards target with wobble var dx = this.targetX - this.sprite.x; var dy = this.targetY - this.sprite.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 1) { // Add wobble to movement var wobble = Math.sin(this.wobbleOffset + Date.now() / 1000) * 5 * this.wobbleSpeed; this.sprite.x += dx * this.moveSpeed; this.sprite.y += dy * this.moveSpeed + wobble * 0.1; // Rotate bird based on movement direction var angle = Math.atan2(dy, dx); this.sprite.rotation = angle + Math.PI / 2; // Check if bird is too far from tree and remove it var distFromTree = Math.sqrt(Math.pow(this.sprite.x - tree.x, 2) + Math.pow(this.sprite.y - tree.y, 2)); if (distFromTree > LK.canvas.width) { var index = birds.indexOf(this); if (index > -1) { birds.splice(index, 1); LK.remove(this.sprite); } } } } }, { key: "handleCharmed", value: function handleCharmed() { var _this3 = this; if (this.charmed) { return 0; } this.charmed = true; // Visual feedback for charmed state this.sprite.tint = 0xFFAAFF; this.sprite.alpha = 0.8; // Remove bird after floating away setTimeout(function () { var index = birds.indexOf(_this3); if (index > -1) { birds.splice(index, 1); } }, 3000); return GAME_CONFIG.catCharmPower; } }]); }(); var UFO = /*#__PURE__*/function () { function UFO(x, y) { _classCallCheck(this, UFO); this.sprite = LK.getAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); this.sprite.x = x; this.sprite.y = y; this.targetSparkle = null; } return _createClass(UFO, [{ key: "findNearestSparkle", value: function findNearestSparkle() { var nearest = null; var minDist = Infinity; for (var _i2 = 0, _sparkles = sparkles; _i2 < _sparkles.length; _i2++) { var sparkle = _sparkles[_i2]; if (sparkle.targetedByUFO) { continue; } var dx = sparkle.sprite.x - this.sprite.x; var dy = sparkle.sprite.y - this.sprite.y; var distSq = dx * dx + dy * dy; if (distSq < minDist) { minDist = distSq; nearest = sparkle; } } return nearest; } }, { key: "moveToSparkle", value: function moveToSparkle() { if (!this.targetSparkle) { return; } var dx = this.targetSparkle.sprite.x - this.sprite.x; var dy = this.targetSparkle.sprite.y - this.sprite.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > GAME_CONFIG.ufoCollectRange) { this.sprite.x += dx / dist * GAME_CONFIG.ufoCollectSpeed * 0.016; this.sprite.y += dy / dist * GAME_CONFIG.ufoCollectSpeed * 0.016; // Rotate UFO based on movement direction this.sprite.rotation = Math.atan2(dy, dx) + Math.PI / 2; // Add collection beam effect when close if (dist < GAME_CONFIG.ufoCollectRange * 2) { var beam = LK.getAsset('beam', { anchorX: 0.5 }); beam.x = this.sprite.x; beam.y = this.sprite.y; beam.alpha = 0.3; beam.rotation = this.sprite.rotation; setTimeout(function () { LK.remove(beam); }, 100); } } else { this.collectSparkle(); } } }, { key: "collectSparkle", value: function collectSparkle() { if (!this.targetSparkle) { return; } sparkleDust += this.targetSparkle.value; var index = sparkles.indexOf(this.targetSparkle); if (index > -1) { sparkles.splice(index, 1); } this.targetSparkle = null; } }, { key: "update", value: function update() { if (!this.targetSparkle) { this.targetSparkle = this.findNearestSparkle(); if (this.targetSparkle) { this.targetSparkle.targetedByUFO = this; } } this.moveToSparkle(); } }]); }(); var Sparkle = /*#__PURE__*/function () { function Sparkle(x, y, value) { _classCallCheck(this, Sparkle); this.sprite = LK.getAsset('sparkle', { anchorX: 0.5, anchorY: 0.5 }); this.sprite.x = x; this.sprite.y = y; this.value = value; this.targetedByUFO = null; this.floatOffset = Math.random() * Math.PI * 2; this.floatSpeed = 1 + Math.random(); this.collected = false; } return _createClass(Sparkle, [{ key: "update", value: function update() { if (this.collected) { // Fade out collected sparkles this.sprite.alpha = Math.max(0, this.sprite.alpha - 0.05); if (this.sprite.alpha <= 0) { var index = sparkles.indexOf(this); if (index > -1) { sparkles.splice(index, 1); LK.remove(this.sprite); } } return; } // Floating animation this.sprite.y += Math.sin(this.floatOffset + Date.now() / 1000) * 0.5 * this.floatSpeed; // Gentle sparkle rotation this.sprite.rotation += 0.01 * this.floatSpeed; // Pulsing effect this.sprite.alpha = 0.7 + Math.sin(Date.now() / 500) * 0.3; } }, { key: "handleCollection", value: function handleCollection() { if (this.collected) { return false; } this.collected = true; return true; } }]); }(); var Game = /*#__PURE__*/function () { function Game() { _classCallCheck(this, Game); } return _createClass(Game, [{ key: "initialize", value: function initialize() { Game.instance = this; LK.backgroundColor = 0x87CEFA; // Set background color through LK // Ensure LK is initialized before accessing canvas if (!LK || !LK.canvas) { console.error('LK engine not properly initialized'); return; } // Reset all game arrays cats = []; kittens = []; birds = []; ufos = []; sparkles = []; this.setupTree(); this.setupInitialState(); this.setupEventListeners(); this.startBirdSpawner(); } }, { key: "startBirdSpawner", value: function startBirdSpawner() { setInterval(function () { if (birds.length < GAME_CONFIG.maxBirds) { birds.push(new Bird()); } }, GAME_CONFIG.birdSpawnInterval); } }, { key: "createSparkle", value: function createSparkle(x, y, value) { var sparkle = new Sparkle(x, y, value); sparkles.push(sparkle); } }, { key: "setupTree", value: function setupTree() { var _this4 = this; if (!LK || !LK.canvas) { return; } tree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 1 }); tree.x = LK.canvas.width / 2; tree.y = LK.canvas.height - 10; // Make tree interactive for sparkle generation tree.interactive = true; tree.on('pointerdown', function (obj) { var pos = scope.toLocal(obj.global); _this4.createSparkle(pos.x, pos.y, 1); }); } }, { key: "setupInitialState", value: function setupInitialState() { sparkleDust = 50; this.addCat(); this.addUFO(); } }, { key: "setupEventListeners", value: function setupEventListeners() { var _this5 = this; // Create UI buttons using LK var buttonStyle = { backgroundColor: 0x4CAF50, textColor: 0xFFFFFF }; var catButton = LK.CreateButton(_objectSpread(_objectSpread({ text: "Buy Cat (".concat(GAME_CONFIG.catCost, ")"), x: 10, y: 40, width: 120, height: 30 }, buttonStyle), {}, { pointerup: function pointerup() { return _this5.addCat(); }, scope: this })); var kittenButton = LK.CreateButton(_objectSpread(_objectSpread({ text: "Buy Kitten (".concat(GAME_CONFIG.kittenCost, ")"), x: 10, y: 80, width: 120, height: 30 }, buttonStyle), {}, { pointerup: function pointerup() { return _this5.addKitten(); }, scope: this })); var ufoButton = LK.CreateButton(_objectSpread(_objectSpread({ text: "Buy UFO (".concat(GAME_CONFIG.ufoCost, ")"), x: 10, y: 120, width: 120, height: 30 }, buttonStyle), {}, { pointerup: function pointerup() { return _this5.addUFO(); }, scope: this })); // Create sparkle dust counter this.sparkleDustText = LK.CreateText({ text: "Sparkle Dust: ".concat(sparkleDust), x: 10, y: 10, style: { fill: 0xFFFFFF, fontSize: 16 } }); } }, { key: "update", value: function update() { cats.forEach(function (cat) { return cat.update(); }); kittens.forEach(function (kitten) { return kitten.update(); }); birds.forEach(function (bird) { return bird.update(); }); ufos.forEach(function (ufo) { return ufo.update(); }); sparkles.forEach(function (sparkle) { return sparkle.update(); }); this.updateUI(); } }, { key: "addCat", value: function addCat() { if (sparkleDust >= GAME_CONFIG.catCost) { var cat = new Cat(tree.x + Math.random() * 100 - 50, tree.y - Math.random() * 100); cats.push(cat); sparkleDust -= GAME_CONFIG.catCost; this.updateUI(); } } }, { key: "addKitten", value: function addKitten() { if (sparkleDust >= GAME_CONFIG.kittenCost) { var kitten = new Kitten(tree.x + Math.random() * 100 - 50, tree.y - Math.random() * 100); kittens.push(kitten); sparkleDust -= GAME_CONFIG.kittenCost; this.updateUI(); } } }, { key: "addUFO", value: function addUFO() { if (sparkleDust >= GAME_CONFIG.ufoCost) { var ufo = new UFO(tree.x + Math.random() * 200 - 100, tree.y - Math.random() * 200); ufos.push(ufo); sparkleDust -= GAME_CONFIG.ufoCost; this.updateUI(); } } }, { key: "updateUI", value: function updateUI() { if (this.sparkleDustText) { this.sparkleDustText.text = "Sparkle Dust: ".concat(Math.floor(sparkleDust)); } } // Additional game methods... }]); }(); _defineProperty(Game, "instance", null);
===================================================================
--- original.js
+++ change.js
@@ -7,54 +7,30 @@
/****
* Game Code
****/
-var TREE_ASSET_ID = 'tree_graphic';
-// and destroyed in the global scope of `gamecode.js`. (Guideline 1)
-// Ensure that important variables, instances, arrays, and variables are created
-// --- Global Scope Variables ---
-/**
-* gamecode.js
-*
-* This file contains the core game logic for the Cosmic Cat Tree game.
-* It defines the game objects, their behaviors, and manages the overall game state
-* according to the provided plan and guidelines.
-*/
-if (!LK.Assets) {
- LK.Assets = {};
-}
-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;
+// Game objects in global scope
+function ownKeys(e, r) {
+ var t = Object.keys(e);
+ if (Object.getOwnPropertySymbols) {
+ var o = Object.getOwnPropertySymbols(e);
+ r && (o = o.filter(function (r) {
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
+ })), t.push.apply(t, o);
}
+ return t;
}
-function _iterableToArray(r) {
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) {
- return Array.from(r);
+function _objectSpread(e) {
+ for (var r = 1; r < arguments.length; r++) {
+ var t = null != arguments[r] ? arguments[r] : {};
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
+ _defineProperty(e, r, t[r]);
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
+ });
}
+ return e;
}
-function _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 _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
@@ -158,676 +134,515 @@
var kittens = [];
var birds = [];
var ufos = [];
var sparkles = [];
-// Game State Variables
-var sparkleCount = 0;
-var maxBirds = 10; // Maximum number of birds allowed on screen
-var birdSpawnTimer = 0;
-var birdSpawnInterval = 1.5; // Seconds between bird spawns
-var treePosition = {
- x: 0,
- y: 0
-}; // Center of the tree (set in Initialize Game)
-// UI Elements
-var sparkleCountText = null;
-var addKittenButton = null;
-// Add more UI elements for upgrades if needed
-// Constants
-var CAT_CHARM_RADIUS = 100;
-var CAT_CHARM_COOLDOWN = 2.0; // seconds
-var KITTEN_CHARM_RADIUS = 60;
-var KITTEN_CHARM_COOLDOWN = 3.0; // seconds
-var BIRD_SPEED = 50; // pixels per second
-var UFO_SPEED = 150; // pixels per second
-var SPARKLE_VALUE = 1;
-var KITTEN_COST = 10;
-// --- Asset IDs (Ensure these match the assets uploaded in the LK editor) ---
-var CAT_ASSET_ID = 'cat_graphic';
-var KITTEN_ASSET_ID = 'kitten_graphic';
-var BIRD_ASSET_ID = 'bird_graphic';
-var UFO_ASSET_ID = 'ufo_graphic';
-var SPARKLE_ASSET_ID = 'sparkle_graphic';
-// Optional tree graphic
-// const TREE_ASSET_ID = 'tree_graphic';
-// --- Utility Functions ---
-function distance(x1, y1, x2, y2) {
- var dx = x1 - x2;
- var dy = y1 - y2;
- return Math.sqrt(dx * dx + dy * dy);
-}
-// --- Game Object Classes --- (Guideline 2)
-/**
-* Base class for charming entities (Cats and Kittens)
-*/
-var Charmer = /*#__PURE__*/function () {
- function Charmer(assetId, x, y, charmRadius, charmCooldown) {
- _classCallCheck(this, Charmer);
- // Asset Retrieval & Positioning (Guideline 3, 13)
- this.sprite = LK.getAsset(assetId, {
+var tree;
+var sparkleDust = 0;
+// Game parameters
+var GAME_CONFIG = {
+ catCost: 10,
+ kittenCost: 50,
+ ufoCost: 200,
+ catCharmPower: 1,
+ kittenCharmPower: 3,
+ catCharmInterval: 5000,
+ kittenCharmInterval: 3000,
+ ufoCollectSpeed: 150,
+ ufoCollectRange: 100,
+ birdSpawnInterval: 3000,
+ maxBirds: 10
+};
+var Cat = /*#__PURE__*/function () {
+ function Cat(x, y) {
+ _classCallCheck(this, Cat);
+ this.sprite = LK.getAsset('cat', {
anchorX: 0.5,
anchorY: 0.5
});
this.sprite.x = x;
this.sprite.y = y;
- LK.add(this.sprite);
- this.charmRadius = charmRadius;
- this.charmCooldownTime = charmCooldown;
- this.charmTimer = 0; // Ready to charm immediately
- this.isCharmer = true; // Property to identify charmers
+ this.charmingCooldown = false;
}
- // Define interaction range (Plan 2)
- return _createClass(Charmer, [{
+ return _createClass(Cat, [{
key: "getCharmRadius",
value: function getCharmRadius() {
- return this.charmRadius;
+ return 100;
}
- // Manage charm timing (Plan 2)
}, {
- key: "handleCharmCooldown",
- value: function handleCharmCooldown(deltaTime) {
- if (this.charmTimer > 0) {
- this.charmTimer -= deltaTime;
- }
- }
- // Check nearby birds and attempt to charm them (Plan 2)
- }, {
key: "tryCharmBird",
value: function tryCharmBird() {
- if (this.charmTimer > 0) {
- return false; // Still on cooldown
+ if (this.charmingCooldown) {
+ return;
}
- for (var i = birds.length - 1; i >= 0; i--) {
- var bird = birds[i];
- if (!bird.isCharmed) {
- var dist = distance(this.sprite.x, this.sprite.y, bird.sprite.x, bird.sprite.y);
- if (dist <= this.getCharmRadius()) {
- bird.handleCharmed(); // Bird handles its state change and reward (sparkle)
- this.charmTimer = this.charmCooldownTime; // Reset cooldown
- // Optionally add visual feedback here (e.g., particle effect if available)
- return true; // Charmed a bird
- }
+ for (var _i = 0, _birds = birds; _i < _birds.length; _i++) {
+ var bird = _birds[_i];
+ if (bird.charmed) {
+ continue;
}
+ var dx = bird.sprite.x - this.sprite.x;
+ var dy = bird.sprite.y - this.sprite.y;
+ var distSq = dx * dx + dy * dy;
+ if (distSq <= this.getCharmRadius() * this.getCharmRadius()) {
+ var sparkleValue = bird.handleCharmed();
+ this.handleCharmCooldown();
+ // Create visual feedback for successful charm
+ var charm = LK.getAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ charm.x = bird.sprite.x;
+ charm.y = bird.sprite.y;
+ charm.alpha = 0.7;
+ // Animate and remove the charm effect
+ setTimeout(function () {
+ charm.alpha = 0;
+ setTimeout(function () {
+ return LK.remove(charm);
+ }, 500);
+ }, 500);
+ return sparkleValue;
+ }
}
- return false; // No bird charmed
+ return 0;
}
}, {
- key: "update",
- value: function update(deltaTime) {
- this.handleCharmCooldown(deltaTime);
- this.tryCharmBird(); // Attempt to charm every frame if cooldown is ready
+ key: "handleCharmCooldown",
+ value: function handleCharmCooldown() {
+ var _this = this;
+ this.charmingCooldown = true;
+ setTimeout(function () {
+ _this.charmingCooldown = false;
+ }, GAME_CONFIG.catCharmInterval);
}
}, {
- key: "destroy",
- value: function destroy() {
- LK.remove(this.sprite);
+ key: "update",
+ value: function update() {
+ var sparkleValue = this.tryCharmBird();
+ if (sparkleValue > 0) {
+ Game.instance.createSparkle(this.sprite.x, this.sprite.y, sparkleValue);
+ }
}
}]);
}();
-/**
-* Cat Class
-*/
-var Cat = /*#__PURE__*/function (_Charmer) {
- function Cat(x, y) {
- _classCallCheck(this, Cat);
- return _callSuper(this, Cat, [CAT_ASSET_ID, x, y, CAT_CHARM_RADIUS, CAT_CHARM_COOLDOWN]); // Cat-specific properties can be added here
- }
- // Cat-specific methods can be added here
- _inherits(Cat, _Charmer);
- return _createClass(Cat);
-}(Charmer);
-/**
-* Kitten Class
-*/
-var Kitten = /*#__PURE__*/function (_Charmer2) {
+var Kitten = /*#__PURE__*/function (_Cat) {
function Kitten(x, y) {
+ var _this2;
_classCallCheck(this, Kitten);
- return _callSuper(this, Kitten, [KITTEN_ASSET_ID, x, y, KITTEN_CHARM_RADIUS, KITTEN_CHARM_COOLDOWN]); // Kitten-specific properties can be added here
+ _this2 = _callSuper(this, Kitten, [x, y]);
+ _this2.sprite = LK.getAsset('kitten', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return _this2;
}
- // Kitten-specific methods can be added here
- _inherits(Kitten, _Charmer2);
+ _inherits(Kitten, _Cat);
return _createClass(Kitten);
-}(Charmer);
-/**
-* Bird Class
-*/
+}(Cat);
var Bird = /*#__PURE__*/function () {
function Bird() {
_classCallCheck(this, Bird);
- // Asset Retrieval (Guideline 3)
- this.sprite = LK.getAsset(BIRD_ASSET_ID, {
+ this.sprite = LK.getAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
- this.setRandomPosition(); // Set starting position and target (Plan 2)
- LK.add(this.sprite);
- this.speed = BIRD_SPEED + (Math.random() * 20 - 10); // Add slight speed variation
- this.isCharmed = false;
- this.targetX = treePosition.x;
- this.targetY = treePosition.y;
- this.toBeRemoved = false;
+ this.charmed = false;
+ this.setRandomPosition();
}
- // Set starting position and target (Plan 2)
return _createClass(Bird, [{
key: "setRandomPosition",
value: function setRandomPosition() {
- var side = Math.floor(Math.random() * 4);
- var edgeBuffer = 50; // Spawn slightly off-screen
- switch (side) {
- case 0:
- // Top
- this.sprite.x = Math.random() * LK.canvas.width;
- this.sprite.y = -edgeBuffer;
- break;
- case 1:
- // Right
- this.sprite.x = LK.canvas.width + edgeBuffer;
- this.sprite.y = Math.random() * LK.canvas.height;
- break;
- case 2:
- // Bottom
- this.sprite.x = Math.random() * LK.canvas.width;
- this.sprite.y = LK.canvas.height + edgeBuffer;
- break;
- case 3:
- // Left
- this.sprite.x = -edgeBuffer;
- this.sprite.y = Math.random() * LK.canvas.height;
- break;
- }
+ // Start from either side of screen
+ this.sprite.x = Math.random() < 0.5 ? -50 : LK.width + 50;
+ this.sprite.y = Math.random() * (LK.height * 0.6);
+ // Target position near tree with more varied positions
+ this.targetX = tree.x + (Math.random() * 400 - 200);
+ this.targetY = tree.y - (Math.random() * 400 + 50);
+ // Set random movement speed
+ this.moveSpeed = 0.01 + Math.random() * 0.02;
+ // Set random wobble for natural movement
+ this.wobbleOffset = Math.random() * Math.PI * 2;
+ this.wobbleSpeed = 1 + Math.random();
}
- // Handle movement towards tree (Plan 2)
}, {
key: "update",
- value: function update(deltaTime) {
- if (this.isCharmed || this.toBeRemoved) {
- // Potentially add a "falling" or "poof" animation here if possible
- // For now, charmed birds are handled instantly
+ value: function update() {
+ if (this.charmed) {
+ // Charmed birds slowly float upward with spiral motion
+ this.sprite.y -= 0.5;
+ this.sprite.x += Math.sin(Date.now() / 500) * 0.5;
+ this.sprite.rotation += 0.02;
+ this.sprite.alpha = Math.max(0.2, this.sprite.alpha - 0.001);
+ // Remove bird when it's nearly invisible
+ if (this.sprite.alpha <= 0.2) {
+ var index = birds.indexOf(this);
+ if (index > -1) {
+ birds.splice(index, 1);
+ LK.remove(this.sprite);
+ }
+ }
return;
}
+ // Move towards target with wobble
var dx = this.targetX - this.sprite.x;
var dy = this.targetY - this.sprite.y;
var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist < 5) {
- // Reached the tree (or close enough)
- this.toBeRemoved = true; // Mark for removal without reward
- } else {
- var moveX = dx / dist * this.speed * deltaTime;
- var moveY = dy / dist * this.speed * deltaTime;
- this.sprite.x += moveX;
- this.sprite.y += moveY;
- // Flip sprite based on direction
- this.sprite.scale.x = dx > 0 ? 1 : -1;
+ if (dist > 1) {
+ // Add wobble to movement
+ var wobble = Math.sin(this.wobbleOffset + Date.now() / 1000) * 5 * this.wobbleSpeed;
+ this.sprite.x += dx * this.moveSpeed;
+ this.sprite.y += dy * this.moveSpeed + wobble * 0.1;
+ // Rotate bird based on movement direction
+ var angle = Math.atan2(dy, dx);
+ this.sprite.rotation = angle + Math.PI / 2;
+ // Check if bird is too far from tree and remove it
+ var distFromTree = Math.sqrt(Math.pow(this.sprite.x - tree.x, 2) + Math.pow(this.sprite.y - tree.y, 2));
+ if (distFromTree > LK.canvas.width) {
+ var index = birds.indexOf(this);
+ if (index > -1) {
+ birds.splice(index, 1);
+ LK.remove(this.sprite);
+ }
+ }
}
}
- // Manage charmed state and rewards (Plan 2)
}, {
key: "handleCharmed",
value: function handleCharmed() {
- if (this.isCharmed) {
- return;
- } // Already charmed
- this.isCharmed = true;
- // Trigger sparkle generation (Plan 1)
- Game.Instance.createSparkle(this.sprite.x, this.sprite.y, SPARKLE_VALUE);
- this.toBeRemoved = true; // Mark for removal after being charmed
+ var _this3 = this;
+ if (this.charmed) {
+ return 0;
+ }
+ this.charmed = true;
+ // Visual feedback for charmed state
+ this.sprite.tint = 0xFFAAFF;
+ this.sprite.alpha = 0.8;
+ // Remove bird after floating away
+ setTimeout(function () {
+ var index = birds.indexOf(_this3);
+ if (index > -1) {
+ birds.splice(index, 1);
+ }
+ }, 3000);
+ return GAME_CONFIG.catCharmPower;
}
- }, {
- key: "destroy",
- value: function destroy() {
- LK.remove(this.sprite);
- }
}]);
}();
-/**
-* UFO Class
-*/
var UFO = /*#__PURE__*/function () {
function UFO(x, y) {
_classCallCheck(this, UFO);
- // Asset Retrieval (Guideline 3, 13)
- this.sprite = LK.getAsset(UFO_ASSET_ID, {
+ this.sprite = LK.getAsset('ufo', {
anchorX: 0.5,
anchorY: 0.5
});
this.sprite.x = x;
this.sprite.y = y;
- LK.add(this.sprite);
- this.speed = UFO_SPEED;
this.targetSparkle = null;
- this.isCollecting = false; // State flag
}
- // Locate closest collectible sparkle (Plan 2)
return _createClass(UFO, [{
key: "findNearestSparkle",
value: function findNearestSparkle() {
- var closestDist = Infinity;
var nearest = null;
- for (var _i = 0, _sparkles = sparkles; _i < _sparkles.length; _i++) {
- var sparkle = _sparkles[_i];
- if (!sparkle.isBeingCollected && !sparkle.isCollected) {
- var dist = distance(this.sprite.x, this.sprite.y, sparkle.sprite.x, sparkle.sprite.y);
- if (dist < closestDist) {
- closestDist = dist;
- nearest = sparkle;
- }
+ var minDist = Infinity;
+ for (var _i2 = 0, _sparkles = sparkles; _i2 < _sparkles.length; _i2++) {
+ var sparkle = _sparkles[_i2];
+ if (sparkle.targetedByUFO) {
+ continue;
}
+ var dx = sparkle.sprite.x - this.sprite.x;
+ var dy = sparkle.sprite.y - this.sprite.y;
+ var distSq = dx * dx + dy * dy;
+ if (distSq < minDist) {
+ minDist = distSq;
+ nearest = sparkle;
+ }
}
- if (nearest) {
- this.targetSparkle = nearest;
- this.targetSparkle.isBeingCollected = true; // Mark sparkle so other UFOs ignore it
- this.isCollecting = true;
- } else {
- this.targetSparkle = null;
- this.isCollecting = false;
- }
+ return nearest;
}
- // Navigate to target sparkle (Plan 2)
}, {
key: "moveToSparkle",
- value: function moveToSparkle(deltaTime) {
- if (!this.targetSparkle || this.targetSparkle.isCollected) {
- this.isCollecting = false;
- this.targetSparkle = null;
+ value: function moveToSparkle() {
+ if (!this.targetSparkle) {
return;
}
- var targetX = this.targetSparkle.sprite.x;
- var targetY = this.targetSparkle.sprite.y;
- var dx = targetX - this.sprite.x;
- var dy = targetY - this.sprite.y;
+ var dx = this.targetSparkle.sprite.x - this.sprite.x;
+ var dy = this.targetSparkle.sprite.y - this.sprite.y;
var dist = Math.sqrt(dx * dx + dy * dy);
- if (dist < 10) {
- // Close enough to collect
- this.collectSparkle();
+ if (dist > GAME_CONFIG.ufoCollectRange) {
+ this.sprite.x += dx / dist * GAME_CONFIG.ufoCollectSpeed * 0.016;
+ this.sprite.y += dy / dist * GAME_CONFIG.ufoCollectSpeed * 0.016;
+ // Rotate UFO based on movement direction
+ this.sprite.rotation = Math.atan2(dy, dx) + Math.PI / 2;
+ // Add collection beam effect when close
+ if (dist < GAME_CONFIG.ufoCollectRange * 2) {
+ var beam = LK.getAsset('beam', {
+ anchorX: 0.5
+ });
+ beam.x = this.sprite.x;
+ beam.y = this.sprite.y;
+ beam.alpha = 0.3;
+ beam.rotation = this.sprite.rotation;
+ setTimeout(function () {
+ LK.remove(beam);
+ }, 100);
+ }
} else {
- var moveX = dx / dist * this.speed * deltaTime;
- var moveY = dy / dist * this.speed * deltaTime;
- this.sprite.x += moveX;
- this.sprite.y += moveY;
- // Optional: Point UFO towards sparkle
- // this.sprite.rotation = Math.atan2(dy, dx);
+ this.collectSparkle();
}
}
- // Handle collection and rewards (Plan 2)
}, {
key: "collectSparkle",
value: function collectSparkle() {
- if (this.targetSparkle && !this.targetSparkle.isCollected) {
- var value = this.targetSparkle.handleCollection(); // Sparkle handles its removal
- Game.Instance.addSparkles(value); // Add to global count via Game method
- this.targetSparkle = null;
- this.isCollecting = false;
- // Optionally add visual feedback for collection
+ if (!this.targetSparkle) {
+ return;
}
+ sparkleDust += this.targetSparkle.value;
+ var index = sparkles.indexOf(this.targetSparkle);
+ if (index > -1) {
+ sparkles.splice(index, 1);
+ }
+ this.targetSparkle = null;
}
}, {
key: "update",
- value: function update(deltaTime) {
- if (!this.isCollecting) {
- this.findNearestSparkle(); // Look for a new target if not currently collecting
+ value: function update() {
+ if (!this.targetSparkle) {
+ this.targetSparkle = this.findNearestSparkle();
+ if (this.targetSparkle) {
+ this.targetSparkle.targetedByUFO = this;
+ }
}
- if (this.targetSparkle) {
- this.moveToSparkle(deltaTime); // Move towards target if one exists
- } else {
- // Optional: Add idle behavior (e.g., slow drift or patrol)
- // this.sprite.x += Math.sin(LK.Time.now * 0.5) * 0.5 * deltaTime * 60;
- }
+ this.moveToSparkle();
}
- }, {
- key: "destroy",
- value: function destroy() {
- LK.remove(this.sprite);
- }
}]);
}();
-/**
-* Sparkle Class
-*/
var Sparkle = /*#__PURE__*/function () {
function Sparkle(x, y, value) {
_classCallCheck(this, Sparkle);
- // Asset Retrieval (Guideline 3, 13)
- this.sprite = LK.getAsset(SPARKLE_ASSET_ID, {
+ this.sprite = LK.getAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
this.sprite.x = x;
this.sprite.y = y;
- LK.add(this.sprite);
this.value = value;
- this.isCollected = false;
- this.isBeingCollected = false; // Flag to prevent multiple UFOs targeting same sparkle
- this.lifeTimer = 0; // Used for animation
- this.floatAmplitude = 3;
- this.floatSpeed = 2;
+ this.targetedByUFO = null;
+ this.floatOffset = Math.random() * Math.PI * 2;
+ this.floatSpeed = 1 + Math.random();
+ this.collected = false;
}
- // Handle floating animation (Plan 2)
return _createClass(Sparkle, [{
key: "update",
- value: function update(deltaTime) {
- if (this.isCollected) {
+ value: function update() {
+ if (this.collected) {
+ // Fade out collected sparkles
+ this.sprite.alpha = Math.max(0, this.sprite.alpha - 0.05);
+ if (this.sprite.alpha <= 0) {
+ var index = sparkles.indexOf(this);
+ if (index > -1) {
+ sparkles.splice(index, 1);
+ LK.remove(this.sprite);
+ }
+ }
return;
}
- this.lifeTimer += deltaTime;
- // Simple vertical float
- this.sprite.y += Math.sin(this.lifeTimer * this.floatSpeed) * this.floatAmplitude * deltaTime;
- // Optional: Add slight drift, fade-out over time, etc.
+ // Floating animation
+ this.sprite.y += Math.sin(this.floatOffset + Date.now() / 1000) * 0.5 * this.floatSpeed;
+ // Gentle sparkle rotation
+ this.sprite.rotation += 0.01 * this.floatSpeed;
+ // Pulsing effect
+ this.sprite.alpha = 0.7 + Math.sin(Date.now() / 500) * 0.3;
}
- // Manage collection state (Plan 2)
}, {
key: "handleCollection",
value: function handleCollection() {
- if (this.isCollected) {
- return 0;
- } // Already collected
- this.isCollected = true;
- // Mark for removal in the main game loop
- this.destroy(); // Remove sprite immediately
- return this.value;
+ if (this.collected) {
+ return false;
+ }
+ this.collected = true;
+ return true;
}
- }, {
- key: "destroy",
- value: function destroy() {
- LK.remove(this.sprite);
- }
}]);
-}(); // --- Game Class ---
+}();
var Game = /*#__PURE__*/function () {
function Game() {
_classCallCheck(this, Game);
- Game.Instance = this; // Set static instance
- // Game initialization logic
}
- /**
- * Initialize Game
- * Called once when the game starts or resets.
- * Only set background color here directly. (Guideline 7)
- * Initialize global state, arrays, and create initial objects.
- */
return _createClass(Game, [{
- key: 'Initialize Game',
- value: function Initialize_Game() {
- console.log("Initializing Cosmic Cat Tree Game...");
- LK.backgroundColor = 0x1a1a2e; // Dark space blue
- // Reset Global State
- sparkleCount = 0;
- birdSpawnTimer = 0;
- treePosition = {
- x: LK.canvas.width / 2,
- y: LK.canvas.height / 2
- };
- // Create placeholder asset for the tree trunk after canvas dimensions are available
- // Create placeholder asset for the tree trunk after canvas dimensions are available
- createPlaceholderAsset(TREE_ASSET_ID, 0x8b4513, 5, LK.canvas.height * 0.6); // Brown Tree Trunk (adjust height as needed)
- // Clear existing objects from previous sessions (if any) - Belt and suspenders
- this.clearAllObjects();
- // Initialize Arrays
+ key: "initialize",
+ value: function initialize() {
+ Game.instance = this;
+ LK.backgroundColor = 0x87CEFA; // Set background color through LK
+ // Ensure LK is initialized before accessing canvas
+ if (!LK || !LK.canvas) {
+ console.error('LK engine not properly initialized');
+ return;
+ }
+ // Reset all game arrays
cats = [];
kittens = [];
birds = [];
ufos = [];
sparkles = [];
- // --- Create Initial Game Objects ---
- // Optional: Add a visual representation for the tree
- // try {
- // const treeSprite = LK.getAsset(TREE_ASSET_ID, 'The Cat Tree', 0.5, 1.0); // Anchor bottom-center
- // treeSprite.x = treePosition.x;
- // treeSprite.y = LK.canvas.height; // Place at bottom center
- // LK.add(treeSprite);
- // // Note: Tree isn't added to an array as it's static background element
- // } catch (e) {
- // console.warn("Tree asset not found or failed to load:", e);
- // }
- // Create the initial Cat (adjust position as needed)
- var initialCat = new Cat(treePosition.x, treePosition.y);
- cats.push(initialCat);
- // Create the initial UFO
- var initialUFO = new UFO(treePosition.x, treePosition.y - 150); // Start near the tree
- ufos.push(initialUFO);
- // --- Initialize UI ---
- this.setupUI();
- console.log("Game Initialized");
- console.log("Canvas dimensions:", LK.canvas.width, LK.canvas.height);
- console.log("Tree Position:", treePosition.x, treePosition.y);
+ this.setupTree();
+ this.setupInitialState();
+ this.setupEventListeners();
+ this.startBirdSpawner();
}
- /**
- * Setup UI Elements
- * Creates text displays and buttons.
- */
}, {
- key: "setupUI",
- value: function setupUI() {
- // Sparkle Counter Display
- sparkleCountText = LK.CreateText({
- text: "Sparkles: ".concat(sparkleCount),
- x: 10,
- y: 10,
- style: {
- fill: 0xFFFFFF,
- fontSize: 20
- },
- anchor: {
- x: 0,
- y: 0
- } // Anchor top-left
+ key: "startBirdSpawner",
+ value: function startBirdSpawner() {
+ setInterval(function () {
+ if (birds.length < GAME_CONFIG.maxBirds) {
+ birds.push(new Bird());
+ }
+ }, GAME_CONFIG.birdSpawnInterval);
+ }
+ }, {
+ key: "createSparkle",
+ value: function createSparkle(x, y, value) {
+ var sparkle = new Sparkle(x, y, value);
+ sparkles.push(sparkle);
+ }
+ }, {
+ key: "setupTree",
+ value: function setupTree() {
+ var _this4 = this;
+ if (!LK || !LK.canvas) {
+ return;
+ }
+ tree = LK.getAsset('tree', {
+ anchorX: 0.5,
+ anchorY: 1
});
- LK.add(sparkleCountText);
- // --- Purchase Button Example --- (Plan 3: handlePurchases)
- addKittenButton = LK.CreateButton({
- text: "Add Kitten (".concat(KITTEN_COST, ")"),
- x: LK.canvas.width - 10,
- y: 10,
- width: 150,
- height: 40,
- backgroundColor: 0x33aa33,
- textColor: 0xffffff,
- pointerup: this.handlePurchaseKitten,
- // Reference the handler method
- scope: this,
- // Ensure 'this' inside the handler refers to the Game instance
- anchor: {
- x: 1,
- y: 0
- } // Anchor top-right
+ tree.x = LK.canvas.width / 2;
+ tree.y = LK.canvas.height - 10;
+ // Make tree interactive for sparkle generation
+ tree.interactive = true;
+ tree.on('pointerdown', function (obj) {
+ var pos = scope.toLocal(obj.global);
+ _this4.createSparkle(pos.x, pos.y, 1);
});
- LK.add(addKittenButton);
}
- // Manage resource spending (Plan 3)
- // Event handler for the Add Kitten button (Guideline 8)
}, {
- key: "handlePurchaseKitten",
- value: function handlePurchaseKitten(obj) {
- // 'this' refers to the Game instance because scope was set
- // 'obj' contains event data if needed, but not used here
- console.log("Attempting to purchase kitten...");
- if (sparkleCount >= KITTEN_COST) {
- sparkleCount -= KITTEN_COST;
- this.updateUI(); // Update display immediately
- // Add a new kitten at a randomish position near the tree
- var angle = Math.random() * Math.PI * 2;
- var radius = 50 + Math.random() * 50; // Place 50-100 pixels from center
- var kx = treePosition.x + Math.cos(angle) * radius;
- var ky = treePosition.y + Math.sin(angle) * radius;
- var newKitten = new Kitten(kx, ky);
- kittens.push(newKitten);
- console.log("Kitten purchased!");
- } else {
- console.log("Not enough sparkles to purchase kitten.");
- // Optional: Add feedback like button changing color briefly
- }
+ key: "setupInitialState",
+ value: function setupInitialState() {
+ sparkleDust = 50;
+ this.addCat();
+ this.addUFO();
}
- /**
- * Update Game
- * Called every frame by the LK engine.
- * @param {number} deltaTime - Time elapsed since the last frame in seconds.
- */
}, {
- key: 'Update Game',
- value: function Update_Game(deltaTime) {
- // --- Update Game Logic ---
- // 1. Spawn Birds (Plan 3)
- this.spawnBirds(deltaTime);
- // 2. Update Cats & Kittens
- for (var _i2 = 0, _cats = cats; _i2 < _cats.length; _i2++) {
- var cat = _cats[_i2];
- cat.update(deltaTime);
- }
- for (var _i3 = 0, _kittens = kittens; _i3 < _kittens.length; _i3++) {
- var kitten = _kittens[_i3];
- kitten.update(deltaTime);
- }
- // 3. Update Birds (and handle removal)
- for (var i = birds.length - 1; i >= 0; i--) {
- var bird = birds[i];
- bird.update(deltaTime);
- if (bird.toBeRemoved) {
- bird.destroy();
- birds.splice(i, 1);
+ key: "setupEventListeners",
+ value: function setupEventListeners() {
+ var _this5 = this;
+ // Create UI buttons using LK
+ var buttonStyle = {
+ backgroundColor: 0x4CAF50,
+ textColor: 0xFFFFFF
+ };
+ var catButton = LK.CreateButton(_objectSpread(_objectSpread({
+ text: "Buy Cat (".concat(GAME_CONFIG.catCost, ")"),
+ x: 10,
+ y: 40,
+ width: 120,
+ height: 30
+ }, buttonStyle), {}, {
+ pointerup: function pointerup() {
+ return _this5.addCat();
+ },
+ scope: this
+ }));
+ var kittenButton = LK.CreateButton(_objectSpread(_objectSpread({
+ text: "Buy Kitten (".concat(GAME_CONFIG.kittenCost, ")"),
+ x: 10,
+ y: 80,
+ width: 120,
+ height: 30
+ }, buttonStyle), {}, {
+ pointerup: function pointerup() {
+ return _this5.addKitten();
+ },
+ scope: this
+ }));
+ var ufoButton = LK.CreateButton(_objectSpread(_objectSpread({
+ text: "Buy UFO (".concat(GAME_CONFIG.ufoCost, ")"),
+ x: 10,
+ y: 120,
+ width: 120,
+ height: 30
+ }, buttonStyle), {}, {
+ pointerup: function pointerup() {
+ return _this5.addUFO();
+ },
+ scope: this
+ }));
+ // Create sparkle dust counter
+ this.sparkleDustText = LK.CreateText({
+ text: "Sparkle Dust: ".concat(sparkleDust),
+ x: 10,
+ y: 10,
+ style: {
+ fill: 0xFFFFFF,
+ fontSize: 16
}
- }
- // 4. Update UFOs
- for (var _i4 = 0, _ufos = ufos; _i4 < _ufos.length; _i4++) {
- var ufo = _ufos[_i4];
- ufo.update(deltaTime);
- }
- // 5. Update Sparkles (and handle removal) (Plan 3: updateSparkles)
- // Although individual sparkles update, we check for collected ones here
- for (var i = sparkles.length - 1; i >= 0; i--) {
- var sparkle = sparkles[i];
- if (sparkle.isCollected) {
- // Sparkle.destroy() already called LK.remove
- sparkles.splice(i, 1);
- } else {
- sparkle.update(deltaTime); // Handle animation
- }
- }
- // 6. Update UI (Plan 3) - Done periodically or when values change
- // This is called frequently, consider optimizing if performance issues arise
- // this.updateUI(); // Called when sparkleCount changes instead for efficiency
+ });
}
- /**
- * Cleans up all game objects. Called before Initialize Game on reset.
- */
}, {
- key: "clearAllObjects",
- value: function clearAllObjects() {
- console.log("Clearing objects...");
- [].concat(_toConsumableArray(cats), _toConsumableArray(kittens), _toConsumableArray(birds), _toConsumableArray(ufos), _toConsumableArray(sparkles)).forEach(function (obj) {
- return obj.destroy();
+ key: "update",
+ value: function update() {
+ cats.forEach(function (cat) {
+ return cat.update();
});
- cats = [];
- kittens = [];
- birds = [];
- ufos = [];
- sparkles = [];
- // Remove UI elements explicitly if they exist
- if (sparkleCountText) {
- LK.remove(sparkleCountText);
- }
- if (addKittenButton) {
- LK.remove(addKittenButton);
- }
- sparkleCountText = null;
- addKittenButton = null;
- console.log("Objects cleared.");
+ kittens.forEach(function (kitten) {
+ return kitten.update();
+ });
+ birds.forEach(function (bird) {
+ return bird.update();
+ });
+ ufos.forEach(function (ufo) {
+ return ufo.update();
+ });
+ sparkles.forEach(function (sparkle) {
+ return sparkle.update();
+ });
+ this.updateUI();
}
- // --- Game Class Helper Methods ---
- // Manage bird population (Plan 3)
}, {
- key: "spawnBirds",
- value: function spawnBirds(deltaTime) {
- birdSpawnTimer += deltaTime;
- if (birdSpawnTimer >= birdSpawnInterval && birds.length < maxBirds) {
- birdSpawnTimer = 0; // Reset timer
- var newBird = new Bird();
- birds.push(newBird);
+ key: "addCat",
+ value: function addCat() {
+ if (sparkleDust >= GAME_CONFIG.catCost) {
+ var cat = new Cat(tree.x + Math.random() * 100 - 50, tree.y - Math.random() * 100);
+ cats.push(cat);
+ sparkleDust -= GAME_CONFIG.catCost;
+ this.updateUI();
}
}
- // Generate new sparkles (Plan 3) - Called by Bird.handleCharmed
}, {
- key: "createSparkle",
- value: function createSparkle(x, y, value) {
- var newSparkle = new Sparkle(x, y, value);
- sparkles.push(newSparkle);
+ key: "addKitten",
+ value: function addKitten() {
+ if (sparkleDust >= GAME_CONFIG.kittenCost) {
+ var kitten = new Kitten(tree.x + Math.random() * 100 - 50, tree.y - Math.random() * 100);
+ kittens.push(kitten);
+ sparkleDust -= GAME_CONFIG.kittenCost;
+ this.updateUI();
+ }
}
- // Method to add sparkles to the global count (called by UFO)
}, {
- key: "addSparkles",
- value: function addSparkles(amount) {
- sparkleCount += amount;
- this.updateUI(); // Update UI when count changes
+ key: "addUFO",
+ value: function addUFO() {
+ if (sparkleDust >= GAME_CONFIG.ufoCost) {
+ var ufo = new UFO(tree.x + Math.random() * 200 - 100, tree.y - Math.random() * 200);
+ ufos.push(ufo);
+ sparkleDust -= GAME_CONFIG.ufoCost;
+ this.updateUI();
+ }
}
- // Keep display current (Plan 3)
}, {
key: "updateUI",
value: function updateUI() {
- if (sparkleCountText) {
- sparkleCountText.text = "Sparkles: ".concat(sparkleCount);
+ if (this.sparkleDustText) {
+ this.sparkleDustText.text = "Sparkle Dust: ".concat(Math.floor(sparkleDust));
}
- if (addKittenButton) {
- // Update button text/state if needed (e.g., disable if too poor)
- addKittenButton.setText("Add Kitten (".concat(KITTEN_COST, ")"));
- addKittenButton.button.disabled = sparkleCount < KITTEN_COST; // Example of disabling
- addKittenButton.button.backgroundColor = sparkleCount < KITTEN_COST ? 0x888888 : 0x33aa33;
- }
- // Update other UI elements as needed
}
- /**
- * Draw Foreground
- * Called after Update Game. Used for drawing elements on top of sprites.
- * Not typically used if UI elements cover needs.
- */
- // 'Draw Foreground'() {
- // }
- /**
- * Draw Background
- * Called before Update Game. Used for background elements.
- * Avoid adding backgrounds unless specifically requested (Guideline 4).
- */
- // 'Draw Background'() {
- // }
+ // Additional game methods...
}]);
-}(); // Attach the Game class to the global LK context
-// Static instance holder
-_defineProperty(Game, "Instance", null);
-LK.Game = Game;
-// --- Asset Definitions ---
-// IMPORTANT: Make sure these IDs match the assets uploaded in the LK Editor
-// and the constants defined at the top of the file. (Guideline 4)
-// Example Asset Definitions (Replace with actual asset details)
-// LK.Assets['assets/cat.png'] = { id: CAT_ASSET_ID, frameWidth: 64, frameHeight: 64, frameTags: {} };
-// LK.Assets['assets/kitten.png'] = { id: KITTEN_ASSET_ID, frameWidth: 48, frameHeight: 48, frameTags: {} };
-// LK.Assets['assets/bird.png'] = { id: BIRD_ASSET_ID, frameWidth: 32, frameHeight: 32, frameTags: {} };
-// LK.Assets['assets/ufo.png'] = { id: UFO_ASSET_ID, frameWidth: 80, frameHeight: 40, frameTags: {} };
-// LK.Assets['assets/sparkle.png'] = { id: SPARKLE_ASSET_ID, frameWidth: 16, frameHeight: 16, frameTags: {} };
-// LK.Assets['assets/tree.png'] = { id: TREE_ASSET_ID, frameWidth: 200, frameHeight: 400, frameTags: {} };
-// Placeholder assets if actual graphics aren't available - REMOVE IF USING REAL ASSETS
-// Using simple squares as placeholders if real assets aren't loaded
-function createPlaceholderAsset(id, color, width, height) {
- if (!LK.Assets[id]) {
- // Only create if not already defined (e.g., by uploaded assets)
- var shape;
- var shape;
- var tex = LK.getAsset(id, {
- width: width,
- height: height,
- color: color,
- shape: 'box'
- }); // Generate texture for LK
- LK.Assets[id] = {
- id: id,
- texture: tex,
- frameWidth: width,
- frameHeight: height,
- frameTags: {}
- };
- console.log("Created placeholder asset for ".concat(id));
- }
-}
-createPlaceholderAsset(CAT_ASSET_ID, 0xffccaa, 50, 50); // Beige Cat
-createPlaceholderAsset(KITTEN_ASSET_ID, 0xffebcc, 35, 35); // Lighter Beige Kitten
-createPlaceholderAsset(BIRD_ASSET_ID, 0xadd8e6, 25, 20); // Light Blue Bird
-createPlaceholderAsset(UFO_ASSET_ID, 0xcccccc, 60, 30); // Grey UFO
-createPlaceholderAsset(SPARKLE_ASSET_ID, 0xffff00, 10, 10); // Yellow Sparkle
-createPlaceholderAsset(TREE_ASSET_ID, 0x8b4513, 5, 300); // Brown Tree Trunk (simple line)
-createPlaceholderAsset(SPARKLE_ASSET_ID, 0xffff00, 10, 10); // Yellow Sparkle
-createPlaceholderAsset(TREE_ASSET_ID, 0x8b4513, 5, LK.canvas.height * 0.6); // Brown Tree Trunk (adjust height as needed);
\ No newline at end of file
+}();
+_defineProperty(Game, "instance", null);
\ 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
wings1
Sound effect
ufo1
Sound effect
cricket1
Sound effect
frog1
Sound effect
bgm1
Music
breeze1
Sound effect
songbird1
Sound effect
laser1
Sound effect
teslacoil
Sound effect
chitter
Sound effect
laser2
Sound effect
dead1
Sound effect
electro
Sound effect