User prompt
add a line to flight and add a grapf. Shortly improve visuals
User prompt
make ui better
Code edit (1 edits merged)
Please save this source code
User prompt
Aviator Cashout
Initial prompt
make me a game like "Aviator" gambling game. It works with game money. So add money system and user must be select bet amount before the game. Than game has start. If user withdraws his money back before the flied crash it win his money with mulitplied.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
balance: 1000
});
/****
* Classes
****/
// Button class
var GameButton = Container.expand(function () {
var self = Container.call(this);
self.bg = null;
self.label = null;
self.setAsset = function (assetId, labelText, color) {
if (self.bg) self.bg.destroy();
self.bg = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
if (color !== undefined) self.bg.tint = color;
if (self.label) self.label.destroy();
self.label = new Text2(labelText, {
size: 60,
fill: "#fff"
});
self.label.anchor.set(0.5, 0.5);
self.addChild(self.label);
};
self.setText = function (txt) {
if (self.label) self.label.setText(txt);
};
return self;
});
// Default balance
// Plane class
var Plane = Container.expand(function () {
var self = Container.call(this);
var planeGfx = self.attachAsset('plane', {
anchorX: 0.5,
anchorY: 0.5
});
self.crashed = false;
self.setCrashed = function () {
self.crashed = true;
// Show crash effect
var crash = LK.getAsset('crash', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
self.addChild(crash);
tween(crash, {
alpha: 0
}, {
duration: 700,
onFinish: function onFinish() {
crash.destroy();
}
});
// Fade out plane
tween(planeGfx, {
alpha: 0
}, {
duration: 700
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a2233
});
/****
* Game Code
****/
// --- Game State Variables ---
// Plane (the flying object)
// Bet button
// Cashout button
// Crash explosion
// Virtual chip
var balance = storage.balance || 1000;
var betAmount = 100;
var minBet = 10;
var maxBet = 1000;
var betStep = 10;
var inRound = false;
var hasBet = false;
var hasCashedOut = false;
var roundMultiplier = 1.00;
var roundStartTick = 0;
var crashTick = 0;
var cashoutMultiplier = 0;
var plane = null;
var crashHappened = false;
var lastTick = 0;
var betBtn = null;
var cashoutBtn = null;
var betAmountTxt = null;
var balanceTxt = null;
var multiplierTxt = null;
var infoTxt = null;
var chipIcon = null;
// --- GUI Elements ---
// Balance display (larger, bolder, with chip icon closer)
multiplierTxt = new Text2("1.00x", {
size: 180,
fill: 0xFFE066,
stroke: "#222",
strokeThickness: 10,
dropShadow: true,
dropShadowColor: "#000",
dropShadowDistance: 8,
dropShadowAngle: Math.PI / 2,
dropShadowBlur: 8,
fontWeight: "bold"
});
multiplierTxt.anchor.set(0.5, 0);
multiplierTxt.y = 40;
LK.gui.top.addChild(multiplierTxt);
// Info text (centered, below multiplier, with shadow and spacing)
infoTxt = new Text2("Place your bet!", {
size: 70,
fill: "#fff",
stroke: "#222",
strokeThickness: 6,
dropShadow: true,
dropShadowColor: "#000",
dropShadowDistance: 4,
dropShadowAngle: Math.PI / 2,
dropShadowBlur: 6,
fontWeight: "bold"
});
infoTxt.anchor.set(0.5, 0);
infoTxt.y = multiplierTxt.y + multiplierTxt.height + 20;
LK.gui.top.addChild(infoTxt);
// Chip icon (left of balance)
chipIcon = LK.getAsset('chip', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
chipIcon.width = 90;
chipIcon.height = 90;
LK.gui.top.addChild(chipIcon);
balanceTxt = new Text2("Balance: $" + balance, {
size: 90,
fill: "#fff",
stroke: "#222",
strokeThickness: 6,
fontWeight: "bold"
});
balanceTxt.anchor.set(0, 0.5);
balanceTxt.x = chipIcon.x + chipIcon.width / 2 + 18;
LK.gui.top.addChild(balanceTxt);
// Bet amount display (larger, bolder)
betAmountTxt = new Text2("Bet: $" + betAmount, {
size: 90,
fill: "#fff",
stroke: "#222",
strokeThickness: 6,
fontWeight: "bold"
});
betAmountTxt.anchor.set(1, 0.5);
betAmountTxt.x = 2048 - 60;
LK.gui.topRight.addChild(betAmountTxt);
// --- Bet Button ---
betBtn = new GameButton();
betBtn.setAsset('betBtn', "BET", 0x2ecc40);
betBtn.bg.width = 520;
betBtn.bg.height = 180;
betBtn.bg.radius = 40;
betBtn.bg.dropShadow = true;
betBtn.bg.dropShadowColor = 0x222222;
betBtn.bg.dropShadowDistance = 8;
betBtn.bg.dropShadowAngle = Math.PI / 2;
betBtn.bg.dropShadowBlur = 8;
betBtn.x = 2048 / 2 - 320;
betBtn.y = 2732 - 260;
game.addChild(betBtn);
// --- Cashout Button ---
cashoutBtn = new GameButton();
cashoutBtn.setAsset('cashoutBtn', "CASHOUT", 0xe67e22);
cashoutBtn.bg.width = 520;
cashoutBtn.bg.height = 180;
cashoutBtn.bg.radius = 40;
cashoutBtn.bg.dropShadow = true;
cashoutBtn.bg.dropShadowColor = 0x222222;
cashoutBtn.bg.dropShadowDistance = 8;
cashoutBtn.bg.dropShadowAngle = Math.PI / 2;
cashoutBtn.bg.dropShadowBlur = 8;
cashoutBtn.x = 2048 / 2 + 320;
cashoutBtn.y = 2732 - 260;
game.addChild(cashoutBtn);
cashoutBtn.visible = false;
// --- Bet Amount Adjust (plus/minus buttons) ---
var betMinusBtn = new GameButton();
betMinusBtn.setAsset('betBtn', "-", 0x16a085);
betMinusBtn.bg.width = 120;
betMinusBtn.bg.height = 120;
betMinusBtn.bg.radius = 60;
betMinusBtn.x = 2048 - 420;
betMinusBtn.y = 180;
LK.gui.topRight.addChild(betMinusBtn);
var betPlusBtn = new GameButton();
betPlusBtn.setAsset('betBtn', "+", 0x16a085);
betPlusBtn.bg.width = 120;
betPlusBtn.bg.height = 120;
betPlusBtn.bg.radius = 60;
betPlusBtn.x = 2048 - 180;
betPlusBtn.y = 180;
LK.gui.topRight.addChild(betPlusBtn);
betMinusBtn.down = function (x, y, obj) {
if (inRound) return;
betAmount -= betStep;
if (betAmount < minBet) betAmount = maxBet;
betAmountTxt.setText("Bet: $" + betAmount);
};
betPlusBtn.down = function (x, y, obj) {
if (inRound) return;
betAmount += betStep;
if (betAmount > maxBet) betAmount = minBet;
betAmountTxt.setText("Bet: $" + betAmount);
};
// --- Bet Button Handler ---
betBtn.down = function (x, y, obj) {
if (inRound || hasBet) return;
if (balance < betAmount) {
infoTxt.setText("Not enough balance!");
return;
}
hasBet = true;
infoTxt.setText("Waiting for takeoff...");
betBtn.setText("WAIT");
betBtn.bg.tint = 0xaaaaaa;
// Deduct bet immediately
balance -= betAmount;
storage.balance = balance;
balanceTxt.setText("Balance: $" + balance);
// Start round after short delay
LK.setTimeout(startRound, 900);
};
// --- Cashout Button Handler ---
cashoutBtn.down = function (x, y, obj) {
if (!inRound || !hasBet || hasCashedOut || crashHappened) return;
hasCashedOut = true;
cashoutMultiplier = roundMultiplier;
var win = Math.floor(betAmount * cashoutMultiplier);
balance += win;
storage.balance = balance;
balanceTxt.setText("Balance: $" + balance);
infoTxt.setText("You cashed out: $" + win + " (" + cashoutMultiplier.toFixed(2) + "x)");
cashoutBtn.visible = false;
betBtn.visible = false;
// Animate plane off screen
if (plane) {
tween(plane, {
y: -200
}, {
duration: 800,
easing: tween.cubicOut,
onFinish: function onFinish() {
endRound();
}
});
} else {
endRound();
}
};
// --- Start Round ---
function startRound() {
inRound = true;
crashHappened = false;
hasCashedOut = false;
cashoutMultiplier = 0;
roundMultiplier = 1.00;
roundStartTick = LK.ticks;
// Random crash time: between 2s and 8s (120-480 ticks)
crashTick = roundStartTick + 120 + Math.floor(Math.random() * 360);
// Place plane at bottom center
if (plane) plane.destroy();
plane = new Plane();
plane.x = 2048 / 2;
plane.y = 2732 - 600;
game.addChild(plane);
// Animate plane takeoff
tween(plane, {
y: 2732 / 2
}, {
duration: 1200,
easing: tween.cubicOut
});
// UI
betBtn.visible = false;
cashoutBtn.visible = true;
cashoutBtn.setText("CASHOUT");
cashoutBtn.bg.tint = 0xe67e22;
infoTxt.setText("Flying... Tap CASHOUT to win!");
multiplierTxt.setText("1.00x");
}
// --- End Round ---
function endRound() {
inRound = false;
hasBet = false;
hasCashedOut = false;
betBtn.visible = true;
betBtn.setText("BET");
betBtn.bg.tint = 0x2ecc40;
cashoutBtn.visible = false;
if (plane) {
plane.destroy();
plane = null;
}
// If player lost, show info
if (crashHappened && !cashoutMultiplier) {
infoTxt.setText("Crashed! You lost $" + betAmount);
} else if (!crashHappened && cashoutMultiplier) {
infoTxt.setText("You won $" + Math.floor(betAmount * cashoutMultiplier) + "!");
} else {
infoTxt.setText("Place your bet!");
}
// Reset multiplier display
multiplierTxt.setText("1.00x");
// Update bet amount display
betAmountTxt.setText("Bet: $" + betAmount);
}
// --- Crash Handler ---
function handleCrash() {
crashHappened = true;
if (plane) plane.setCrashed();
cashoutBtn.visible = false;
betBtn.visible = false;
if (!hasCashedOut) {
cashoutMultiplier = 0;
// Show crash info
infoTxt.setText("Crashed! You lost $" + betAmount);
// End round after short delay
LK.setTimeout(endRound, 1200);
} else {
// Already cashed out, just end round
LK.setTimeout(endRound, 800);
}
}
// --- Main Game Update ---
game.update = function () {
if (!inRound) return;
// Calculate multiplier: Exponential growth, e.g. 1.00x to ~20x in 8s
var ticksElapsed = LK.ticks - roundStartTick;
// Multiplier formula: 1.002^(ticksElapsed*2) for smooth curve
roundMultiplier = Math.max(1, Math.floor(100 * Math.pow(1.002, ticksElapsed * 2)) / 100);
multiplierTxt.setText(roundMultiplier.toFixed(2) + "x");
// Animate plane moving up and right as multiplier increases
if (plane && !plane.crashed) {
plane.x = 2048 / 2 + ticksElapsed * 2.5;
plane.y = 2732 - 600 - ticksElapsed * 3.2;
}
// Crash?
if (LK.ticks >= crashTick && !crashHappened) {
handleCrash();
}
};
// --- Reset on Game Over (handled by LK) ---
// --- Touchscreen: Prevent elements in top left 100x100
// (All GUI elements are placed away from top left)
// --- Initial UI State ---
betBtn.visible = true;
cashoutBtn.visible = false;
infoTxt.setText("Place your bet!");
multiplierTxt.setText("1.00x");
balanceTxt.setText("Balance: $" + balance);
betAmountTxt.setText("Bet: $" + betAmount); ===================================================================
--- original.js
+++ change.js
@@ -80,14 +80,14 @@
/****
* Game Code
****/
-// Virtual chip
-// Crash explosion
-// Cashout button
-// Bet button
-// Plane (the flying object)
// --- Game State Variables ---
+// Plane (the flying object)
+// Bet button
+// Cashout button
+// Crash explosion
+// Virtual chip
var balance = storage.balance || 1000;
var betAmount = 100;
var minBet = 10;
var maxBet = 1000;