Code edit (1 edits merged)
Please save this source code
User prompt
add a conffeti animation and call it in gameResult if profit > 0
Code edit (13 edits merged)
Please save this source code
User prompt
after liquidate update balanceText and stocksNumber
Code edit (7 edits merged)
Please save this source code
User prompt
if profit is >0 set profitText color to green
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
add a function liquidate() to player object and call it in gameResult
Code edit (1 edits merged)
Please save this source code
User prompt
in the gameResult display a Text with the final balance
Code edit (8 edits merged)
Please save this source code
User prompt
when hasFinished call a gameResult function. in this function show a 'popup' asset at the center of the screen then call GameOver
Code edit (1 edits merged)
Please save this source code
User prompt
increase updateStockValueText call rate
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'replace')' in or related to this line: 'var currentValue = parseFloat(stockValueText.text.replace('$', '')) || 0;' Line Number: 418
User prompt
in updateStockValueText add an interpolation
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: stockValueText is not defined' in or related to this line: 'stockValueText.alpha = 1;' Line Number: 579
User prompt
make the stockValueText update smooth
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
In the following code ensure that slideAmount is never 0 self.x -= slideAmount;
Code edit (8 edits merged)
Please save this source code
User prompt
dynamicSlideAdjustment Should depend on self.x and the limits (game.width * 0.25 and game.width * 0.75)
===================================================================
--- original.js
+++ change.js
@@ -235,8 +235,29 @@
});
self.setText(self.currentText);
});
});
+var StockValueDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ self.text = new Text2('', {
+ size: 75,
+ fill: "#FFFFFF"
+ });
+ self.text.anchor.set(1, 2);
+ self.text.alpha = 0;
+ self.addChild(self.text);
+ self.currentValue = 0;
+ self.targetValue = 0;
+ self.updateValue = function (newValue) {
+ self.targetValue = newValue;
+ };
+ self.tick = function () {
+ if (self.currentValue !== self.targetValue) {
+ self.currentValue += (self.targetValue - self.currentValue) * 0.1;
+ self.text.setText('$' + Math.round(self.currentValue));
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -244,9 +265,9 @@
/****
* Game Code
****/
-var debug = true;
+var debug = false;
var slideAmount = 6.5;
var slideAmountVertical = 0.10; // Reduced speed for smoother vertical movement
var moveSegmentsVertically = 0;
var verticalSlideThreshold = 500; // Define a global threshold for vertical sliding
@@ -271,9 +292,10 @@
var graphPoints = [];
var graphWidth = game.width;
var segmentWidth = graphWidth / 5; //; / stockValuesHistory.length;
var dollarToYPixelRatio = game.height * 0.5 / 100;
-var maxValueDelta = 80;
+var beginingValueDelta = 10;
+var maxValueDelta = 100;
var segmentDrawInterval = null;
var secondsPerSegment = 2.0;
var stockDisplay = []; // Array to hold stock display elements
/****
@@ -388,18 +410,13 @@
fill: "#ffffff"
});
vsaText.anchor.set(0, 0);
LK.gui.topLeft.addChild(vsaText);
-var stockValueText = new Text2('', {
- size: 75,
- fill: "#FFFFFF"
-});
-stockValueText.anchor.set(1, 2);
-stockValueText.alpha = 0;
-LK.gui.right.addChild(stockValueText);
+var stockValueDisplay = game.addChild(new StockValueDisplay());
+LK.gui.right.addChild(stockValueDisplay);
function updateStockValueText() {
if (graphIndex < stockValuesHistory.length) {
- stockValueText.setText('$' + stockValuesHistory[graphIndex].toFixed(0));
+ stockValueDisplay.updateValue(stockValuesHistory[graphIndex]);
}
}
/****
* Game Functions
@@ -442,17 +459,17 @@
var distance = Math.sqrt(Math.pow(pointB.x - pointA.x, 2) + Math.pow(pointB.y - pointA.y, 2)); // Calculate the distance between points A and B
var lastSegment = graphSegments.length > 0 ? graphSegments[graphSegments.length - 1] : null;
var lastSegmentEndX = lastSegment ? lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width : graphPoints[graphIndex].x;
var lastSegmentEndY = lastSegment ? lastSegment.y + Math.sin(lastSegment.rotation) * lastSegment.width : graphPoints[graphIndex].y;
+ pointA.x = lastSegmentEndX;
pointA.y = lastSegmentEndY > lowerLimit ? lowerLimit : lastSegmentEndY;
var nextSegmentEndY = pointA.y + Math.sin(nextSegmentRotation) * distance;
// Adjust distance to ensure segment's end doesn't exceed lowerLimit
if (nextSegmentEndY > lowerLimit) {
distance = (lowerLimit - pointA.y) / Math.sin(nextSegmentRotation);
}
if (nextSegmentEndY < upperLimit || nextSegmentEndY >= game.height * 0.5 && stockValuesHistory[graphIndex + 1] >= 100 && deltaY != 0) {
moveSegmentsVertically = -1 * Math.sign(deltaY);
- console.log('Start moveSegmentsVertically');
} else {
moveSegmentsVertically = 0;
}
var delay = 0.5; // Reduce delay to speed up the drawing of segments
@@ -488,9 +505,8 @@
LK.setTimeout(updateWidth, 16);
} else {
if (!moveSegments && segment.x + segment.width / 2 >= game.width * 0.5) {
moveSegments = true;
- console.log("Past center !");
}
segment.isFinished = true;
graphIndex++;
drawingInProgress = false;
@@ -515,15 +531,22 @@
function startGame() {
// Initialize
// Generate random deltas and add to previous value for stockValuesHistory
var previousValue = stockValuesHistory[stockValuesHistory.length - 1];
- for (var i = 0; i < nbTotalValues; i++) {
+ for (var i = 0; i < 5; i++) {
+ var delta = Math.floor((Math.random() - 0.5) * beginingValueDelta); // Generate a delta between -beginingValueDelta/2 and beginingValueDelta/2
+ var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta));
+ stockValuesHistory.push(newValue);
+ previousValue = newValue;
+ }
+ previousValue = stockValuesHistory[stockValuesHistory.length - 1];
+ for (var i = 5; i < nbTotalValues; i++) {
var delta = Math.floor((Math.random() - 0.5) * maxValueDelta); // Generate a delta between -maxValueDelta/2 and maxValueDelta/2
var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta));
stockValuesHistory.push(newValue);
previousValue = newValue;
- buyButton.updateButtonState();
}
+ buyButton.updateButtonState();
if (debug) {
setDebugValues(); // DEBUG MODE
}
var x, y;
@@ -543,9 +566,9 @@
// Set up a tick event to call drawNextSegment every second
segmentDrawInterval = LK.setInterval(drawNextSegment, 10);
// Set up a timer to update the timer text every second
var timerUpdateInterval = LK.setInterval(function () {
- var currentTime = nbTotalValues - graphIndex;
+ var currentTime = nbTotalValues - graphIndex - 1;
timerText.setText(currentTime.toString().padStart(3, '0'));
}, 1000);
}
// Main game loop
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.