/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Hangman drawing class var HangmanDrawing = Container.expand(function () { var self = Container.call(this); // Gallows var base = self.attachAsset('gallows_base', { anchorX: 0.5, anchorY: 1, x: 0, y: 0 }); var pole = self.attachAsset('gallows_pole', { anchorX: 0.5, anchorY: 1, x: 0, y: -base.height }); // Create beam first at a temporary position to access its dimensions var beam = self.attachAsset('gallows_beam', { anchorX: 0, anchorY: 1, x: 0, y: 0 }); // Now set the correct position using pole and base dimensions beam.x = pole.width / 2; beam.y = -base.height - pole.height + beam.height / 2; var rope = self.attachAsset('gallows_rope', { anchorX: 0.5, anchorY: 0, x: beam.x + beam.width - 40, y: beam.y - beam.height / 2 }); // Hangman parts (hidden initially) var head = self.attachAsset('hangman_head', { anchorX: 0.5, anchorY: 0, x: rope.x, y: rope.y + rope.height }); var body = self.attachAsset('hangman_body', { anchorX: 0.5, anchorY: 0, x: head.x, y: head.y + head.height }); var leftArm = self.attachAsset('hangman_arm', { anchorX: 1, anchorY: 0.5, x: body.x, y: body.y + body.height * 0.2, rotation: -Math.PI / 4 }); var rightArm = self.attachAsset('hangman_arm', { anchorX: 0, anchorY: 0.5, x: body.x, y: body.y + body.height * 0.2, rotation: Math.PI / 4 }); var leftLeg = self.attachAsset('hangman_leg', { anchorX: 1, anchorY: 0.5, x: body.x, y: body.y + body.height, rotation: -Math.PI / 4 }); var rightLeg = self.attachAsset('hangman_leg', { anchorX: 0, anchorY: 0.5, x: body.x, y: body.y + body.height, rotation: Math.PI / 4 }); // Store parts in order of appearance self.parts = [head, body, leftArm, rightArm, leftLeg, rightLeg]; // Hide all hangman parts initially for (var i = 0; i < self.parts.length; ++i) { self.parts[i].visible = false; } // Show up to n parts self.showParts = function (n) { for (var i = 0; i < self.parts.length; ++i) { self.parts[i].visible = i < n; } }; // Reset drawing self.reset = function () { self.showParts(0); }; return self; }); // Letter button class with beautiful layered design var LetterButton = Container.expand(function () { var self = Container.call(this); // Default: not used self.used = false; self.letter = ''; self.isPressed = false; // Create layered button appearance var btnBg = self.attachAsset('letter_btn_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0 }); var btnMain = self.attachAsset('letter_btn_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -2 }); var btnHighlight = self.attachAsset('letter_btn_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -4 }); // Store original positions for animation self.originalY = self.y; btnMain.originalY = btnMain.y; btnHighlight.originalY = btnHighlight.y; // Letter text with shadow effect var txtShadow = new Text2('', { size: 68, fill: '#000044' }); txtShadow.anchor.set(0.5, 0.5); txtShadow.x = 2; txtShadow.y = 2; self.addChild(txtShadow); var txt = new Text2('', { size: 68, fill: '#ffffff' }); txt.anchor.set(0.5, 0.5); txt.x = 0; txt.y = -2; self.addChild(txt); // Set letter self.setLetter = function (letter) { self.letter = letter; txt.setText(letter); txtShadow.setText(letter); }; // Mark as used with smooth transition self.setUsed = function () { self.used = true; // Animate button press and fade tween(self, { y: self.y + 6 }, { duration: 150 }); tween(btnMain, { y: btnMain.y + 4 }, { duration: 150 }); tween(btnHighlight, { y: btnHighlight.y + 6 }, { duration: 150 }); tween(txt, { y: txt.y + 4 }, { duration: 150 }); tween(txtShadow, { y: txtShadow.y + 4 }, { duration: 150 }); // After animation, replace with used appearance LK.setTimeout(function () { btnBg.destroy(); btnMain.destroy(); btnHighlight.destroy(); var usedBg = self.attachAsset('letter_btn_used_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 6 }); var usedMain = self.attachAsset('letter_btn_used_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 4 }); var usedHighlight = self.attachAsset('letter_btn_used_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 2 }); txt.fill = '#aaaaaa'; txtShadow.fill = '#333333'; }, 150); }; // Touch events with press animation self.down = function (x, y, obj) { if (self.used || self.isPressed) { return; } self.isPressed = true; // Play button press sound LK.getSound('button').play(); // Animate button press tween(self, { y: self.y + 4 }, { duration: 100 }); tween(btnMain, { y: btnMain.y + 2 }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.y + 4 }, { duration: 100 }); tween(txt, { y: txt.y + 2 }, { duration: 100 }); tween(txtShadow, { y: txtShadow.y + 2 }, { duration: 100 }); }; self.up = function (x, y, obj) { if (self.used || !self.isPressed) { return; } self.isPressed = false; // Animate button release tween(self, { y: self.originalY }, { duration: 100 }); tween(btnMain, { y: btnMain.originalY }, { duration: 100 }); tween(btnHighlight, { y: btnHighlight.originalY }, { duration: 100 }); tween(txt, { y: txt.y - 2 }, { duration: 100 }); tween(txtShadow, { y: txtShadow.y - 2 }, { duration: 100 }); if (typeof self.onSelect === 'function') { self.onSelect(self.letter, self); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222244 }); /**** * Game Code ****/ // Word list (all uppercase, no spaces) // Hangman parts: head, body, left arm, right arm, left leg, right leg, gallows base, pole, beam, rope // Letter button asset var WORDS = ["APPLE", "BANANA", "ORANGE", "ELEPHANT", "GUITAR", "PYTHON", "JAZZ", "ROCKET", "PLANET", "MONKEY", "UMBRELLA", "VIOLET", "ZEBRA", "KANGAROO", "BICYCLE", "CIRCUS", "DIAMOND", "FROG", "HAMBURGER", "ISLAND"]; // Game state variables var currentWord = ''; var revealed = []; var wrongGuesses = 0; var maxWrong = 6; // 6 hangman parts var guessedLetters = []; var correctLetters = []; var wrongLetters = []; var letterButtons = []; var hangmanDrawing = null; var wordDisplay = null; var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''); var wordY = 650; var hangmanX = 200; var hangmanY = 900; var letterGridY = 1800; var claudeHelpUsed = false; // Track if Claude help has been used this game // Score display (win/loss count) var winCount = 0; var lossCount = 0; var winTxt = new Text2('Wins 0', { size: 100, fill: '#00ff88', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); winTxt.anchor.set(0, 0); LK.gui.top.addChild(winTxt); var lossTxt = new Text2('Losses 0', { size: 100, fill: '#ff4444', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); lossTxt.anchor.set(1, 0); LK.gui.topRight.addChild(lossTxt); // Helper: pick a random word function pickWord() { var idx = Math.floor(Math.random() * WORDS.length); return WORDS[idx]; } // Helper: update word display function updateWordDisplay() { var s = ''; for (var i = 0; i < revealed.length; ++i) { s += revealed[i] ? currentWord[i] : '_'; if (i < revealed.length - 1) { s += ' '; } } wordDisplay.setText(s); } // Helper: update win/loss text function updateScoreDisplay() { winTxt.setText('Wins ' + winCount); lossTxt.setText('Losses ' + lossCount); } // Helper: update letter displays function updateLetterDisplays() { var correctText = ''; for (var i = 0; i < correctLetters.length; ++i) { correctText += correctLetters[i]; if (i < correctLetters.length - 1) { correctText += ' '; } } correctLettersText.setText(correctText || '---'); var wrongText = ''; for (var i = 0; i < wrongLetters.length; ++i) { wrongText += wrongLetters[i]; if (i < wrongLetters.length - 1) { wrongText += ' '; } } wrongLettersText.setText(wrongText || '---'); } // Start a new game function startGame() { // Remove old letter buttons for (var i = 0; i < letterButtons.length; ++i) { letterButtons[i].destroy(); } letterButtons = []; guessedLetters = []; correctLetters = []; wrongLetters = []; wrongGuesses = 0; claudeHelpUsed = false; // Reset Claude help for new game // Pick word currentWord = pickWord(); revealed = []; for (var i = 0; i < currentWord.length; ++i) { revealed.push(false); } // Set subject/category text // Simple subject detection based on word var fruits = ["APPLE", "BANANA", "ORANGE"]; var animals = ["ELEPHANT", "MONKEY", "ZEBRA", "KANGAROO", "FROG"]; var objects = ["GUITAR", "PYTHON", "JAZZ", "ROCKET", "PLANET", "UMBRELLA", "VIOLET", "BICYCLE", "CIRCUS", "DIAMOND", "HAMBURGER", "ISLAND"]; var subject = "Word"; if (fruits.indexOf(currentWord) !== -1) { subject = "Fruit"; } else if (animals.indexOf(currentWord) !== -1) { subject = "Animal"; } else if (objects.indexOf(currentWord) !== -1) { subject = "Object"; } subjectDisplay.setText("Subject: " + subject); // Update word display updateWordDisplay(); // Reset hangman hangmanDrawing.reset(); // Create beautiful keyboard layout (A-Z, optimized rows) var keyboardRows = [['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']]; var btnSize = 140; var spacingX = 20; var spacingY = 25; var startY = letterGridY; for (var row = 0; row < keyboardRows.length; ++row) { var rowLetters = keyboardRows[row]; var rowWidth = rowLetters.length * btnSize + (rowLetters.length - 1) * spacingX; var startX = (2048 - rowWidth) / 2 + btnSize / 2; // Offset middle and bottom rows slightly for natural keyboard feel if (row === 1) { startX += btnSize / 4; } if (row === 2) { startX += btnSize / 2; } for (var col = 0; col < rowLetters.length; ++col) { var btn = new LetterButton(); btn.setLetter(rowLetters[col]); btn.x = startX + col * (btnSize + spacingX); btn.y = startY + row * (btnSize + spacingY); btn.originalY = btn.y; // Letter select handler btn.onSelect = onLetterSelected; game.addChild(btn); letterButtons.push(btn); } } } // Letter selected handler function onLetterSelected(letter, btn) { // Mark as used btn.setUsed(); guessedLetters.push(letter); // Check if letter is in word var found = false; for (var i = 0; i < currentWord.length; ++i) { if (currentWord[i] === letter) { revealed[i] = true; found = true; } } updateWordDisplay(); if (found) { // Add to correct letters correctLetters.push(letter); // Play correct letter sound LK.getSound('correct').play(); // Check win var allRevealed = true; for (var i = 0; i < revealed.length; ++i) { if (!revealed[i]) { allRevealed = false; break; } } if (allRevealed) { winCount += 1; updateScoreDisplay(); LK.effects.flashScreen(0x00ff00, 800); // Play win sound LK.getSound('win').play(); LK.showYouWin(); } } else { // Wrong guess wrongLetters.push(letter); wrongGuesses += 1; // Play wrong letter sound LK.getSound('wrong').play(); hangmanDrawing.showParts(wrongGuesses); if (wrongGuesses >= maxWrong) { lossCount += 1; updateScoreDisplay(); LK.effects.flashScreen(0xff0000, 800); // Play game over sound LK.getSound('gameover').play(); // Reveal word for (var i = 0; i < revealed.length; ++i) { revealed[i] = true; } updateWordDisplay(); // Death animation for hangman // Animate the head tilting (death pose) tween(hangmanDrawing.parts[0], { rotation: Math.PI / 6 // Tilt head to the right }, { duration: 800, easing: tween.easeOut }); // Animate the body swaying slightly tween(hangmanDrawing.parts[1], { rotation: Math.PI / 12 // Slight body rotation }, { duration: 1000, easing: tween.easeInOut }); // Animate arms dropping down tween(hangmanDrawing.parts[2], { rotation: -Math.PI / 2 // Left arm drops down }, { duration: 600, easing: tween.easeOut }); tween(hangmanDrawing.parts[3], { rotation: Math.PI / 2 // Right arm drops down }, { duration: 650, easing: tween.easeOut }); // Fade out the entire hangman slightly to show death tween(hangmanDrawing, { alpha: 0.7 }, { duration: 1200, easing: tween.easeOut, onFinish: function onFinish() { // Show game over after animation completes LK.showGameOver(); } }); } } // Update letter displays updateLetterDisplays(); // Reset Claude help button resetClaudeButton(); } // Create hangman drawing hangmanDrawing = new HangmanDrawing(); hangmanDrawing.x = hangmanX; hangmanDrawing.y = hangmanY; game.addChild(hangmanDrawing); // Create subject/category display var subjectDisplay = new Text2('', { size: 90, fill: '#ffff99' }); subjectDisplay.anchor.set(0.5, 0.5); subjectDisplay.x = 2048 / 2 + 120; subjectDisplay.y = wordY - 120; game.addChild(subjectDisplay); // Create word display wordDisplay = new Text2('', { size: 140, fill: '#ffffff' }); wordDisplay.anchor.set(0.5, 0.5); wordDisplay.x = 2048 / 2 + 120; wordDisplay.y = wordY; game.addChild(wordDisplay); // Create correct letters display with better styling var correctLettersDisplay = new Text2('✓ Correct Letters', { size: 90, fill: '#00ff88', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); correctLettersDisplay.anchor.set(0.5, 0.5); correctLettersDisplay.x = 2048 / 4; correctLettersDisplay.y = 1400; game.addChild(correctLettersDisplay); // Create wrong letters display with better styling var wrongLettersDisplay = new Text2('✗ Wrong Letters', { size: 90, fill: '#ff4444', font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" }); wrongLettersDisplay.anchor.set(0.5, 0.5); wrongLettersDisplay.x = 2048 / 4 * 3; wrongLettersDisplay.y = 1400; game.addChild(wrongLettersDisplay); // Create actual letter display areas var correctLettersText = new Text2('', { size: 70, fill: '#88ffaa' }); correctLettersText.anchor.set(0.5, 0); correctLettersText.x = 2048 / 4; correctLettersText.y = 1460; game.addChild(correctLettersText); var wrongLettersText = new Text2('', { size: 70, fill: '#ffaaaa' }); wrongLettersText.anchor.set(0.5, 0); wrongLettersText.x = 2048 / 4 * 3; wrongLettersText.y = 1460; game.addChild(wrongLettersText); // Create Claude AI help button var claudeHelpBtn = new Container(); var claudeBg = claudeHelpBtn.attachAsset('letter_btn_bg', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 2.5, scaleY: 1.2 }); var claudeMain = claudeHelpBtn.attachAsset('letter_btn_main', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -2, scaleX: 2.4, scaleY: 1.1 }); var claudeHighlight = claudeHelpBtn.attachAsset('letter_btn_highlight', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -4, scaleX: 2.3, scaleY: 1.0 }); var claudeText = new Text2('Glaud', { size: 75, fill: '#00ddff' }); claudeText.anchor.set(0.5, 0.5); claudeText.x = 0; claudeText.y = -2; claudeHelpBtn.addChild(claudeText); // Position Claude button below keyboard claudeHelpBtn.x = 2048 / 2; claudeHelpBtn.y = letterGridY + 500; game.addChild(claudeHelpBtn); // Claude button functionality claudeHelpBtn.down = function (x, y, obj) { // Play button press sound LK.getSound('button').play(); // Animate button press tween(claudeHelpBtn, { y: claudeHelpBtn.y + 4 }, { duration: 100 }); tween(claudeMain, { y: claudeMain.y + 2 }, { duration: 100 }); tween(claudeHighlight, { y: claudeHighlight.y + 4 }, { duration: 100 }); tween(claudeText, { y: claudeText.y + 2 }, { duration: 100 }); }; claudeHelpBtn.up = function (x, y, obj) { // Check if help has already been used this game if (claudeHelpUsed) { // Flash red to indicate help already used LK.effects.flashScreen(0x440000, 300); return; } // Animate button release tween(claudeHelpBtn, { y: claudeHelpBtn.y - 4 }, { duration: 100 }); tween(claudeMain, { y: claudeMain.y - 2 }, { duration: 100 }); tween(claudeHighlight, { y: claudeHighlight.y - 4 }, { duration: 100 }); tween(claudeText, { y: claudeText.y - 2 }, { duration: 100 }); // Find a correct letter that hasn't been guessed yet var availableCorrectLetters = []; for (var i = 0; i < currentWord.length; ++i) { var letter = currentWord[i]; if (guessedLetters.indexOf(letter) === -1) { availableCorrectLetters.push(letter); } } if (availableCorrectLetters.length > 0) { // Mark help as used claudeHelpUsed = true; // Play help sound LK.getSound('help').play(); // Change button appearance to indicate it's been used claudeText.setText('Perfect'); claudeText.fill = '#666666'; tween(claudeHelpBtn, { alpha: 0.5 }, { duration: 300 }); // Pick a random correct letter var randomIndex = Math.floor(Math.random() * availableCorrectLetters.length); var suggestedLetter = availableCorrectLetters[randomIndex]; // Find and activate the corresponding button for (var i = 0; i < letterButtons.length; ++i) { var btn = letterButtons[i]; if (btn.letter === suggestedLetter && !btn.used) { // Flash the button to highlight it LK.effects.flashObject(btn, 0x00ff00, 500); // Auto-select the letter after a short delay LK.setTimeout(function () { onLetterSelected(suggestedLetter, btn); }, 600); break; } } // Flash screen green to indicate help LK.effects.flashScreen(0x004400, 300); } }; // Function to reset Claude button appearance function resetClaudeButton() { claudeText.setText('Close'); claudeText.fill = '#00ddff'; claudeHelpBtn.alpha = 1; } // Start first game startGame(); // On game reset, start a new game game.on('reset', function () { startGame(); });
===================================================================
--- original.js
+++ change.js
@@ -96,50 +96,183 @@
self.showParts(0);
};
return self;
});
-// Letter button class
+// Letter button class with beautiful layered design
var LetterButton = Container.expand(function () {
var self = Container.call(this);
// Default: not used
self.used = false;
self.letter = '';
- // Button background
- var btn = self.attachAsset('letter_btn', {
+ self.isPressed = false;
+ // Create layered button appearance
+ var btnBg = self.attachAsset('letter_btn_bg', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
- // Letter text
+ var btnMain = self.attachAsset('letter_btn_main', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -2
+ });
+ var btnHighlight = self.attachAsset('letter_btn_highlight', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -4
+ });
+ // Store original positions for animation
+ self.originalY = self.y;
+ btnMain.originalY = btnMain.y;
+ btnHighlight.originalY = btnHighlight.y;
+ // Letter text with shadow effect
+ var txtShadow = new Text2('', {
+ size: 68,
+ fill: '#000044'
+ });
+ txtShadow.anchor.set(0.5, 0.5);
+ txtShadow.x = 2;
+ txtShadow.y = 2;
+ self.addChild(txtShadow);
var txt = new Text2('', {
- size: 64,
+ size: 68,
fill: '#ffffff'
});
txt.anchor.set(0.5, 0.5);
txt.x = 0;
- txt.y = 0;
+ txt.y = -2;
self.addChild(txt);
// Set letter
self.setLetter = function (letter) {
self.letter = letter;
txt.setText(letter);
+ txtShadow.setText(letter);
};
- // Mark as used
+ // Mark as used with smooth transition
self.setUsed = function () {
self.used = true;
- btn.destroy();
- // Replace with used button asset
- var usedBtn = self.attachAsset('letter_btn_used', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 0,
- y: 0
+ // Animate button press and fade
+ tween(self, {
+ y: self.y + 6
+ }, {
+ duration: 150
});
+ tween(btnMain, {
+ y: btnMain.y + 4
+ }, {
+ duration: 150
+ });
+ tween(btnHighlight, {
+ y: btnHighlight.y + 6
+ }, {
+ duration: 150
+ });
+ tween(txt, {
+ y: txt.y + 4
+ }, {
+ duration: 150
+ });
+ tween(txtShadow, {
+ y: txtShadow.y + 4
+ }, {
+ duration: 150
+ });
+ // After animation, replace with used appearance
+ LK.setTimeout(function () {
+ btnBg.destroy();
+ btnMain.destroy();
+ btnHighlight.destroy();
+ var usedBg = self.attachAsset('letter_btn_used_bg', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 6
+ });
+ var usedMain = self.attachAsset('letter_btn_used_main', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 4
+ });
+ var usedHighlight = self.attachAsset('letter_btn_used_highlight', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 2
+ });
+ txt.fill = '#aaaaaa';
+ txtShadow.fill = '#333333';
+ }, 150);
};
- // Touch event
+ // Touch events with press animation
self.down = function (x, y, obj) {
- if (self.used) return;
+ if (self.used || self.isPressed) {
+ return;
+ }
+ self.isPressed = true;
+ // Play button press sound
+ LK.getSound('button').play();
+ // Animate button press
+ tween(self, {
+ y: self.y + 4
+ }, {
+ duration: 100
+ });
+ tween(btnMain, {
+ y: btnMain.y + 2
+ }, {
+ duration: 100
+ });
+ tween(btnHighlight, {
+ y: btnHighlight.y + 4
+ }, {
+ duration: 100
+ });
+ tween(txt, {
+ y: txt.y + 2
+ }, {
+ duration: 100
+ });
+ tween(txtShadow, {
+ y: txtShadow.y + 2
+ }, {
+ duration: 100
+ });
+ };
+ self.up = function (x, y, obj) {
+ if (self.used || !self.isPressed) {
+ return;
+ }
+ self.isPressed = false;
+ // Animate button release
+ tween(self, {
+ y: self.originalY
+ }, {
+ duration: 100
+ });
+ tween(btnMain, {
+ y: btnMain.originalY
+ }, {
+ duration: 100
+ });
+ tween(btnHighlight, {
+ y: btnHighlight.originalY
+ }, {
+ duration: 100
+ });
+ tween(txt, {
+ y: txt.y - 2
+ }, {
+ duration: 100
+ });
+ tween(txtShadow, {
+ y: txtShadow.y - 2
+ }, {
+ duration: 100
+ });
if (typeof self.onSelect === 'function') {
self.onSelect(self.letter, self);
}
};
@@ -155,38 +288,43 @@
/****
* Game Code
****/
-// Letter button asset
-// Hangman parts: head, body, left arm, right arm, left leg, right leg, gallows base, pole, beam, rope
// Word list (all uppercase, no spaces)
+// Hangman parts: head, body, left arm, right arm, left leg, right leg, gallows base, pole, beam, rope
+// Letter button asset
var WORDS = ["APPLE", "BANANA", "ORANGE", "ELEPHANT", "GUITAR", "PYTHON", "JAZZ", "ROCKET", "PLANET", "MONKEY", "UMBRELLA", "VIOLET", "ZEBRA", "KANGAROO", "BICYCLE", "CIRCUS", "DIAMOND", "FROG", "HAMBURGER", "ISLAND"];
// Game state variables
var currentWord = '';
var revealed = [];
var wrongGuesses = 0;
var maxWrong = 6; // 6 hangman parts
var guessedLetters = [];
+var correctLetters = [];
+var wrongLetters = [];
var letterButtons = [];
var hangmanDrawing = null;
var wordDisplay = null;
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
var wordY = 650;
-var hangmanX = 400;
+var hangmanX = 200;
var hangmanY = 900;
var letterGridY = 1800;
+var claudeHelpUsed = false; // Track if Claude help has been used this game
// Score display (win/loss count)
var winCount = 0;
var lossCount = 0;
-var winTxt = new Text2('Wins: 0', {
- size: 80,
- fill: '#aaffaa'
+var winTxt = new Text2('Wins 0', {
+ size: 100,
+ fill: '#00ff88',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
winTxt.anchor.set(0, 0);
LK.gui.top.addChild(winTxt);
-var lossTxt = new Text2('Losses: 0', {
- size: 80,
- fill: '#ffaaaa'
+var lossTxt = new Text2('Losses 0', {
+ size: 100,
+ fill: '#ff4444',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
lossTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(lossTxt);
// Helper: pick a random word
@@ -198,26 +336,50 @@
function updateWordDisplay() {
var s = '';
for (var i = 0; i < revealed.length; ++i) {
s += revealed[i] ? currentWord[i] : '_';
- if (i < revealed.length - 1) s += ' ';
+ if (i < revealed.length - 1) {
+ s += ' ';
+ }
}
wordDisplay.setText(s);
}
// Helper: update win/loss text
function updateScoreDisplay() {
- winTxt.setText('Wins: ' + winCount);
- lossTxt.setText('Losses: ' + lossCount);
+ winTxt.setText('Wins ' + winCount);
+ lossTxt.setText('Losses ' + lossCount);
}
+// Helper: update letter displays
+function updateLetterDisplays() {
+ var correctText = '';
+ for (var i = 0; i < correctLetters.length; ++i) {
+ correctText += correctLetters[i];
+ if (i < correctLetters.length - 1) {
+ correctText += ' ';
+ }
+ }
+ correctLettersText.setText(correctText || '---');
+ var wrongText = '';
+ for (var i = 0; i < wrongLetters.length; ++i) {
+ wrongText += wrongLetters[i];
+ if (i < wrongLetters.length - 1) {
+ wrongText += ' ';
+ }
+ }
+ wrongLettersText.setText(wrongText || '---');
+}
// Start a new game
function startGame() {
// Remove old letter buttons
for (var i = 0; i < letterButtons.length; ++i) {
letterButtons[i].destroy();
}
letterButtons = [];
guessedLetters = [];
+ correctLetters = [];
+ wrongLetters = [];
wrongGuesses = 0;
+ claudeHelpUsed = false; // Reset Claude help for new game
// Pick word
currentWord = pickWord();
revealed = [];
for (var i = 0; i < currentWord.length; ++i) {
@@ -228,34 +390,48 @@
var fruits = ["APPLE", "BANANA", "ORANGE"];
var animals = ["ELEPHANT", "MONKEY", "ZEBRA", "KANGAROO", "FROG"];
var objects = ["GUITAR", "PYTHON", "JAZZ", "ROCKET", "PLANET", "UMBRELLA", "VIOLET", "BICYCLE", "CIRCUS", "DIAMOND", "HAMBURGER", "ISLAND"];
var subject = "Word";
- if (fruits.indexOf(currentWord) !== -1) subject = "Fruit";else if (animals.indexOf(currentWord) !== -1) subject = "Animal";else if (objects.indexOf(currentWord) !== -1) subject = "Object";
+ if (fruits.indexOf(currentWord) !== -1) {
+ subject = "Fruit";
+ } else if (animals.indexOf(currentWord) !== -1) {
+ subject = "Animal";
+ } else if (objects.indexOf(currentWord) !== -1) {
+ subject = "Object";
+ }
subjectDisplay.setText("Subject: " + subject);
// Update word display
updateWordDisplay();
// Reset hangman
hangmanDrawing.reset();
- // Create letter buttons (A-Z, 7 per row)
- var cols = 7;
- var rows = Math.ceil(alphabet.length / cols);
- var btnSize = 120;
- var spacing = 30;
- var gridWidth = cols * btnSize + (cols - 1) * spacing;
- var startX = (2048 - gridWidth) / 2 + btnSize / 2;
+ // Create beautiful keyboard layout (A-Z, optimized rows)
+ var keyboardRows = [['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']];
+ var btnSize = 140;
+ var spacingX = 20;
+ var spacingY = 25;
var startY = letterGridY;
- for (var i = 0; i < alphabet.length; ++i) {
- var btn = new LetterButton();
- btn.setLetter(alphabet[i]);
- // Position in grid
- var col = i % cols;
- var row = Math.floor(i / cols);
- btn.x = startX + col * (btnSize + spacing);
- btn.y = startY + row * (btnSize + spacing);
- // Letter select handler
- btn.onSelect = onLetterSelected;
- game.addChild(btn);
- letterButtons.push(btn);
+ for (var row = 0; row < keyboardRows.length; ++row) {
+ var rowLetters = keyboardRows[row];
+ var rowWidth = rowLetters.length * btnSize + (rowLetters.length - 1) * spacingX;
+ var startX = (2048 - rowWidth) / 2 + btnSize / 2;
+ // Offset middle and bottom rows slightly for natural keyboard feel
+ if (row === 1) {
+ startX += btnSize / 4;
+ }
+ if (row === 2) {
+ startX += btnSize / 2;
+ }
+ for (var col = 0; col < rowLetters.length; ++col) {
+ var btn = new LetterButton();
+ btn.setLetter(rowLetters[col]);
+ btn.x = startX + col * (btnSize + spacingX);
+ btn.y = startY + row * (btnSize + spacingY);
+ btn.originalY = btn.y;
+ // Letter select handler
+ btn.onSelect = onLetterSelected;
+ game.addChild(btn);
+ letterButtons.push(btn);
+ }
}
}
// Letter selected handler
function onLetterSelected(letter, btn) {
@@ -271,8 +447,12 @@
}
}
updateWordDisplay();
if (found) {
+ // Add to correct letters
+ correctLetters.push(letter);
+ // Play correct letter sound
+ LK.getSound('correct').play();
// Check win
var allRevealed = true;
for (var i = 0; i < revealed.length; ++i) {
if (!revealed[i]) {
@@ -283,26 +463,75 @@
if (allRevealed) {
winCount += 1;
updateScoreDisplay();
LK.effects.flashScreen(0x00ff00, 800);
+ // Play win sound
+ LK.getSound('win').play();
LK.showYouWin();
}
} else {
// Wrong guess
+ wrongLetters.push(letter);
wrongGuesses += 1;
+ // Play wrong letter sound
+ LK.getSound('wrong').play();
hangmanDrawing.showParts(wrongGuesses);
if (wrongGuesses >= maxWrong) {
lossCount += 1;
updateScoreDisplay();
LK.effects.flashScreen(0xff0000, 800);
+ // Play game over sound
+ LK.getSound('gameover').play();
// Reveal word
for (var i = 0; i < revealed.length; ++i) {
revealed[i] = true;
}
updateWordDisplay();
- LK.showGameOver();
+ // Death animation for hangman
+ // Animate the head tilting (death pose)
+ tween(hangmanDrawing.parts[0], {
+ rotation: Math.PI / 6 // Tilt head to the right
+ }, {
+ duration: 800,
+ easing: tween.easeOut
+ });
+ // Animate the body swaying slightly
+ tween(hangmanDrawing.parts[1], {
+ rotation: Math.PI / 12 // Slight body rotation
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ // Animate arms dropping down
+ tween(hangmanDrawing.parts[2], {
+ rotation: -Math.PI / 2 // Left arm drops down
+ }, {
+ duration: 600,
+ easing: tween.easeOut
+ });
+ tween(hangmanDrawing.parts[3], {
+ rotation: Math.PI / 2 // Right arm drops down
+ }, {
+ duration: 650,
+ easing: tween.easeOut
+ });
+ // Fade out the entire hangman slightly to show death
+ tween(hangmanDrawing, {
+ alpha: 0.7
+ }, {
+ duration: 1200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ // Show game over after animation completes
+ LK.showGameOver();
+ }
+ });
}
}
+ // Update letter displays
+ updateLetterDisplays();
+ // Reset Claude help button
+ resetClaudeButton();
}
// Create hangman drawing
hangmanDrawing = new HangmanDrawing();
hangmanDrawing.x = hangmanX;
@@ -325,8 +554,184 @@
wordDisplay.anchor.set(0.5, 0.5);
wordDisplay.x = 2048 / 2 + 120;
wordDisplay.y = wordY;
game.addChild(wordDisplay);
+// Create correct letters display with better styling
+var correctLettersDisplay = new Text2('✓ Correct Letters', {
+ size: 90,
+ fill: '#00ff88',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
+});
+correctLettersDisplay.anchor.set(0.5, 0.5);
+correctLettersDisplay.x = 2048 / 4;
+correctLettersDisplay.y = 1400;
+game.addChild(correctLettersDisplay);
+// Create wrong letters display with better styling
+var wrongLettersDisplay = new Text2('✗ Wrong Letters', {
+ size: 90,
+ fill: '#ff4444',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
+});
+wrongLettersDisplay.anchor.set(0.5, 0.5);
+wrongLettersDisplay.x = 2048 / 4 * 3;
+wrongLettersDisplay.y = 1400;
+game.addChild(wrongLettersDisplay);
+// Create actual letter display areas
+var correctLettersText = new Text2('', {
+ size: 70,
+ fill: '#88ffaa'
+});
+correctLettersText.anchor.set(0.5, 0);
+correctLettersText.x = 2048 / 4;
+correctLettersText.y = 1460;
+game.addChild(correctLettersText);
+var wrongLettersText = new Text2('', {
+ size: 70,
+ fill: '#ffaaaa'
+});
+wrongLettersText.anchor.set(0.5, 0);
+wrongLettersText.x = 2048 / 4 * 3;
+wrongLettersText.y = 1460;
+game.addChild(wrongLettersText);
+// Create Claude AI help button
+var claudeHelpBtn = new Container();
+var claudeBg = claudeHelpBtn.attachAsset('letter_btn_bg', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 0,
+ scaleX: 2.5,
+ scaleY: 1.2
+});
+var claudeMain = claudeHelpBtn.attachAsset('letter_btn_main', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -2,
+ scaleX: 2.4,
+ scaleY: 1.1
+});
+var claudeHighlight = claudeHelpBtn.attachAsset('letter_btn_highlight', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -4,
+ scaleX: 2.3,
+ scaleY: 1.0
+});
+var claudeText = new Text2('Glaud', {
+ size: 75,
+ fill: '#00ddff'
+});
+claudeText.anchor.set(0.5, 0.5);
+claudeText.x = 0;
+claudeText.y = -2;
+claudeHelpBtn.addChild(claudeText);
+// Position Claude button below keyboard
+claudeHelpBtn.x = 2048 / 2;
+claudeHelpBtn.y = letterGridY + 500;
+game.addChild(claudeHelpBtn);
+// Claude button functionality
+claudeHelpBtn.down = function (x, y, obj) {
+ // Play button press sound
+ LK.getSound('button').play();
+ // Animate button press
+ tween(claudeHelpBtn, {
+ y: claudeHelpBtn.y + 4
+ }, {
+ duration: 100
+ });
+ tween(claudeMain, {
+ y: claudeMain.y + 2
+ }, {
+ duration: 100
+ });
+ tween(claudeHighlight, {
+ y: claudeHighlight.y + 4
+ }, {
+ duration: 100
+ });
+ tween(claudeText, {
+ y: claudeText.y + 2
+ }, {
+ duration: 100
+ });
+};
+claudeHelpBtn.up = function (x, y, obj) {
+ // Check if help has already been used this game
+ if (claudeHelpUsed) {
+ // Flash red to indicate help already used
+ LK.effects.flashScreen(0x440000, 300);
+ return;
+ }
+ // Animate button release
+ tween(claudeHelpBtn, {
+ y: claudeHelpBtn.y - 4
+ }, {
+ duration: 100
+ });
+ tween(claudeMain, {
+ y: claudeMain.y - 2
+ }, {
+ duration: 100
+ });
+ tween(claudeHighlight, {
+ y: claudeHighlight.y - 4
+ }, {
+ duration: 100
+ });
+ tween(claudeText, {
+ y: claudeText.y - 2
+ }, {
+ duration: 100
+ });
+ // Find a correct letter that hasn't been guessed yet
+ var availableCorrectLetters = [];
+ for (var i = 0; i < currentWord.length; ++i) {
+ var letter = currentWord[i];
+ if (guessedLetters.indexOf(letter) === -1) {
+ availableCorrectLetters.push(letter);
+ }
+ }
+ if (availableCorrectLetters.length > 0) {
+ // Mark help as used
+ claudeHelpUsed = true;
+ // Play help sound
+ LK.getSound('help').play();
+ // Change button appearance to indicate it's been used
+ claudeText.setText('Perfect');
+ claudeText.fill = '#666666';
+ tween(claudeHelpBtn, {
+ alpha: 0.5
+ }, {
+ duration: 300
+ });
+ // Pick a random correct letter
+ var randomIndex = Math.floor(Math.random() * availableCorrectLetters.length);
+ var suggestedLetter = availableCorrectLetters[randomIndex];
+ // Find and activate the corresponding button
+ for (var i = 0; i < letterButtons.length; ++i) {
+ var btn = letterButtons[i];
+ if (btn.letter === suggestedLetter && !btn.used) {
+ // Flash the button to highlight it
+ LK.effects.flashObject(btn, 0x00ff00, 500);
+ // Auto-select the letter after a short delay
+ LK.setTimeout(function () {
+ onLetterSelected(suggestedLetter, btn);
+ }, 600);
+ break;
+ }
+ }
+ // Flash screen green to indicate help
+ LK.effects.flashScreen(0x004400, 300);
+ }
+};
+// Function to reset Claude button appearance
+function resetClaudeButton() {
+ claudeText.setText('Close');
+ claudeText.fill = '#00ddff';
+ claudeHelpBtn.alpha = 1;
+}
// Start first game
startGame();
// On game reset, start a new game
game.on('reset', function () {