User prompt
make the coinflip animation smoother
User prompt
make it so when you either hit 2000$ or 100$, the game ends and a picture of an explosion filling the entire screen appears
User prompt
make it so you win or lose 200$ instead of 100$
User prompt
show the results of the coinflip when the animation is done
User prompt
make a rolling animation for the coin when clicking the 'button_heads' or 'button_tails'
User prompt
make a flipping animation for coin, when you click either of the buttons
User prompt
make it so if you hit 2000$ or 100$, the game ends
User prompt
make a counter for the money
User prompt
Fix Bug: 'TypeError: coinGraphics.setTexture is not a function' in this line: 'coinGraphics.setTexture(LK.getAsset('coin_' + result, 'Coin with ' + result + ' side up', 0.5, 0.5));' Line Number: 14
Initial prompt
Coinflip
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,23 @@
/****
* Classes
****/
+// Counter class to display and update the player's balance
+var Counter = Container.expand(function (initialValue, posX, posY) {
+ var self = Container.call(this);
+ var text = new Text2(initialValue.toString(), {
+ size: 100,
+ fill: "#ffffff"
+ });
+ text.anchor.set(0.5, 0);
+ text.x = posX;
+ text.y = posY;
+ self.addChild(text);
+ // Method to update the displayed text
+ self.updateText = function (newValue) {
+ text.setText(newValue.toString());
+ };
+});
// Coin class to represent the coin being flipped
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.createAsset('coin_heads', 'Coin with heads side up', 0.5, 0.5);
@@ -41,28 +57,21 @@
coin.x = game.width / 2;
coin.y = game.height / 2 - 200;
// Initialize the player
var player = new Player();
-// Create the balance text
-var balanceTxt = new Text2(player.balance.toString(), {
- size: 100,
- fill: "#ffffff"
-});
-balanceTxt.anchor.set(0.5, 0);
-balanceTxt.x = game.width / 2;
-balanceTxt.y = 100;
-LK.gui.top.addChild(balanceTxt);
+// Create the balance counter using the Counter class
+var balanceCounter = game.addChild(new Counter(player.balance, game.width / 2, 100));
// Create the Heads button
var headsButton = game.addChild(LK.getAsset('button_heads', 'Heads Button', 0.5, 0.5));
headsButton.x = game.width / 4;
headsButton.y = game.height - 300;
// Create the Tails button
var tailsButton = game.addChild(LK.getAsset('button_tails', 'Tails Button', 0.5, 0.5));
tailsButton.x = game.width / 4 * 3;
tailsButton.y = game.height - 300;
-// Function to update the balance text
+// Function to update the balance counter display
function updateBalanceText() {
- balanceTxt.setText(player.balance.toString());
+ balanceCounter.updateText(player.balance);
}
// Function to handle the flip result
function handleFlipResult(choice) {
if (player.balance <= 0) {