Code edit (1 edits merged)
Please save this source code
User prompt
put the vertical axe on the left
User prompt
draw the axes
Code edit (1 edits merged)
Please save this source code
User prompt
updateStockValueText should be call in drawNextSegment
Code edit (2 edits merged)
Please save this source code
User prompt
updateStockValueText should display current Value that is stockValuesHistory[graphIndex]
User prompt
add a text on top right that displays the current stock value. Create a dedicated updateStockValueText function and ensure variables scopes are correct
User prompt
in "new segment" console log don't display decimals
Code edit (5 edits merged)
Please save this source code
User prompt
apply the same logic of lastSegmentEndX to the lastSegmentEndY in order to avoid vertical gaps between segments
Code edit (1 edits merged)
Please save this source code
User prompt
4. **Vertical Sliding Mechanism:** : Prevents the graph from raising out of the screen by applying a vertical slide - Similar to the horizontal sliding mechanism already in place for moving the graph segments leftward, you would implement a vertical sliding mechanism. - This vertical slide would be activated via a global varibale moveSegmentsVertically when the Y values of the segments exceed a predefined global threshold. - The direction of the slide (up or down) would depend on whether the stock price is increasing or decreasing. - This mecanism comes in addition to the horizontal slide mecanism and is is independant from it - the threshold is a global variable - All segments (the graph) move the same way. So the slideAmountVertical should be global like slideAmount
User prompt
4. **Vertical Sliding Mechanism:** : Prevents the graph from raising out of the screen by applying a vertical slide - Similar to the horizontal sliding mechanism already in place for moving the graph segments leftward, you would implement a vertical sliding mechanism. - This vertical slide would be activated via a global varibale moveSegmentsVertically when the Y values of the segments exceed a predefined global threshold. - The direction of the slide (up or down) would depend on whether the stock price is increasing or decreasing. - This mecanism comes in addition to the horizontal slide mecanism and is is independant from it - the threshold is a global variable - All segments (the graph) move the same way
User prompt
4. **Vertical Sliding Mechanism:** - Similar to the horizontal sliding mechanism already in place for moving the graph segments leftward, you would implement a vertical sliding mechanism. - This vertical slide would be activated via a global varibale moveSegmentsVertically when the Y values of the segments exceed a predefined global threshold. - The direction of the slide (up or down) would depend on whether the stock price is increasing or decreasing. - This mecanism comes in addition to the horizontal slide mecanism and is is independant from it - the threshold is a global variable - All segments (the graph) move the same way
User prompt
4. **Vertical Sliding Mechanism:** - Similar to the horizontal sliding mechanism already in place for moving the graph segments leftward, you would implement a vertical sliding mechanism. - This vertical slide would be activated when the Y values of the segments exceed a predefined global threshold. - The direction of the slide (up or down) would depend on whether the stock price is increasing or decreasing. - This mecanism comes in addition to the horizontal slide mecanism and is is independant from it
User prompt
4. **Vertical Sliding Mechanism:** - Similar to the horizontal sliding mechanism already in place for moving the graph segments leftward, you would implement a vertical sliding mechanism. - This vertical slide would be activated when the Y values of the segments exceed a predefined threshold. - The direction of the slide (up or down) would depend on whether the stock price is increasing or decreasing.
User prompt
3. **Monitoring Y Values of Segments:** - As the graph is drawn and updated, you would keep track of the Y values of each graph segment. - This tracking would allow you to determine when the stock price reaches certain thresholds that may trigger buying or selling actions.
User prompt
2. **Clamping Values:** - After applying the delta to the previous stock value, you would check if the new value falls below 0. - If it does, you would clamp the value to 0 to prevent negative stock prices.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
1. **Random Deltas for Stock Values:** - Instead of assigning random values directly to the stockValuesHistory array, you would generate random deltas (changes in value). - These deltas would be added to the previous value in the stockValuesHistory to create a more realistic fluctuation in stock prices.
Code edit (1 edits merged)
Please save this source code
User prompt
Stop the game after the last graphPoint is reached
Code edit (7 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -64,9 +64,9 @@
****/
var slideAmount = 5.0;
var slideAmountVertical = 5.0;
var moveSegmentsVertically = false;
-var verticalSlideThreshold = 500; // Define a global threshold for vertical sliding
+var verticalSlideThreshold = 200; // Define a global threshold for vertical sliding
// Create and add background asset
var running = false;
var moveSegments = false;
var drawingInProgress = false;
@@ -102,24 +102,8 @@
x: x,
y: y
});
}
-function addNewStockValues() {
- if (moveSegments) {
- var newStockValue = Math.floor(Math.random() * 100) + 1;
- stockValuesHistory.push(newStockValue);
- var totalSlideDistance = graphSegments.length > 0 ? graphSegments[0].startX - graphSegments[0].x : 0;
- var newGraphPoint = {
- x: graphPoints[graphPoints.length - 1].x + segmentWidth - totalSlideDistance,
- y: game.height / 2 - newStockValue * 10
- };
- graphPoints.push(newGraphPoint);
- // Determine if vertical sliding should be activated
- var lastYValue = graphPoints[graphPoints.length - 2].y;
- moveSegmentsVertically = newGraphPoint.y < lastYValue - verticalSlideThreshold || newGraphPoint.y > lastYValue + verticalSlideThreshold;
- }
- LK.setTimeout(addNewStockValues, 1000); // Continue adding new values every second
-}
var segmentDrawInterval = null;
var stockDisplay = []; // Array to hold stock display elements
var balanceText = new Text2('Balance: $' + player.getBalance(), {
size: 50,
@@ -154,8 +138,12 @@
var lastSegment = graphSegments.length > 0 ? graphSegments[graphSegments.length - 1] : null;
var lastSegmentEndX = lastSegment ? lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width : 0;
pointA.x = lastSegment ? lastSegmentEndX : 0;
var pointB = graphPoints[graphIndex + 1];
+ if (!moveSegmentsVertically && pointB.y < verticalSlideThreshold) {
+ moveSegmentsVertically = true;
+ console.log("Past Upper limit !");
+ }
var delay = 1; // Reduce delay if segments are moving
drawingInProgress = true;
drawSegment(game, graphIndex, pointA.x, pointA.y, pointB.x, pointB.y, delay);
graphIndex++;
@@ -209,10 +197,8 @@
// Initialize and start the game logic here
running = true;
// Set up a tick event to call drawNextSegment every second
segmentDrawInterval = LK.setInterval(drawNextSegment, 100);
- // Add ValueIndicator to the game and update its position
- //LK.setTimeout(addNewStockValues, 1000);
}
// Main game loop
LK.on('tick', function () {
if (!running) {
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.