User prompt
Colócale una buena música de fondo y efectos de sonido
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'text')' in or related to this line: 'LK.init.text('gameTitle', {' Line Number: 295
User prompt
Hazlo un poco más pequeña para que se entienda y agregalo a activos para yo reemplazarlo a mi gusto
User prompt
Colócalo un poco más grande y coloca la h en mayúscula y está ves escríbelo con una tipografía pixel para un juego retro
User prompt
En ves del título space dodger agrega "hasta el infinito y más allá" y has con letras amarillas en un formato de caligrafía retro
User prompt
El botón de disparo no se dispara corrige eso y has que al presionarlo salga del avión un proyectil que elimine los asteroides ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que el botón naranja sea un botón de disparo para disparar un proyectil y poder explotar un asteroide y has q el botón solo se pueda usar cada 15 segundos y agrega una animación de carga para indicar cuándo se puede volver a usar ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Colócalos mas arriba de manera dónde se vean pero que no interfiera con el contador de tiempo
User prompt
Coloca los corazones un poco más abajo para que se puedan ver un poco mejor
User prompt
Has que el avión haga un dash al presionar el botón de impulso ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Mueve los corazones a la parte de arriba del contador del tiempo para que no interfieran con la visión del contador de monedas
User prompt
Has que el avion tenga una animación de velocidad que lo tenga eleve más arriba al presionar el botón de impulso ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has un sistema de tres corazones en el juego y un poder que caiga cada 25 segundos que al atraparlo te haga inmune durante 10 segundos ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has una música para el juego y un sonido al perder y al agarrar las monedas
User prompt
Has un poder para que el avion acelere por 20 segundos y has una animación de aceleración ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Has que las palabras en los botones no se vean y coloca solo los activos de colores para yo poder sustituirlos por imágenes coloca el activo del botón de inicio también
User prompt
Has monedas en la partida para recolectar ↪💡 Consider importing and using the following plugins: @upit/storage.v1, @upit/tween.v1
User prompt
Has que cada 10 segundos la velocidad del avión aumente así como la de la caída de objetos para aumentar la velocidad del juego y así su dificultad
User prompt
El avión coliciona antes de llegar completamente al meteorito o escombro corrige eso y has que solo pierda si las dos imágenes se tocan correctamente
User prompt
Coloca en el menú un botón donde lleve a un apartado diferente dónde puedas elegir otro tipo de avión disponible para jugar en partida ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Has que el avión solo pierda si toca a un meteorito o escombro
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(self.scale, 200, {' Line Number: 83 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'storage.get is not a function' in or related to this line: 'var sensitivity = storage.get('sensitivity') || 1.0;' Line Number: 219 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Has un menú donde pongas un botón de iniciar partida, otro botón para ajustar la sensibilidad de la barra y decora
User prompt
Has que la barra de la parte de abajo sea más grande para poder manejarla mejor
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var BackButton = Container.expand(function (text) {
var self = Container.call(this);
var buttonBg = self.attachAsset('backButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 0.9,
y: 0.9
});
};
self.up = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 1.0,
y: 1.0
});
};
return self;
});
var Debris = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('debris', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.lastY = undefined;
self.update = function () {
self.y += self.speed;
};
return self;
});
var MenuButton = Container.expand(function (text, color) {
var self = Container.call(this);
var buttonBg = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5
});
if (color) buttonBg.tint = color;
var buttonText = new Text2(text, {
size: 60,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 0.9,
y: 0.9
});
};
self.up = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 1.0,
y: 1.0
});
};
return self;
});
var Meteorite = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('meteorite', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 4;
self.lastY = undefined;
self.update = function () {
self.y += self.speed;
};
return self;
});
var SensitivitySlider = Container.expand(function () {
var self = Container.call(this);
var sliderBar = self.attachAsset('sensSlider', {
anchorX: 0.5,
anchorY: 0.5
});
var sliderHandle = self.addChild(LK.getAsset('sensHandle', {
anchorX: 0.5,
anchorY: 0.5
}));
self.minX = -280;
self.maxX = 280;
self.isDragging = false;
self.down = function (x, y, obj) {
self.isDragging = true;
self.updateHandle(x);
};
self.up = function (x, y, obj) {
self.isDragging = false;
};
self.updateHandle = function (x) {
var localX = x - self.x;
localX = Math.max(self.minX, Math.min(self.maxX, localX));
sliderHandle.x = localX;
};
self.getSensitivity = function () {
return (sliderHandle.x + 280) / 560; // 0 to 1
};
self.setSensitivity = function (value) {
sliderHandle.x = value * 560 - 280;
};
return self;
});
var SettingsButton = Container.expand(function (text) {
var self = Container.call(this);
var buttonBg = self.attachAsset('settingsButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 50,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 0.9,
y: 0.9
});
};
self.up = function (x, y, obj) {
tween.to(self.scale, 200, {
x: 1.0,
y: 1.0
});
};
return self;
});
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var TouchSlider = Container.expand(function () {
var self = Container.call(this);
var sliderBar = self.attachAsset('sliderBar', {
anchorX: 0.5,
anchorY: 0.5
});
var sliderHandle = self.addChild(LK.getAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5
}));
self.minX = -380;
self.maxX = 380;
self.isDragging = false;
self.down = function (x, y, obj) {
self.isDragging = true;
self.updateHandle(x);
};
self.up = function (x, y, obj) {
self.isDragging = false;
};
self.updateHandle = function (x) {
var localX = x - self.x;
localX = Math.max(self.minX, Math.min(self.maxX, localX));
sliderHandle.x = localX;
};
self.getSliderValue = function () {
return sliderHandle.x / 380;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000011
});
/****
* Game Code
****/
// Game state management
var gameState = 'menu'; // 'menu', 'settings', 'playing'
var sensitivity = storage.get('sensitivity') || 1.0;
// Menu elements
var titleText = new Text2('SPACE DODGER', {
size: 120,
fill: 0x00aaff
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 600;
game.addChild(titleText);
var startButton = game.addChild(new MenuButton('INICIAR PARTIDA', 0x4444aa));
startButton.x = 2048 / 2;
startButton.y = 1200;
var settingsButton = game.addChild(new SettingsButton('SENSIBILIDAD'));
settingsButton.x = 2048 / 2;
settingsButton.y = 1400;
// Settings menu elements (initially hidden)
var settingsTitle = new Text2('AJUSTAR SENSIBILIDAD', {
size: 80,
fill: 0xFFFFFF
});
settingsTitle.anchor.set(0.5, 0.5);
settingsTitle.x = 2048 / 2;
settingsTitle.y = 800;
settingsTitle.visible = false;
game.addChild(settingsTitle);
var sensitivitySlider = game.addChild(new SensitivitySlider());
sensitivitySlider.x = 2048 / 2;
sensitivitySlider.y = 1200;
sensitivitySlider.visible = false;
sensitivitySlider.setSensitivity(sensitivity);
var sensValueText = new Text2('Sensibilidad: ' + Math.round(sensitivity * 100) + '%', {
size: 60,
fill: 0xFFFFFF
});
sensValueText.anchor.set(0.5, 0.5);
sensValueText.x = 2048 / 2;
sensValueText.y = 1350;
sensValueText.visible = false;
game.addChild(sensValueText);
var backButton = game.addChild(new BackButton('VOLVER'));
backButton.x = 2048 / 2;
backButton.y = 1500;
backButton.visible = false;
// Decorative elements
var stars = [];
for (var i = 0; i < 50; i++) {
var star = game.addChild(LK.getAsset('star', {
anchorX: 0.5,
anchorY: 0.5
}));
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
star.alpha = Math.random() * 0.8 + 0.2;
stars.push(star);
}
var planet1 = game.addChild(LK.getAsset('planet', {
anchorX: 0.5,
anchorY: 0.5
}));
planet1.x = 200;
planet1.y = 300;
planet1.alpha = 0.6;
planet1.tint = 0x8888ff;
var planet2 = game.addChild(LK.getAsset('planet', {
anchorX: 0.5,
anchorY: 0.5
}));
planet2.x = 1800;
planet2.y = 2400;
planet2.alpha = 0.4;
planet2.tint = 0xff8888;
planet2.scaleX = 0.7;
planet2.scaleY = 0.7;
// Game elements (initially hidden)
var spaceship;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var gameSpeed = 1;
var spaceshipSpeed = 1;
var survivalTime = 0;
var difficultyTimer = 0;
var lastScoreCheck = 0;
var slider;
// GUI elements (created but initially hidden)
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.visible = false;
LK.gui.top.addChild(scoreTxt);
var timeTxt = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(1, 0);
timeTxt.visible = false;
LK.gui.topRight.addChild(timeTxt);
timeTxt.x = -20;
timeTxt.y = 100;
game.move = function (x, y, obj) {
if (gameState === 'playing' && slider && slider.isDragging) {
slider.updateHandle(x);
var sliderValue = slider.getSliderValue();
spaceship.x = 2048 / 2 + sliderValue * 800 * spaceshipSpeed * sensitivity;
spaceship.x = Math.max(100, Math.min(1948, spaceship.x));
} else if (gameState === 'settings' && sensitivitySlider.isDragging) {
sensitivitySlider.updateHandle(x);
sensitivity = sensitivitySlider.getSensitivity();
sensValueText.setText('Sensibilidad: ' + Math.round(sensitivity * 100) + '%');
storage.set('sensitivity', sensitivity);
}
};
// Button handlers
startButton.up = function (x, y, obj) {
tween.to(startButton.scale, 200, {
x: 1.0,
y: 1.0
});
startGame();
};
settingsButton.up = function (x, y, obj) {
tween.to(settingsButton.scale, 200, {
x: 1.0,
y: 1.0
});
showSettings();
};
backButton.up = function (x, y, obj) {
tween.to(backButton.scale, 200, {
x: 1.0,
y: 1.0
});
showMenu();
};
function startGame() {
gameState = 'playing';
// Hide menu elements
titleText.visible = false;
startButton.visible = false;
settingsButton.visible = false;
// Show game elements
spaceship = game.addChild(new Spaceship());
spaceship.x = 2048 / 2;
spaceship.y = 2000;
slider = game.addChild(new TouchSlider());
slider.x = 2048 / 2;
slider.y = 2600;
scoreTxt.visible = true;
timeTxt.visible = true;
// Reset game variables
obstacles = [];
obstacleSpawnTimer = 0;
obstacleSpawnRate = 90;
gameSpeed = 1;
spaceshipSpeed = 1;
survivalTime = 0;
difficultyTimer = 0;
lastScoreCheck = 0;
LK.setScore(0);
scoreTxt.setText('0');
timeTxt.setText('Time: 0s');
}
function showSettings() {
gameState = 'settings';
// Hide menu elements
titleText.visible = false;
startButton.visible = false;
settingsButton.visible = false;
// Show settings elements
settingsTitle.visible = true;
sensitivitySlider.visible = true;
sensValueText.visible = true;
backButton.visible = true;
}
function showMenu() {
gameState = 'menu';
// Hide settings elements
settingsTitle.visible = false;
sensitivitySlider.visible = false;
sensValueText.visible = false;
backButton.visible = false;
// Hide game elements if they exist
if (spaceship) {
spaceship.destroy();
spaceship = null;
}
if (slider) {
slider.destroy();
slider = null;
}
scoreTxt.visible = false;
timeTxt.visible = false;
// Clear obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
// Show menu elements
titleText.visible = true;
startButton.visible = true;
settingsButton.visible = true;
}
game.update = function () {
// Animate stars
for (var s = 0; s < stars.length; s++) {
stars[s].alpha = Math.sin(LK.ticks * 0.02 + s) * 0.3 + 0.5;
}
// Rotate planets slowly
planet1.rotation += 0.005;
planet2.rotation -= 0.003;
// Only run game logic during gameplay
if (gameState !== 'playing' || !spaceship) {
return;
}
survivalTime++;
difficultyTimer++;
if (survivalTime % 60 === 0) {
var seconds = Math.floor(survivalTime / 60);
timeTxt.setText('Time: ' + seconds + 's');
}
// Every 15 seconds (900 ticks), increase obstacle speed by 5%
if (difficultyTimer >= 900) {
difficultyTimer = 0;
gameSpeed *= 1.05;
obstacleSpawnRate = Math.max(30, obstacleSpawnRate - 5);
}
// Every 50 points, increase spaceship speed slightly
var currentScore = LK.getScore();
if (Math.floor(currentScore / 50) > Math.floor(lastScoreCheck / 50)) {
spaceshipSpeed += 0.1;
}
lastScoreCheck = currentScore;
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnRate) {
obstacleSpawnTimer = 0;
var obstacle;
if (Math.random() < 0.7) {
obstacle = new Meteorite();
} else {
obstacle = new Debris();
}
obstacle.x = Math.random() * 1800 + 124;
obstacle.y = -100;
obstacle.speed *= gameSpeed;
obstacle.lastY = obstacle.y;
obstacles.push(obstacle);
game.addChild(obstacle);
}
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastY < 2800 && obstacle.y >= 2800) {
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
}
if (obstacle.y > 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
if (spaceship.intersects(obstacle)) {
LK.getSound('destroy').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
showMenu();
return;
}
obstacle.lastY = obstacle.y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,12 +1,39 @@
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
+var BackButton = Container.expand(function (text) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('backButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 0.9,
+ y: 0.9
+ });
+ };
+ self.up = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ };
+ return self;
+});
var Debris = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('debris', {
anchorX: 0.5,
@@ -18,8 +45,35 @@
self.y += self.speed;
};
return self;
});
+var MenuButton = Container.expand(function (text, color) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('menuButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ if (color) buttonBg.tint = color;
+ var buttonText = new Text2(text, {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 0.9,
+ y: 0.9
+ });
+ };
+ self.up = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ };
+ return self;
+});
var Meteorite = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('meteorite', {
anchorX: 0.5,
@@ -31,8 +85,67 @@
self.y += self.speed;
};
return self;
});
+var SensitivitySlider = Container.expand(function () {
+ var self = Container.call(this);
+ var sliderBar = self.attachAsset('sensSlider', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var sliderHandle = self.addChild(LK.getAsset('sensHandle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ self.minX = -280;
+ self.maxX = 280;
+ self.isDragging = false;
+ self.down = function (x, y, obj) {
+ self.isDragging = true;
+ self.updateHandle(x);
+ };
+ self.up = function (x, y, obj) {
+ self.isDragging = false;
+ };
+ self.updateHandle = function (x) {
+ var localX = x - self.x;
+ localX = Math.max(self.minX, Math.min(self.maxX, localX));
+ sliderHandle.x = localX;
+ };
+ self.getSensitivity = function () {
+ return (sliderHandle.x + 280) / 560; // 0 to 1
+ };
+ self.setSensitivity = function (value) {
+ sliderHandle.x = value * 560 - 280;
+ };
+ return self;
+});
+var SettingsButton = Container.expand(function (text) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('settingsButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(text, {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 0.9,
+ y: 0.9
+ });
+ };
+ self.up = function (x, y, obj) {
+ tween.to(self.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ };
+ return self;
+});
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('spaceship', {
anchorX: 0.5,
@@ -80,45 +193,227 @@
/****
* Game Code
****/
-var spaceship = game.addChild(new Spaceship());
-spaceship.x = 2048 / 2;
-spaceship.y = 2000;
+// Game state management
+var gameState = 'menu'; // 'menu', 'settings', 'playing'
+var sensitivity = storage.get('sensitivity') || 1.0;
+// Menu elements
+var titleText = new Text2('SPACE DODGER', {
+ size: 120,
+ fill: 0x00aaff
+});
+titleText.anchor.set(0.5, 0.5);
+titleText.x = 2048 / 2;
+titleText.y = 600;
+game.addChild(titleText);
+var startButton = game.addChild(new MenuButton('INICIAR PARTIDA', 0x4444aa));
+startButton.x = 2048 / 2;
+startButton.y = 1200;
+var settingsButton = game.addChild(new SettingsButton('SENSIBILIDAD'));
+settingsButton.x = 2048 / 2;
+settingsButton.y = 1400;
+// Settings menu elements (initially hidden)
+var settingsTitle = new Text2('AJUSTAR SENSIBILIDAD', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+settingsTitle.anchor.set(0.5, 0.5);
+settingsTitle.x = 2048 / 2;
+settingsTitle.y = 800;
+settingsTitle.visible = false;
+game.addChild(settingsTitle);
+var sensitivitySlider = game.addChild(new SensitivitySlider());
+sensitivitySlider.x = 2048 / 2;
+sensitivitySlider.y = 1200;
+sensitivitySlider.visible = false;
+sensitivitySlider.setSensitivity(sensitivity);
+var sensValueText = new Text2('Sensibilidad: ' + Math.round(sensitivity * 100) + '%', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+sensValueText.anchor.set(0.5, 0.5);
+sensValueText.x = 2048 / 2;
+sensValueText.y = 1350;
+sensValueText.visible = false;
+game.addChild(sensValueText);
+var backButton = game.addChild(new BackButton('VOLVER'));
+backButton.x = 2048 / 2;
+backButton.y = 1500;
+backButton.visible = false;
+// Decorative elements
+var stars = [];
+for (var i = 0; i < 50; i++) {
+ var star = game.addChild(LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ star.x = Math.random() * 2048;
+ star.y = Math.random() * 2732;
+ star.alpha = Math.random() * 0.8 + 0.2;
+ stars.push(star);
+}
+var planet1 = game.addChild(LK.getAsset('planet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+planet1.x = 200;
+planet1.y = 300;
+planet1.alpha = 0.6;
+planet1.tint = 0x8888ff;
+var planet2 = game.addChild(LK.getAsset('planet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+planet2.x = 1800;
+planet2.y = 2400;
+planet2.alpha = 0.4;
+planet2.tint = 0xff8888;
+planet2.scaleX = 0.7;
+planet2.scaleY = 0.7;
+// Game elements (initially hidden)
+var spaceship;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnRate = 90;
var gameSpeed = 1;
var spaceshipSpeed = 1;
var survivalTime = 0;
var difficultyTimer = 0;
var lastScoreCheck = 0;
-var slider = game.addChild(new TouchSlider());
-slider.x = 2048 / 2;
-slider.y = 2600;
+var slider;
+// GUI elements (created but initially hidden)
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
+scoreTxt.visible = false;
LK.gui.top.addChild(scoreTxt);
var timeTxt = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(1, 0);
+timeTxt.visible = false;
LK.gui.topRight.addChild(timeTxt);
timeTxt.x = -20;
timeTxt.y = 100;
game.move = function (x, y, obj) {
- if (slider.isDragging) {
+ if (gameState === 'playing' && slider && slider.isDragging) {
slider.updateHandle(x);
var sliderValue = slider.getSliderValue();
- spaceship.x = 2048 / 2 + sliderValue * 800 * spaceshipSpeed;
+ spaceship.x = 2048 / 2 + sliderValue * 800 * spaceshipSpeed * sensitivity;
spaceship.x = Math.max(100, Math.min(1948, spaceship.x));
+ } else if (gameState === 'settings' && sensitivitySlider.isDragging) {
+ sensitivitySlider.updateHandle(x);
+ sensitivity = sensitivitySlider.getSensitivity();
+ sensValueText.setText('Sensibilidad: ' + Math.round(sensitivity * 100) + '%');
+ storage.set('sensitivity', sensitivity);
}
};
+// Button handlers
+startButton.up = function (x, y, obj) {
+ tween.to(startButton.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ startGame();
+};
+settingsButton.up = function (x, y, obj) {
+ tween.to(settingsButton.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ showSettings();
+};
+backButton.up = function (x, y, obj) {
+ tween.to(backButton.scale, 200, {
+ x: 1.0,
+ y: 1.0
+ });
+ showMenu();
+};
+function startGame() {
+ gameState = 'playing';
+ // Hide menu elements
+ titleText.visible = false;
+ startButton.visible = false;
+ settingsButton.visible = false;
+ // Show game elements
+ spaceship = game.addChild(new Spaceship());
+ spaceship.x = 2048 / 2;
+ spaceship.y = 2000;
+ slider = game.addChild(new TouchSlider());
+ slider.x = 2048 / 2;
+ slider.y = 2600;
+ scoreTxt.visible = true;
+ timeTxt.visible = true;
+ // Reset game variables
+ obstacles = [];
+ obstacleSpawnTimer = 0;
+ obstacleSpawnRate = 90;
+ gameSpeed = 1;
+ spaceshipSpeed = 1;
+ survivalTime = 0;
+ difficultyTimer = 0;
+ lastScoreCheck = 0;
+ LK.setScore(0);
+ scoreTxt.setText('0');
+ timeTxt.setText('Time: 0s');
+}
+function showSettings() {
+ gameState = 'settings';
+ // Hide menu elements
+ titleText.visible = false;
+ startButton.visible = false;
+ settingsButton.visible = false;
+ // Show settings elements
+ settingsTitle.visible = true;
+ sensitivitySlider.visible = true;
+ sensValueText.visible = true;
+ backButton.visible = true;
+}
+function showMenu() {
+ gameState = 'menu';
+ // Hide settings elements
+ settingsTitle.visible = false;
+ sensitivitySlider.visible = false;
+ sensValueText.visible = false;
+ backButton.visible = false;
+ // Hide game elements if they exist
+ if (spaceship) {
+ spaceship.destroy();
+ spaceship = null;
+ }
+ if (slider) {
+ slider.destroy();
+ slider = null;
+ }
+ scoreTxt.visible = false;
+ timeTxt.visible = false;
+ // Clear obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ obstacles[i].destroy();
+ }
+ obstacles = [];
+ // Show menu elements
+ titleText.visible = true;
+ startButton.visible = true;
+ settingsButton.visible = true;
+}
game.update = function () {
+ // Animate stars
+ for (var s = 0; s < stars.length; s++) {
+ stars[s].alpha = Math.sin(LK.ticks * 0.02 + s) * 0.3 + 0.5;
+ }
+ // Rotate planets slowly
+ planet1.rotation += 0.005;
+ planet2.rotation -= 0.003;
+ // Only run game logic during gameplay
+ if (gameState !== 'playing' || !spaceship) {
+ return;
+ }
survivalTime++;
difficultyTimer++;
if (survivalTime % 60 === 0) {
var seconds = Math.floor(survivalTime / 60);
@@ -166,8 +461,9 @@
if (spaceship.intersects(obstacle)) {
LK.getSound('destroy').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
+ showMenu();
return;
}
obstacle.lastY = obstacle.y;
}