/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CashOutButton = Container.expand(function () {
var self = Container.call(this);
var buttonBg = self.attachAsset('cashOutButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2('CASH OUT', {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
if (gameState === 'flying') {
cashOut();
}
};
return self;
});
var Rocket = Container.expand(function () {
var self = Container.call(this);
var rocketGraphics = self.attachAsset('rocket', {
anchorX: 0.5,
anchorY: 1.0
});
var flame = self.attachAsset('flame', {
anchorX: 0.5,
anchorY: 0,
y: 5
});
self.speed = 0;
self.trailTimer = 0;
self.update = function () {
// Add flame animation
flame.scaleX = 0.8 + Math.sin(LK.ticks * 0.3) * 0.3;
flame.scaleY = 0.8 + Math.sin(LK.ticks * 0.2) * 0.4;
// Create trail particles
self.trailTimer++;
if (self.trailTimer % 3 === 0) {
var trail = new TrailParticle();
trail.x = self.x + (Math.random() - 0.5) * 20;
trail.y = self.y + 10;
game.addChild(trail);
trailParticles.push(trail);
}
};
return self;
});
var TrailParticle = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('trail', {
anchorX: 0.5,
anchorY: 0.5
});
self.life = 60;
self.maxLife = 60;
self.update = function () {
self.life--;
graphics.alpha = self.life / self.maxLife;
if (self.life <= 0) {
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
// Game state variables
var gameState = 'betting'; // 'betting', 'flying', 'crashed'
var currentMultiplier = 1.0;
var betAmount = 10;
var crashPoint = 0;
var rocketStartY = 2400;
var rocketCurrentY = rocketStartY;
var flightStartTime = 0;
var hasPlayerCashedOut = false;
var playerBalance = storage.balance || 1000;
var trailParticles = [];
var previousCrashes = storage.crashes || [];
// UI Elements
var backgroundGraphics = game.attachAsset('background', {
anchorX: 0,
anchorY: 0
});
var rocket = new Rocket();
rocket.x = 1024;
rocket.y = rocketStartY;
game.addChild(rocket);
var multiplierText = new Text2('1.00x', {
size: 80,
fill: 0xFFFFFF
});
multiplierText.anchor.set(0.5, 0);
LK.gui.top.addChild(multiplierText);
multiplierText.y = 200;
var balanceText = new Text2('Balance: $' + playerBalance, {
size: 40,
fill: 0xFFFFFF
});
balanceText.anchor.set(0, 0);
LK.gui.topRight.addChild(balanceText);
balanceText.x = -20;
balanceText.y = 20;
var betText = new Text2('Bet: $' + betAmount, {
size: 50,
fill: 0xFFFFFF
});
betText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(betText);
betText.y = -200;
var statusText = new Text2('Place your bet and tap to launch!', {
size: 40,
fill: 0xFFFF00
});
statusText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(statusText);
var cashOutButton = new CashOutButton();
cashOutButton.x = 1024;
cashOutButton.y = 2200;
cashOutButton.alpha = 0;
game.addChild(cashOutButton);
var betButton = game.attachAsset('betButton', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 2600
});
var betButtonText = new Text2('LAUNCH ($' + betAmount + ')', {
size: 30,
fill: 0xFFFFFF
});
betButtonText.anchor.set(0.5, 0.5);
betButtonText.x = 1024;
betButtonText.y = 2570;
game.addChild(betButtonText);
// Previous crashes display
var crashHistoryText = new Text2('Previous crashes: ' + (previousCrashes.length > 0 ? previousCrashes.slice(-5).join('x, ') + 'x' : 'None'), {
size: 30,
fill: 0x888888
});
crashHistoryText.anchor.set(0.5, 0);
LK.gui.top.addChild(crashHistoryText);
crashHistoryText.y = 120;
function generateCrashPoint() {
// Generate crash point between 1.01x and 10.00x with higher probability for lower values
var random = Math.random();
if (random < 0.5) {
return 1.01 + Math.random() * 1.99; // 1.01x - 3.00x (50% chance)
} else if (random < 0.8) {
return 3.0 + Math.random() * 2.0; // 3.00x - 5.00x (30% chance)
} else {
return 5.0 + Math.random() * 5.0; // 5.00x - 10.00x (20% chance)
}
}
function startRound() {
if (playerBalance < betAmount) {
statusText.setText('Insufficient balance!');
return;
}
gameState = 'flying';
playerBalance -= betAmount;
hasPlayerCashedOut = false;
crashPoint = generateCrashPoint();
flightStartTime = LK.ticks;
rocketCurrentY = rocketStartY;
currentMultiplier = 1.0;
// Update UI
balanceText.setText('Balance: $' + Math.floor(playerBalance));
statusText.setText('Cash out before it crashes!');
// Show cash out button
tween(cashOutButton, {
alpha: 1
}, {
duration: 300
});
// Hide bet button
tween(betButton, {
alpha: 0
}, {
duration: 300
});
tween(betButtonText, {
alpha: 0
}, {
duration: 300
});
LK.getSound('launch').play();
}
function cashOut() {
if (gameState !== 'flying' || hasPlayerCashedOut) return;
hasPlayerCashedOut = true;
var winnings = Math.floor(betAmount * currentMultiplier);
playerBalance += winnings;
statusText.setText('Cashed out! Won $' + winnings);
balanceText.setText('Balance: $' + Math.floor(playerBalance));
// Hide cash out button
tween(cashOutButton, {
alpha: 0
}, {
duration: 300
});
LK.getSound('cashout').play();
// End round after delay
LK.setTimeout(function () {
endRound();
}, 2000);
}
function crashRocket() {
gameState = 'crashed';
if (!hasPlayerCashedOut) {
statusText.setText('CRASHED! You lost $' + betAmount);
}
// Add crash point to history
previousCrashes.push(parseFloat(currentMultiplier.toFixed(2)));
if (previousCrashes.length > 10) {
previousCrashes.shift();
}
// Flash screen red
LK.effects.flashScreen(0xff0000, 500);
// Hide cash out button
tween(cashOutButton, {
alpha: 0
}, {
duration: 300
});
LK.getSound('crash').play();
// End round after delay
LK.setTimeout(function () {
endRound();
}, 2000);
}
function endRound() {
gameState = 'betting';
// Reset rocket position
rocket.y = rocketStartY;
rocketCurrentY = rocketStartY;
// Clear trail particles
for (var i = trailParticles.length - 1; i >= 0; i--) {
trailParticles[i].destroy();
trailParticles.splice(i, 1);
}
// Show bet button
betButton.alpha = 1;
betButtonText.alpha = 1;
betButtonText.setText('LAUNCH ($' + betAmount + ')');
// Update crash history
crashHistoryText.setText('Previous crashes: ' + (previousCrashes.length > 0 ? previousCrashes.slice(-5).join('x, ') + 'x' : 'None'));
statusText.setText('Place your bet and tap to launch!');
// Save data
storage.balance = playerBalance;
storage.crashes = previousCrashes;
}
// Event handlers
game.down = function (x, y, obj) {
var localPos = game.toLocal({
x: x,
y: y
});
// Check if bet button was clicked
if (gameState === 'betting' && localPos.x > betButton.x - betButton.width / 2 && localPos.x < betButton.x + betButton.width / 2 && localPos.y > betButton.y - betButton.height && localPos.y < betButton.y) {
startRound();
}
};
game.update = function () {
// Update trail particles
for (var i = trailParticles.length - 1; i >= 0; i--) {
if (trailParticles[i] && trailParticles[i].life <= 0) {
trailParticles.splice(i, 1);
}
}
if (gameState === 'flying') {
// Calculate flight time and multiplier
var flightTime = (LK.ticks - flightStartTime) / 60; // Convert to seconds
currentMultiplier = 1.0 + flightTime * 0.5; // Multiplier increases by 0.5 per second
// Update rocket position (move up as multiplier increases)
var progress = (currentMultiplier - 1.0) / 9.0; // Progress from 0 to 1 over 9x multiplier
rocket.y = rocketStartY - progress * 1800;
// Add slight wobble to rocket
rocket.x = 1024 + Math.sin(LK.ticks * 0.1) * 10;
// Update multiplier display
multiplierText.setText(currentMultiplier.toFixed(2) + 'x');
// Check if rocket should crash
if (currentMultiplier >= crashPoint && !hasPlayerCashedOut) {
crashRocket();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -274,9 +274,9 @@
x: x,
y: y
});
// Check if bet button was clicked
- if (gameState === 'betting' && localPos.x > betButton.x - 100 && localPos.x < betButton.x + 100 && localPos.y > betButton.y - 30 && localPos.y < betButton.y + 30) {
+ if (gameState === 'betting' && localPos.x > betButton.x - betButton.width / 2 && localPos.x < betButton.x + betButton.width / 2 && localPos.y > betButton.y - betButton.height && localPos.y < betButton.y) {
startRound();
}
};
game.update = function () {