User prompt
Haz que los corazones y el texto de los corazones Esteban a la par de altura
User prompt
Mueve hacia la izquierda un poco los corazones
User prompt
Haz las vidas más grandes
User prompt
Haz los otros botones más grandes
User prompt
Haz las palabras más grandes
User prompt
No aparece
User prompt
Haz que al pausar el juego arriba a la derecha ponga la puntuación maxima de cada idioma ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Haz que el fondo de las palabras mal escritas sea el mismo que el de las palabras bien escritas
User prompt
Haz que las palabras mal escritas al tocar el suelo no pierdas vidas
User prompt
Haz que halla palabras mal escritas que al pincharlas te quite una vida
User prompt
Haz que al entrar al juego suene la musica
User prompt
Haz que el botón también active y desactive la música de las letras ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Haz un botón que desactive y active la música del juego ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Can't find variable: storage' in or related to this line: 'var currentLanguage = storage.selectedLanguage || 'es';' Line Number: 154
User prompt
Elimina la función de decir palabras
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var utterance = new SpeechSynthesisUtterance(self.word);' Line Number: 163
User prompt
Haz que cada vez que toque una palabra suene la palabra y que allá un botón para desactivar esta función ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Haz que el botón de cambiar el idioma está abajo que las vidas
User prompt
Elimina el menu
User prompt
Haz que cuando toque jugar oculte el menú y empiecen a caer las palabras
User prompt
Sigue sin llevarme al juego
User prompt
Haz que al pinchar en jugar me lleve al juego
User prompt
Haz que cuando pinche en jugar me lleve al juego
User prompt
Haz el menú más grande
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'var localPos = self.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 158
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Heart = Container.expand(function () { var self = Container.call(this); var heartGraphic = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var LanguageButton = Container.expand(function () { var self = Container.call(this); // Create button background var buttonBg = self.attachAsset('wordBubble', { anchorX: 0.5, anchorY: 0.5 }); buttonBg.width = 200; buttonBg.height = 60; // Create text for the button self.buttonText = new Text2('Español', { size: 36, fill: 0xFFFFFF }); self.buttonText.anchor.set(0.5, 0.5); self.addChild(self.buttonText); self.setLanguage = function (lang) { if (lang === 'es') { self.buttonText.setText('Español'); } else if (lang === 'en') { self.buttonText.setText('English'); } else if (lang === 'fr') { self.buttonText.setText('Français'); } }; // Touch handler for language cycling self.down = function (x, y, obj) { // Cycle through languages if (currentLanguage === 'es') { currentLanguage = 'en'; } else if (currentLanguage === 'en') { currentLanguage = 'fr'; } else { currentLanguage = 'es'; } // Save language preference storage.selectedLanguage = currentLanguage; // Update button text self.setLanguage(currentLanguage); // Update word categories updateWordCategories(); // Visual feedback LK.effects.flashObject(self, 0xFFEB3B, 300); }; return self; }); var MenuInterface = Container.expand(function () { var self = Container.call(this); // Menu background var menuBg = LK.getAsset('wordBubble', { anchorX: 0.5, anchorY: 0.5 }); menuBg.width = 600; menuBg.height = 800; menuBg.tint = 0x2196F3; self.addChild(menuBg); // Title self.titleText = new Text2('Palabras Volantes', { size: 72, fill: 0xFFFFFF }); self.titleText.anchor.set(0.5, 0.5); self.titleText.y = -300; self.addChild(self.titleText); // Play button self.playButton = LK.getAsset('wordBubble', { anchorX: 0.5, anchorY: 0.5 }); self.playButton.width = 300; self.playButton.height = 80; self.playButton.y = -100; self.playButton.tint = 0x4CAF50; self.addChild(self.playButton); self.playText = new Text2('Jugar', { size: 48, fill: 0xFFFFFF }); self.playText.anchor.set(0.5, 0.5); self.playText.y = -100; self.addChild(self.playText); // Language button self.languageButton = LK.getAsset('wordBubble', { anchorX: 0.5, anchorY: 0.5 }); self.languageButton.width = 300; self.languageButton.height = 80; self.languageButton.y = 20; self.languageButton.tint = 0xFF9800; self.addChild(self.languageButton); self.languageText = new Text2('Idioma: Español', { size: 40, fill: 0xFFFFFF }); self.languageText.anchor.set(0.5, 0.5); self.languageText.y = 20; self.addChild(self.languageText); // High score display self.highScoreText = new Text2('Mejor puntuación: 0', { size: 36, fill: 0xFFFFFF }); self.highScoreText.anchor.set(0.5, 0.5); self.highScoreText.y = 140; self.addChild(self.highScoreText); // Update texts based on language self.updateLanguage = function () { if (currentLanguage === 'es') { self.titleText.setText('Palabras Volantes'); self.playText.setText('Jugar'); self.languageText.setText('Idioma: Español'); var highScore = storage.highScoreEs || 0; self.highScoreText.setText('Mejor puntuación: ' + highScore); } else if (currentLanguage === 'en') { self.titleText.setText('Flying Words'); self.playText.setText('Play'); self.languageText.setText('Language: English'); var highScore = storage.highScoreEn || 0; self.highScoreText.setText('High Score: ' + highScore); } else if (currentLanguage === 'fr') { self.titleText.setText('Mots Volants'); self.playText.setText('Jouer'); self.languageText.setText('Langue: Français'); var highScore = storage.highScoreFr || 0; self.highScoreText.setText('Meilleur score: ' + highScore); } }; // Touch handlers self.down = function (x, y, obj) { // Convert global coordinates to local coordinates relative to self var localPos = { x: x - self.x, y: y - self.y }; // Check play button if (localPos.y > -140 && localPos.y < -60 && Math.abs(localPos.x) < 150) { startGame(); LK.effects.flashObject(self.playButton, 0xFFEB3B, 300); } // Check language button if (localPos.y > -20 && localPos.y < 60 && Math.abs(localPos.x) < 150) { cycleLanguage(); LK.effects.flashObject(self.languageButton, 0xFFEB3B, 300); } }; return self; }); var Word = Container.expand(function () { var self = Container.call(this); // Create word bubble background var bubble = self.attachAsset('wordBubble', { anchorX: 0.5, anchorY: 0.5 }); // Create text for the word self.wordText = new Text2('', { size: 48, fill: 0xFFFFFF }); self.wordText.anchor.set(0.5, 0.5); self.addChild(self.wordText); // Word properties self.fallSpeed = 2; self.word = ''; self.missed = false; // Set the word text self.setWord = function (word) { self.word = word; self.wordText.setText(word); }; // Update method called every frame self.update = function () { self.y += self.fallSpeed; }; // Touch handler self.down = function (x, y, obj) { if (!self.missed) { // Word was touched correctly LK.setScore(LK.getScore() + 10); scoreText.setText(LK.getScore()); // Visual effect LK.effects.flashObject(self, 0xFFEB3B, 300); tween(self, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); // Play sound LK.getSound('correctWord').play(); // Remove from words array for (var i = words.length - 1; i >= 0; i--) { if (words[i] === self) { words.splice(i, 1); break; } } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1976D2 }); /**** * Game Code ****/ // Game state management var gameState = 'menu'; // 'menu' or 'playing' var menuInterface; // Game variables var words = []; var lives = 3; var hearts = []; var currentSpeed = 2; var wordSpawnTimer = 0; var spawnInterval = 120; // Spawn every 2 seconds at 60 FPS var backgroundColors = [0x1976D2, 0x7B1FA2, 0xD32F2F, 0xF57C00, 0x388E3C, 0x1976D2]; var currentColorIndex = 0; var lastSpeedLevel = 0; // Language system var currentLanguage = storage.selectedLanguage || 'es'; var languageButton; var scoreText; var livesContainer; // Multi-language words by category var allLanguageWords = { es: { animales: ['gato', 'perro', 'pájaro', 'pez', 'león', 'tigre', 'oso', 'ratón'], colores: ['rojo', 'azul', 'verde', 'amarillo', 'naranja', 'morado', 'rosa', 'negro'], comida: ['manzana', 'pan', 'agua', 'leche', 'queso', 'pollo', 'arroz', 'pasta'], objetos: ['mesa', 'silla', 'libro', 'lápiz', 'coche', 'casa', 'puerta', 'ventana'] }, en: { animals: ['cat', 'dog', 'bird', 'fish', 'lion', 'tiger', 'bear', 'mouse'], colors: ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'black'], food: ['apple', 'bread', 'water', 'milk', 'cheese', 'chicken', 'rice', 'pasta'], objects: ['table', 'chair', 'book', 'pencil', 'car', 'house', 'door', 'window'] }, fr: { animaux: ['chat', 'chien', 'oiseau', 'poisson', 'lion', 'tigre', 'ours', 'souris'], couleurs: ['rouge', 'bleu', 'vert', 'jaune', 'orange', 'violet', 'rose', 'noir'], nourriture: ['pomme', 'pain', 'eau', 'lait', 'fromage', 'poulet', 'riz', 'pâtes'], objets: ['table', 'chaise', 'livre', 'crayon', 'voiture', 'maison', 'porte', 'fenêtre'] } }; var wordCategories = {}; var allWords = []; // Function to update word categories based on current language function updateWordCategories() { wordCategories = allLanguageWords[currentLanguage]; allWords = []; for (var category in wordCategories) { allWords = allWords.concat(wordCategories[category]); } } // Initialize with current language updateWordCategories(); // Function to start the game function startGame() { gameState = 'playing'; // Hide menu if (menuInterface) { menuInterface.visible = false; } // Reset game variables words = []; lives = 3; currentSpeed = 2; wordSpawnTimer = 0; currentColorIndex = 0; lastSpeedLevel = 0; LK.setScore(0); // Show game UI showGameUI(); // Reset hearts for (var i = 0; i < hearts.length; i++) { hearts[i].alpha = 1; } // Update score display if (scoreText) { scoreText.setText(LK.getScore()); } } // Function to cycle language function cycleLanguage() { if (currentLanguage === 'es') { currentLanguage = 'en'; } else if (currentLanguage === 'en') { currentLanguage = 'fr'; } else { currentLanguage = 'es'; } // Save language preference storage.selectedLanguage = currentLanguage; // Update word categories updateWordCategories(); // Update menu interface if (menuInterface) { menuInterface.updateLanguage(); } // Update language button if visible if (languageButton) { languageButton.setLanguage(currentLanguage); } } // Function to show game UI function showGameUI() { if (scoreText) { scoreText.visible = true; } if (livesContainer) { livesContainer.visible = true; } if (languageButton) { languageButton.visible = true; } } // Function to hide game UI function hideGameUI() { if (scoreText) { scoreText.visible = false; } if (livesContainer) { livesContainer.visible = false; } if (languageButton) { languageButton.visible = false; } } // Function to show menu function showMenu() { gameState = 'menu'; // Hide game UI hideGameUI(); // Clear existing words for (var i = words.length - 1; i >= 0; i--) { words[i].destroy(); words.splice(i, 1); } // Show menu interface if (menuInterface) { menuInterface.visible = true; menuInterface.updateLanguage(); } } // Create menu interface menuInterface = new MenuInterface(); menuInterface.x = 2048 / 2; menuInterface.y = 2732 / 2; game.addChild(menuInterface); // Score display scoreText = new Text2('0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); scoreText.y = 50; // Lives display - Create a container for hearts with better positioning livesContainer = new Container(); livesContainer.x = -150; // Offset to position hearts better in top right livesContainer.y = 50; LK.gui.topRight.addChild(livesContainer); // Add hearts to the lives container for (var i = 0; i < 3; i++) { var heart = new Heart(); heart.x = i * 60; heart.y = 0; hearts.push(heart); livesContainer.addChild(heart); } // Add "Lives:" label next to hearts var livesLabel = new Text2('Lives:', { size: 40, fill: 0xFFFFFF }); livesLabel.anchor.set(1, 0.5); livesLabel.x = -20; livesLabel.y = 20; livesContainer.addChild(livesLabel); // Language selection button languageButton = new LanguageButton(); languageButton.x = 150; languageButton.y = 120; languageButton.setLanguage(currentLanguage); LK.gui.topLeft.addChild(languageButton); // Initially hide game UI and show menu hideGameUI(); showMenu(); // Function to spawn a new word function spawnWord() { var word = new Word(); var randomWord = allWords[Math.floor(Math.random() * allWords.length)]; word.setWord(randomWord); // Random horizontal position word.x = Math.random() * (2048 - 300) + 150; word.y = -100; word.fallSpeed = currentSpeed; words.push(word); game.addChild(word); } // Function to lose a life function loseLife() { lives--; if (lives >= 0 && lives < hearts.length) { hearts[lives].alpha = 0.3; } if (lives <= 0) { // Save high score before game over var currentScore = LK.getScore(); var highScoreKey = 'highScore' + currentLanguage.charAt(0).toUpperCase() + currentLanguage.slice(1); var currentHighScore = storage[highScoreKey] || 0; if (currentScore > currentHighScore) { storage[highScoreKey] = currentScore; } // Show game over and return to menu after delay LK.showGameOver(); LK.setTimeout(function () { showMenu(); }, 2000); } // Play wrong sound LK.getSound('wrongWord').play(); // Flash screen red LK.effects.flashScreen(0xFF1744, 500); } // Game update loop game.update = function () { // Only update game logic when playing if (gameState !== 'playing') { return; } // Spawn new words wordSpawnTimer++; if (wordSpawnTimer >= spawnInterval) { spawnWord(); wordSpawnTimer = 0; } // Update and check words for (var i = words.length - 1; i >= 0; i--) { var word = words[i]; // Check if word reached bottom if (word.y > 2732 + 50) { if (!word.missed) { word.missed = true; loseLife(); } word.destroy(); words.splice(i, 1); } } // Increase speed every 20 points var speedLevel = Math.floor(LK.getScore() / 20); currentSpeed = 2 + speedLevel * 0.5; // Decrease spawn interval slightly as speed increases spawnInterval = Math.max(60, 120 - speedLevel * 5); // Change background color when speed level increases if (speedLevel !== lastSpeedLevel) { currentColorIndex = speedLevel % backgroundColors.length; var targetColor = backgroundColors[currentColorIndex]; // Simple immediate color change - tween doesn't work well with color interpolation in this context game.setBackgroundColor(targetColor); lastSpeedLevel = speedLevel; } }; // Play background music LK.playMusic('backgroundMusic');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphic = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var LanguageButton = Container.expand(function () {
var self = Container.call(this);
// Create button background
var buttonBg = self.attachAsset('wordBubble', {
anchorX: 0.5,
anchorY: 0.5
});
buttonBg.width = 200;
buttonBg.height = 60;
// Create text for the button
self.buttonText = new Text2('Español', {
size: 36,
fill: 0xFFFFFF
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
self.setLanguage = function (lang) {
if (lang === 'es') {
self.buttonText.setText('Español');
} else if (lang === 'en') {
self.buttonText.setText('English');
} else if (lang === 'fr') {
self.buttonText.setText('Français');
}
};
// Touch handler for language cycling
self.down = function (x, y, obj) {
// Cycle through languages
if (currentLanguage === 'es') {
currentLanguage = 'en';
} else if (currentLanguage === 'en') {
currentLanguage = 'fr';
} else {
currentLanguage = 'es';
}
// Save language preference
storage.selectedLanguage = currentLanguage;
// Update button text
self.setLanguage(currentLanguage);
// Update word categories
updateWordCategories();
// Visual feedback
LK.effects.flashObject(self, 0xFFEB3B, 300);
};
return self;
});
var MenuInterface = Container.expand(function () {
var self = Container.call(this);
// Menu background
var menuBg = LK.getAsset('wordBubble', {
anchorX: 0.5,
anchorY: 0.5
});
menuBg.width = 600;
menuBg.height = 800;
menuBg.tint = 0x2196F3;
self.addChild(menuBg);
// Title
self.titleText = new Text2('Palabras Volantes', {
size: 72,
fill: 0xFFFFFF
});
self.titleText.anchor.set(0.5, 0.5);
self.titleText.y = -300;
self.addChild(self.titleText);
// Play button
self.playButton = LK.getAsset('wordBubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.playButton.width = 300;
self.playButton.height = 80;
self.playButton.y = -100;
self.playButton.tint = 0x4CAF50;
self.addChild(self.playButton);
self.playText = new Text2('Jugar', {
size: 48,
fill: 0xFFFFFF
});
self.playText.anchor.set(0.5, 0.5);
self.playText.y = -100;
self.addChild(self.playText);
// Language button
self.languageButton = LK.getAsset('wordBubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.languageButton.width = 300;
self.languageButton.height = 80;
self.languageButton.y = 20;
self.languageButton.tint = 0xFF9800;
self.addChild(self.languageButton);
self.languageText = new Text2('Idioma: Español', {
size: 40,
fill: 0xFFFFFF
});
self.languageText.anchor.set(0.5, 0.5);
self.languageText.y = 20;
self.addChild(self.languageText);
// High score display
self.highScoreText = new Text2('Mejor puntuación: 0', {
size: 36,
fill: 0xFFFFFF
});
self.highScoreText.anchor.set(0.5, 0.5);
self.highScoreText.y = 140;
self.addChild(self.highScoreText);
// Update texts based on language
self.updateLanguage = function () {
if (currentLanguage === 'es') {
self.titleText.setText('Palabras Volantes');
self.playText.setText('Jugar');
self.languageText.setText('Idioma: Español');
var highScore = storage.highScoreEs || 0;
self.highScoreText.setText('Mejor puntuación: ' + highScore);
} else if (currentLanguage === 'en') {
self.titleText.setText('Flying Words');
self.playText.setText('Play');
self.languageText.setText('Language: English');
var highScore = storage.highScoreEn || 0;
self.highScoreText.setText('High Score: ' + highScore);
} else if (currentLanguage === 'fr') {
self.titleText.setText('Mots Volants');
self.playText.setText('Jouer');
self.languageText.setText('Langue: Français');
var highScore = storage.highScoreFr || 0;
self.highScoreText.setText('Meilleur score: ' + highScore);
}
};
// Touch handlers
self.down = function (x, y, obj) {
// Convert global coordinates to local coordinates relative to self
var localPos = {
x: x - self.x,
y: y - self.y
};
// Check play button
if (localPos.y > -140 && localPos.y < -60 && Math.abs(localPos.x) < 150) {
startGame();
LK.effects.flashObject(self.playButton, 0xFFEB3B, 300);
}
// Check language button
if (localPos.y > -20 && localPos.y < 60 && Math.abs(localPos.x) < 150) {
cycleLanguage();
LK.effects.flashObject(self.languageButton, 0xFFEB3B, 300);
}
};
return self;
});
var Word = Container.expand(function () {
var self = Container.call(this);
// Create word bubble background
var bubble = self.attachAsset('wordBubble', {
anchorX: 0.5,
anchorY: 0.5
});
// Create text for the word
self.wordText = new Text2('', {
size: 48,
fill: 0xFFFFFF
});
self.wordText.anchor.set(0.5, 0.5);
self.addChild(self.wordText);
// Word properties
self.fallSpeed = 2;
self.word = '';
self.missed = false;
// Set the word text
self.setWord = function (word) {
self.word = word;
self.wordText.setText(word);
};
// Update method called every frame
self.update = function () {
self.y += self.fallSpeed;
};
// Touch handler
self.down = function (x, y, obj) {
if (!self.missed) {
// Word was touched correctly
LK.setScore(LK.getScore() + 10);
scoreText.setText(LK.getScore());
// Visual effect
LK.effects.flashObject(self, 0xFFEB3B, 300);
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
// Play sound
LK.getSound('correctWord').play();
// Remove from words array
for (var i = words.length - 1; i >= 0; i--) {
if (words[i] === self) {
words.splice(i, 1);
break;
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1976D2
});
/****
* Game Code
****/
// Game state management
var gameState = 'menu'; // 'menu' or 'playing'
var menuInterface;
// Game variables
var words = [];
var lives = 3;
var hearts = [];
var currentSpeed = 2;
var wordSpawnTimer = 0;
var spawnInterval = 120; // Spawn every 2 seconds at 60 FPS
var backgroundColors = [0x1976D2, 0x7B1FA2, 0xD32F2F, 0xF57C00, 0x388E3C, 0x1976D2];
var currentColorIndex = 0;
var lastSpeedLevel = 0;
// Language system
var currentLanguage = storage.selectedLanguage || 'es';
var languageButton;
var scoreText;
var livesContainer;
// Multi-language words by category
var allLanguageWords = {
es: {
animales: ['gato', 'perro', 'pájaro', 'pez', 'león', 'tigre', 'oso', 'ratón'],
colores: ['rojo', 'azul', 'verde', 'amarillo', 'naranja', 'morado', 'rosa', 'negro'],
comida: ['manzana', 'pan', 'agua', 'leche', 'queso', 'pollo', 'arroz', 'pasta'],
objetos: ['mesa', 'silla', 'libro', 'lápiz', 'coche', 'casa', 'puerta', 'ventana']
},
en: {
animals: ['cat', 'dog', 'bird', 'fish', 'lion', 'tiger', 'bear', 'mouse'],
colors: ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'black'],
food: ['apple', 'bread', 'water', 'milk', 'cheese', 'chicken', 'rice', 'pasta'],
objects: ['table', 'chair', 'book', 'pencil', 'car', 'house', 'door', 'window']
},
fr: {
animaux: ['chat', 'chien', 'oiseau', 'poisson', 'lion', 'tigre', 'ours', 'souris'],
couleurs: ['rouge', 'bleu', 'vert', 'jaune', 'orange', 'violet', 'rose', 'noir'],
nourriture: ['pomme', 'pain', 'eau', 'lait', 'fromage', 'poulet', 'riz', 'pâtes'],
objets: ['table', 'chaise', 'livre', 'crayon', 'voiture', 'maison', 'porte', 'fenêtre']
}
};
var wordCategories = {};
var allWords = [];
// Function to update word categories based on current language
function updateWordCategories() {
wordCategories = allLanguageWords[currentLanguage];
allWords = [];
for (var category in wordCategories) {
allWords = allWords.concat(wordCategories[category]);
}
}
// Initialize with current language
updateWordCategories();
// Function to start the game
function startGame() {
gameState = 'playing';
// Hide menu
if (menuInterface) {
menuInterface.visible = false;
}
// Reset game variables
words = [];
lives = 3;
currentSpeed = 2;
wordSpawnTimer = 0;
currentColorIndex = 0;
lastSpeedLevel = 0;
LK.setScore(0);
// Show game UI
showGameUI();
// Reset hearts
for (var i = 0; i < hearts.length; i++) {
hearts[i].alpha = 1;
}
// Update score display
if (scoreText) {
scoreText.setText(LK.getScore());
}
}
// Function to cycle language
function cycleLanguage() {
if (currentLanguage === 'es') {
currentLanguage = 'en';
} else if (currentLanguage === 'en') {
currentLanguage = 'fr';
} else {
currentLanguage = 'es';
}
// Save language preference
storage.selectedLanguage = currentLanguage;
// Update word categories
updateWordCategories();
// Update menu interface
if (menuInterface) {
menuInterface.updateLanguage();
}
// Update language button if visible
if (languageButton) {
languageButton.setLanguage(currentLanguage);
}
}
// Function to show game UI
function showGameUI() {
if (scoreText) {
scoreText.visible = true;
}
if (livesContainer) {
livesContainer.visible = true;
}
if (languageButton) {
languageButton.visible = true;
}
}
// Function to hide game UI
function hideGameUI() {
if (scoreText) {
scoreText.visible = false;
}
if (livesContainer) {
livesContainer.visible = false;
}
if (languageButton) {
languageButton.visible = false;
}
}
// Function to show menu
function showMenu() {
gameState = 'menu';
// Hide game UI
hideGameUI();
// Clear existing words
for (var i = words.length - 1; i >= 0; i--) {
words[i].destroy();
words.splice(i, 1);
}
// Show menu interface
if (menuInterface) {
menuInterface.visible = true;
menuInterface.updateLanguage();
}
}
// Create menu interface
menuInterface = new MenuInterface();
menuInterface.x = 2048 / 2;
menuInterface.y = 2732 / 2;
game.addChild(menuInterface);
// Score display
scoreText = new Text2('0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 50;
// Lives display - Create a container for hearts with better positioning
livesContainer = new Container();
livesContainer.x = -150; // Offset to position hearts better in top right
livesContainer.y = 50;
LK.gui.topRight.addChild(livesContainer);
// Add hearts to the lives container
for (var i = 0; i < 3; i++) {
var heart = new Heart();
heart.x = i * 60;
heart.y = 0;
hearts.push(heart);
livesContainer.addChild(heart);
}
// Add "Lives:" label next to hearts
var livesLabel = new Text2('Lives:', {
size: 40,
fill: 0xFFFFFF
});
livesLabel.anchor.set(1, 0.5);
livesLabel.x = -20;
livesLabel.y = 20;
livesContainer.addChild(livesLabel);
// Language selection button
languageButton = new LanguageButton();
languageButton.x = 150;
languageButton.y = 120;
languageButton.setLanguage(currentLanguage);
LK.gui.topLeft.addChild(languageButton);
// Initially hide game UI and show menu
hideGameUI();
showMenu();
// Function to spawn a new word
function spawnWord() {
var word = new Word();
var randomWord = allWords[Math.floor(Math.random() * allWords.length)];
word.setWord(randomWord);
// Random horizontal position
word.x = Math.random() * (2048 - 300) + 150;
word.y = -100;
word.fallSpeed = currentSpeed;
words.push(word);
game.addChild(word);
}
// Function to lose a life
function loseLife() {
lives--;
if (lives >= 0 && lives < hearts.length) {
hearts[lives].alpha = 0.3;
}
if (lives <= 0) {
// Save high score before game over
var currentScore = LK.getScore();
var highScoreKey = 'highScore' + currentLanguage.charAt(0).toUpperCase() + currentLanguage.slice(1);
var currentHighScore = storage[highScoreKey] || 0;
if (currentScore > currentHighScore) {
storage[highScoreKey] = currentScore;
}
// Show game over and return to menu after delay
LK.showGameOver();
LK.setTimeout(function () {
showMenu();
}, 2000);
}
// Play wrong sound
LK.getSound('wrongWord').play();
// Flash screen red
LK.effects.flashScreen(0xFF1744, 500);
}
// Game update loop
game.update = function () {
// Only update game logic when playing
if (gameState !== 'playing') {
return;
}
// Spawn new words
wordSpawnTimer++;
if (wordSpawnTimer >= spawnInterval) {
spawnWord();
wordSpawnTimer = 0;
}
// Update and check words
for (var i = words.length - 1; i >= 0; i--) {
var word = words[i];
// Check if word reached bottom
if (word.y > 2732 + 50) {
if (!word.missed) {
word.missed = true;
loseLife();
}
word.destroy();
words.splice(i, 1);
}
}
// Increase speed every 20 points
var speedLevel = Math.floor(LK.getScore() / 20);
currentSpeed = 2 + speedLevel * 0.5;
// Decrease spawn interval slightly as speed increases
spawnInterval = Math.max(60, 120 - speedLevel * 5);
// Change background color when speed level increases
if (speedLevel !== lastSpeedLevel) {
currentColorIndex = speedLevel % backgroundColors.length;
var targetColor = backgroundColors[currentColorIndex];
// Simple immediate color change - tween doesn't work well with color interpolation in this context
game.setBackgroundColor(targetColor);
lastSpeedLevel = speedLevel;
}
};
// Play background music
LK.playMusic('backgroundMusic');