User prompt
play victory sound at the end if profit > 0 and play failed sound if < 0
User prompt
play corresponding sounds when buying or selling
User prompt
increase and decrease should be played during the game not only on game preparation
User prompt
play increase and decrease sounds when value change
User prompt
play countdown sound during the initial countdown
User prompt
Migrate to the latest version of LK
Code edit (9 edits merged)
Please save this source code
User prompt
buyButton should be enabled only when mar = true (game running)
Code edit (2 edits merged)
Please save this source code
User prompt
Add a big 3 second countdown before starting game
User prompt
set the score to be the profit using LK.setScore()
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught LK.Game can only be initialized once' in or related to this line: 'var j = new LK.Game({});' Line Number: 301
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'confetti.destroy();' Line Number: 353
Code edit (1 edits merged)
Please save this source code
User prompt
make confetti rotation random
Code edit (1 edits merged)
Please save this source code
User prompt
fix the conffetti colors not applying
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: game.getChildByName is not a function' in or related to this line: 'if (profit > 0 && !game.getChildByName('confetti')) {' Line Number: 333
User prompt
Confettiis called to much times
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: confettiColors is not defined' in or related to this line: 'var particle = self.addChild(LK.getAsset('segment', {' Line Number: 265
User prompt
in Confetti Change the ' Math.random() * 0xFFFFFF,' , use an array of colors instead
===================================================================
--- original.js
+++ change.js
@@ -1,45 +1,13 @@
/****
* Classes
-****/
-var cp = Container.expand(function (color) {
- var self = Container.call(this);
- var confettiGraphics = self.attachAsset('confetti', {
- width: 40,
- height: 20,
- color: color,
- anchorX: 0.5,
- anchorY: 0.5
- });
- confettiGraphics.rotation = Math.random() * Math.PI * 2;
-});
-var bi = Container.expand(function () {
- var self = Container.call(this);
- var iconGraphics = self.attachAsset('balanceIcon', {
- anchorX: 0.5,
- anchorY: 0.5
- });
-});
-var ti = Container.expand(function () {
- var self = Container.call(this);
- var iconGraphics = self.attachAsset('timerIcon', {
- anchorX: 0.5,
- anchorY: 0.5
- });
-});
-var si = Container.expand(function () {
- var self = Container.call(this);
- var iconGraphics = self.attachAsset('stockIcon', {
- anchorX: 0.5,
- anchorY: 0.5
- });
-});
+****/
var al = Container.expand(function (value) {
var self = Container.call(this);
self.value = value;
var label = new Text2('$' + value, {
size: 70,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.alpha = 0;
@@ -54,8 +22,124 @@
}
self.y = axisY - self.value * epx - alfs / 2;
};
});
+var ax = Container.expand(function (ev) {
+ var self = Container.call(this);
+ var vin = 0.02;
+ self.ev = ev;
+ self.yValue = 0;
+ self.updateSlide = function () {
+ var sd = Math.max(0, svh[gi + 1] - 100);
+ var targetY = ll + sd * epx;
+ if (!self.ev) {
+ var deltaY = (targetY - self.y) * vin;
+ self.y += deltaY;
+ if (Math.abs(deltaY) < 1) {
+ self.y = targetY;
+ }
+ if (msv && self.y <= ll) {
+ self.y = ll;
+ msv = 0;
+ }
+ self.alpha = self.y > j.height * 0.85 ? 0 : 1;
+ }
+ };
+ self.drawAxis = function () {
+ var axisGraphics = self.addChild(LK.getAsset('axis', {
+ height: 4
+ }));
+ };
+});
+var bb = Container.expand(function () {
+ var self = Container.call(this);
+ self.currentText = "Buy";
+ self.updateButtonState = function () {
+ var stockPrice = svh[gi];
+ var canBuy = p.getBalance() >= stockPrice && stockPrice > 0 && mar;
+ this.alpha = canBuy ? 1 : 0.5;
+ this.interactive = canBuy;
+ };
+ self.setText = function (text, isPressed) {
+ self.currentText = text;
+ var buttonTextSize = isPressed ? 230 : 250;
+ var buttonText = new Text2(text, {
+ size: buttonTextSize,
+ fill: 0xFFFFFF,
+ font: "'Arial-BoldMT', 'Arial', sans-serif"
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ };
+ var buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
+ });
+ self.on('down', function () {
+ if (self.interactive) {
+ buttonGraphics = self.attachAsset('bigButtonPressed', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
+ });
+ LK.effects.flashScreen(0xFFA500, 100);
+ self.setText(self.currentText, true);
+ buyStock(1);
+ }
+ }).on('up', function () {
+ buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
+ });
+ self.setText(self.currentText);
+ self.updateButtonState();
+ });
+ self.updateButtonState();
+});
+var bi = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('balanceIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var cf = Container.expand(function () {
+ var self = Container.call(this);
+ self.particles = [];
+ var confettiColors = [0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x4B0082, 0x9400D3];
+ for (var i = 0; i < 50; i++) {
+ var particle = self.addChild(new cp(confettiColors[i % confettiColors.length]));
+ particle.x = Math.random() * j.width;
+ particle.y = Math.random() * j.height;
+ particle.vx = (Math.random() - 0.5) * 10;
+ particle.vy = (Math.random() - 0.5) * 10;
+ self.particles.push(particle);
+ }
+ self._update_migrated = function () {
+ self.particles.forEach(function (particle) {
+ particle.x += particle.vx;
+ particle.y += particle.vy;
+ particle.vy += 0.2;
+ if (particle.y > j.height) {
+ particle.y = 0;
+ particle.vy = (Math.random() - 0.5) * 10;
+ }
+ });
+ };
+});
+var cp = Container.expand(function (color) {
+ var self = Container.call(this);
+ var confettiGraphics = self.attachAsset('confetti', {
+ width: 40,
+ height: 40,
+ color: color,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ confettiGraphics.rotation = Math.random() * Math.PI * 2;
+});
var gs = Container.expand(function () {
var self = Container.call(this);
self.index1 = null;
self.pad = 0;
@@ -91,35 +175,8 @@
var segmentGraphics = self.attachAsset('segment', {
anchorY: 0.5
});
});
-var ax = Container.expand(function (ev) {
- var self = Container.call(this);
- var vin = 0.02;
- self.ev = ev;
- self.yValue = 0;
- self.updateSlide = function () {
- var sd = Math.max(0, svh[gi + 1] - 100);
- var targetY = ll + sd * epx;
- if (!self.ev) {
- var deltaY = (targetY - self.y) * vin;
- self.y += deltaY;
- if (Math.abs(deltaY) < 1) {
- self.y = targetY;
- }
- if (msv && self.y <= ll) {
- self.y = ll;
- msv = 0;
- }
- self.alpha = self.y > j.height * 0.85 ? 0 : 1;
- }
- };
- self.drawAxis = function () {
- var axisGraphics = self.addChild(LK.getAsset('axis', {
- height: 4
- }));
- };
-});
var pr = Container.expand(function () {
var self = Container.call(this);
self.balance = 100;
self.stocks = 0;
@@ -160,64 +217,17 @@
self.getPortfolio = function () {
return self.stocks;
};
});
-var bb = Container.expand(function () {
- var self = Container.call(this);
- self.currentText = "Buy";
- self.updateButtonState = function () {
- var stockPrice = svh[gi];
- var canBuy = p.getBalance() >= stockPrice && stockPrice > 0 && mar;
- this.alpha = canBuy ? 1 : 0.5;
- this.interactive = canBuy;
- };
- self.setText = function (text, isPressed) {
- self.currentText = text;
- var buttonTextSize = isPressed ? 230 : 250;
- var buttonText = new Text2(text, {
- size: buttonTextSize,
- fill: "#ffffff",
- font: "'Arial-BoldMT', 'Arial', sans-serif"
- });
- buttonText.anchor.set(0.5, 0.5);
- self.addChild(buttonText);
- };
- var buttonGraphics = self.attachAsset('bigButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0xFFA500
- });
- self.on('down', function () {
- if (self.interactive) {
- buttonGraphics = self.attachAsset('bigButtonPressed', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0xFFA500
- });
- LK.effects.flashScreen(0xFFA500, 100);
- self.setText(self.currentText, true);
- buyStock(1);
- }
- }).on('up', function () {
- buttonGraphics = self.attachAsset('bigButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0xFFA500
- });
- self.setText(self.currentText);
- self.updateButtonState();
- });
- self.updateButtonState();
-});
var sb = Container.expand(function () {
var self = Container.call(this);
self.currentText = "ON";
self.setText = function (text, isPressed) {
self.currentText = text;
var buttonTextSize = isPressed ? 230 : 250;
var buttonText = new Text2(text, {
size: buttonTextSize,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
font: "'Arial-BoldMT', 'Arial', sans-serif"
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
@@ -244,50 +254,41 @@
});
self.setText(self.currentText);
});
});
-var cf = Container.expand(function () {
+var si = Container.expand(function () {
var self = Container.call(this);
- self.particles = [];
- var confettiColors = [0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x4B0082, 0x9400D3];
- for (var i = 0; i < 50; i++) {
- var particle = self.addChild(new cp(confettiColors[i % confettiColors.length]));
- particle.x = Math.random() * j.width;
- particle.y = Math.random() * j.height;
- particle.vx = (Math.random() - 0.5) * 10;
- particle.vy = (Math.random() - 0.5) * 10;
- self.particles.push(particle);
- }
- self.update = function () {
- self.particles.forEach(function (particle) {
- particle.x += particle.vx;
- particle.y += particle.vy;
- particle.vy += 0.2;
- if (particle.y > j.height) {
- particle.y = 0;
- particle.vy = (Math.random() - 0.5) * 10;
- }
- });
- };
+ var iconGraphics = self.attachAsset('stockIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
+var ti = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('timerIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
-****/
+****/
var j = game;
function ce() {
return j.children.some(function (child) {
return child.name === 'confetti';
});
}
function gr() {
+ mar = false;
p.liquidate();
var profit = p.getBalance() - md;
LK.setScore(profit);
var popup = j.addChild(LK.getAsset('popup', {
@@ -298,9 +299,9 @@
popup.y = j.height / 2 - 300;
resultText = 'Initial:\t$' + md + '\r\n' + 'Final:\t\t$' + p.getBalance().toFixed(0) + '\r\n' + 'Profit:';
var finalBalanceText = new Text2(resultText, {
size: 100,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
anchorX: 0.5,
anchorY: 0.5
});
finalBalanceText.x = j.width / 2 - 500;
@@ -319,9 +320,9 @@
if (profit > 0 && !ce()) {
var confetti = j.addChild(new cf());
confetti.name = 'confetti';
LK.on('tick', function () {
- confetti.update();
+ confetti._update_migrated();
});
}
LK.setTimeout(function () {
LK.showGameOver();
@@ -340,9 +341,9 @@
var mar = false;
var ms = false;
var dip = false;
var p = new pr();
-var ntv = 10;
+var ntv = 180;
var ss = [];
var svh = [50];
var gi = 0;
var gss = [];
@@ -426,9 +427,9 @@
sellButton.updateButtonState();
var timerIcon = j.addChild(new ti());
var timerText = new Text2('000', {
size: 100,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
anchorX: 0.5
});
timerText.anchor.set(-.95, -0.7);
LK.gui.topLeft.addChild(timerText);
@@ -441,30 +442,30 @@
stockIcon.x = j.width * 0.94;
stockIcon.y = j.height * 0.028;
var balanceText = new Text2('$' + p.getBalance() + ' ', {
size: 100,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
anchorX: 0.5
});
balanceText.anchor.set(.5, -0.7);
LK.gui.top.addChild(balanceText);
var stocksNumber = new Text2(p.getPortfolio(), {
size: 100,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
anchorX: 0.5
});
stocksNumber.anchor.set(1.6, -0.7);
LK.gui.topRight.addChild(stocksNumber);
var verticalSlideAmount = 0;
var vsaText = new Text2('', {
size: 50,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
vsaText.anchor.set(0, 0);
LK.gui.topLeft.addChild(vsaText);
var stockValueText = new Text2('', {
size: 75,
- fill: "#FFFFFF"
+ fill: 0xFFFFFF
});
stockValueText.anchor.set(1, 4);
stockValueText.alpha = 0;
LK.gui.right.addChild(stockValueText);
@@ -604,9 +605,9 @@
});
var startTime = Date.now();
var countdownText = new Text2('3', {
size: 300,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
anchorX: 0.5,
anchorY: 0.5
});
countdownText.x = j.width / 2 - 100;
A Technical dark background. Nothing just a gradiant of colors from black to dark blue. Theme : stock market. background
A modern clean empty rectangular button without borders. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
without shadow
a basic empty ui popup with a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.