User prompt
show the ValueIndicator
User prompt
remove the Stock class
User prompt
Bug : I can't see the valueindicator
User prompt
show the ValueIndicator at the left center of the screen
User prompt
add a visual object that will represent the current value of the stock on the graph
Code edit (1 edits merged)
Please save this source code
User prompt
remove the stocks
User prompt
add an asset for th background
Code edit (1 edits merged)
Please save this source code
Initial prompt
Hyper Stocks
===================================================================
--- original.js
+++ change.js
@@ -1,127 +1,127 @@
-/****
+/****
* Classes
****/
// Stock class to represent a stock in the market
var Stock = Container.expand(function () {
- var self = Container.call(this);
- var stockGraphics = self.createAsset('stock', 'Stock representation', 0.5, 0.5);
- self.price = Math.random() * 100; // Initialize with a random price
- self.history = []; // Keep track of price history
-
- self.updatePrice = function () {
- // Simulate market fluctuation
- self.price += (Math.random() - 0.5) * 10;
- self.history.push(self.price);
- if (self.history.length > 100) {
- self.history.shift(); // Keep the history array at a fixed size
- }
- };
- self.getPrice = function () {
- return self.price;
- };
- self.getHistory = function () {
- return self.history;
- };
+ var self = Container.call(this);
+ var stockGraphics = self.createAsset('stock', 'Stock representation', 0.5, 0.5);
+ self.price = Math.random() * 100; // Initialize with a random price
+ self.history = []; // Keep track of price history
+ self.updatePrice = function () {
+ // Simulate market fluctuation
+ self.price += (Math.random() - 0.5) * 10;
+ self.history.push(self.price);
+ if (self.history.length > 100) {
+ self.history.shift(); // Keep the history array at a fixed size
+ }
+ };
+ self.getPrice = function () {
+ return self.price;
+ };
+ self.getHistory = function () {
+ return self.history;
+ };
});
// Player class to represent the player's portfolio
var Player = Container.expand(function () {
- var self = Container.call(this);
- self.balance = 1000; // Start with $1000
- self.stocks = {}; // Object to hold stocks and quantities
-
- self.buyStock = function (stock, quantity) {
- var cost = stock.getPrice() * quantity;
- if (self.balance >= cost) {
- self.balance -= cost;
- if (!self.stocks[stock]) {
- self.stocks[stock] = 0;
- }
- self.stocks[stock] += quantity;
- }
- };
- 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.getBalance = function () {
- return self.balance;
- };
- self.getPortfolio = function () {
- return self.stocks;
- };
+ var self = Container.call(this);
+ self.balance = 100; // Start with $100
+ self.stocks = {}; // Object to hold stocks and quantities
+ self.buyStock = function (stock, quantity) {
+ var cost = stock.getPrice() * quantity;
+ if (self.balance >= cost) {
+ self.balance -= cost;
+ if (!self.stocks[stock]) {
+ self.stocks[stock] = 0;
+ }
+ self.stocks[stock] += quantity;
+ }
+ };
+ 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.getBalance = function () {
+ return self.balance;
+ };
+ self.getPortfolio = function () {
+ return self.stocks;
+ };
});
-/****
+
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+
+/****
* Game Code
****/
// Initialize game elements
var player = new Player();
var stocks = [];
var stockDisplay = []; // Array to hold stock display elements
var balanceText = new Text2('Balance: $' + player.getBalance(), {
- size: 50,
- fill: "#ffffff"
+ size: 50,
+ fill: "#ffffff"
});
balanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(balanceText);
// Create a few stocks to trade
for (var i = 0; i < 5; i++) {
- var stock = new Stock();
- stock.x = 2048 / 2;
- stock.y = 2732 / 2 + i * 150;
- stocks.push(stock);
- game.addChild(stock);
+ var stock = new Stock();
+ stock.x = 2048 / 2;
+ stock.y = 2732 / 2 + i * 150;
+ stocks.push(stock);
+ game.addChild(stock);
}
// Update the player's balance display
function updateBalanceDisplay() {
- balanceText.setText('Balance: $' + player.getBalance().toFixed(2));
+ balanceText.setText('Balance: $' + player.getBalance().toFixed(2));
}
// Function to handle buying stocks
function buyStock(stock) {
- player.buyStock(stock, 1); // Buy 1 stock for simplicity
- updateBalanceDisplay();
+ 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();
+ player.sellStock(stock, 1); // Sell 1 stock for simplicity
+ updateBalanceDisplay();
}
// Add event listeners to stocks for buying/selling
stocks.forEach(function (stock) {
- stock.on('down', function () {
- buyStock(stock);
- });
- stock.on('up', function () {
- sellStock(stock);
- });
+ stock.on('down', function () {
+ buyStock(stock);
+ });
+ stock.on('up', function () {
+ sellStock(stock);
+ });
});
// Main game loop
LK.on('tick', function () {
- // Update stock prices
- stocks.forEach(function (stock) {
- stock.updatePrice();
- // Update stock display if needed
- });
+ // Update stock prices
+ stocks.forEach(function (stock) {
+ stock.updatePrice();
+ // Update stock display if needed
+ });
- // Check for game over conditions (e.g., player runs out of money)
- if (player.getBalance() <= 0) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
+ // Check for game over conditions (e.g., player runs out of money)
+ if (player.getBalance() <= 0) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
});
\ 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.