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
User prompt
Just tell me how can I make the stocknumber text position fixed ? Independent from Texts lenghts
User prompt
So how can I make the stocknumber text position fixed ? Independent from Texts lenghts
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'Script error.' in or related to this line: 'LK.gui.roght.addChild(stockValueText);' Line Number: 400
Code edit (1 edits merged)
Please save this source code
User prompt
Add a timerIcon at the left of the balance icon
Code edit (3 edits merged)
Please save this source code
User prompt
Disable sell button when player has no stocks
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -50,16 +50,22 @@
self.x2 = 0;
self.y2 = 0;
self.isFinished = false;
var verticalSlideRatio = 1;
- var interpolationSpeed = 0.5; // Adjust this value for speed
+ 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.2) {
+ slideAmount = Math.max(1, slideAmount - 0.5);
+ }
+ if (self.index1 == graphIndex && self.x1 > game.width * 0.8) {
+ slideAmount = Math.min(15, slideAmount + 0.5);
+ }
}
if (moveSegmentsVertically) {
- var currentDelta = horizontalAxis.y - game.height * 0.75;
- var targetY = game.height * 0.75 - dollarToYPixelRatio * self.stockValue1 + currentDelta;
+ var currentDelta = horizontalAxis.y - lowerLimit;
+ var targetY = lowerLimit - dollarToYPixelRatio * self.stockValue1 + currentDelta;
var deltaY = (targetY - self.y) * interpolationSpeed;
self.y += deltaY;
if (Math.abs(deltaY) <= 1) {
self.y = targetY;
@@ -108,28 +114,36 @@
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++;
+ } else {
+ LK.effects.flashScreen(0xFF0000, 100);
}
};
- self.sellStock = function (stock, quantity) {
- if (self.stocks[stock] && self.stocks[stock] >= quantity) {
- self.balance += stock.getPrice() * quantity;
- self.stocks[stock] -= quantity;
- if (self.stocks[stock] === 0) {
- delete self.stocks[stock];
- }
+ self.sellStock = function (quantity) {
+ if (self.stocks > 0) {
+ var price = stockValuesHistory[graphIndex];
+ self.balance += price * quantity;
+ self.stocks -= quantity;
+ self.orders++;
+ } else {
+ LK.effects.flashScreen(0xFF0000, 100);
}
};
self.getBalance = function () {
return self.balance;
};
+ self.getStockCount = function () {
+ return self.stocks;
+ };
self.getPortfolio = function () {
return self.stocks;
};
});
@@ -196,11 +210,9 @@
tint: 0x008000
});
LK.effects.flashScreen(0x008000, 100);
self.setText(self.currentText, true);
- if (currentStock) {
- sellStock(currentStock);
- }
+ sellStock(1);
}).on('up', function () {
buttonGraphics = self.attachAsset('bigButton', {
anchorX: 0.5,
anchorY: 0.5,
@@ -217,14 +229,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 = false;
var verticalSlideThreshold = 500; // Define a global threshold for vertical sliding
-var upperLimit = game.height * 0.35;
+var upperLimit = game.height * 0.5;
var lowerLimit = game.height * 0.75; // Define lowerLimit for use in segment positioning
var axisLabelFontSize = 50;
var running = false;
var moveSegments = false;
@@ -244,9 +256,9 @@
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 secondsPerSegment = 3.0;
var stockDisplay = []; // Array to hold stock display elements
/****
* UI Elements
****/
@@ -329,9 +341,9 @@
size: 100,
fill: "#ffffff",
anchorX: 0.5
});
-stocksNumber.anchor.set(-1.05, 0.3);
+stocksNumber.anchor.set(-4, -0.7);
LK.gui.top.addChild(stocksNumber);
// Create a text display for the verticalSlideAmount labeled VSA
var verticalSlideAmount = 0;
var vsaText = new Text2('', {
@@ -356,8 +368,9 @@
****/
// Update the player's balance display
function updateBalanceDisplay() {
balanceText.setText('$' + player.getBalance() + ' ');
+ stocksNumber.setText(player.getStockCount());
}
// Function to handle buying stocks
function buyStock(stock) {
player.buyStock(stock, 1); // Buy 1 stock for simplicity
@@ -395,10 +408,11 @@
distance = (lowerLimit - pointA.y) / Math.sin(nextSegmentRotation);
}
if (nextSegmentEndY < upperLimit || nextSegmentEndY > upperLimit && stockValuesHistory[graphIndex + 1] >= 100) {
moveSegmentsVertically = true;
+ console.log('Start moveSegmentsVertically');
}
- var delay = 0.5; // Reduce delay to speed up the drawing of segments
+ var delay = 0.95; // Reduce delay to speed up the drawing of segments
drawingInProgress = true;
drawSegment(game, graphIndex, pointA.x, pointA.y, nextSegmentRotation, distance, delay);
}
}
@@ -444,8 +458,9 @@
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];
+ series = [1, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 500, 450, 400, 350, 300, 250, 200, 150, 100, 50, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100, 1, 100];
for (var i = 0; i < 1; i++) {
stockValuesHistory = stockValuesHistory.concat(series);
}
}
@@ -454,9 +469,9 @@
// Generate random deltas and add to previous value for stockValuesHistory
var previousValue = stockValuesHistory[stockValuesHistory.length - 1];
for (var i = 0; i < 100; i++) {
var delta = Math.floor((Math.random() - 0.5) * 100); // Generate a delta between -50 and 50
- var newValue = Math.max(0, previousValue + (previousValue == 0 ? Math.abs(delta) : delta));
+ var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta));
stockValuesHistory.push(newValue);
previousValue = newValue;
}
if (debug) {
@@ -473,9 +488,9 @@
});
}
running = true;
// Set up a tick event to call drawNextSegment every second
- segmentDrawInterval = LK.setInterval(drawNextSegment, 20);
+ segmentDrawInterval = LK.setInterval(drawNextSegment, 10);
}
// 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.