Code edit (4 edits merged)
Please save this source code
User prompt
change the multiplier text to remove the X from the text and just leave the value
Code edit (1 edits merged)
Please save this source code
User prompt
change the multiplier UI text to remove the word multiplier and just leave the "X1"
User prompt
move the flipping coin 50 pixels lower
Code edit (1 edits merged)
Please save this source code
Initial prompt
Copy Toss the Toast
/****
* Classes
****/
var HeadsAsset = Container.expand(function () {
var self = Container.call(this);
self.headsGraphics = self.attachAsset('heads', {
anchorX: 0.5,
anchorY: 0.5
});
self.headsGraphics.visible = true;
});
var TailsAsset = Container.expand(function () {
var self = Container.call(this);
self.tailsGraphics = self.attachAsset('tails', {
anchorX: 0.5,
anchorY: 0.5
});
self.tailsGraphics.visible = false;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
self.heads = new HeadsAsset();
self.tails = new TailsAsset();
self.addChild(self.heads);
self.addChild(self.tails);
self.currentSide = 'heads';
self.flipDuration = 60;
self.maxDuration = 660;
self.flipInterval = null;
self.flipTimeout = null;
self.flip = function (onFlipEnd) {
var flipCoin = function flipCoin() {
self.currentSide = self.currentSide === 'heads' ? 'tails' : 'heads';
self.heads.headsGraphics.visible = self.currentSide === 'heads';
self.tails.tailsGraphics.visible = self.currentSide === 'tails';
self.flipDuration *= 1.5;
if (self.flipDuration <= self.maxDuration) {
self.flipInterval = LK.setTimeout(flipCoin, self.flipDuration);
} else {
LK.clearTimeout(self.flipInterval);
self.flipTimeout = LK.setTimeout(function () {
var finalSide = Math.random() < 0.5 ? 'heads' : 'tails';
self.currentSide = finalSide;
self.heads.headsGraphics.visible = finalSide === 'heads';
self.tails.tailsGraphics.visible = finalSide === 'tails';
if (typeof onFlipEnd === 'function') {
onFlipEnd(finalSide === 'heads');
}
self.flipDuration = 60;
game.enableButtons();
game.headsButton.visible = true;
game.tailsButton.visible = true;
game.coinFlipping = false;
}, 1000);
}
};
LK.clearTimeout(self.flipInterval);
LK.clearTimeout(self.flipTimeout);
self.flipDuration = 60;
flipCoin();
};
});
var ChoiceButton = Container.expand(function (assetId, description, isHeads) {
var self = Container.call(this);
self.isHeads = isHeads;
self.gameInstance = null;
var buttonGraphic = self.createAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.interactive = true;
self.buttonMode = true;
self.on('down', function () {
if (!self.gameInstance.coinFlipping) {
self.gameInstance.coinFlipping = true;
self.gameInstance.headsButton.visible = false;
self.gameInstance.tailsButton.visible = false;
self.gameInstance.resetBackground(); // Reset and animate background
self.gameInstance.coin.flip(function (flipResult) {
if (flipResult !== self.isHeads) {
game.lives -= 1;
game.updateLivesDisplay();
if (game.lives <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
game.multiplier = 1;
LK.showGameOver();
}
return;
}
self.gameInstance.multiplier *= 2;
self.gameInstance.updateMultiplierDisplay();
});
self.gameInstance.disableButtons();
}
});
});
var MultiplierDisplay = Container.expand(function () {
var self = Container.call(this);
self.multiplierText = new Text2('MULTIPLIER X 1', {
size: 70,
fill: "#ffffff",
align: 'center',
stroke: '#000000',
strokeThickness: 15
});
self.multiplierText.anchor.set(0.5, 0);
self.addChild(self.multiplierText);
self.multiplierText.x = LK.gui.topCenter.x - 700;
self.multiplierText.y = LK.gui.top.y + 330;
self.updateMultiplier = function (multiplier) {
self.multiplierText.setText('MULTIPLIER X ' + multiplier.toString());
};
});
var LivesDisplay = Container.expand(function () {
var self = Container.call(this);
self.livesIcons = [];
for (var i = 0; i < 3; i++) {
var icon = self.attachAsset('lives', {
anchorX: 0.5,
anchorY: 0.5
});
icon.x = i * icon.width + i * 10;
self.livesIcons.push(icon);
}
self.updateLives = function (lives) {
for (var i = 0; i < self.livesIcons.length; i++) {
if (i < lives) {
self.livesIcons[i].tint = 0xFFFFFF; // Reset to white if life is available
} else {
self.livesIcons[i].tint = 0x000000; // Change to black if life is lost
}
}
};
self.y = 2732 / 20 - self.livesIcons[0].height / 10;
self.x = 2048 / 1.8 - ((self.livesIcons[0].width + 10) * self.livesIcons.length - 10) / 2; // Position the lives display at the middle of the screen
});
var Background = Container.expand(function () {
var self = Container.call(this);
self.shakeBackground = function () {
var shakeDuration = 5; // quarter of a second at 60FPS
var shakeAmount = 10; // shake by 10 pixels
var shakeInterval = null;
var shake = function shake() {
if (shakeDuration-- > 0) {
self.backgroundGraphics.x += (Math.random() - 0.5) * shakeAmount;
self.backgroundGraphics.y += (Math.random() - 0.5) * shakeAmount;
} else {
LK.clearInterval(shakeInterval);
self.backgroundGraphics.x = 2048 / 2;
self.backgroundGraphics.y = 2732 / 2; // Reset to original position
}
};
shakeInterval = LK.setInterval(shake, 1000 / 60);
};
self.backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
self.backgroundGraphics.x = 2048 / 2;
self.backgroundGraphics.y = 2732 / 2; // Start centered on the screen
self.moveToCenter = function () {
var startY = self.backgroundGraphics.y;
var endY = 2732 / 2;
var duration = 130; // 1.5 seconds at 60FPS
var distance = startY - endY;
var step = distance / duration; // Adjust step for 1.5 seconds duration
var currentFrame = 0;
var moveBackground = function moveBackground() {
if (currentFrame < duration) {
self.backgroundGraphics.y -= step;
currentFrame++;
} else {
LK.clearInterval(self.moveInterval);
self.backgroundGraphics.y = endY;
self.shakeBackground();
}
};
self.moveInterval = LK.setInterval(moveBackground, 1000 / 60);
};
self.resetBackground = function () {
if (self.moveInterval) {
LK.clearInterval(self.moveInterval);
}
self.backgroundGraphics.destroy();
self.backgroundGraphics = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
self.backgroundGraphics.x = 2048 / 2;
self.backgroundGraphics.y = 2732 + self.backgroundGraphics.height / 2;
self.moveToCenter();
};
});
/****
* Initialize Game
****/
// Later in the code, after game initialization
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
game.resetBackground = function () {
if (game.backgroundInstance) {
game.backgroundInstance.resetBackground();
}
};
game.backgroundInstance = game.addChild(new Background());
// Later in the code, after game initialization
game.livesDisplayInstance = game.addChild(new LivesDisplay());
game.updateLivesDisplay = function () {
game.livesDisplayInstance.updateLives(game.lives);
};
game.multiplier = 1;
game.lives = 3; // Initialize the lives system with 3 lives
game.updateScoreDisplay = function () {
scoreDisplay.setText(game.score.toString());
};
game.multiplierDisplay = LK.gui.topCenter.addChild(new MultiplierDisplay());
game.updateMultiplierDisplay = function () {
game.multiplierDisplay.updateMultiplier(game.multiplier);
};
game.updateMultiplierDisplay();
game.setBackgroundColor(0x6fd7da);
game.coinFlipping = false;
game.disableButtons = function () {
game.headsButton.interactive = false;
game.tailsButton.interactive = false;
};
game.enableButtons = function () {
game.headsButton.interactive = true;
game.tailsButton.interactive = true;
};
game.coin = game.addChild(new Coin());
game.coin.x = 2048 / 2;
game.coin.y = 2732 / 2 - 150;
game.coin.on('added', function () {
game.coin.x = 2048 / 2 - game.coin.width / 2;
game.coin.y = 2732 / 2 - game.coin.height / 2;
});
game.headsButton = game.addChild(new ChoiceButton('heads', 'Heads Button', true));
game.headsButton.gameInstance = game;
game.headsButton.isHeads = true;
game.tailsButton = game.addChild(new ChoiceButton('tails', 'Tails Button', false));
game.tailsButton.gameInstance = game;
game.tailsButton.isHeads = false;
game.tailsButton.x = 2048 * 3 / 4;
game.tailsButton.y = 2732 - game.tailsButton.height / 2 - 100;
game.headsButton.x = 2048 / 4;
game.headsButton.y = 2732 - game.headsButton.height / 2 - 100;
isometric silver coin with a pirate monkey face. pirate themed. pixelated. 8 bit. viewed from the top as if the coin is resting flat.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
clean isometric silver doubloon. pirate themed. pixelated. 8 bit. viewed from the top as if the coin is resting flat.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
isometric tiny mini pirate island that floats in the sky. an red painted X marks the spot located in the center of the map. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
isometric doubloon copper coin icon featuring a skull. shaped like a heart. pirate themed. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
text saying "Arghhh". pirate themes. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
simple golden text saying "WIN". text is bursting out of the treasure chest with golden coins bursting behind the text. pirate themed banner. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.