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)
User prompt
Update the following code to make the value 0.3 dynamic so when delta x is big the value is bigger, and lower when delta is low
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: console.Log is not a function' in or related to this line: 'console.Log("FIXING GAP : " + moveSegmentsVertically < 0 ? downwardGapFix : 0);' Line Number: 90
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Here is current code: ``` var pointA = graphPoints[graphIndex]; var pointB = graphPoints[graphIndex + 1]; var deltaY = pointB.y - pointA.y; // Calculate next segment rotation based on pointA and pointB coordinates var deltaX = pointB.x - pointA.x; var nextSegmentRotation = Math.atan2(deltaY, deltaX); var distance = Math.sqrt(Math.pow(pointB.x - pointA.x, 2) + Math.pow(pointB.y - pointA.y, 2)); 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; // Re-compute the rotation (rotation * (180 / Math.PI)).toFixed(2) var deltaY2 = pointB.y - pointA.y; // Calculate next segment rotation based on pointA and pointB coordinates var deltaX2 = pointB.x - pointA.x; var tempRotFixed = Math.atan2(deltaY2, deltaX2); if (deltaX2 < 0 || deltaY > 0) { tempRotFixed += Math.PI; } var tempRotFixedDeltaDeg = ((nextSegmentRotation - tempRotFixed) * (180 / Math.PI)).toFixed(0); console.log('original rotation Rad: ' + nextSegmentRotation + ' / fixed rotation Rad :' + tempRotFixed + " -> Delta Deg " + tempRotFixedDeltaDeg); ``` And here is produced log : ``` original rotation Rad: -1.0305921674056044 / fixed rotation Rad :-1.0084043587880687 -> Delta Deg -1 Start moveSegmentsVertically Please draw graphIndex=9 1242,-254 / Rot= -59 distance=796.4051481501108 new segment index=9-10 450-500$ 1242 -254 rotation=-59.05 degrees width=796 original rotation Rad: -1.0305921674056038 / fixed rotation Rad :-1.0109702920137162 -> Delta Deg -1 Start moveSegmentsVertically Please draw graphIndex=10 1249,-268 / Rot= -59 distance=796.405148150111 new segment index=10-11 500-550$ 1249 -268 rotation=-59.05 degrees width=796 original rotation Rad: 1.0305921674056038 / fixed rotation Rad :2.2522788402901393 -> Delta Deg -70 Start moveSegmentsVertically Please draw graphIndex=11 1262,-278 / Rot= 59 distance=796.405148150111 new segment index=11-12 550-500$ 1262 -278 rotation=59.05 degrees width=796 original rotation Rad: 1.0305921674056049 / fixed rotation Rad :2.234469655823067 -> Delta Deg -69 ``` What change to tempRotFixed should be done to keep the delta around -1 ??
===================================================================
--- original.js
+++ change.js
@@ -41,11 +41,8 @@
self.value -= (nbMarkers - 1) * 25;
label.setText('$' + self.value);
}
self.y = axisY - self.value * dollarToYPixelRatio - axisLabelFontSize / 2;
- // Set alpha based on y position
- //self.alpha = self.y > game.height * 0.85 ? 0 : 1;
- // CONTINUER ICI !!! : SI y > .... => value += 200 => y= ...
};
});
var GraphSegment = Container.expand(function () {
var self = Container.call(this);
@@ -56,30 +53,24 @@
self.y1 = 0;
self.x2 = 0;
self.y2 = 0;
self.isFinished = false;
- var verticalSlideRatio = 1;
var interpolationSpeed = 1; // Adjust this value for speed
self.updateSlide = function () {
if (moveSegments) {
if (self.index1 == graphIndex) {
var dynamicSlideAdjustment = Math.abs(self.x - game.width * 0.25) / (game.width * 0.5);
if (self.x < game.width * 0.35) {
slideAmount = Math.max(1, slideAmount * (1 - dynamicSlideAdjustment));
- //slideAmount = Math.max(slideAmount, 0.1); // Ensure slideAmount is never 0
} else if (self.x > game.width * 0.65) {
slideAmount = Math.min(15, slideAmount * (1 + dynamicSlideAdjustment));
}
}
self.x -= slideAmount * 1;
}
if (moveSegmentsVertically) {
- //&& self.isFinished
- var tempGapFix = moveSegmentsVertically < 0 && self.stockValue2 >= 100 ? downwardGapFix : 0;
- var currentDelta = horizontalAxis.y - lowerLimit + tempGapFix;
- //console.log("FIXING GAP : " + tempGapFix + ' currentDelta=' + currentDelta);
- var targetY = lowerLimit - self.stockValue1 * dollarToYPixelRatio + currentDelta; // TEMP Test +50
- //targetY = dollarToYPixelRatio * self.stockValue1 + currentDelta; // TEMP DEBUG TEST
+ var currentDelta = horizontalAxis.y - lowerLimit;
+ var targetY = lowerLimit - self.stockValue1 * dollarToYPixelRatio + currentDelta;
var deltaY = (targetY - self.y) * interpolationSpeed;
self.y += deltaY;
if (Math.abs(deltaY) <= 1) {
self.y = targetY;
@@ -98,9 +89,9 @@
self.isVertical = isVertical; // Property to determine if the axis is vertical
self.yValue = 0; // Track the Y value of the axis for vertical movement
self.updateSlide = function () {
// Current stock value excedent over 100$ (ignore below 100$)
- var stockDelta = Math.max(0, stockValuesHistory[graphIndex] - 100);
+ var stockDelta = Math.max(0, stockValuesHistory[graphIndex + 1] - 100);
// Target = base axis + delta in pixels
var targetY = lowerLimit + stockDelta * dollarToYPixelRatio;
if (!self.isVertical) {
// Smooth interpolation
@@ -111,9 +102,8 @@
}
if (moveSegmentsVertically && self.y <= lowerLimit) {
self.y = lowerLimit;
moveSegmentsVertically = 0;
- console.log('STOP Vertical move!');
}
// Set alpha based on y position
self.alpha = self.y > game.height * 0.85 ? 0 : 1;
}
@@ -149,10 +139,8 @@
self.balance += price * quantity;
self.stocks -= quantity;
self.orders++;
sellButton.updateButtonState();
- } else {
- //LK.effects.flashScreen(0xFF0000, 100);
}
};
self.getBalance = function () {
return self.balance;
@@ -256,15 +244,14 @@
/****
* Game Code
****/
-var debug = false;
+var debug = true;
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
-var downwardGapFix = -300; // 300 Magic fixing of the complex downward gaps
-var upperLimit = game.height * 0.25;
+var upperLimit = game.height * 0.5; //0.25
var lowerLimit = game.height * 0.75; // Define lowerLimit for use in segment positioning
var axisLabelFontSize = 70;
var running = false;
var moveSegments = false;
@@ -433,9 +420,8 @@
player.sellStock(stock, 1); // Sell 1 stock for simplicity
updateBalanceDisplay();
}
function drawNextSegment() {
- //console.log("drawNextSegment " + graphIndex + ' isDrawing = ' + drawingInProgress);
var hasFinished = graphIndex >= graphPoints.length - 1;
if (hasFinished) {
running = false;
LK.showGameOver();
@@ -456,45 +442,22 @@
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;
- var pointAXMovement = lastSegmentEndX - pointA.x;
- var pointAYMovement = lastSegmentEndY - pointA.y;
- pointA.x = lastSegmentEndX;
- if (pointAYMovement) {
- //console.log('pointAYMovement ! graphIndex=' + graphIndex + ' / pointAYMovement=' + pointAYMovement);
- }
pointA.y = lastSegmentEndY > lowerLimit ? lowerLimit : lastSegmentEndY;
- // Re-compute the rotation (rotation * (180 / Math.PI)).toFixed(2)
- //var tempRotFixed = Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x);
- var deltaY2 = pointB.y - pointA.y; // Calculate next segment rotation based on pointA and pointB coordinates
- var deltaX2 = pointB.x - pointA.x;
- var tempRotFixed = Math.atan2(deltaY2, deltaX2);
- /*if (deltaX2 < 0) {
- tempRotFixed += Math.PI;
- } else if (deltaY2 > 0) {
- tempRotFixed += 2 * Math.PI;
- }*/
- if (deltaY < 0) {
- //tempRotFixed += 2 * Math.PI;
- }
- var tempRotFixedDeltaDeg = ((nextSegmentRotation - tempRotFixed) * (180 / Math.PI)).toFixed(0);
- console.log('ORIGINAL rotation Rad: ' + nextSegmentRotation.toFixed(2) + ' / fixed rotation Rad :' + tempRotFixed.toFixed(2) + ' sign1=' + Math.sign(deltaY) + ' sign2=' + Math.sign(deltaY2) + " -> Delta Deg " + tempRotFixedDeltaDeg);
- //nextSegmentRotation = Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x); // Calculate next segment rotation based on pointA and pointB coordinates
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) {
+ if (nextSegmentEndY < upperLimit || nextSegmentEndY >= game.height * 0.5 && stockValuesHistory[graphIndex + 1] >= 100 && deltaY != 0) {
moveSegmentsVertically = -1 * Math.sign(deltaY);
- //console.log('Start moveSegmentsVertically');
+ console.log('Start moveSegmentsVertically');
} else {
moveSegmentsVertically = 0;
}
var delay = 0.5; // Reduce delay to speed up the drawing of segments
drawingInProgress = true;
- console.log('Please draw graphIndex=' + graphIndex + " " + Math.floor(pointA.x) + "," + Math.floor(pointA.y) + " / Rot=", (nextSegmentRotation * (180 / Math.PI)).toFixed(0), 'distance=' + distance);
drawSegment(game, graphIndex, pointA.x, pointA.y, nextSegmentRotation, distance, delay);
}
}
function drawSegment(gameRef, index, x1, y1, rotation, width, delay) {
@@ -508,9 +471,8 @@
segment.width = 1; // Start with a width of 1 and animate to the target width
segment.height = 20;
// Add the new segment to the global graphSegments array
graphSegments.push(segment);
- console.log('new segment index=' + index + '-' + (index + 1) + " " + stockValuesHistory[index] + "-" + stockValuesHistory[index + 1] + "$", Math.floor(x1), Math.floor(y1), 'rotation=' + (rotation * (180 / Math.PI)).toFixed(2) + ' degrees', 'width=' + Math.floor(width));
segment.x = x1;
segment.y = y1;
var startTime = Date.now();
var endTime = startTime + delay * 1000 * secondsPerSegment;
@@ -542,9 +504,9 @@
//series = [0, 25, 50, 75, 100, 125, 125, 125, 125, 100, 75, 50, 25, 0, 0, 0];
// Links bug
series = [1, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 500, 450, 400, 350, 300, 250, 200, 150, 100, 50, 1, 1, 1];
// Links bug Fast
- series = [1, 50, 100, 150, 200, 250, 200, 150, 100, 50, 1, 1, 1];
+ //series = [1, 50, 100, 150, 200, 250, 200, 150, 100, 50, 1, 1, 1];
// Accuracy test
//series = [1, 100, 1, 100, 1, 100, 1, 100, 1, 1, 100, 1, 100, 1, 100, 1, 100, 1, 1, 100, 1, 100, 1, 100, 1, 100, 1, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100];
for (var i = 0; i < 1; i++) {
stockValuesHistory = stockValuesHistory.concat(series);
@@ -554,9 +516,9 @@
// Initialize
// Generate random deltas and add to previous value for stockValuesHistory
var previousValue = stockValuesHistory[stockValuesHistory.length - 1];
for (var i = 0; i < nbTotalValues; i++) {
- var delta = Math.floor((Math.random() - 0.5) * maxValueDelta); // Generate a delta between -30 and 30
+ 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();
@@ -582,11 +544,8 @@
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 minutes = Math.floor(currentTime / 60).toString().padStart(2, '0');
- //var seconds = (currentTime % 60).toString().padStart(2, '0');
- //timerText.updateTime(minutes + ':' + seconds);
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.