User prompt
el boton de back de inventario este un poco mas abajo
User prompt
quiero que el titulo de inventario este un poco mas arriba
User prompt
tambien quiero que lo quiten cuando apriestas el lugar de inventario
User prompt
te dije que cuando este en el menu de inicio quites eso de altitud y score
User prompt
quita todo el texto que dice adentro de inventario, solo deja el boton de back y inventory
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of null (reading 'destroy')' in or related to this line: 'shopButton.destroy();' Line Number: 884
User prompt
se ve que se te complica mejor configuremos lo que esta adentro del boton de inventario
User prompt
el color azul en el boton de shop
User prompt
pero en el boton de shop
User prompt
Deep sky quiero ese
User prompt
pero se pone de color amarillo y yo no pido eso
User prompt
dije celeste no amarillo
User prompt
entonces de colo celeste
User prompt
el color del boton de shop que sea AZUL
User prompt
dije color blue, AZUL, que es ese color que pusiste we
User prompt
pero el fondo del boton de la tienda que sea azul
User prompt
agrega un boton solamente con el diseño de start game, y que sea de color azul y su funcion sea para tienda, que este colocado abajo del boton de inventario
User prompt
quita el boton de tienda
User prompt
dije de color azul no negro
User prompt
el boton de tienda quiero que sea de color azul
User prompt
quiero que la tienda sea de color azul
User prompt
quiero que el boton de tienda no te lleve a ningun sitio, yo solo queria el diseño
User prompt
quiero que en ves de decir inventario diga tienda, y sea de color azul
User prompt
quiero que dupliques el boton de inventario y lo coloques mas abajo
User prompt
quiero que cuando topes el boton de inventario te lleve a otro sitio parecido a la pantalla de inicio
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.0,
scaleY: 3.0
});
self.speed = 12 + Math.random() * 10;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.update = function () {
self.y += self.speed;
asteroidGraphics.rotation += self.rotationSpeed;
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.5,
scaleY: 2.5
});
self.speed = 8 + Math.random() * 4;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
// Add floating animation
self.floatDirection = 1;
self.floatSpeed = 0.03 + Math.random() * 0.02;
self.floatAmount = 12 + Math.random() * 8;
self.floatTimer = Math.random() * 120;
self.update = function () {
self.y += self.speed;
coinGraphics.rotation += self.rotationSpeed;
// Add floating effect
self.floatTimer += self.floatSpeed;
var floatOffset = Math.sin(self.floatTimer) * self.floatAmount;
coinGraphics.y = floatOffset;
};
return self;
});
var Debris = Container.expand(function () {
var self = Container.call(this);
var debrisGraphics = self.attachAsset('debris', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
// Make medium debris darker
debrisGraphics.tint = 0x404040;
self.speed = 10 + Math.random() * 8;
self.horizontalSpeed = (Math.random() - 0.5) * 2;
self.update = function () {
self.y += self.speed;
self.x += self.horizontalSpeed;
};
return self;
});
var Fuel = Container.expand(function () {
var self = Container.call(this);
var fuelGraphics = self.attachAsset('fuel', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3.0,
scaleY: 3.0
});
self.speed = 9 + Math.random() * 6;
// Start floating animation
self.floatDirection = 1;
self.floatSpeed = 0.02 + Math.random() * 0.02;
self.floatAmount = 15 + Math.random() * 10;
self.originalY = 0;
self.floatTimer = Math.random() * 120;
// Add diverse rotation properties
self.rotationSpeed = (Math.random() - 0.5) * 0.04; // Random speed between -0.02 and 0.02
self.rotationDirection = Math.random() > 0.5 ? 1 : -1; // Random direction
self.update = function () {
self.y += self.speed;
// Add floating effect
self.floatTimer += self.floatSpeed;
var floatOffset = Math.sin(self.floatTimer) * self.floatAmount;
fuelGraphics.y = floatOffset;
// Add diverse rotation
fuelGraphics.rotation += self.rotationSpeed * self.rotationDirection;
};
return self;
});
var Spaceship = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('spaceship', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2.0,
scaleY: 2.0
});
self.speed = 0;
self.maxSpeed = 8;
self.acceleration = 0.3;
self.friction = 0.85;
self.targetX = 1024; // Default center position
self.update = function () {
// Smoothly move towards target position
var deltaX = self.targetX - self.x;
self.x += deltaX * 0.2; // Smooth interpolation factor
// Keep ship within bounds
if (self.x < 40) {
self.x = 40;
}
if (self.x > 2008) {
self.x = 2008;
}
};
self.moveLeft = function () {
self.speed = Math.max(self.speed - self.acceleration, -self.maxSpeed);
};
self.moveRight = function () {
self.speed = Math.min(self.speed + self.acceleration, self.maxSpeed);
};
self.setTargetX = function (x) {
self.targetX = x;
};
return self;
});
var Spark = Container.expand(function () {
var self = Container.call(this);
var sparkGraphics = self.attachAsset('debris', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2 + Math.random() * 0.3,
scaleY: 0.5 + Math.random() * 0.6
});
// Make all sparks orange color
sparkGraphics.tint = 0xff6600;
self.speed = 8 + Math.random() * 6;
self.horizontalSpeed = (Math.random() - 0.5) * 4;
self.life = 30 + Math.random() * 20;
self.maxLife = self.life;
self.update = function () {
self.y += self.speed;
self.x += self.horizontalSpeed;
self.life--;
// Fade out over time with higher minimum opacity
self.alpha = Math.max(0.3, self.life / self.maxLife);
// Scale down over time but maintain larger minimum size
var scale = Math.max(0.2, self.life / self.maxLife * 0.5);
sparkGraphics.scaleX = scale;
sparkGraphics.scaleY = scale;
};
return self;
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('debris', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2 + Math.random() * 0.3,
scaleY: 0.2 + Math.random() * 0.3
});
// Make stars white and bright
starGraphics.tint = 0xffffff;
self.speed = 3 + Math.random() * 4;
self.twinkleTimer = Math.random() * 120;
self.maxAlpha = 0.8 + Math.random() * 0.2;
self.alpha = self.maxAlpha;
self.update = function () {
self.y += self.speed;
// Twinkling effect
self.twinkleTimer += 1;
var twinkle = Math.sin(self.twinkleTimer * 0.05) * 0.3 + 0.7;
self.alpha = self.maxAlpha * twinkle;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000011
});
/****
* Game Code
****/
// Game state management
var gameStarted = false;
var inventoryScreenShown = false;
var startScreen = null;
var startButton = null;
var secondButton = null;
var secondButtonText = null;
var shopButton = null;
var shopButtonText = null;
var inventoryScreen = null;
var inventoryBackButton = null;
var inventoryBackButtonText = null;
var spaceship = new Spaceship();
var obstacles = [];
var stars = [];
var sparks = [];
var scrollSpeed = 6;
var spawnTimer = 0;
var spawnRate = 120; // frames between spawns
var gameSpeed = 1;
var altitude = 0;
var lastTouchX = null;
var isDragging = false;
var maxHealth = 100;
var currentHealth = 100;
var healthBarBg;
var healthBarFill;
var maxFuel = 100;
var currentFuel = 100;
var fuelBarBg;
var fuelBarFill;
var fuelConsumptionRate = 0.15; // Fuel consumed per frame
var fuelPickups = [];
var coins = [];
// Create horizontal bar behind spaceship
var spaceshipBar = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5
});
spaceshipBar.x = 1024;
spaceshipBar.y = 2400;
spaceshipBar.alpha = 0.5; // Make bar even more transparent
game.addChild(spaceshipBar);
// Position spaceship
spaceship.x = 1024;
spaceship.y = 2400;
game.addChild(spaceship);
// Create score display
var scoreText = new Text2('Altitude: 0m', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
scoreText.visible = false; // Hide initially
LK.gui.top.addChild(scoreText);
// Create altitude display
var altitudeText = new Text2('Score: 0', {
size: 50,
fill: 0xFFFFFF
});
altitudeText.anchor.set(0.5, 0);
altitudeText.y = 80;
altitudeText.visible = false; // Hide initially
LK.gui.top.addChild(altitudeText);
// Create health bar background
healthBarBg = LK.getAsset('healthBarBg', {
anchorX: 0.5,
anchorY: 0.0
});
healthBarBg.x = 1024;
healthBarBg.y = 200;
game.addChild(healthBarBg);
// Create health bar fill
healthBarFill = LK.getAsset('healthBarFill', {
anchorX: 0.5,
anchorY: 0.0
});
healthBarFill.x = 1024;
healthBarFill.y = 202;
game.addChild(healthBarFill);
// Create fuel bar background
fuelBarBg = LK.getAsset('fuelBarBg', {
anchorX: 0.5,
anchorY: 0.0
});
fuelBarBg.x = 150;
fuelBarBg.y = 300;
game.addChild(fuelBarBg);
// Create fuel bar fill
fuelBarFill = LK.getAsset('fuelBarFill', {
anchorX: 0.5,
anchorY: 0.0
});
fuelBarFill.x = 150;
fuelBarFill.y = 302;
game.addChild(fuelBarFill);
// Create fuel icon below fuel bar
var fuelIcon = LK.getAsset('fuel', {
anchorX: 0.5,
anchorY: 0.0,
scaleX: 2.5,
scaleY: 2.5
});
fuelIcon.x = 150;
fuelIcon.y = 1850; // Position below the fuel bar
game.addChild(fuelIcon);
// Start pulsing animation for fuel icon
function startFuelIconPulse() {
tween(fuelIcon, {
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(fuelIcon, {
scaleX: 2.5,
scaleY: 2.5
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: startFuelIconPulse
});
}
});
}
startFuelIconPulse();
function createObstacle() {
var obstacle;
if (Math.random() < 0.7) {
obstacle = new Asteroid();
} else {
obstacle = new Debris();
}
obstacle.x = Math.random() * (2048 - 100) + 50;
obstacle.y = -50;
obstacles.push(obstacle);
game.addChild(obstacle);
// Z-index management: larger objects (asteroids) should render above smaller objects (debris)
// Find the correct index to insert this obstacle
var targetIndex = game.getChildIndex(obstacle); // Start with current index
var maxIndex = game.children.length - 1;
// Only reorder if we have other obstacles to compare with
if (obstacle instanceof Asteroid) {
// Asteroids should be above debris - find the highest debris index
for (var j = 0; j < game.children.length; j++) {
var child = game.children[j];
if (child instanceof Debris) {
targetIndex = Math.min(j + 1, maxIndex);
}
}
} else if (obstacle instanceof Debris) {
// Debris should be below asteroids - find the lowest asteroid index
for (var j = 0; j < game.children.length; j++) {
var child = game.children[j];
if (child instanceof Asteroid) {
targetIndex = Math.max(j - 1, 0);
break; // Insert before first asteroid
}
}
}
// Ensure targetIndex is within valid bounds
targetIndex = Math.max(0, Math.min(targetIndex, maxIndex));
game.setChildIndex(obstacle, targetIndex);
}
function handleTouch(x, y) {
// Directly set spaceship target to cursor position
spaceship.setTargetX(x);
}
game.down = function (x, y, obj) {
if (inventoryScreenShown) {
// Check if back button was clicked in inventory screen
if (inventoryBackButton && x >= inventoryBackButton.x - 495 && x <= inventoryBackButton.x + 495 && y >= inventoryBackButton.y - 48 && y <= inventoryBackButton.y + 48) {
inventoryScreenShown = false;
removeInventoryScreen();
createStartScreen();
}
return;
}
if (!gameStarted) {
// Check if start button was clicked
if (startButton && x >= startButton.x - 495 && x <= startButton.x + 495 && y >= startButton.y - 48 && y <= startButton.y + 48) {
gameStarted = true;
removeStartScreen();
}
// Check if second button was clicked
if (secondButton && x >= secondButton.x - 495 && x <= secondButton.x + 495 && y >= secondButton.y - 48 && y <= secondButton.y + 48) {
// Show inventory screen
inventoryScreenShown = true;
removeStartScreen();
createInventoryScreen();
}
return;
}
isDragging = true;
lastTouchX = x;
handleTouch(x, y);
};
game.move = function (x, y, obj) {
if (!gameStarted) return;
// Always follow cursor, not just when dragging
handleTouch(x, y);
};
game.up = function (x, y, obj) {
isDragging = false;
lastTouchX = null;
};
game.update = function () {
if (inventoryScreenShown || !gameStarted) {
// Only update twinkling stars on start screen and inventory screen
if (LK.ticks % 15 === 0) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = -10;
stars.push(star);
game.addChild(star);
// Move star behind everything
game.setChildIndex(star, 0);
}
// Update and cleanup stars
for (var s = stars.length - 1; s >= 0; s--) {
var star = stars[s];
if (star.lastY === undefined) star.lastY = star.y;
if (star.lastY < 2800 && star.y >= 2800) {
star.destroy();
stars.splice(s, 1);
continue;
}
star.lastY = star.y;
}
return;
}
// Update altitude only
altitude += scrollSpeed;
// Update displays
scoreText.setText('Altitude: ' + Math.floor(altitude) + 'm');
altitudeText.setText('Score: ' + LK.getScore());
// Increase difficulty over time
if (LK.ticks % 600 === 0) {
// Every 10 seconds
gameSpeed += 0.1;
scrollSpeed = Math.min(scrollSpeed + 0.3, 10);
spawnRate = Math.max(spawnRate - 5, 30);
}
// Spawn obstacles - increase frequency based on altitude
spawnTimer++;
// Calculate dynamic spawn rate based on altitude
var altitudeBasedSpawnRate = Math.max(spawnRate - Math.floor(altitude / 500), 15); // Decrease spawn rate (increase frequency) every 500m altitude, minimum 15 frames
if (spawnTimer >= altitudeBasedSpawnRate) {
// Spawn normal obstacle first
createObstacle();
// Spawn additional large asteroids based on altitude (not small debris)
var extraAsteroidCount = Math.floor(altitude / 2000); // Add extra asteroid every 2000m altitude
for (var obs = 0; obs < extraAsteroidCount; obs++) {
// Force spawn only asteroids for altitude-based increases
var asteroid = new Asteroid();
asteroid.x = Math.random() * (2048 - 100) + 50;
asteroid.y = -50;
obstacles.push(asteroid);
game.addChild(asteroid);
// Z-index management for asteroids
var targetIndex = game.getChildIndex(asteroid);
var maxIndex = game.children.length - 1;
for (var j = 0; j < game.children.length; j++) {
var child = game.children[j];
if (child instanceof Debris) {
targetIndex = Math.min(j + 1, maxIndex);
}
}
targetIndex = Math.max(0, Math.min(targetIndex, maxIndex));
game.setChildIndex(asteroid, targetIndex);
}
spawnTimer = 0;
}
// Consume fuel constantly
currentFuel -= fuelConsumptionRate;
if (currentFuel < 0) currentFuel = 0;
// Update fuel bar
var fuelPercent = currentFuel / maxFuel;
fuelBarFill.scaleY = fuelPercent;
fuelBarFill.y = 302 + 1596 * (1 - fuelPercent);
// Fuel bar maintains original blue color - no color changes
// Lose health when out of fuel
if (currentFuel <= 0) {
currentHealth -= 1;
// Update health bar
var healthPercent = currentHealth / maxHealth;
healthBarFill.scaleX = healthPercent;
healthBarFill.x = 1024 - 148 + 296 * healthPercent * 0.5;
// Check if health is depleted
if (currentHealth <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Spawn fuel pickups occasionally
if (LK.ticks % 300 === 0) {
// Every 5 seconds
var fuelPickup = new Fuel();
fuelPickup.x = Math.random() * (2048 - 100) + 50;
fuelPickup.y = -50;
fuelPickups.push(fuelPickup);
game.addChild(fuelPickup);
}
// Spawn coins regularly
if (LK.ticks % 180 === 0) {
// Every 3 seconds
var coin = new Coin();
coin.x = Math.random() * (2048 - 100) + 50;
coin.y = -50;
coins.push(coin);
game.addChild(coin);
}
// Update fuel pickups and check collisions
for (var f = fuelPickups.length - 1; f >= 0; f--) {
var fuelPickup = fuelPickups[f];
// Track last position for cleanup
if (fuelPickup.lastY === undefined) fuelPickup.lastY = fuelPickup.y;
// Remove fuel pickups that are off screen
if (fuelPickup.lastY < 2800 && fuelPickup.y >= 2800) {
fuelPickup.destroy();
fuelPickups.splice(f, 1);
continue;
}
// Check collision with spaceship
if (fuelPickup.intersects(spaceship)) {
// Completely refill fuel
currentFuel = maxFuel;
LK.getSound('fuel_pickup').play();
fuelPickup.destroy();
fuelPickups.splice(f, 1);
continue;
}
fuelPickup.lastY = fuelPickup.y;
}
// Update coins and check collisions
for (var c = coins.length - 1; c >= 0; c--) {
var coin = coins[c];
// Track last position for cleanup
if (coin.lastY === undefined) coin.lastY = coin.y;
// Remove coins that are off screen
if (coin.lastY < 2800 && coin.y >= 2800) {
coin.destroy();
coins.splice(c, 1);
continue;
}
// Check collision with spaceship
if (coin.intersects(spaceship)) {
// Increase score when collecting coin
LK.setScore(LK.getScore() + 1);
LK.getSound('coin_collect').play();
coin.destroy();
coins.splice(c, 1);
continue;
}
coin.lastY = coin.y;
}
// Update obstacles and check collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Track last position for cleanup
if (obstacle.lastY === undefined) obstacle.lastY = obstacle.y;
// Remove obstacles that are off screen
if (obstacle.lastY < 2800 && obstacle.y >= 2800) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with spaceship
if (obstacle.intersects(spaceship)) {
// Only deal damage if it's an asteroid (not small debris or stars)
if (obstacle instanceof Asteroid) {
// Reduce health instead of immediate game over
currentHealth -= 20;
// Update health bar
var healthPercent = currentHealth / maxHealth;
healthBarFill.scaleX = healthPercent;
healthBarFill.x = 1024 - 148 + 296 * healthPercent * 0.5;
// Flash screen red briefly
LK.effects.flashScreen(0xff0000, 300);
LK.getSound('explosion').play();
// Check if health is depleted
if (currentHealth <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Remove only asteroids that hit us
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
}
obstacle.lastY = obstacle.y;
}
// Spawn beautiful twinkling stars
if (LK.ticks % 15 === 0) {
var star = new Star();
star.x = Math.random() * 2048;
star.y = -10;
stars.push(star);
game.addChild(star);
// Move star behind spaceship bar
game.setChildIndex(star, 0);
}
// Update stars and remove off-screen ones
for (var s = stars.length - 1; s >= 0; s--) {
var star = stars[s];
// Track last position for cleanup
if (star.lastY === undefined) star.lastY = star.y;
// Remove stars that are off screen
if (star.lastY < 2800 && star.y >= 2800) {
star.destroy();
stars.splice(s, 1);
continue;
}
star.lastY = star.y;
}
// Spawn fire sparks from spaceship thrusters
if (LK.ticks % 3 === 0) {
// Create 2-3 sparks every few frames
var sparkCount = 2 + Math.floor(Math.random() * 2);
for (var sp = 0; sp < sparkCount; sp++) {
var spark = new Spark();
// Position sparks at bottom of spaceship with some spread
spark.x = spaceship.x + (Math.random() - 0.5) * 60;
spark.y = spaceship.y + 60; // Bottom of spaceship
sparks.push(spark);
game.addChild(spark);
}
}
// Move spaceship elements to front every frame to stay above obstacles
game.setChildIndex(spaceshipBar, game.children.length - 1);
game.setChildIndex(spaceship, game.children.length - 1);
// Move all sparks to front to stay above obstacles
for (var sp = 0; sp < sparks.length; sp++) {
var spark = sparks[sp];
if (spark.parent === game) {
game.setChildIndex(spark, game.children.length - 1);
}
}
// Update sparks and remove dead ones
for (var k = sparks.length - 1; k >= 0; k--) {
var spark = sparks[k];
// Remove sparks that are dead or off screen
if (spark.life <= 0 || spark.y > 2800) {
spark.destroy();
sparks.splice(k, 1);
continue;
}
}
};
// Pause functionality is handled automatically by LK engine
function createStartScreen() {
// Create semi-transparent background
startScreen = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.0,
scaleY: 137.0
});
startScreen.x = 1024;
startScreen.y = 1366;
startScreen.alpha = 0.8;
startScreen.tint = 0x000033;
game.addChild(startScreen);
// Create background for text content
var textBackground = LK.getAsset('startScreenBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.28,
scaleY: 2.732
});
textBackground.x = 1024;
textBackground.y = 1366;
textBackground.alpha = 1.0;
game.addChild(textBackground);
// Create title text
var titleText = new Text2('SPACE NAVIGATOR', {
size: 120,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 150;
game.addChild(titleText);
// Create start button
startButton = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.45,
scaleY: 12.0
});
startButton.x = 1024;
startButton.y = 1000;
startButton.tint = 0x00AA00;
game.addChild(startButton);
// Start pulsing animation for start button
function startButtonPulse() {
tween(startButton, {
scaleX: 0.4,
scaleY: 11.5,
tint: 0x00FF00
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 0.45,
scaleY: 12.0,
tint: 0x00AA00
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: startButtonPulse
});
}
});
}
startButtonPulse();
// Create button text
var buttonText = new Text2('START GAME', {
size: 80,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
buttonText.anchor.set(0.5, 0.5);
buttonText.x = 1024;
buttonText.y = 1000;
game.addChild(buttonText);
// Create second button
secondButton = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.45,
scaleY: 12.0
});
secondButton.x = 1024;
secondButton.y = 1300;
secondButton.tint = 0xD2B48C;
game.addChild(secondButton);
// Start pulsing animation for second button
function secondButtonPulse() {
tween(secondButton, {
scaleX: 0.4,
scaleY: 11.5,
tint: 0xF5DEB3
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(secondButton, {
scaleX: 0.45,
scaleY: 12.0,
tint: 0xD2B48C
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: secondButtonPulse
});
}
});
}
secondButtonPulse();
// Create second button text
secondButtonText = new Text2('INVENTORY', {
size: 80,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
secondButtonText.anchor.set(0.5, 0.5);
secondButtonText.x = 1024;
secondButtonText.y = 1300;
game.addChild(secondButtonText);
// Create shop button
var shopButton = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.45,
scaleY: 12.0
});
shopButton.x = 1024;
shopButton.y = 1600;
shopButton.tint = 0x00BFFF;
game.addChild(shopButton);
// Start pulsing animation for shop button
function shopButtonPulse() {
tween(shopButton, {
scaleX: 0.4,
scaleY: 11.5,
tint: 0x00BFFF
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(shopButton, {
scaleX: 0.45,
scaleY: 12.0,
tint: 0x00BFFF
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: shopButtonPulse
});
}
});
}
shopButtonPulse();
// Create shop button text
var shopButtonText = new Text2('SHOP', {
size: 80,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
shopButtonText.anchor.set(0.5, 0.5);
shopButtonText.x = 1024;
shopButtonText.y = 1600;
game.addChild(shopButtonText);
// Hide main menu button when start screen is shown
mainMenuButton.visible = false;
// Store references for cleanup
startScreen.titleText = titleText;
startScreen.buttonText = buttonText;
startScreen.textBackground = textBackground;
startScreen.secondButton = secondButton;
startScreen.secondButtonText = secondButtonText;
startScreen.shopButton = shopButton;
startScreen.shopButtonText = shopButtonText;
}
function removeStartScreen() {
if (startScreen) {
// Stop any ongoing tween animations on the start button
if (startButton) {
tween.stop(startButton);
}
// Stop any ongoing tween animations on the second button
if (secondButton) {
tween.stop(secondButton);
}
// Stop any ongoing tween animations on the shop button
if (shopButton) {
tween.stop(shopButton);
}
// Show main menu button when game starts
mainMenuButton.visible = true;
// Show altitude and score text when game starts
scoreText.visible = true;
altitudeText.visible = true;
startScreen.destroy();
startScreen.titleText.destroy();
startScreen.buttonText.destroy();
startScreen.textBackground.destroy();
startButton.destroy();
secondButton.destroy();
secondButtonText.destroy();
shopButton.destroy();
shopButtonText.destroy();
startScreen = null;
startButton = null;
secondButton = null;
secondButtonText = null;
shopButton = null;
shopButtonText = null;
}
}
// Create main menu button next to pause button
var mainMenuButton = new Text2('MENU', {
size: 55,
fill: 0xFFFFFF
});
mainMenuButton.anchor.set(0, 0);
mainMenuButton.x = 160; // Position to the right of pause button area
mainMenuButton.y = 50;
LK.gui.addChild(mainMenuButton);
// Add touch handler for main menu button
mainMenuButton.down = function (x, y, obj) {
// Reset game state and show start screen
gameStarted = false;
inventoryScreenShown = false;
// Hide altitude and score text when returning to main menu
scoreText.visible = false;
altitudeText.visible = false;
// Clear all game objects
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].destroy();
}
obstacles = [];
for (var s = stars.length - 1; s >= 0; s--) {
stars[s].destroy();
}
stars = [];
for (var sp = sparks.length - 1; sp >= 0; sp--) {
sparks[sp].destroy();
}
sparks = [];
for (var f = fuelPickups.length - 1; f >= 0; f--) {
fuelPickups[f].destroy();
}
fuelPickups = [];
for (var c = coins.length - 1; c >= 0; c--) {
coins[c].destroy();
}
coins = [];
// Reset game variables
altitude = 0;
scrollSpeed = 6;
spawnTimer = 0;
spawnRate = 120;
gameSpeed = 1;
currentHealth = 100;
currentFuel = 100;
LK.setScore(0);
// Reset spaceship position
spaceship.x = 1024;
spaceship.y = 2400;
spaceship.targetX = 1024;
// Reset health bar
var healthPercent = currentHealth / maxHealth;
healthBarFill.scaleX = healthPercent;
healthBarFill.x = 1024 - 148 + 296 * healthPercent * 0.5;
// Reset fuel bar
var fuelPercent = currentFuel / maxFuel;
fuelBarFill.scaleY = fuelPercent;
fuelBarFill.y = 302 + 1596 * (1 - fuelPercent);
// Show start screen
createStartScreen();
};
function createInventoryScreen() {
// Create semi-transparent background
inventoryScreen = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.0,
scaleY: 137.0
});
inventoryScreen.x = 1024;
inventoryScreen.y = 1366;
inventoryScreen.alpha = 0.8;
inventoryScreen.tint = 0x000033;
game.addChild(inventoryScreen);
// Create background for content
var inventoryBackground = LK.getAsset('startScreenBg', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.28,
scaleY: 2.732
});
inventoryBackground.x = 1024;
inventoryBackground.y = 1366;
inventoryBackground.alpha = 1.0;
game.addChild(inventoryBackground);
// Create title text
var inventoryTitleText = new Text2('INVENTORY', {
size: 120,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
inventoryTitleText.anchor.set(0.5, 0.5);
inventoryTitleText.x = 1024;
inventoryTitleText.y = 300;
game.addChild(inventoryTitleText);
// Create back button
inventoryBackButton = LK.getAsset('spaceshipBar', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.45,
scaleY: 12.0
});
inventoryBackButton.x = 1024;
inventoryBackButton.y = 2200;
inventoryBackButton.tint = 0x666666;
game.addChild(inventoryBackButton);
// Start pulsing animation for back button
function inventoryBackButtonPulse() {
tween(inventoryBackButton, {
scaleX: 0.4,
scaleY: 11.5,
tint: 0x888888
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(inventoryBackButton, {
scaleX: 0.45,
scaleY: 12.0,
tint: 0x666666
}, {
duration: 600,
easing: tween.easeInOut,
onFinish: inventoryBackButtonPulse
});
}
});
}
inventoryBackButtonPulse();
// Create coins display
var coinsText = new Text2('Coins: ' + LK.getScore(), {
size: 80,
fill: 0xFFD700,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
coinsText.anchor.set(0.5, 0.5);
coinsText.x = 1024;
coinsText.y = 500;
game.addChild(coinsText);
// Create fuel tank upgrade section
var fuelUpgradeText = new Text2('Fuel Tank Upgrade', {
size: 70,
fill: 0x00AAFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
fuelUpgradeText.anchor.set(0.5, 0.5);
fuelUpgradeText.x = 1024;
fuelUpgradeText.y = 800;
game.addChild(fuelUpgradeText);
var fuelUpgradeDesc = new Text2('Increase fuel capacity by 25%', {
size: 50,
fill: 0xCCCCCC,
font: "'Arial', sans-serif"
});
fuelUpgradeDesc.anchor.set(0.5, 0.5);
fuelUpgradeDesc.x = 1024;
fuelUpgradeDesc.y = 880;
game.addChild(fuelUpgradeDesc);
var fuelUpgradeCost = new Text2('Cost: 50 coins', {
size: 60,
fill: 0xFFD700,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
fuelUpgradeCost.anchor.set(0.5, 0.5);
fuelUpgradeCost.x = 1024;
fuelUpgradeCost.y = 940;
game.addChild(fuelUpgradeCost);
// Create ship speed upgrade section
var speedUpgradeText = new Text2('Ship Speed Upgrade', {
size: 70,
fill: 0xFF6600,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
speedUpgradeText.anchor.set(0.5, 0.5);
speedUpgradeText.x = 1024;
speedUpgradeText.y = 1200;
game.addChild(speedUpgradeText);
var speedUpgradeDesc = new Text2('Increase ship maneuverability', {
size: 50,
fill: 0xCCCCCC,
font: "'Arial', sans-serif"
});
speedUpgradeDesc.anchor.set(0.5, 0.5);
speedUpgradeDesc.x = 1024;
speedUpgradeDesc.y = 1280;
game.addChild(speedUpgradeDesc);
var speedUpgradeCost = new Text2('Cost: 30 coins', {
size: 60,
fill: 0xFFD700,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
speedUpgradeCost.anchor.set(0.5, 0.5);
speedUpgradeCost.x = 1024;
speedUpgradeCost.y = 1340;
game.addChild(speedUpgradeCost);
// Create armor upgrade section
var armorUpgradeText = new Text2('Armor Plating', {
size: 70,
fill: 0x888888,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
armorUpgradeText.anchor.set(0.5, 0.5);
armorUpgradeText.x = 1024;
armorUpgradeText.y = 1600;
game.addChild(armorUpgradeText);
var armorUpgradeDesc = new Text2('Reduce damage taken by 25%', {
size: 50,
fill: 0xCCCCCC,
font: "'Arial', sans-serif"
});
armorUpgradeDesc.anchor.set(0.5, 0.5);
armorUpgradeDesc.x = 1024;
armorUpgradeDesc.y = 1680;
game.addChild(armorUpgradeDesc);
var armorUpgradeCost = new Text2('Cost: 75 coins', {
size: 60,
fill: 0xFFD700,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
armorUpgradeCost.anchor.set(0.5, 0.5);
armorUpgradeCost.x = 1024;
armorUpgradeCost.y = 1740;
game.addChild(armorUpgradeCost);
// Create back button text
inventoryBackButtonText = new Text2('BACK', {
size: 80,
fill: 0xFFFFFF,
font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
});
inventoryBackButtonText.anchor.set(0.5, 0.5);
inventoryBackButtonText.x = 1024;
inventoryBackButtonText.y = 2200;
game.addChild(inventoryBackButtonText);
// Hide main menu button when inventory screen is shown
mainMenuButton.visible = false;
// Store references for cleanup
inventoryScreen.inventoryTitleText = inventoryTitleText;
inventoryScreen.inventoryBackground = inventoryBackground;
inventoryScreen.inventoryBackButton = inventoryBackButton;
inventoryScreen.inventoryBackButtonText = inventoryBackButtonText;
inventoryScreen.coinsText = coinsText;
inventoryScreen.fuelUpgradeText = fuelUpgradeText;
inventoryScreen.fuelUpgradeDesc = fuelUpgradeDesc;
inventoryScreen.fuelUpgradeCost = fuelUpgradeCost;
inventoryScreen.speedUpgradeText = speedUpgradeText;
inventoryScreen.speedUpgradeDesc = speedUpgradeDesc;
inventoryScreen.speedUpgradeCost = speedUpgradeCost;
inventoryScreen.armorUpgradeText = armorUpgradeText;
inventoryScreen.armorUpgradeDesc = armorUpgradeDesc;
inventoryScreen.armorUpgradeCost = armorUpgradeCost;
}
function removeInventoryScreen() {
if (inventoryScreen) {
// Stop any ongoing tween animations on the back button
if (inventoryBackButton) {
tween.stop(inventoryBackButton);
}
// Show main menu button when returning to start screen
mainMenuButton.visible = true;
inventoryScreen.destroy();
inventoryScreen.inventoryTitleText.destroy();
inventoryScreen.inventoryBackground.destroy();
inventoryScreen.coinsText.destroy();
inventoryScreen.fuelUpgradeText.destroy();
inventoryScreen.fuelUpgradeDesc.destroy();
inventoryScreen.fuelUpgradeCost.destroy();
inventoryScreen.speedUpgradeText.destroy();
inventoryScreen.speedUpgradeDesc.destroy();
inventoryScreen.speedUpgradeCost.destroy();
inventoryScreen.armorUpgradeText.destroy();
inventoryScreen.armorUpgradeDesc.destroy();
inventoryScreen.armorUpgradeCost.destroy();
inventoryBackButton.destroy();
inventoryBackButtonText.destroy();
inventoryScreen = null;
inventoryBackButton = null;
inventoryBackButtonText = null;
}
}
// Initialize start screen
createStartScreen();
// Start background music
LK.playMusic('space_music');
; ===================================================================
--- original.js
+++ change.js
@@ -987,8 +987,102 @@
}
});
}
inventoryBackButtonPulse();
+ // Create coins display
+ var coinsText = new Text2('Coins: ' + LK.getScore(), {
+ size: 80,
+ fill: 0xFFD700,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ coinsText.anchor.set(0.5, 0.5);
+ coinsText.x = 1024;
+ coinsText.y = 500;
+ game.addChild(coinsText);
+ // Create fuel tank upgrade section
+ var fuelUpgradeText = new Text2('Fuel Tank Upgrade', {
+ size: 70,
+ fill: 0x00AAFF,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ fuelUpgradeText.anchor.set(0.5, 0.5);
+ fuelUpgradeText.x = 1024;
+ fuelUpgradeText.y = 800;
+ game.addChild(fuelUpgradeText);
+ var fuelUpgradeDesc = new Text2('Increase fuel capacity by 25%', {
+ size: 50,
+ fill: 0xCCCCCC,
+ font: "'Arial', sans-serif"
+ });
+ fuelUpgradeDesc.anchor.set(0.5, 0.5);
+ fuelUpgradeDesc.x = 1024;
+ fuelUpgradeDesc.y = 880;
+ game.addChild(fuelUpgradeDesc);
+ var fuelUpgradeCost = new Text2('Cost: 50 coins', {
+ size: 60,
+ fill: 0xFFD700,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ fuelUpgradeCost.anchor.set(0.5, 0.5);
+ fuelUpgradeCost.x = 1024;
+ fuelUpgradeCost.y = 940;
+ game.addChild(fuelUpgradeCost);
+ // Create ship speed upgrade section
+ var speedUpgradeText = new Text2('Ship Speed Upgrade', {
+ size: 70,
+ fill: 0xFF6600,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ speedUpgradeText.anchor.set(0.5, 0.5);
+ speedUpgradeText.x = 1024;
+ speedUpgradeText.y = 1200;
+ game.addChild(speedUpgradeText);
+ var speedUpgradeDesc = new Text2('Increase ship maneuverability', {
+ size: 50,
+ fill: 0xCCCCCC,
+ font: "'Arial', sans-serif"
+ });
+ speedUpgradeDesc.anchor.set(0.5, 0.5);
+ speedUpgradeDesc.x = 1024;
+ speedUpgradeDesc.y = 1280;
+ game.addChild(speedUpgradeDesc);
+ var speedUpgradeCost = new Text2('Cost: 30 coins', {
+ size: 60,
+ fill: 0xFFD700,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ speedUpgradeCost.anchor.set(0.5, 0.5);
+ speedUpgradeCost.x = 1024;
+ speedUpgradeCost.y = 1340;
+ game.addChild(speedUpgradeCost);
+ // Create armor upgrade section
+ var armorUpgradeText = new Text2('Armor Plating', {
+ size: 70,
+ fill: 0x888888,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ armorUpgradeText.anchor.set(0.5, 0.5);
+ armorUpgradeText.x = 1024;
+ armorUpgradeText.y = 1600;
+ game.addChild(armorUpgradeText);
+ var armorUpgradeDesc = new Text2('Reduce damage taken by 25%', {
+ size: 50,
+ fill: 0xCCCCCC,
+ font: "'Arial', sans-serif"
+ });
+ armorUpgradeDesc.anchor.set(0.5, 0.5);
+ armorUpgradeDesc.x = 1024;
+ armorUpgradeDesc.y = 1680;
+ game.addChild(armorUpgradeDesc);
+ var armorUpgradeCost = new Text2('Cost: 75 coins', {
+ size: 60,
+ fill: 0xFFD700,
+ font: "'Arial Black', 'Impact', 'Helvetica Bold', sans-serif"
+ });
+ armorUpgradeCost.anchor.set(0.5, 0.5);
+ armorUpgradeCost.x = 1024;
+ armorUpgradeCost.y = 1740;
+ game.addChild(armorUpgradeCost);
// Create back button text
inventoryBackButtonText = new Text2('BACK', {
size: 80,
fill: 0xFFFFFF,
@@ -1004,8 +1098,18 @@
inventoryScreen.inventoryTitleText = inventoryTitleText;
inventoryScreen.inventoryBackground = inventoryBackground;
inventoryScreen.inventoryBackButton = inventoryBackButton;
inventoryScreen.inventoryBackButtonText = inventoryBackButtonText;
+ inventoryScreen.coinsText = coinsText;
+ inventoryScreen.fuelUpgradeText = fuelUpgradeText;
+ inventoryScreen.fuelUpgradeDesc = fuelUpgradeDesc;
+ inventoryScreen.fuelUpgradeCost = fuelUpgradeCost;
+ inventoryScreen.speedUpgradeText = speedUpgradeText;
+ inventoryScreen.speedUpgradeDesc = speedUpgradeDesc;
+ inventoryScreen.speedUpgradeCost = speedUpgradeCost;
+ inventoryScreen.armorUpgradeText = armorUpgradeText;
+ inventoryScreen.armorUpgradeDesc = armorUpgradeDesc;
+ inventoryScreen.armorUpgradeCost = armorUpgradeCost;
}
function removeInventoryScreen() {
if (inventoryScreen) {
// Stop any ongoing tween animations on the back button
@@ -1016,8 +1120,18 @@
mainMenuButton.visible = true;
inventoryScreen.destroy();
inventoryScreen.inventoryTitleText.destroy();
inventoryScreen.inventoryBackground.destroy();
+ inventoryScreen.coinsText.destroy();
+ inventoryScreen.fuelUpgradeText.destroy();
+ inventoryScreen.fuelUpgradeDesc.destroy();
+ inventoryScreen.fuelUpgradeCost.destroy();
+ inventoryScreen.speedUpgradeText.destroy();
+ inventoryScreen.speedUpgradeDesc.destroy();
+ inventoryScreen.speedUpgradeCost.destroy();
+ inventoryScreen.armorUpgradeText.destroy();
+ inventoryScreen.armorUpgradeDesc.destroy();
+ inventoryScreen.armorUpgradeCost.destroy();
inventoryBackButton.destroy();
inventoryBackButtonText.destroy();
inventoryScreen = null;
inventoryBackButton = null;