Code edit (11 edits merged)
Please save this source code
User prompt
make stockValueText follow the current segment y
Code edit (6 edits merged)
Please save this source code
User prompt
move the stock price to the left center
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Add a new text2 named socksNumber, in the same way as balanceText
Code edit (1 edits merged)
Please save this source code
Code edit (18 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: BalanceIcon is not defined' in or related to this line: 'var balanceIcon = game.addChild(new BalanceIcon());' Line Number: 307
User prompt
Add a new stockIcon asset similar to balanceIcon, place it at the right of balanceIcon
Code edit (1 edits merged)
Please save this source code
User prompt
add a new icon for balance
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
'reuse' the axis labels and ensure that values are always visible without creating too many Text label instances, you can implement a recycling mechanism for the labels.
User prompt
make axis labels values dynamic so that visible values are always centered on stockValuesHistory[graphIndex + 1]
Code edit (2 edits merged)
Please save this source code
User prompt
call labels updatePosition with the y position of horizontal axis
Code edit (1 edits merged)
Please save this source code
User prompt
instiate axis labels (but not as children of vertical axis)
Code edit (4 edits merged)
Please save this source code
User prompt
detach the labels from the vertical axis : the should not be children of vertivalAxis
Code edit (1 edits merged)
Please save this source code
User prompt
Rotate labels by -90°
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,14 @@
/****
* Classes
****/
+var BalanceIcon = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('balanceIcon', {
+ 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, {
@@ -9,18 +16,19 @@
fill: "#ffffff"
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
+ self.alpha = 0;
self.updatePosition = function (axisY) {
- self.y = axisY - value * dollarToYPixelRatio - axisLabelFontSize / 2;
- if (self.y > game.height * 0.85) {
- self.value += 200;
- self.y = axisY - value * dollarToYPixelRatio - axisLabelFontSize / 2;
+ var newY = axisY - self.value * dollarToYPixelRatio - axisLabelFontSize / 2;
+ if (newY > game.height * 0.85) {
+ self.value += (nbMarkers - 1) * 25;
+ label.setText('$' + self.value);
+ } else if (newY < game.height * 0.10) {
+ self.value -= (nbMarkers - 1) * 25;
+ label.setText('$' + self.value);
}
- if (self.y < game.height * 0.15) {
- self.value -= 200;
- self.y = axisY - value * dollarToYPixelRatio - axisLabelFontSize / 2;
- }
+ 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= ...
};
@@ -206,8 +214,9 @@
/****
* Game Code
****/
+var debug = false;
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
@@ -270,9 +279,8 @@
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 fixed horizontal Marker axis
// 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
@@ -281,11 +289,14 @@
verticalAxis.height = 10;
verticalAxis.y = 0;
// Instantiate axis labels separately
var axisLabels = [];
-for (var i = 0; i < 6; i++) {
+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
@@ -296,39 +307,43 @@
var sellButton = game.addChild(new SellButton());
sellButton.setText('Sell');
sellButton.x = game.width * 0.75;
sellButton.y = game.height - sellButton.height / 2 - 20;
-var balanceText = new Text2('Balance: $' + player.getBalance(), {
+var balanceText = new Text2('Balance\r\n$' + player.getBalance(), {
size: 50,
- fill: "#ffffff"
+ fill: "#ffffff",
+ anchorX: 0
});
// Create a text display for the verticalSlideAmount labeled VSA
var verticalSlideAmount = 0;
-var vsaText = new Text2('VSA: ' + verticalSlideAmount.toFixed(0), {
+var vsaText = new Text2('', {
size: 50,
fill: "#ffffff"
});
vsaText.anchor.set(0, 0);
LK.gui.topLeft.addChild(vsaText);
-var stockValueText = new Text2('Stock Value: $' + stockValuesHistory[stockValuesHistory.length - 1].toFixed(2), {
+var stockValueText = new Text2('Price\n$' + stockValuesHistory[stockValuesHistory.length - 1].toFixed(0), {
size: 50,
fill: "#ffffff"
});
stockValueText.anchor.set(1, 0);
LK.gui.topRight.addChild(stockValueText);
function updateStockValueText() {
if (graphIndex < stockValuesHistory.length) {
- stockValueText.setText('Stock Value: $' + stockValuesHistory[graphIndex + 1].toFixed(0));
+ stockValueText.setText('Price\n\t$' + stockValuesHistory[graphIndex + 1].toFixed(0));
}
}
+var balanceIcon = game.addChild(new BalanceIcon());
+balanceIcon.x = balanceText.x - balanceText.width / 2 - balanceIcon.width / 2 - 10;
+balanceIcon.y = balanceText.y + balanceText.height / 2;
balanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(balanceText);
/****
* Game Functions
****/
// Update the player's balance display
function updateBalanceDisplay() {
- balanceText.setText('Balance: $' + player.getBalance().toFixed(2));
+ balanceText.setText('Balance\r\n$' + player.getBalance().toFixed(2));
}
// Function to handle buying stocks
function buyStock(stock) {
player.buyStock(stock, 1); // Buy 1 stock for simplicity
@@ -429,9 +444,11 @@
var newValue = Math.max(0, previousValue + (previousValue == 0 ? Math.abs(delta) : delta));
stockValuesHistory.push(newValue);
previousValue = newValue;
}
- //setDebugValues(); // DEBUG MODE
+ 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;
@@ -458,14 +475,11 @@
// Update the position of axis labels based on the y position of the horizontal axis
axisLabels.forEach(function (label) {
label.updatePosition(horizontalAxis.y);
});
- // Update the vertical slide amount text periodically
- vsaText.setText(graphIndex + ' VSA: ' + verticalSlideAmount.toFixed(0) + " " + moveSegmentsVertically);
- // Check for game over conditions (e.g., player runs out of money)
- if (player.getBalance() <= 0) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
+ if (debug) {
+ // Update the vertical slide amount text periodically
+ vsaText.setText(graphIndex + ' VSA: ' + verticalSlideAmount.toFixed(0) + " " + moveSegmentsVertically);
}
});
LK.setTimeout(function () {
startGame();
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.