User prompt
Migrate to the latest version of LK
User prompt
increase te win lose animation to 2 seconds
Code edit (8 edits merged)
Please save this source code
User prompt
make the multiplier font size larger
Code edit (3 edits merged)
Please save this source code
User prompt
the score multiplier has a delay before becoming visible. add 100 to that value
Code edit (4 edits merged)
Please save this source code
User prompt
increase the multiplier delay by 100
User prompt
add a 100 miliseconds delay before making the score multiplier text visible, while keeping it invisible during the flipping animation. just that instead of instantly showing it when the coin lands, we add a delay
User prompt
add a 100 miliseconds delay before making the score multiplier text visible
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -1,68 +1,74 @@
/****
* Classes
-****/
-var HeadsAsset = Container.expand(function () {
+****/
+var Background = Container.expand(function () {
var self = Container.call(this);
- self.headsGraphics = self.attachAsset('heads', {
+ 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.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 = 10;
- self.maxDuration = 220;
- 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.1;
- if (self.flipDuration <= self.maxDuration) {
- self.flipInterval = LK.setTimeout(flipCoin, self.flipDuration);
+ 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 = startY - 2000;
+ var downDuration = 10; // 1 second at 60FPS
+ var upDuration = 130; // 1 second at 60FPS
+ var downStep = 2000 / downDuration;
+ var upStep = 2000 / upDuration;
+ var currentFrame = 0;
+ var moveBackgroundDown = function moveBackgroundDown() {
+ if (currentFrame < downDuration) {
+ self.backgroundGraphics.y += downStep;
+ currentFrame++;
} 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', finalSide);
- }
- self.flipDuration = 60;
- game.enableButtons();
- game.headsButton.visible = true;
- game.tailsButton.visible = true;
- game.coinFlipping = false;
- LK.setTimeout(function () {
- game.multiplierDisplay.visible = true;
- }, 400);
- }, 440);
+ LK.clearInterval(self.moveInterval);
+ currentFrame = 0;
+ self.moveInterval = LK.setInterval(moveBackgroundUp, 1000 / 60);
}
};
- LK.clearTimeout(self.flipInterval);
- LK.clearTimeout(self.flipTimeout);
- self.flipDuration = 60;
- flipCoin();
+ var moveBackgroundUp = function moveBackgroundUp() {
+ if (currentFrame < upDuration) {
+ self.backgroundGraphics.y -= upStep;
+ currentFrame++;
+ } else {
+ LK.clearInterval(self.moveInterval);
+ self.backgroundGraphics.y = startY;
+ self.shakeBackground();
+ }
+ };
+ self.moveInterval = LK.setInterval(moveBackgroundDown, 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 / 2;
+ self.moveToCenter();
+ };
});
var ChoiceButton = Container.expand(function (assetId, description, isHeads) {
var self = Container.call(this);
self.isHeads = isHeads;
@@ -119,25 +125,62 @@
game.multiplierDisplay.visible = false;
}
});
});
-var MultiplierDisplay = Container.expand(function () {
+var Coin = Container.expand(function () {
var self = Container.call(this);
- self.multiplierText = new Text2('X 1', {
- size: 200,
- fill: "#ffffff",
- align: 'center',
- stroke: '#000000',
- strokeThickness: 30
- });
- self.multiplierText.anchor.set(0.5, 0);
- self.addChild(self.multiplierText);
- self.multiplierText.x = 0;
- self.multiplierText.y = 220;
- self.updateMultiplier = function (multiplier) {
- self.multiplierText.setText(multiplier.toString());
+ self.heads = new HeadsAsset();
+ self.tails = new TailsAsset();
+ self.addChild(self.heads);
+ self.addChild(self.tails);
+ self.currentSide = 'heads';
+ self.flipDuration = 10;
+ self.maxDuration = 220;
+ 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.1;
+ 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', finalSide);
+ }
+ self.flipDuration = 60;
+ game.enableButtons();
+ game.headsButton.visible = true;
+ game.tailsButton.visible = true;
+ game.coinFlipping = false;
+ LK.setTimeout(function () {
+ game.multiplierDisplay.visible = true;
+ }, 400);
+ }, 440);
+ }
+ };
+ LK.clearTimeout(self.flipInterval);
+ LK.clearTimeout(self.flipTimeout);
+ self.flipDuration = 60;
+ flipCoin();
};
});
+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 LivesDisplay = Container.expand(function () {
var self = Container.call(this);
self.livesIcons = [];
for (var i = 0; i < 3; i++) {
@@ -159,88 +202,45 @@
};
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 MultiplierDisplay = 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.multiplierText = new Text2('X 1', {
+ size: 200,
+ fill: "#ffffff",
+ align: 'center',
+ stroke: '#000000',
+ strokeThickness: 30
+ });
+ self.multiplierText.anchor.set(0.5, 0);
+ self.addChild(self.multiplierText);
+ self.multiplierText.x = 0;
+ self.multiplierText.y = 220;
+ self.updateMultiplier = function (multiplier) {
+ self.multiplierText.setText(multiplier.toString());
};
- self.backgroundGraphics = self.attachAsset('background', {
+});
+var TailsAsset = Container.expand(function () {
+ var self = Container.call(this);
+ self.tailsGraphics = self.attachAsset('tails', {
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 = startY - 2000;
- var downDuration = 10; // 1 second at 60FPS
- var upDuration = 130; // 1 second at 60FPS
- var downStep = 2000 / downDuration;
- var upStep = 2000 / upDuration;
- var currentFrame = 0;
- var moveBackgroundDown = function moveBackgroundDown() {
- if (currentFrame < downDuration) {
- self.backgroundGraphics.y += downStep;
- currentFrame++;
- } else {
- LK.clearInterval(self.moveInterval);
- currentFrame = 0;
- self.moveInterval = LK.setInterval(moveBackgroundUp, 1000 / 60);
- }
- };
- var moveBackgroundUp = function moveBackgroundUp() {
- if (currentFrame < upDuration) {
- self.backgroundGraphics.y -= upStep;
- currentFrame++;
- } else {
- LK.clearInterval(self.moveInterval);
- self.backgroundGraphics.y = startY;
- self.shakeBackground();
- }
- };
- self.moveInterval = LK.setInterval(moveBackgroundDown, 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 / 2;
- self.moveToCenter();
- };
+ self.tailsGraphics.visible = false;
});
/****
* 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();
}
@@ -255,9 +255,9 @@
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.multiplierDisplay = LK.gui.top.addChild(new MultiplierDisplay());
game.updateMultiplierDisplay = function () {
game.multiplierDisplay.updateMultiplier(game.multiplier);
};
game.updateMultiplierDisplay();
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.