User prompt
Show a pop-up message " You're Dead " for 2 seconds with an explosion effetc when the game ends ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
create another menu to choose categories
User prompt
before the start of the game create a menu to choose difficulty "Easy" , "Medium" and "Hard". when "Easy" is clicked choose simple level words; when "Medium" is clicked choose elementary level words; and when "Hard" is clicked advanced level words are chosen. Easy words are 1 points , Medium words are 2 points and Hard words are 3 points.
User prompt
change the frame color with white
User prompt
remove brown back round and make a black frame add bomb effetcs when the game ends ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the hang man backround white and center it
Code edit (1 edits merged)
Please save this source code
User prompt
Word Master Hangman
Initial prompt
hang man game words are chosen from 5 categories " animals" , "vegetables" , "fruits" , "names" , "films and movies"
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var HangmanDrawing = Container.expand(function () {
var self = Container.call(this);
self.wrongGuesses = 0;
self.bodyParts = [];
// White frame instead of brown gallows
var frame = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 1,
scaleX: 40,
scaleY: 4
});
// Rope
var rope = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0
});
rope.x = 50;
rope.y = -280;
// Body parts (initially hidden)
var head = self.attachAsset('head', {
anchorX: 0.5,
anchorY: 0.5
});
head.x = 50;
head.y = -220;
head.alpha = 0;
self.bodyParts.push(head);
var body = self.attachAsset('body', {
anchorX: 0.5,
anchorY: 0
});
body.x = 50;
body.y = -200;
body.alpha = 0;
self.bodyParts.push(body);
var leftArm = self.attachAsset('leftArm', {
anchorX: 1,
anchorY: 0.5
});
leftArm.x = 48;
leftArm.y = -170;
leftArm.alpha = 0;
self.bodyParts.push(leftArm);
var rightArm = self.attachAsset('rightArm', {
anchorX: 0,
anchorY: 0.5
});
rightArm.x = 52;
rightArm.y = -170;
rightArm.alpha = 0;
self.bodyParts.push(rightArm);
var leftLeg = self.attachAsset('leftLeg', {
anchorX: 0.5,
anchorY: 0
});
leftLeg.x = 42;
leftLeg.y = -120;
leftLeg.alpha = 0;
self.bodyParts.push(leftLeg);
var rightLeg = self.attachAsset('rightLeg', {
anchorX: 0.5,
anchorY: 0
});
rightLeg.x = 58;
rightLeg.y = -120;
rightLeg.alpha = 0;
self.bodyParts.push(rightLeg);
self.addBodyPart = function () {
if (self.wrongGuesses < self.bodyParts.length) {
var part = self.bodyParts[self.wrongGuesses];
part.alpha = 1;
tween(part, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(part, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
self.wrongGuesses++;
}
};
self.reset = function () {
self.wrongGuesses = 0;
self.scaleX = 1;
self.scaleY = 1;
self.alpha = 1;
for (var i = 0; i < self.bodyParts.length; i++) {
self.bodyParts[i].alpha = 0;
self.bodyParts[i].scaleX = 1;
self.bodyParts[i].scaleY = 1;
}
};
return self;
});
var LetterButton = Container.expand(function (letter) {
var self = Container.call(this);
self.letter = letter;
self.isPressed = false;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5
});
var letterText = new Text2(letter, {
size: 40,
fill: 0xFFFFFF
});
letterText.anchor.set(0.5, 0.5);
self.addChild(letterText);
self.markPressed = function () {
if (self.isPressed) return;
self.isPressed = true;
buttonBg.tint = 0x666666;
letterText.tint = 0x999999;
};
self.down = function (x, y, obj) {
if (self.isPressed) return;
handleLetterGuess(self.letter);
self.markPressed();
};
return self;
});
var WordDisplay = Container.expand(function () {
var self = Container.call(this);
self.currentWord = "";
self.guessedLetters = [];
self.wordSpaces = [];
self.setWord = function (word) {
// Clear existing word spaces
for (var i = 0; i < self.wordSpaces.length; i++) {
self.wordSpaces[i].destroy();
}
self.wordSpaces = [];
self.guessedLetters = [];
self.currentWord = word.toUpperCase();
var totalWidth = self.currentWord.length * 70;
var startX = -totalWidth / 2;
for (var i = 0; i < self.currentWord.length; i++) {
var space = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 0.5
});
space.x = startX + i * 70 + 35;
space.y = 0;
var letterText = new Text2("", {
size: 40,
fill: 0x000000
});
letterText.anchor.set(0.5, 0.5);
space.addChild(letterText);
space.letterText = letterText;
self.wordSpaces.push(space);
}
};
self.revealLetter = function (letter) {
letter = letter.toUpperCase();
var found = false;
for (var i = 0; i < self.currentWord.length; i++) {
if (self.currentWord[i] === letter) {
self.wordSpaces[i].letterText.setText(letter);
found = true;
}
}
if (found && self.guessedLetters.indexOf(letter) === -1) {
self.guessedLetters.push(letter);
}
return found;
};
self.isWordComplete = function () {
var uniqueLetters = [];
for (var i = 0; i < self.currentWord.length; i++) {
var letter = self.currentWord[i];
if (uniqueLetters.indexOf(letter) === -1) {
uniqueLetters.push(letter);
}
}
for (var i = 0; i < uniqueLetters.length; i++) {
if (self.guessedLetters.indexOf(uniqueLetters[i]) === -1) {
return false;
}
}
return true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF0F0F0
});
/****
* Game Code
****/
// Word categories
var wordCategories = {
animals: ["CAT", "DOG", "ELEPHANT", "TIGER", "LION", "BEAR", "RABBIT", "HORSE", "MONKEY", "GIRAFFE"],
vegetables: ["CARROT", "POTATO", "ONION", "TOMATO", "CUCUMBER", "PEPPER", "BROCCOLI", "SPINACH", "CORN", "BEANS"],
fruits: ["APPLE", "BANANA", "ORANGE", "GRAPE", "STRAWBERRY", "MANGO", "PINEAPPLE", "CHERRY", "PEACH", "KIWI"],
names: ["JOHN", "MARY", "DAVID", "SARAH", "MICHAEL", "LISA", "ROBERT", "ANNA", "JAMES", "EMMA"],
movies: ["AVATAR", "TITANIC", "FROZEN", "BATMAN", "SUPERMAN", "ROCKY", "JAWS", "ALIEN", "SHREK", "CARS"]
};
var currentCategory = "";
var currentWord = "";
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var letterButtons = [];
var gameState = "playing"; // "playing", "won", "lost"
// Game elements
var hangmanDrawing = game.addChild(new HangmanDrawing());
hangmanDrawing.x = 1024;
hangmanDrawing.y = 1000;
var wordDisplay = game.addChild(new WordDisplay());
wordDisplay.x = 1024;
wordDisplay.y = 1200;
// Category display
var categoryText = new Text2("", {
size: 60,
fill: 0x333333
});
categoryText.anchor.set(0.5, 0.5);
categoryText.x = 1024;
categoryText.y = 400;
game.addChild(categoryText);
// Score display
var scoreText = new Text2("Score: 0", {
size: 50,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create alphabet buttons
var buttonStartY = 1500;
var buttonsPerRow = 7;
var buttonSpacing = 90;
var rowSpacing = 90;
for (var i = 0; i < alphabet.length; i++) {
var letter = alphabet[i];
var button = game.addChild(new LetterButton(letter));
var row = Math.floor(i / buttonsPerRow);
var col = i % buttonsPerRow;
var rowWidth = Math.min(buttonsPerRow, alphabet.length - row * buttonsPerRow) * buttonSpacing;
var startX = 1024 - rowWidth / 2 + buttonSpacing / 2;
button.x = startX + col * buttonSpacing;
button.y = buttonStartY + row * rowSpacing;
letterButtons.push(button);
}
function getRandomWord() {
var categories = Object.keys(wordCategories);
currentCategory = categories[Math.floor(Math.random() * categories.length)];
var words = wordCategories[currentCategory];
currentWord = words[Math.floor(Math.random() * words.length)];
return currentWord;
}
function handleLetterGuess(letter) {
if (gameState !== "playing") return;
var isCorrect = wordDisplay.revealLetter(letter);
if (isCorrect) {
LK.getSound('correct').play();
if (wordDisplay.isWordComplete()) {
gameState = "won";
LK.getSound('win').play();
LK.setScore(LK.getScore() + 1);
scoreText.setText("Score: " + LK.getScore());
LK.setTimeout(function () {
startNewGame();
}, 2000);
}
} else {
LK.getSound('wrong').play();
hangmanDrawing.addBodyPart();
if (hangmanDrawing.wrongGuesses >= 6) {
gameState = "lost";
LK.getSound('lose').play();
// Reveal the word
for (var i = 0; i < currentWord.length; i++) {
wordDisplay.revealLetter(currentWord[i]);
}
// Bomb explosion effect
tween(hangmanDrawing, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0.5
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(hangmanDrawing, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 300,
easing: tween.easeIn
});
}
});
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
}
}
function startNewGame() {
gameState = "playing";
// Reset hangman drawing
hangmanDrawing.reset();
// Get new word
var newWord = getRandomWord();
wordDisplay.setWord(newWord);
// Update category display
categoryText.setText("Category: " + currentCategory.toUpperCase());
// Reset letter buttons
for (var i = 0; i < letterButtons.length; i++) {
letterButtons[i].isPressed = false;
letterButtons[i].children[0].tint = 0xFFFFFF; // Reset button background
letterButtons[i].children[1].tint = 0xFFFFFF; // Reset letter text
}
}
// Initialize first game
startNewGame(); ===================================================================
--- original.js
+++ change.js
@@ -9,10 +9,10 @@
var HangmanDrawing = Container.expand(function () {
var self = Container.call(this);
self.wrongGuesses = 0;
self.bodyParts = [];
- // Black frame instead of brown gallows
- var frame = self.attachAsset('body', {
+ // White frame instead of brown gallows
+ var frame = self.attachAsset('wordSpace', {
anchorX: 0.5,
anchorY: 1,
scaleX: 40,
scaleY: 4