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 ??
Code edit (1 edits merged)
Please save this source code
User prompt
Here is the rotation calculation : 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); if (deltaX < 0) { nextSegmentRotation += Math.PI; } shouldn't it check deltaY too ?
Code edit (15 edits merged)
Please save this source code
User prompt
ok, but what should be changed to the line : var nextSegmentRotation = Math.atan2(pointB.y - pointA.y, pointB.x - pointA.x); to take into account the direction ?
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (12 edits merged)
Please save this source code
User prompt
UPDATE BUY BUTTON STATUS WHEN STOCK VALUE CHANGES. (Hint: When graphIndex changes)
User prompt
Fix buy button status
User prompt
Update buy button status every time stock value changes or balance changes
User prompt
Like for sell button, disable buy button when current stock price is above balance
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Pad timer text with 0 so the text length is always 3
Code edit (7 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: timerText.updateTime is not a function. (In 'timerText.updateTime(currentTime)', 'timerText.updateTime' is undefined)' in or related to this line: 'timerText.updateTime(currentTime);' Line Number: 551
User prompt
Update declaration of timerText to make it like balanceText and stockNumber, do not use a class
Code edit (1 edits merged)
Please save this source code
User prompt
For timer, use currentTime=nbTotalStock-graphIndex
User prompt
Fix Bug: 'Timeout.tick error: Can't find variable: startTime' in or related to this line: 'var currentTime = Math.floor((Date.now() - startTime) / 1000);' Line Number: 554
User prompt
Add a timerText at the top left
Code edit (4 edits merged)
Please save this source code
User prompt
Donβt do it, Just tell me how can I make the stocknumber text position fixed ? Independent from Texts lenghts
/**** * Classes ****/ var BalanceIcon = Container.expand(function () { var self = Container.call(this); var iconGraphics = self.attachAsset('balanceIcon', { anchorX: 0.5, anchorY: 0.5 }); }); var TimerIcon = Container.expand(function () { var self = Container.call(this); var iconGraphics = self.attachAsset('timerIcon', { anchorX: 0.5, anchorY: 0.5 }); }); var StockIcon = Container.expand(function () { var self = Container.call(this); var iconGraphics = self.attachAsset('stockIcon', { anchorX: 0.5, anchorY: 0.5 }); }); var AxisLabel = Container.expand(function (value) { var self = Container.call(this); self.value = value; var label = new Text2('$' + value, { size: 70, fill: "#ffffff" }); label.anchor.set(0.5, 0.5); self.addChild(label); self.alpha = 0; self.updatePosition = function (axisY) { var newY = axisY - self.value * dollarToYPixelRatio - axisLabelFontSize / 2; if (newY > game.height * 0.82) { self.value += (nbMarkers - 1) * 25; label.setText('$' + self.value); } else if (newY < game.height * 0.07) { 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); self.index1 = null; self.stockValue1 = 0; self.stockValue2 = 0; self.x1 = 0; 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) { self.x -= slideAmount * 1; if (self.index1 == graphIndex && self.x1 < game.width * 0.25) { slideAmount = Math.max(1, slideAmount - 0.3); } if (self.index1 == graphIndex && self.x1 > game.width * 0.85) { slideAmount = Math.min(15, slideAmount + 0.3); } } if (moveSegmentsVertically && self.isFinished) { var currentDelta = horizontalAxis.y - lowerLimit; var targetY = lowerLimit - self.stockValue1 * dollarToYPixelRatio + currentDelta; //targetY = dollarToYPixelRatio * self.stockValue1 + currentDelta; // TEMP DEBUG TEST var deltaY = (targetY - self.y) * interpolationSpeed; self.y += deltaY; if (Math.abs(deltaY) <= 1) { self.y = targetY; } } }; var segmentGraphics = self.attachAsset('segment', { anchorY: 0.5 }); }); // Axis class to represent the graph axes var Axis = Container.expand(function (isVertical) { var self = Container.call(this); var interpolationSpeed = 0.02; // Adjust this value for speed var lowerLimit = game.height * 0.75; 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); // Target = base axis + delta in pixels var targetY = lowerLimit + stockDelta * dollarToYPixelRatio; if (!self.isVertical) { // Smooth interpolation var deltaY = (targetY - self.y) * interpolationSpeed; self.y += deltaY; if (Math.abs(deltaY) < 1) { self.y = targetY; } if (moveSegmentsVertically && self.y <= lowerLimit) { self.y = lowerLimit; moveSegmentsVertically = false; console.log('STOP Vertical move!'); } // Set alpha based on y position self.alpha = self.y > game.height * 0.85 ? 0 : 1; } }; self.drawAxis = function () { var axisGraphics = self.addChild(LK.getAsset('axis', { height: 4 // Thin line for the axis })); }; }); // ValueIndicator class to represent the current value of the stock on the graph // Player class to represent the player's portfolio var Player = Container.expand(function () { var self = Container.call(this); self.balance = 100; // Start with $100 self.stocks = 0; // Counter to hold stock quantity self.orders = 0; // Counter to hold stock quantity self.buyStock = function (quantity) { var price = stockValuesHistory[graphIndex]; var cost = price * quantity; if (self.balance >= cost) { self.balance -= cost; self.stocks += quantity; self.orders++; sellButton.updateButtonState(); } else { LK.effects.flashScreen(0xFF0000, 100); } }; self.sellStock = function (quantity) { if (self.stocks > 0) { var price = stockValuesHistory[graphIndex]; self.balance += price * quantity; self.stocks -= quantity; self.orders++; sellButton.updateButtonState(); } else { //LK.effects.flashScreen(0xFF0000, 100); } }; self.getBalance = function () { return self.balance; }; self.getStockCount = function () { return self.stocks; }; self.getPortfolio = function () { return self.stocks; }; }); var BuyButton = Container.expand(function () { var self = Container.call(this); self.currentText = "Buy"; self.updateButtonState = function () { var stockPrice = stockValuesHistory[graphIndex]; var canBuy = player.getBalance() >= stockPrice && stockPrice > 0; 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 SellButton = 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", 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: 0x008000 }); self.on('down', function () { buttonGraphics = self.attachAsset('bigButtonPressed', { anchorX: 0.5, anchorY: 0.5, tint: 0x008000 }); LK.effects.flashScreen(0x008000, 100); self.setText(self.currentText, true); sellStock(1); }).on('up', function () { buttonGraphics = self.attachAsset('bigButton', { anchorX: 0.5, anchorY: 0.5, tint: 0x008000 }); self.setText(self.currentText); }); }); /**** * Initialize Game ****/ var game = new LK.Game({}); /**** * Game Code ****/ var debug = true; var slideAmount = 6.5; var slideAmountVertical = 0.10; // Reduced speed for smoother vertical movement var moveSegmentsVertically = false; var verticalSlideThreshold = 500; // Define a global threshold for vertical sliding var upperLimit = game.height * 0.25; var lowerLimit = game.height * 0.75; // Define lowerLimit for use in segment positioning var axisLabelFontSize = 70; var running = false; var moveSegments = false; var drawingInProgress = false; // Initialize game elements var player = new Player(); var nbTotalValues = 180; // Graph lenght <=> Round duration var stocks = []; // Initialize stock values history with the first value of $10 var stockValuesHistory = [50]; // Define graphIndex and initialize to 0 var graphIndex = 0; // Declare a global array to store graph segments var graphSegments = []; // Define a global variable for the current stock var currentStock = null; var graphPoints = []; var graphWidth = game.width; var segmentWidth = graphWidth / 5; //; / stockValuesHistory.length; var dollarToYPixelRatio = game.height * 0.5 / 100; var segmentDrawInterval = null; var secondsPerSegment = 2.0; var stockDisplay = []; // Array to hold stock display elements /**** * UI Elements ****/ var farBackground = game.addChild(LK.getAsset('farBackground', { anchorX: 0.5, anchorY: 0.5, alpha: 0.25 })); farBackground.x = game.width / 2; farBackground.y = game.height / 2; var boardBackground = game.addChild(LK.getAsset('board', { anchorX: 0.5, anchorY: 0.5 })); boardBackground.x = game.width / 2; boardBackground.y = game.height * 0.9; var boardBorder = game.addChild(LK.getAsset('boardBorder', { anchorX: 0.5, anchorY: 0.5 })); boardBorder.x = game.width / 2; boardBorder.y = game.height * 0.85; var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 })); background.x = 1024; // Center x position background.y = 2732 * 0.71; // Center y position // Create and draw horizontal axis var horizontalAxis = game.addChild(new Axis(false)); // false indicates this is a horizontal axis horizontalAxis.yValue = game.height * 0.75; // Initialize yValue for vertical movement horizontalAxis.drawAxis(); horizontalAxis.y = horizontalAxis.yValue; horizontalAxis.width = game.width; horizontalAxis.height = 10; horizontalAxis.x = 0; // Move axis to the left side of the screen // Create and draw vertical axis var verticalAxis = new Axis(true); // true indicates this is a vertical axis verticalAxis.drawAxis(); verticalAxis.rotation = Math.PI / 2; // Rotate to make it vertical verticalAxis.x = 20; // Move axis to the left side of the screen verticalAxis.width = game.height; verticalAxis.height = 10; verticalAxis.y = 0; // Instantiate axis labels separately var axisLabels = []; var nbMarkers = 7; for (var i = 0; i < nbMarkers; i++) { var axisLabel = new AxisLabel(i * 25); axisLabel.x = verticalAxis.x + 60; // Position labels to the left of the vertical axis axisLabel.updatePosition(horizontalAxis.y); axisLabel.alpha = 1; axisLabels.push(axisLabel); game.addChild(axisLabel); } // Create buttons var buyButton = game.addChild(new BuyButton()); buyButton.setText('Buy'); buyButton.x = game.width * 0.25; buyButton.y = game.height - buyButton.height / 2 - 20; var sellButton = game.addChild(new SellButton()); sellButton.setText('Sell'); sellButton.x = game.width * 0.75; sellButton.y = game.height - sellButton.height / 2 - 20; sellButton.updateButtonState = function () { if (player.getStockCount() > 0) { this.alpha = 1; this.interactive = true; } else { this.alpha = 0.5; this.interactive = false; } }; sellButton.updateButtonState(); var timerIcon = game.addChild(new TimerIcon()); var timerText = new Text2('000', { size: 100, fill: "#ffffff", anchorX: 0.5 }); timerText.anchor.set(-.95, -0.7); LK.gui.topLeft.addChild(timerText); timerIcon.x = game.width * 0.165; // Position to the left of the balance icon timerIcon.y = game.height * 0.025; var balanceIcon = game.addChild(new BalanceIcon()); balanceIcon.x = game.width * 0.5; balanceIcon.y = game.height * 0.025; var stockIcon = game.addChild(new StockIcon()); stockIcon.x = game.width * 0.94; stockIcon.y = game.height * 0.028; var balanceText = new Text2('$' + player.getBalance() + ' ', { size: 100, fill: "#ffffff", anchorX: 0.5 }); balanceText.anchor.set(.5, -0.7); LK.gui.top.addChild(balanceText); // Create a text display for the number of stocks the player holds var stocksNumber = new Text2(player.getPortfolio(), { size: 100, fill: "#ffffff", anchorX: 0.5 }); stocksNumber.anchor.set(1.5, -0.7); LK.gui.topRight.addChild(stocksNumber); // Create a text display for the verticalSlideAmount labeled VSA var verticalSlideAmount = 0; var vsaText = new Text2('', { size: 50, 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); function updateStockValueText() { if (graphIndex < stockValuesHistory.length) { stockValueText.setText('$' + stockValuesHistory[graphIndex].toFixed(0)); } } /**** * Game Functions ****/ // Update the player's balance display function updateBalanceDisplay() { balanceText.setText('$' + player.getBalance() + ' '); stocksNumber.setText(player.getStockCount()); buyButton.updateButtonState(); } // Function to handle buying stocks function buyStock(stock) { player.buyStock(stock, 1); // Buy 1 stock for simplicity updateBalanceDisplay(); } // Function to handle selling stocks function sellStock(stock) { 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(); return; } if (!drawingInProgress) { updateStockValueText(); // Update the BuyButton status when the stock value changes buyButton.updateButtonState(); 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); if (deltaX < 0) { nextSegmentRotation += Math.PI; } 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; } var tempRotFixedDeltaDeg = ((nextSegmentRotation - tempRotFixed) * (180 / Math.PI)).toFixed(0); console.log('nextSegmentRotation fix : ' + (nextSegmentRotation - tempRotFixed) + " -> " + 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.75 && stockValuesHistory[graphIndex + 1] >= 100) { moveSegmentsVertically = true; console.log('Start moveSegmentsVertically'); } 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) { var segment = gameRef.addChild(new GraphSegment()); segment.index1 = index; segment.stockValue1 = stockValuesHistory[index]; segment.stockValue2 = stockValuesHistory[index + 1]; segment.x1 = x1; segment.y1 = y1; segment.rotation = rotation; 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; var updateWidth = function updateWidth() { if (!running) { return; } var currentTime = Date.now(); var timeElapsed = currentTime - startTime; var newWidth = Math.min(timeElapsed / (delay * 1000 * secondsPerSegment) * width, width); segment.width = newWidth; if (currentTime < endTime) { 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; } }; updateWidth(); } function setDebugValues() { stockValuesHistory = []; var series = [0, 25, 50, 75, 100, 125, 150, 175, 200, 175, 150, 125, 100, 75, 50, 25, 0, 0, 0]; //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]; // 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); } } 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++) { var delta = Math.floor((Math.random() - 0.5) * 100); // Generate a delta between -50 and 50 var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta)); stockValuesHistory.push(newValue); previousValue = newValue; buyButton.updateButtonState(); } if (debug) { setDebugValues(); // DEBUG MODE } var x, y; // Compute the coordinates for the graph based on stockValuesHistory for (var i = 0; i < stockValuesHistory.length; i++) { x = segmentWidth * i; y = game.height * 0.75 - stockValuesHistory[i] * dollarToYPixelRatio; // Calculate Y based on new mapping graphPoints.push({ x: x, y: y }); } running = true; LK.setTimeout(function () { stockValueText.alpha = 1; }, 100); // 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 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 LK.on('tick', function () { if (!running) { return; } // Update slide for each graph segment and the horizontal axis graphSegments.forEach(function (segment) { segment.updateSlide(); }); horizontalAxis.updateSlide(); // Slide the horizontal axis vertically // Update the position of axis labels based on the y position of the horizontal axis axisLabels.forEach(function (label) { label.updatePosition(horizontalAxis.y); }); if (debug) { // Update the vertical slide amount text periodically vsaText.setText(graphIndex + ' VSA: ' + verticalSlideAmount.toFixed(0) + " " + moveSegmentsVertically); } }); var startTime = Date.now(); LK.setTimeout(function () { startGame(); }, 1000);
===================================================================
--- original.js
+++ change.js
@@ -456,9 +456,15 @@
//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 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;
+ }
var tempRotFixedDeltaDeg = ((nextSegmentRotation - tempRotFixed) * (180 / Math.PI)).toFixed(0);
console.log('nextSegmentRotation fix : ' + (nextSegmentRotation - tempRotFixed) + " -> " + 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;
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.