User prompt
Sube más al jugador en la pantalla para que no interfiera con la barras de ansiedad y credibilidad
User prompt
Peor dejalas las barras de ansidad y credibilidad en la parte baja de la pantalla por favor
User prompt
Ajusta mejor los texto para el turno del jugador los ataques no se ven bien, tambien puedes poner la barra de ansiedad arriba y texto "Ansiedad" debajo de ella? haz lo mismo con la barra de credibilidad por favor
User prompt
AHora tambien has los cuadros dentro de los cuales están los textos más grandes por favor, si algo se sale de la pantalla ajusta el texto para que no salga
User prompt
Genial, un detalle menor podrias hacer un pco más grande la letra de todo? es que siento que no se ve mucho
User prompt
Bueno no se arregla pero estáq bien, ahora cuando el enemigo muere no deberia poder tirar más ataques, cuando lo probé tiró ataques puedes solucionarlo?
User prompt
No se sigue sin ver la barra de salud del enemigo despues de darle continuar
User prompt
Okey, casi está bien, soluciones un pequeño bug que noté. Apenas empieza el nivel la barra de salud del enmigo no se puede ver y cuando se le da el primer ataque la barra de salud se ve en color negro, puede arreglar eso primero?
User prompt
si
User prompt
si
User prompt
si
User prompt
Puedes poner un poco más abajo al enemigo por favor? para que la barra de vida no lo tape
User prompt
SUper me gusta, quiero que hagas explicita la barra de vida del enemigo en la parte superior ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Bien un cambio más es que quiero que cuando la barra de ansiedad suba, la credibilidad baje tambien quita la parte de arriba que dice puntos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Si ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Sigue sin funcionar bien, quiero que entonces el enemigo tire sus 3 ataques, si el jugador a esquivado el ultimo ataque que salga el cuadro de texto para que el jugador pueda atacar ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
A ver intentemos otra cosa hasta que el jugador no precione que ataque quiere hacer el enemigo no deberia poder atacar, arreglemos eso primero ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Okey está funcionando masomenos, quiero que cuando el ultimo ataque del enemigo sea esquivado o recibido por el jugador salga el cuadro de texto para que el jugador pueda hacer su ataque ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
intenta otra vez ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Por ahora solo que funcione, en este momento el enemigo siempre está atacando y el jugador solo tiene unos segundos para presionar su ataque por lo que quiero que arreglemos primero esto ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Okey quiero que el jugador este arriba de las barras de ansiedad y credibilidad primero que todo ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Pero no me puedo mover primero que todo jajajja
User prompt
Okey me gusta quiero intentar hacer algo un poco diferente, quiero la mecanica principal sea por turnos primero atacará el enemigo con las letras y luego atacaré yo con algo relacionado a la cosas buenas de tutorias, la barra de ansiedad subirá cada vez que el enemigo me ataque y la confianza cuando yo atine los golpes, quiero los medidores de ansiedad y credibilidad estén en la parte inferior mejor, muy al estilo Undertale ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
si
User prompt
Ahora los dialogos se dañaron se salen de la pantalla
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var GreenTextAttack = Container.expand(function () {
var self = Container.call(this);
// Create random positive text
var positiveTexts = ['CALMA', 'PAZ', 'FUERZA', 'ESPERANZA', 'CONFIANZA'];
var randomText = positiveTexts[Math.floor(Math.random() * positiveTexts.length)];
var textGraphics = self.addChild(new Text2(randomText, {
size: getTextSize(true, level),
fill: 0x00ff00,
stroke: 0x000000,
strokeThickness: 3
}));
textGraphics.anchor.set(0.5, 0.5);
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement properties
self.speed = HEART_SPEED;
self.isMovingLeft = false;
self.isMovingRight = false;
// Health
self.health = 100;
self.update = function () {
// Keyboard movement
if (self.isMovingLeft) {
self.x -= self.speed;
}
if (self.isMovingRight) {
self.x += self.speed;
}
// Boundary checking
if (self.x < GAME_LEFT + HEART_MARGIN) {
self.x = GAME_LEFT + HEART_MARGIN;
}
if (self.x > GAME_RIGHT - HEART_MARGIN) {
self.x = GAME_RIGHT - HEART_MARGIN;
}
};
self.takeDamage = function (amount) {
if (amount === undefined) amount = 10;
self.health = Math.max(0, self.health - amount);
// Flash red effect
tween(heartGraphics, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(heartGraphics, {
tint: 0xffffff
}, {
duration: 200
});
}
});
if (self.health <= 0) {
LK.showGameOver();
}
};
return self;
});
var TechniqueMenu = Container.expand(function () {
var self = Container.call(this);
// Background
var bg = self.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
bg.width = 600;
bg.height = 400;
bg.tint = 0x333333;
// Title
var title = self.addChild(new Text2('Técnica de Relajación', {
size: 32,
fill: 0xffffff
}));
title.anchor.set(0.5, 0.5);
title.y = -120;
// Techniques
var techniques = ['Respiración Profunda', 'Mindfulness', 'Relajación Muscular'];
var selectedTechnique = techniques[Math.floor(Math.random() * techniques.length)];
var techniqueText = self.addChild(new Text2(selectedTechnique, {
size: 28,
fill: 0x00ff00
}));
techniqueText.anchor.set(0.5, 0.5);
techniqueText.y = -50;
// Instructions
var instruction = self.addChild(new Text2('Toca para aplicar', {
size: 24,
fill: 0xcccccc
}));
instruction.anchor.set(0.5, 0.5);
instruction.y = 20;
self.duration = 0;
self.maxDuration = 3000; // 3 seconds
self.update = function () {
self.duration += 16.67;
if (self.duration >= self.maxDuration) {
self.destroy();
}
};
self.down = function () {
// Apply technique - boost credibilidad
credibilidad = Math.min(100, credibilidad + 15);
updateBars();
self.destroy();
};
return self;
});
var TextAttack = Container.expand(function () {
var self = Container.call(this);
// Create random attack text
var attackTexts = ['ESTRÉS', 'MIEDO', 'PÁNICO', 'DUDAS', 'CRÍTICAS'];
var randomText = attackTexts[Math.floor(Math.random() * attackTexts.length)];
var textGraphics = self.addChild(new Text2(randomText, {
size: getTextSize(false, level),
fill: 0xff0000,
stroke: 0x000000,
strokeThickness: 3
}));
textGraphics.anchor.set(0.5, 0.5);
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game Constants
// UI Elements
// Game Elements
// Sounds
var ATTACK_INTERVAL = 90;
var LEVEL_DIFF = 5;
var ANSIEDAD_RATE = 180;
var ANSIEDAD_PASSIVE = 2;
var MAX_LEVEL = 10;
var WIN_CRED = 60;
var SCORE_RATE = 60;
var SCORE_PER_LEVEL = 50;
var LEVEL_CRED_BOOST = 5;
var GAME_LEFT = 300;
var GAME_RIGHT = 1748;
var GAME_TOP = 200;
var GAME_BOTTOM = 2732;
var GAME_WIDTH = GAME_RIGHT - GAME_LEFT;
// Heart movement constants
var HEART_SPEED = 8;
var HEART_MARGIN = 60;
// Text size scaling function
function getTextSize(isGreen, currentLevel) {
var baseSize = 20;
var sizeMultiplier = 10;
var scale;
if (isGreen) {
// Green words: size 5 at level 1, size 1 at level 5
scale = 6 - currentLevel;
} else {
// Red words: size 1 at level 1, size 5 at level 5
scale = currentLevel;
}
// Ensure scale is between 1 and 5
scale = Math.max(1, Math.min(5, scale));
return baseSize + scale * sizeMultiplier;
}
// Game state management
var gameState = 'menu'; // 'menu', 'dialogue', or 'playing'
var menuContainer = game.addChild(new Container());
// Game variables
var level = 1;
var maxLevel = 5;
var dialogueContainer = game.addChild(new Container());
dialogueContainer.visible = false;
// Level narratives
var levelNarratives = ["Nivel 1: Bienvenido a tu primera sesión de tutoría. Los pensamientos negativos comenzarán lentamente.", "Nivel 2: Bien hecho. Ahora los ataques serán más frecuentes. Mantén la calma y usa las técnicas.", "Nivel 3: Excelente progreso. Los pensamientos llegan más rápido, pero ya tienes más experiencia.", "Nivel 4: Casi terminas tu entrenamiento. Los ataques son intensos, confía en tu preparación.", "Nivel 5: Nivel final. Domina completamente las técnicas contra los ataques más desafiantes."];
var score = 0;
var ansiedad = 0;
var credibilidad = 50;
// UI Elements
var ansiedadBarBg = null,
ansiedadBar = null,
credibilidadBarBg = null,
credibilidadBar = null;
var levelText = null,
scoreText = null;
// Initialize UI
function initializeUI() {
// Ansiedad bar
ansiedadBarBg = LK.gui.topLeft.addChild(LK.getAsset('ansiedadBarBg', {
anchorX: 0,
anchorY: 0
}));
ansiedadBarBg.x = 120;
ansiedadBarBg.y = 50;
ansiedadBar = LK.gui.topLeft.addChild(LK.getAsset('ansiedadBar', {
anchorX: 0,
anchorY: 0
}));
ansiedadBar.x = 120;
ansiedadBar.y = 50;
// Credibilidad bar
credibilidadBarBg = LK.gui.topLeft.addChild(LK.getAsset('credibilidadBarBg', {
anchorX: 0,
anchorY: 0
}));
credibilidadBarBg.x = 120;
credibilidadBarBg.y = 90;
credibilidadBar = LK.gui.topLeft.addChild(LK.getAsset('credibilidadBar', {
anchorX: 0,
anchorY: 0
}));
credibilidadBar.x = 120;
credibilidadBar.y = 90;
// Text labels
var ansiedadLabel = LK.gui.topLeft.addChild(new Text2('Ansiedad', {
size: 20,
fill: 0xffffff
}));
ansiedadLabel.x = 10;
ansiedadLabel.y = 60;
var credibilidadLabel = LK.gui.topLeft.addChild(new Text2('Credibilidad', {
size: 20,
fill: 0xffffff
}));
credibilidadLabel.x = 10;
credibilidadLabel.y = 100;
// Level and score
levelText = LK.gui.topRight.addChild(new Text2('Nivel: 1', {
size: 24,
fill: 0xffffff
}));
levelText.anchor.set(1, 0);
levelText.x = -20;
levelText.y = 50;
scoreText = LK.gui.topRight.addChild(new Text2('Puntos: 0', {
size: 24,
fill: 0xffffff
}));
scoreText.anchor.set(1, 0);
scoreText.x = -20;
scoreText.y = 80;
}
function updateBars() {
// Update bar widths based on values
ansiedadBar.width = ansiedad / 100 * 300;
credibilidadBar.width = credibilidad / 100 * 300;
// Update text
levelText.setText('Nivel: ' + level);
scoreText.setText('Puntos: ' + score);
}
function showDialogue(text) {
gameState = 'dialogue';
dialogueContainer.visible = true;
// Clear previous dialogue
dialogueContainer.removeChildren();
// Dialogue background
var dialogueBg = dialogueContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0
}));
dialogueBg.width = 1800;
dialogueBg.height = 200;
dialogueBg.tint = 0x333333;
dialogueBg.x = 1024;
dialogueBg.y = 180;
// Dialogue text
var dialogueText = dialogueContainer.addChild(new Text2(text, {
size: 28,
fill: 0xffffff
}));
dialogueText.anchor.set(0.5, 0.5);
dialogueText.x = 1024;
dialogueText.y = 280;
// Continue button
var continueBtn = dialogueContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
continueBtn.width = 300;
continueBtn.height = 80;
continueBtn.tint = 0x00aa00;
continueBtn.x = 1024;
continueBtn.y = 410;
var continueText = dialogueContainer.addChild(new Text2('Continuar', {
size: 32,
fill: 0xffffff
}));
continueText.anchor.set(0.5, 0.5);
continueText.x = continueBtn.x;
continueText.y = continueBtn.y;
continueBtn.down = function () {
dialogueContainer.visible = false;
gameState = 'playing';
// Initialize and show UI if not already done
if (!ansiedadBarBg || ansiedadBarBg && !ansiedadBarBg.parent) {
initializeUI();
}
updateBars();
heart.visible = true;
};
}
// Create menu elements
var logo = menuContainer.addChild(LK.getAsset('gameLogo', {
anchorX: 0.5,
anchorY: 0.5
}));
logo.x = 2048 / 2;
logo.y = 2732 / 2 - 250;
// Create play button
var playButton = menuContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
playButton.x = 2048 / 2;
playButton.y = 2732 / 2 + 100;
// Play button text
var playText = menuContainer.addChild(new Text2('JUGAR', {
size: 70,
fill: 0xFFFFFF
}));
playText.anchor.set(0.5, 0.5);
playText.x = playButton.x;
playText.y = playButton.y;
// Play button interaction
playButton.down = function (x, y, obj) {
// Flash button on press
tween(playButton, {
tint: 0xffffff
}, {
duration: 100,
onFinish: function onFinish() {
tween(playButton, {
tint: 0xffffff
}, {
duration: 100
});
}
});
};
playButton.up = function (x, y, obj) {
// Show level dialogue first
menuContainer.visible = false;
showDialogue(levelNarratives[level - 1]);
};
// Create the heart character
var heart = game.addChild(new Heart());
heart.x = 2048 / 2;
heart.y = GAME_BOTTOM - 100;
heart.visible = false;
// Keyboard controls - using LK event system instead of window
LK.on('keydown', function (event) {
if (gameState !== 'playing') return;
if (event.key === 'ArrowLeft') {
heart.isMovingLeft = true;
}
if (event.key === 'ArrowRight') {
heart.isMovingRight = true;
}
});
LK.on('keyup', function (event) {
if (gameState !== 'playing') return;
if (event.key === 'ArrowLeft') {
heart.isMovingLeft = false;
}
if (event.key === 'ArrowRight') {
heart.isMovingRight = false;
}
});
// Touch controls for mobile
game.move = function (x, y, obj) {
if (gameState === 'playing') {
// Move heart towards touch position
if (x < heart.x) {
heart.isMovingLeft = true;
heart.isMovingRight = false;
} else if (x > heart.x) {
heart.isMovingRight = true;
heart.isMovingLeft = false;
}
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
heart.isMovingLeft = false;
heart.isMovingRight = false;
}
};
// Game arrays and timers
var textAttacks = [];
var greenTextAttacks = [];
var attackTimer = 0;
var greenAttackTimer = 0;
var ansiedadTimer = 0;
var scoreTimer = 0;
// Main game update loop
game.update = function () {
// Only update game logic when playing
if (gameState !== 'playing') return;
// Spawn TextAttack
attackTimer++;
var spawnInterval = ATTACK_INTERVAL - level * LEVEL_DIFF;
if (attackTimer >= spawnInterval) {
var textAttack = new TextAttack();
textAttack.x = GAME_LEFT + Math.random() * GAME_WIDTH;
textAttack.y = GAME_TOP;
textAttacks.push(textAttack);
game.addChild(textAttack);
attackTimer = 0;
}
// Spawn GreenTextAttack (less frequent)
greenAttackTimer++;
var greenSpawnInterval = (ATTACK_INTERVAL - level * LEVEL_DIFF) * 2;
if (greenAttackTimer >= greenSpawnInterval) {
var greenTextAttack = new GreenTextAttack();
greenTextAttack.x = GAME_LEFT + Math.random() * GAME_WIDTH;
greenTextAttack.y = GAME_TOP;
greenTextAttacks.push(greenTextAttack);
game.addChild(greenTextAttack);
greenAttackTimer = 0;
}
// Update and check TextAttack collisions
for (var i = textAttacks.length - 1; i >= 0; i--) {
var atk = textAttacks[i];
// Check collision with heart
if (atk.intersects(heart)) {
heart.takeDamage(15);
ansiedad = Math.min(100, ansiedad + 10);
updateBars();
atk.destroy();
textAttacks.splice(i, 1);
continue;
}
// Remove off-screen attacks
if (atk.y > GAME_BOTTOM + 100) {
atk.destroy();
textAttacks.splice(i, 1);
}
}
// Update and check GreenTextAttack collisions
for (var k = greenTextAttacks.length - 1; k >= 0; k--) {
var greenAtk = greenTextAttacks[k];
// Check collision with heart
if (greenAtk.intersects(heart)) {
credibilidad = Math.min(100, credibilidad + 8);
updateBars();
greenAtk.destroy();
greenTextAttacks.splice(k, 1);
continue;
}
// Remove off-screen green attacks
if (greenAtk.y > GAME_BOTTOM + 100) {
greenAtk.destroy();
greenTextAttacks.splice(k, 1);
}
}
// Increase ansiedad passively
ansiedadTimer++;
if (ansiedadTimer >= ANSIEDAD_RATE) {
ansiedad = Math.min(100, ansiedad + ANSIEDAD_PASSIVE);
updateBars();
ansiedadTimer = 0;
}
// Update score and level
scoreTimer++;
if (scoreTimer >= SCORE_RATE) {
score++;
// Check for level up
if (score >= level * SCORE_PER_LEVEL && level < maxLevel) {
level++;
storage.currentLevel = level;
credibilidad = Math.min(100, credibilidad + LEVEL_CRED_BOOST);
// Show next level dialogue
showDialogue(levelNarratives[level - 1]);
}
updateBars();
scoreTimer = 0;
}
// Check game over
if (ansiedad >= 100) {
LK.showGameOver();
}
// Check win condition
if (level >= maxLevel && credibilidad >= WIN_CRED) {
LK.showYouWin();
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var GreenTextAttack = Container.expand(function () {
var self = Container.call(this);
// Create random positive text
var positiveTexts = ['CALMA', 'PAZ', 'FUERZA', 'ESPERANZA', 'CONFIANZA'];
var randomText = positiveTexts[Math.floor(Math.random() * positiveTexts.length)];
var textGraphics = self.addChild(new Text2(randomText, {
size: getTextSize(true, level),
fill: 0x00ff00,
stroke: 0x000000,
strokeThickness: 3
}));
textGraphics.anchor.set(0.5, 0.5);
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
// Movement properties
self.speed = HEART_SPEED;
self.isMovingLeft = false;
self.isMovingRight = false;
// Health
self.health = 100;
self.update = function () {
// Keyboard movement
if (self.isMovingLeft) {
self.x -= self.speed;
}
if (self.isMovingRight) {
self.x += self.speed;
}
// Boundary checking
if (self.x < GAME_LEFT + HEART_MARGIN) {
self.x = GAME_LEFT + HEART_MARGIN;
}
if (self.x > GAME_RIGHT - HEART_MARGIN) {
self.x = GAME_RIGHT - HEART_MARGIN;
}
};
self.takeDamage = function (amount) {
if (amount === undefined) amount = 10;
self.health = Math.max(0, self.health - amount);
// Flash red effect
tween(heartGraphics, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(heartGraphics, {
tint: 0xffffff
}, {
duration: 200
});
}
});
if (self.health <= 0) {
LK.showGameOver();
}
};
return self;
});
var TechniqueMenu = Container.expand(function () {
var self = Container.call(this);
// Background
var bg = self.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
bg.width = 600;
bg.height = 400;
bg.tint = 0x333333;
// Title
var title = self.addChild(new Text2('Técnica de Relajación', {
size: 32,
fill: 0xffffff
}));
title.anchor.set(0.5, 0.5);
title.y = -120;
// Techniques
var techniques = ['Respiración Profunda', 'Mindfulness', 'Relajación Muscular'];
var selectedTechnique = techniques[Math.floor(Math.random() * techniques.length)];
var techniqueText = self.addChild(new Text2(selectedTechnique, {
size: 28,
fill: 0x00ff00
}));
techniqueText.anchor.set(0.5, 0.5);
techniqueText.y = -50;
// Instructions
var instruction = self.addChild(new Text2('Toca para aplicar', {
size: 24,
fill: 0xcccccc
}));
instruction.anchor.set(0.5, 0.5);
instruction.y = 20;
self.duration = 0;
self.maxDuration = 3000; // 3 seconds
self.update = function () {
self.duration += 16.67;
if (self.duration >= self.maxDuration) {
self.destroy();
}
};
self.down = function () {
// Apply technique - boost credibilidad
credibilidad = Math.min(100, credibilidad + 15);
updateBars();
self.destroy();
};
return self;
});
var TextAttack = Container.expand(function () {
var self = Container.call(this);
// Create random attack text
var attackTexts = ['ESTRÉS', 'MIEDO', 'PÁNICO', 'DUDAS', 'CRÍTICAS'];
var randomText = attackTexts[Math.floor(Math.random() * attackTexts.length)];
var textGraphics = self.addChild(new Text2(randomText, {
size: getTextSize(false, level),
fill: 0xff0000,
stroke: 0x000000,
strokeThickness: 3
}));
textGraphics.anchor.set(0.5, 0.5);
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game Constants
// UI Elements
// Game Elements
// Sounds
var ATTACK_INTERVAL = 90;
var LEVEL_DIFF = 5;
var ANSIEDAD_RATE = 180;
var ANSIEDAD_PASSIVE = 2;
var MAX_LEVEL = 10;
var WIN_CRED = 60;
var SCORE_RATE = 60;
var SCORE_PER_LEVEL = 50;
var LEVEL_CRED_BOOST = 5;
var GAME_LEFT = 300;
var GAME_RIGHT = 1748;
var GAME_TOP = 200;
var GAME_BOTTOM = 2732;
var GAME_WIDTH = GAME_RIGHT - GAME_LEFT;
// Heart movement constants
var HEART_SPEED = 8;
var HEART_MARGIN = 60;
// Text size scaling function
function getTextSize(isGreen, currentLevel) {
var baseSize = 20;
var sizeMultiplier = 10;
var scale;
if (isGreen) {
// Green words: size 5 at level 1, size 1 at level 5
scale = 6 - currentLevel;
} else {
// Red words: size 1 at level 1, size 5 at level 5
scale = currentLevel;
}
// Ensure scale is between 1 and 5
scale = Math.max(1, Math.min(5, scale));
return baseSize + scale * sizeMultiplier;
}
// Game state management
var gameState = 'menu'; // 'menu', 'dialogue', or 'playing'
var menuContainer = game.addChild(new Container());
// Game variables
var level = 1;
var maxLevel = 5;
var dialogueContainer = game.addChild(new Container());
dialogueContainer.visible = false;
// Level narratives
var levelNarratives = ["Nivel 1: Bienvenido a tu primera sesión de tutoría. Los pensamientos negativos comenzarán lentamente.", "Nivel 2: Bien hecho. Ahora los ataques serán más frecuentes. Mantén la calma y usa las técnicas.", "Nivel 3: Excelente progreso. Los pensamientos llegan más rápido, pero ya tienes más experiencia.", "Nivel 4: Casi terminas tu entrenamiento. Los ataques son intensos, confía en tu preparación.", "Nivel 5: Nivel final. Domina completamente las técnicas contra los ataques más desafiantes."];
var score = 0;
var ansiedad = 0;
var credibilidad = 50;
// UI Elements
var ansiedadBarBg = null,
ansiedadBar = null,
credibilidadBarBg = null,
credibilidadBar = null;
var levelText = null,
scoreText = null;
// Initialize UI
function initializeUI() {
// Ansiedad bar
ansiedadBarBg = LK.gui.topLeft.addChild(LK.getAsset('ansiedadBarBg', {
anchorX: 0,
anchorY: 0
}));
ansiedadBarBg.x = 120;
ansiedadBarBg.y = 50;
ansiedadBar = LK.gui.topLeft.addChild(LK.getAsset('ansiedadBar', {
anchorX: 0,
anchorY: 0
}));
ansiedadBar.x = 120;
ansiedadBar.y = 50;
// Credibilidad bar
credibilidadBarBg = LK.gui.topLeft.addChild(LK.getAsset('credibilidadBarBg', {
anchorX: 0,
anchorY: 0
}));
credibilidadBarBg.x = 120;
credibilidadBarBg.y = 90;
credibilidadBar = LK.gui.topLeft.addChild(LK.getAsset('credibilidadBar', {
anchorX: 0,
anchorY: 0
}));
credibilidadBar.x = 120;
credibilidadBar.y = 90;
// Text labels
var ansiedadLabel = LK.gui.topLeft.addChild(new Text2('Ansiedad', {
size: 20,
fill: 0xffffff
}));
ansiedadLabel.x = 10;
ansiedadLabel.y = 60;
var credibilidadLabel = LK.gui.topLeft.addChild(new Text2('Credibilidad', {
size: 20,
fill: 0xffffff
}));
credibilidadLabel.x = 10;
credibilidadLabel.y = 100;
// Level and score
levelText = LK.gui.topRight.addChild(new Text2('Nivel: 1', {
size: 24,
fill: 0xffffff
}));
levelText.anchor.set(1, 0);
levelText.x = -20;
levelText.y = 50;
scoreText = LK.gui.topRight.addChild(new Text2('Puntos: 0', {
size: 24,
fill: 0xffffff
}));
scoreText.anchor.set(1, 0);
scoreText.x = -20;
scoreText.y = 80;
}
function updateBars() {
// Update bar widths based on values
ansiedadBar.width = ansiedad / 100 * 300;
credibilidadBar.width = credibilidad / 100 * 300;
// Update text
levelText.setText('Nivel: ' + level);
scoreText.setText('Puntos: ' + score);
}
function showDialogue(text) {
gameState = 'dialogue';
dialogueContainer.visible = true;
// Clear previous dialogue
dialogueContainer.removeChildren();
// Dialogue background
var dialogueBg = dialogueContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0
}));
dialogueBg.width = 1800;
dialogueBg.height = 200;
dialogueBg.tint = 0x333333;
dialogueBg.x = 1024;
dialogueBg.y = 180;
// Dialogue text
var dialogueText = dialogueContainer.addChild(new Text2(text, {
size: 28,
fill: 0xffffff
}));
dialogueText.anchor.set(0.5, 0.5);
dialogueText.x = 1024;
dialogueText.y = 280;
// Continue button
var continueBtn = dialogueContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
continueBtn.width = 300;
continueBtn.height = 80;
continueBtn.tint = 0x00aa00;
continueBtn.x = 1024;
continueBtn.y = 410;
var continueText = dialogueContainer.addChild(new Text2('Continuar', {
size: 32,
fill: 0xffffff
}));
continueText.anchor.set(0.5, 0.5);
continueText.x = continueBtn.x;
continueText.y = continueBtn.y;
continueBtn.down = function () {
dialogueContainer.visible = false;
gameState = 'playing';
// Initialize and show UI if not already done
if (!ansiedadBarBg || ansiedadBarBg && !ansiedadBarBg.parent) {
initializeUI();
}
updateBars();
heart.visible = true;
};
}
// Create menu elements
var logo = menuContainer.addChild(LK.getAsset('gameLogo', {
anchorX: 0.5,
anchorY: 0.5
}));
logo.x = 2048 / 2;
logo.y = 2732 / 2 - 250;
// Create play button
var playButton = menuContainer.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
}));
playButton.x = 2048 / 2;
playButton.y = 2732 / 2 + 100;
// Play button text
var playText = menuContainer.addChild(new Text2('JUGAR', {
size: 70,
fill: 0xFFFFFF
}));
playText.anchor.set(0.5, 0.5);
playText.x = playButton.x;
playText.y = playButton.y;
// Play button interaction
playButton.down = function (x, y, obj) {
// Flash button on press
tween(playButton, {
tint: 0xffffff
}, {
duration: 100,
onFinish: function onFinish() {
tween(playButton, {
tint: 0xffffff
}, {
duration: 100
});
}
});
};
playButton.up = function (x, y, obj) {
// Show level dialogue first
menuContainer.visible = false;
showDialogue(levelNarratives[level - 1]);
};
// Create the heart character
var heart = game.addChild(new Heart());
heart.x = 2048 / 2;
heart.y = GAME_BOTTOM - 100;
heart.visible = false;
// Keyboard controls - using LK event system instead of window
LK.on('keydown', function (event) {
if (gameState !== 'playing') return;
if (event.key === 'ArrowLeft') {
heart.isMovingLeft = true;
}
if (event.key === 'ArrowRight') {
heart.isMovingRight = true;
}
});
LK.on('keyup', function (event) {
if (gameState !== 'playing') return;
if (event.key === 'ArrowLeft') {
heart.isMovingLeft = false;
}
if (event.key === 'ArrowRight') {
heart.isMovingRight = false;
}
});
// Touch controls for mobile
game.move = function (x, y, obj) {
if (gameState === 'playing') {
// Move heart towards touch position
if (x < heart.x) {
heart.isMovingLeft = true;
heart.isMovingRight = false;
} else if (x > heart.x) {
heart.isMovingRight = true;
heart.isMovingLeft = false;
}
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
heart.isMovingLeft = false;
heart.isMovingRight = false;
}
};
// Game arrays and timers
var textAttacks = [];
var greenTextAttacks = [];
var attackTimer = 0;
var greenAttackTimer = 0;
var ansiedadTimer = 0;
var scoreTimer = 0;
// Main game update loop
game.update = function () {
// Only update game logic when playing
if (gameState !== 'playing') return;
// Spawn TextAttack
attackTimer++;
var spawnInterval = ATTACK_INTERVAL - level * LEVEL_DIFF;
if (attackTimer >= spawnInterval) {
var textAttack = new TextAttack();
textAttack.x = GAME_LEFT + Math.random() * GAME_WIDTH;
textAttack.y = GAME_TOP;
textAttacks.push(textAttack);
game.addChild(textAttack);
attackTimer = 0;
}
// Spawn GreenTextAttack (less frequent)
greenAttackTimer++;
var greenSpawnInterval = (ATTACK_INTERVAL - level * LEVEL_DIFF) * 2;
if (greenAttackTimer >= greenSpawnInterval) {
var greenTextAttack = new GreenTextAttack();
greenTextAttack.x = GAME_LEFT + Math.random() * GAME_WIDTH;
greenTextAttack.y = GAME_TOP;
greenTextAttacks.push(greenTextAttack);
game.addChild(greenTextAttack);
greenAttackTimer = 0;
}
// Update and check TextAttack collisions
for (var i = textAttacks.length - 1; i >= 0; i--) {
var atk = textAttacks[i];
// Check collision with heart
if (atk.intersects(heart)) {
heart.takeDamage(15);
ansiedad = Math.min(100, ansiedad + 10);
updateBars();
atk.destroy();
textAttacks.splice(i, 1);
continue;
}
// Remove off-screen attacks
if (atk.y > GAME_BOTTOM + 100) {
atk.destroy();
textAttacks.splice(i, 1);
}
}
// Update and check GreenTextAttack collisions
for (var k = greenTextAttacks.length - 1; k >= 0; k--) {
var greenAtk = greenTextAttacks[k];
// Check collision with heart
if (greenAtk.intersects(heart)) {
credibilidad = Math.min(100, credibilidad + 8);
updateBars();
greenAtk.destroy();
greenTextAttacks.splice(k, 1);
continue;
}
// Remove off-screen green attacks
if (greenAtk.y > GAME_BOTTOM + 100) {
greenAtk.destroy();
greenTextAttacks.splice(k, 1);
}
}
// Increase ansiedad passively
ansiedadTimer++;
if (ansiedadTimer >= ANSIEDAD_RATE) {
ansiedad = Math.min(100, ansiedad + ANSIEDAD_PASSIVE);
updateBars();
ansiedadTimer = 0;
}
// Update score and level
scoreTimer++;
if (scoreTimer >= SCORE_RATE) {
score++;
// Check for level up
if (score >= level * SCORE_PER_LEVEL && level < maxLevel) {
level++;
storage.currentLevel = level;
credibilidad = Math.min(100, credibilidad + LEVEL_CRED_BOOST);
// Show next level dialogue
showDialogue(levelNarratives[level - 1]);
}
updateBars();
scoreTimer = 0;
}
// Check game over
if (ansiedad >= 100) {
LK.showGameOver();
}
// Check win condition
if (level >= maxLevel && credibilidad >= WIN_CRED) {
LK.showYouWin();
}
};