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,40 +1,40 @@
-/****
+/****
* Classes
****/
// 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);
- self.side = 'heads'; // Initial side of the coin
- // Function to flip the coin
- self.flip = function (choice) {
- // Randomly choose heads or tails
- var result = Math.random() < 0.5 ? 'heads' : 'tails';
- // Update the coin graphics based on the result
- coinGraphics.setTexture(LK.getAsset('coin_' + result, 'Coin with ' + result + ' side up', 0.5, 0.5));
- self.side = result;
- return result === choice;
- };
+ var self = Container.call(this);
+ var coinGraphics = self.createAsset('coin_heads', 'Coin with heads side up', 0.5, 0.5);
+ self.side = 'heads'; // Initial side of the coin
+ // Function to flip the coin
+ self.flip = function (choice) {
+ // Randomly choose heads or tails
+ var result = Math.random() < 0.5 ? 'heads' : 'tails';
+ // Update the coin graphics based on the result
+ coinGraphics.texture = LK.getAsset('coin_' + result).texture;
+ self.side = result;
+ return result === choice;
+ };
});
// Player class to represent the player's state
var Player = Container.expand(function () {
- var self = Container.call(this);
- self.balance = 1000; // Player starts with $1000
- // Function to update the player's balance
- self.updateBalance = function (amount) {
- self.balance += amount;
- };
+ var self = Container.call(this);
+ self.balance = 1000; // Player starts with $1000
+ // Function to update the player's balance
+ self.updateBalance = function (amount) {
+ self.balance += amount;
+ };
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
****/
// Initialize the coin
var coin = game.addChild(new Coin());
@@ -43,10 +43,10 @@
// Initialize the player
var player = new Player();
// Create the balance text
var balanceTxt = new Text2(player.balance.toString(), {
- size: 100,
- fill: "#ffffff"
+ size: 100,
+ fill: "#ffffff"
});
balanceTxt.anchor.set(0.5, 0);
balanceTxt.x = game.width / 2;
balanceTxt.y = 100;
@@ -60,29 +60,29 @@
tailsButton.x = game.width / 4 * 3;
tailsButton.y = game.height - 300;
// Function to update the balance text
function updateBalanceText() {
- balanceTxt.setText(player.balance.toString());
+ balanceTxt.setText(player.balance.toString());
}
// Function to handle the flip result
function handleFlipResult(choice) {
- if (player.balance <= 0) {
- LK.showGameOver();
- return;
- }
- var win = coin.flip(choice);
- if (win) {
- player.updateBalance(100); // Win $100
- } else {
- player.updateBalance(-100); // Lose $100
- }
- updateBalanceText();
+ if (player.balance <= 0) {
+ LK.showGameOver();
+ return;
+ }
+ var win = coin.flip(choice);
+ if (win) {
+ player.updateBalance(100); // Win $100
+ } else {
+ player.updateBalance(-100); // Lose $100
+ }
+ updateBalanceText();
}
// Event listener for the Heads button
headsButton.on('down', function () {
- handleFlipResult('heads');
+ handleFlipResult('heads');
});
// Event listener for the Tails button
tailsButton.on('down', function () {
- handleFlipResult('tails');
+ handleFlipResult('tails');
});
// No need for a tick function as the game does not have continuous animation or movement
\ No newline at end of file