/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Cat = Container.expand(function () { var self = Container.call(this); self.mood = 'happy'; self.lastResponse = ''; // Cat body var body = self.attachAsset('cat_body', { anchorX: 0.5, anchorY: 1 }); // Cat head var head = self.attachAsset('cat_head', { anchorX: 0.5, anchorY: 0.5 }); head.y = -200; // Cat ears var leftEar = self.attachAsset('cat_ear', { anchorX: 0.5, anchorY: 1 }); leftEar.x = -60; leftEar.y = -280; var rightEar = self.attachAsset('cat_ear', { anchorX: 0.5, anchorY: 1 }); rightEar.x = 60; rightEar.y = -280; // Cat eyes var leftEye = self.attachAsset('cat_eye', { anchorX: 0.5, anchorY: 0.5 }); leftEye.x = -40; leftEye.y = -220; var rightEye = self.attachAsset('cat_eye', { anchorX: 0.5, anchorY: 0.5 }); rightEye.x = 40; rightEye.y = -220; // Cat nose var nose = self.attachAsset('cat_nose', { anchorX: 0.5, anchorY: 0.5 }); nose.y = -180; self.animate = function (type) { if (type === 'happy') { tween(head, { scaleX: 1.1, scaleY: 1.1 }, { duration: 300, easing: tween.easeOut }); tween(head, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeOut }); LK.getSound('purr').play(); } else if (type === 'excited') { tween(self, { y: self.y - 20 }, { duration: 200, easing: tween.easeOut }); tween(self, { y: self.y }, { duration: 200, easing: tween.easeIn }); LK.getSound('meow1').play(); } else if (type === 'thinking') { tween(head, { rotation: 0.2 }, { duration: 500, easing: tween.easeInOut }); tween(head, { rotation: -0.2 }, { duration: 500, easing: tween.easeInOut }); tween(head, { rotation: 0 }, { duration: 500, easing: tween.easeInOut }); } }; self.respond = function (message) { var response = generateResponse(message); self.lastResponse = response; // Determine animation based on message content var lowerMsg = message.toLowerCase(); if (lowerMsg.includes('good') || lowerMsg.includes('nice') || lowerMsg.includes('love')) { self.animate('happy'); } else if (lowerMsg.includes('play') || lowerMsg.includes('fun') || lowerMsg.includes('game')) { self.animate('excited'); } else { self.animate('thinking'); } showChatBubble(response); }; return self; }); var ChatBubble = Container.expand(function () { var self = Container.call(this); var bubble = self.attachAsset('chat_bubble', { anchorX: 0.5, anchorY: 1 }); var text = new Text2('', { size: 30, fill: 0xFFFFFF }); text.anchor.set(0.5, 0.5); text.y = -50; self.addChild(text); self.alpha = 0; self.show = function (message) { text.setText(message); // Adjust bubble size based on text length var textWidth = text.width + 40; var textHeight = text.height + 40; bubble.width = Math.max(textWidth, 200); bubble.height = Math.max(textHeight, 60); self.alpha = 0; tween(self, { alpha: 1 }, { duration: 300, easing: tween.easeOut }); LK.setTimeout(function () { tween(self, { alpha: 0 }, { duration: 500, easing: tween.easeIn }); }, 3000); }; return self; }); var Key = Container.expand(function (letter, x, y) { var self = Container.call(this); self.letter = letter; self.isPressed = false; var keyBg = self.attachAsset('key_normal', { anchorX: 0.5, anchorY: 0.5 }); var keyText = new Text2(letter, { size: 40, fill: 0x2C3E50 }); keyText.anchor.set(0.5, 0.5); self.addChild(keyText); self.x = x; self.y = y; self.press = function () { if (self.isPressed) return; self.isPressed = true; keyBg.removeFromParent(); keyBg = self.attachAsset('key_pressed', { anchorX: 0.5, anchorY: 0.5 }); self.addChildAt(keyBg, 0); LK.getSound('keypress').play(); LK.setTimeout(function () { self.release(); }, 150); }; self.release = function () { self.isPressed = false; keyBg.removeFromParent(); keyBg = self.attachAsset('key_normal', { anchorX: 0.5, anchorY: 0.5 }); self.addChildAt(keyBg, 0); }; self.down = function (x, y, obj) { self.press(); if (self.letter === 'SEND') { sendMessage(); } else if (self.letter === 'DEL') { deleteLastChar(); } else if (self.letter === 'SPACE') { addToMessage(' '); } else { addToMessage(self.letter); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x85C1E9 }); /**** * Game Code ****/ var currentMessage = ''; var messageHistory = []; var keys = []; var cat; var chatBubble; var messageDisplay; // Keyboard layout var keyboardLayout = [['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['Z', 'X', 'C', 'V', 'B', 'N', 'M', 'DEL'], ['SPACE', 'SEND']]; // Create keyboard background var keyboardBg = game.attachAsset('keyboard_bg', { anchorX: 0.5, anchorY: 1 }); keyboardBg.x = 1024; keyboardBg.y = 2732; // Create keyboard keys var startY = 2732 - 380; for (var row = 0; row < keyboardLayout.length; row++) { var rowKeys = keyboardLayout[row]; var keyY = startY + row * 90; var totalWidth = rowKeys.length * 130; var startX = (2048 - totalWidth) / 2 + 65; for (var col = 0; col < rowKeys.length; col++) { var keyX = startX + col * 130; var key = new Key(rowKeys[col], keyX, keyY); if (rowKeys[col] === 'SPACE') { key.width = 300; keyX = 1024; key.x = keyX; } else if (rowKeys[col] === 'SEND') { keyX = 1024 + 200; key.x = keyX; } keys.push(key); game.addChild(key); } } // Create cat cat = new Cat(); cat.x = 1024; cat.y = 1200; game.addChild(cat); // Create chat bubble chatBubble = new ChatBubble(); chatBubble.x = 1024; chatBubble.y = 800; game.addChild(chatBubble); // Create message display messageDisplay = new Text2('Type a message...', { size: 40, fill: 0x2C3E50 }); messageDisplay.anchor.set(0.5, 0.5); messageDisplay.x = 1024; messageDisplay.y = 1400; game.addChild(messageDisplay); function addToMessage(_char) { if (currentMessage.length < 50) { currentMessage += _char; updateMessageDisplay(); } } function deleteLastChar() { if (currentMessage.length > 0) { currentMessage = currentMessage.slice(0, -1); updateMessageDisplay(); } } function updateMessageDisplay() { if (currentMessage.length === 0) { messageDisplay.setText('Type a message...'); messageDisplay.alpha = 0.6; } else { messageDisplay.setText(currentMessage); messageDisplay.alpha = 1; } } function sendMessage() { if (currentMessage.length === 0) return; messageHistory.push(currentMessage); cat.respond(currentMessage); currentMessage = ''; updateMessageDisplay(); } function generateResponse(message) { var lowerMsg = message.toLowerCase(); var responses = []; if (lowerMsg.includes('hello') || lowerMsg.includes('hi')) { responses = ['Meow! Hello there!', 'Hi! Nice to meet you!', 'Purr... hello friend!']; } else if (lowerMsg.includes('how are you')) { responses = ['I\'m purr-fect!', 'Feeling great, meow!', 'I\'m having a paw-some day!']; } else if (lowerMsg.includes('play') || lowerMsg.includes('game')) { responses = ['Let\'s play! Meow!', 'I love games! What shall we play?', 'Pounce! I\'m ready to play!']; } else if (lowerMsg.includes('food') || lowerMsg.includes('eat')) { responses = ['Yum! I love tuna!', 'Meow! Food sounds great!', 'Purr... I\'m always hungry!']; } else if (lowerMsg.includes('love') || lowerMsg.includes('like')) { responses = ['Aww, I love you too!', 'Purr purr purr!', 'You make me so happy!']; } else if (lowerMsg.includes('cat') || lowerMsg.includes('kitty')) { responses = ['Yes, I\'m your virtual kitty!', 'Meow! That\'s me!', 'I\'m the best cat ever!']; } else if (lowerMsg.includes('sleep') || lowerMsg.includes('tired')) { responses = ['Zzz... cats love naps!', 'I could sleep for 16 hours!', 'Time for a cat nap!']; } else if (lowerMsg.includes('funny') || lowerMsg.includes('joke')) { responses = ['Why don\'t cats play poker? Too many cheetahs!', 'What do you call a cat magician? Abra-ca-tabby!', 'Meow meow! That\'s funny!']; } else { responses = ['Meow! Tell me more!', 'Interesting! Purr...', 'I understand! Meow!', 'That\'s cool! Purr purr!', 'Fascinating! What else?']; } return responses[Math.floor(Math.random() * responses.length)]; } function showChatBubble(message) { chatBubble.show(message); } // Make cat blink occasionally var blinkTimer = 0; game.update = function () { blinkTimer++; if (blinkTimer % 180 === 0) { // Every 3 seconds cat.animate('thinking'); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,346 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Cat = Container.expand(function () {
+ var self = Container.call(this);
+ self.mood = 'happy';
+ self.lastResponse = '';
+ // Cat body
+ var body = self.attachAsset('cat_body', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Cat head
+ var head = self.attachAsset('cat_head', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ head.y = -200;
+ // Cat ears
+ var leftEar = self.attachAsset('cat_ear', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ leftEar.x = -60;
+ leftEar.y = -280;
+ var rightEar = self.attachAsset('cat_ear', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ rightEar.x = 60;
+ rightEar.y = -280;
+ // Cat eyes
+ var leftEye = self.attachAsset('cat_eye', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ leftEye.x = -40;
+ leftEye.y = -220;
+ var rightEye = self.attachAsset('cat_eye', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rightEye.x = 40;
+ rightEye.y = -220;
+ // Cat nose
+ var nose = self.attachAsset('cat_nose', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ nose.y = -180;
+ self.animate = function (type) {
+ if (type === 'happy') {
+ tween(head, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(head, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ LK.getSound('purr').play();
+ } else if (type === 'excited') {
+ tween(self, {
+ y: self.y - 20
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ y: self.y
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ LK.getSound('meow1').play();
+ } else if (type === 'thinking') {
+ tween(head, {
+ rotation: 0.2
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
+ tween(head, {
+ rotation: -0.2
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
+ tween(head, {
+ rotation: 0
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
+ }
+ };
+ self.respond = function (message) {
+ var response = generateResponse(message);
+ self.lastResponse = response;
+ // Determine animation based on message content
+ var lowerMsg = message.toLowerCase();
+ if (lowerMsg.includes('good') || lowerMsg.includes('nice') || lowerMsg.includes('love')) {
+ self.animate('happy');
+ } else if (lowerMsg.includes('play') || lowerMsg.includes('fun') || lowerMsg.includes('game')) {
+ self.animate('excited');
+ } else {
+ self.animate('thinking');
+ }
+ showChatBubble(response);
+ };
+ return self;
+});
+var ChatBubble = Container.expand(function () {
+ var self = Container.call(this);
+ var bubble = self.attachAsset('chat_bubble', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ var text = new Text2('', {
+ size: 30,
+ fill: 0xFFFFFF
+ });
+ text.anchor.set(0.5, 0.5);
+ text.y = -50;
+ self.addChild(text);
+ self.alpha = 0;
+ self.show = function (message) {
+ text.setText(message);
+ // Adjust bubble size based on text length
+ var textWidth = text.width + 40;
+ var textHeight = text.height + 40;
+ bubble.width = Math.max(textWidth, 200);
+ bubble.height = Math.max(textHeight, 60);
+ self.alpha = 0;
+ tween(self, {
+ alpha: 1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ LK.setTimeout(function () {
+ tween(self, {
+ alpha: 0
+ }, {
+ duration: 500,
+ easing: tween.easeIn
+ });
+ }, 3000);
+ };
+ return self;
+});
+var Key = Container.expand(function (letter, x, y) {
+ var self = Container.call(this);
+ self.letter = letter;
+ self.isPressed = false;
+ var keyBg = self.attachAsset('key_normal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var keyText = new Text2(letter, {
+ size: 40,
+ fill: 0x2C3E50
+ });
+ keyText.anchor.set(0.5, 0.5);
+ self.addChild(keyText);
+ self.x = x;
+ self.y = y;
+ self.press = function () {
+ if (self.isPressed) return;
+ self.isPressed = true;
+ keyBg.removeFromParent();
+ keyBg = self.attachAsset('key_pressed', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChildAt(keyBg, 0);
+ LK.getSound('keypress').play();
+ LK.setTimeout(function () {
+ self.release();
+ }, 150);
+ };
+ self.release = function () {
+ self.isPressed = false;
+ keyBg.removeFromParent();
+ keyBg = self.attachAsset('key_normal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChildAt(keyBg, 0);
+ };
+ self.down = function (x, y, obj) {
+ self.press();
+ if (self.letter === 'SEND') {
+ sendMessage();
+ } else if (self.letter === 'DEL') {
+ deleteLastChar();
+ } else if (self.letter === 'SPACE') {
+ addToMessage(' ');
+ } else {
+ addToMessage(self.letter);
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x85C1E9
+});
+
+/****
+* Game Code
+****/
+var currentMessage = '';
+var messageHistory = [];
+var keys = [];
+var cat;
+var chatBubble;
+var messageDisplay;
+// Keyboard layout
+var keyboardLayout = [['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['Z', 'X', 'C', 'V', 'B', 'N', 'M', 'DEL'], ['SPACE', 'SEND']];
+// Create keyboard background
+var keyboardBg = game.attachAsset('keyboard_bg', {
+ anchorX: 0.5,
+ anchorY: 1
+});
+keyboardBg.x = 1024;
+keyboardBg.y = 2732;
+// Create keyboard keys
+var startY = 2732 - 380;
+for (var row = 0; row < keyboardLayout.length; row++) {
+ var rowKeys = keyboardLayout[row];
+ var keyY = startY + row * 90;
+ var totalWidth = rowKeys.length * 130;
+ var startX = (2048 - totalWidth) / 2 + 65;
+ for (var col = 0; col < rowKeys.length; col++) {
+ var keyX = startX + col * 130;
+ var key = new Key(rowKeys[col], keyX, keyY);
+ if (rowKeys[col] === 'SPACE') {
+ key.width = 300;
+ keyX = 1024;
+ key.x = keyX;
+ } else if (rowKeys[col] === 'SEND') {
+ keyX = 1024 + 200;
+ key.x = keyX;
+ }
+ keys.push(key);
+ game.addChild(key);
+ }
+}
+// Create cat
+cat = new Cat();
+cat.x = 1024;
+cat.y = 1200;
+game.addChild(cat);
+// Create chat bubble
+chatBubble = new ChatBubble();
+chatBubble.x = 1024;
+chatBubble.y = 800;
+game.addChild(chatBubble);
+// Create message display
+messageDisplay = new Text2('Type a message...', {
+ size: 40,
+ fill: 0x2C3E50
+});
+messageDisplay.anchor.set(0.5, 0.5);
+messageDisplay.x = 1024;
+messageDisplay.y = 1400;
+game.addChild(messageDisplay);
+function addToMessage(_char) {
+ if (currentMessage.length < 50) {
+ currentMessage += _char;
+ updateMessageDisplay();
+ }
+}
+function deleteLastChar() {
+ if (currentMessage.length > 0) {
+ currentMessage = currentMessage.slice(0, -1);
+ updateMessageDisplay();
+ }
+}
+function updateMessageDisplay() {
+ if (currentMessage.length === 0) {
+ messageDisplay.setText('Type a message...');
+ messageDisplay.alpha = 0.6;
+ } else {
+ messageDisplay.setText(currentMessage);
+ messageDisplay.alpha = 1;
+ }
+}
+function sendMessage() {
+ if (currentMessage.length === 0) return;
+ messageHistory.push(currentMessage);
+ cat.respond(currentMessage);
+ currentMessage = '';
+ updateMessageDisplay();
+}
+function generateResponse(message) {
+ var lowerMsg = message.toLowerCase();
+ var responses = [];
+ if (lowerMsg.includes('hello') || lowerMsg.includes('hi')) {
+ responses = ['Meow! Hello there!', 'Hi! Nice to meet you!', 'Purr... hello friend!'];
+ } else if (lowerMsg.includes('how are you')) {
+ responses = ['I\'m purr-fect!', 'Feeling great, meow!', 'I\'m having a paw-some day!'];
+ } else if (lowerMsg.includes('play') || lowerMsg.includes('game')) {
+ responses = ['Let\'s play! Meow!', 'I love games! What shall we play?', 'Pounce! I\'m ready to play!'];
+ } else if (lowerMsg.includes('food') || lowerMsg.includes('eat')) {
+ responses = ['Yum! I love tuna!', 'Meow! Food sounds great!', 'Purr... I\'m always hungry!'];
+ } else if (lowerMsg.includes('love') || lowerMsg.includes('like')) {
+ responses = ['Aww, I love you too!', 'Purr purr purr!', 'You make me so happy!'];
+ } else if (lowerMsg.includes('cat') || lowerMsg.includes('kitty')) {
+ responses = ['Yes, I\'m your virtual kitty!', 'Meow! That\'s me!', 'I\'m the best cat ever!'];
+ } else if (lowerMsg.includes('sleep') || lowerMsg.includes('tired')) {
+ responses = ['Zzz... cats love naps!', 'I could sleep for 16 hours!', 'Time for a cat nap!'];
+ } else if (lowerMsg.includes('funny') || lowerMsg.includes('joke')) {
+ responses = ['Why don\'t cats play poker? Too many cheetahs!', 'What do you call a cat magician? Abra-ca-tabby!', 'Meow meow! That\'s funny!'];
+ } else {
+ responses = ['Meow! Tell me more!', 'Interesting! Purr...', 'I understand! Meow!', 'That\'s cool! Purr purr!', 'Fascinating! What else?'];
+ }
+ return responses[Math.floor(Math.random() * responses.length)];
+}
+function showChatBubble(message) {
+ chatBubble.show(message);
+}
+// Make cat blink occasionally
+var blinkTimer = 0;
+game.update = function () {
+ blinkTimer++;
+ if (blinkTimer % 180 === 0) {
+ // Every 3 seconds
+ cat.animate('thinking');
+ }
+};
\ No newline at end of file