User prompt
in moveSegmentsLeft use the global array of segments to move them
User prompt
store a global array of segments. add them in drawSegment()
User prompt
Fix Bug: 'TypeError: segment.slide is not a function' in this line: 'segment.slide();' Line Number: 189
User prompt
instead of moving the segments "externally" in moveSegmentsLeft, use a global boolean "moveSegments" defaulting to false. when `(segment.x + segment.width / 2 >= game.width / 2)` instead of calling moveSegmentsLeft, set moveSegments to true. Also add a slide() function in segments to make them move left when moveSegments is true
User prompt
the move of segments moveSegmentsLeft should be continous like the one of the indicator, currently their move is jerky !
Code edit (1 edits merged)
Please save this source code
User prompt
store a global array of segments. add them in drawSegment(). use them in moveSegmentsLeft to move them in place of `game.children.filter(function (child) {return child instanceof GraphSegment;})`
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: GraphSegment is not defined' in this line: 'return child instanceof GraphSegment;' Line Number: 219
User prompt
bug : in moveSegmentsLeft : var segments = game.children.filter(function (child) { return child.assetId === 'segment';}); returns 0 segments !
Code edit (4 edits merged)
Please save this source code
User prompt
bug : moveSegmentsLeft is called but the segments doesn't move to the left
Code edit (3 edits merged)
Please save this source code
User prompt
now when the a segment reaches the center (game.width / 2) make all the segments move to the left
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: nextX is not defined' in this line: 'console.log('ValueIndicator moving to next position: ' + stockValuesHistory[historyIndex], nextX, 1366 - targetY);' Line Number: 41
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: startGame is not defined' in this line: 'startGame();' Line Number: 252
User prompt
call startGame after 1 sec
Code edit (2 edits merged)
Please save this source code
User prompt
in drawSegment in updateWidth, with should only change when running is true
User prompt
add a global boolean "running". default false. The indicator and graph updates should occur only when running is true. Do not change anything else
Code edit (4 edits merged)
Please save this source code
User prompt
Fix ValueIndicator not moving after start
===================================================================
--- original.js
+++ change.js
@@ -50,15 +50,15 @@
if (timeElapsed < duration) {
LK.setTimeout(animateY, 16);
} else {
self.y = targetY; // Ensure final position is set
- historyIndex++;
- if (historyIndex < stockValuesHistory.length) {
- LK.setTimeout(updateYPosition, 1000); // Continue updating position
- }
}
};
animateY();
+ historyIndex++;
+ LK.setTimeout(function () {
+ updateYPosition();
+ }, 1000); // Update position every second and add a new segment
}
};
updateYPosition();
};
@@ -105,23 +105,25 @@
/****
* Game Code
****/
// Create and add background asset
+var running = false;
var background = game.addChild(LK.getAsset('background', 'Game background', 0.5, 0.5));
background.x = 1024; // Center x position
background.y = 2732 - background.height / 2; // Center y position
// Initialize game elements
var player = new Player();
var stocks = [];
// Initialize stock values history with the first value of $10
-var running = true;
var stockValuesHistory = [10];
// Add 10 other random stock values
for (var i = 0; i < 10; i++) {
stockValuesHistory.push(Math.floor(Math.random() * 100) + 1);
}
// Instantiate ValueIndicator
var valueIndicator = new ValueIndicator();
+// Add ValueIndicator to the game and update its position
+valueIndicator.updatePosition(100); // Example stock price
game.addChild(valueIndicator);
// Compute the coordinates for ValueIndicator based on stockValuesHistory
var graphPoints = [];
var graphWidth = game.width;
@@ -145,8 +147,10 @@
x: x,
y: y
});
}
+// Pass the series of points to drawGraph
+drawGraph(game, graphPoints);
// Draw a sample square using drawGraph
var stockDisplay = []; // Array to hold stock display elements
var balanceText = new Text2('Balance: $' + player.getBalance(), {
size: 50,
@@ -171,8 +175,11 @@
updateBalanceDisplay();
}
// Main game loop
LK.on('tick', function () {
+ if (!running) {
+ return;
+ }
// Check for game over conditions (e.g., player runs out of money)
if (player.getBalance() <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
@@ -205,11 +212,8 @@
};
updateWidth();
}
function drawGraph(gameRef, points) {
- if (!running) {
- return;
- }
console.log('Starting to draw graph');
if (points.length < 2) {
console.log('Not enough points to draw a graph segment.');
return;
@@ -239,14 +243,5 @@
console.log('Finished drawing graph');
}
}
drawNextSegment(0);
-}
-function startGame() {
- console.log('Starting the game...');
- running = true;
- // Add ValueIndicator to the game and update its position
- valueIndicator.updatePosition(100); // Example stock price
- // Pass the series of points to drawGraph
- drawGraph(game, graphPoints);
-}
-LK.setTimeout(startGame, 1000);
\ No newline at end of file
+}
\ No newline at end of file
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.