User prompt
create a new class for previous card
User prompt
leave a copy of current card on the left so we can compare current with next card visually
User prompt
when next card is spawned it shoud appear on the right and the current card should remain on the left
User prompt
on swipe, update next card on the right asset
User prompt
show card and next card next to each other. next cardwill start empty in the first hand.
User prompt
Fix Bug: 'Cannot read properties of null (reading 'x')' in this line: 'currentCard.x = nextCard.x;' Line Number: 217
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of null (reading 'x')' in this line: 'currentCard.x = nextCard.x;' Line Number: 217
User prompt
1 second after the current card appear on the screen, move it over the current car
User prompt
new next card should position and stop on the right of the current card
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'y')' in this line: 'if (nextCard && swipeDirection > 0 && nextCard.y < 2732 / 2) {' Line Number: 118
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'y')' in this line: 'if (swipeDirection > 0 && nextCard.y < 2732 / 2) {' Line Number: 118
User prompt
on swipe up or down, the next card should come into the screen either form the top or from the bottomrespectively
User prompt
move both cards 400 pixels right
User prompt
move both cards 200 pixelsleft
User prompt
move both cards 300 pixels right
User prompt
on game start show bot cards next to each other current and next. next will be empty on the first hand of the game
User prompt
change correct or wrong text to black
Code edit (1 edits merged)
Please save this source code
User prompt
On game start add a message on the bottom of the screen. Will read: (Swipe up for higher or down for lower)
User prompt
During ready message player shoold not be able to swipe up or down
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'value')' in this line: 'var correctGuess = nextCard !== null && (guess === 'higher' && nextCard.value > currentCard.value || guess === 'lower' && nextCard.value < currentCard.value);' Line Number: 150
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'value')' in this line: 'var correctGuess = nextCard && (guess === 'higher' && nextCard.value > currentCard.value || guess === 'lower' && nextCard.value < currentCard.value);' Line Number: 150
User prompt
Show countwond message and ready messagebon game start
User prompt
Fix Bug: 'TypeError: Cannot read properties of null (reading 'value')' in this line: 'var correctGuess = nextCard !== null && (guess === 'higher' && nextCard.value > currentCard.value || guess === 'lower' && nextCard.value < currentCard.value);' Line Number: 145
User prompt
Show ready message should be displayed alone with no other text on game start
var MessageDisplay = Container.expand(function () { var self = Container.call(this); var messageText = new Text2('', { size: 300, fill: '#ffffff', stroke: '#000000', strokeThickness: 8, anchor: { x: 0.5, y: 0 } }); self.addChild(messageText); messageText.y = 2732 - messageText.height - 200; self.showMessage = function (message) { messageText.setText(message); messageText.x = 2048 / 2 - messageText.width / 2; self.addChild(messageText); LK.setTimeout(function () { messageText.setText(''); }, 2000); }; }); var Card = Container.expand(function () { var self = Container.call(this); self.setSuit = function (suit) { self.suit = suit; var suitAsset = self.createAsset('suit_' + suit, 'Suit Asset', 0.5, 0.5); suitAsset.x = 0; suitAsset.y = 0; self.addChild(suitAsset); }; var cardGraphics = self.createAsset('card', 'Card Graphics', 0.5, 0.5); cardGraphics.anchor.set(0.5, 0.5); var valueText = new Text2('', { size: 168, fill: '#000000', font: 'bold', anchor: { x: 0, y: 0 } }); valueText.anchor.set(0, 0); valueText.x = -cardGraphics.width / 2 + 50; valueText.y = -cardGraphics.height / 2 + 30; var valueText2 = new Text2('', { size: 168, fill: '#000000', font: 'bold', anchor: { x: 1, y: 1 } }); valueText2.anchor.set(0, 0); valueText2.x = cardGraphics.width / 2 - 50; valueText2.y = cardGraphics.height / 2 - 30; valueText2.scale.y = -1; valueText2.scale.x = -1; self.addChild(valueText2); self.setValue = function (value) { self.value = value; valueText.setText(value.toString()); valueText2.setText(value.toString()); }; self.addChild(valueText); self.addChild(valueText2); var suitText = new Text2('', { size: 120, fill: '#000000', anchor: { x: 0.5, y: 1 } }); suitText.y = 0; self.addChild(suitText); self.setValue = function (value) { self.value = value; var displayValue = value; if (value === 11) displayValue = 'J'; else if (value === 12) displayValue = 'Q'; else if (value === 13) displayValue = 'K'; else if (value === 1) displayValue = 'A'; valueText.setText(displayValue.toString()); valueText2.setText(displayValue.toString()); }; self.value = 0; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5); self.score = 0; self.updateScore = function (score) { self.score = score; }; }); var player = new Player(); var Game = Container.expand(function () { var self = Container.call(this); stage.on('up', function (obj) { var endY = obj.event.getLocalPosition(self).y; if (startY === null || endY === null) return; var swipeDirection = startY - endY; var guess = swipeDirection > 0 ? 'higher' : 'lower'; if (deck.length === 0) { LK.showGameOver(); return; } nextCard = deck.pop(); if (!nextCard) return; self.addChild(nextCard); nextCard.x = 2048 / 2 - 90; nextCard.y = 2732 / 2; self.updateCardsLeftDisplay(); if (self.messageDisplay) { self.messageDisplay.destroy(); } self.messageDisplay = self.addChild(new MessageDisplay()); var correctGuess = guess === 'higher' && nextCard.value >= currentCard.value || guess === 'lower' && nextCard.value <= currentCard.value; if (correctGuess) { player.updateScore(player.score + 1); self.updateScoreDisplay(player.score); LK.setScore(player.score); self.messageDisplay.showMessage('Correct!', '#000000'); } else { self.messageDisplay.showMessage('Wrong!', '#000000'); } animateCardMovement(currentCard, swipeDirection); currentCard = nextCard; nextCard = null; startY = null; }); function animateCardMovement(card, direction) { var moveAmount = direction > 0 ? -2732 : 2732; var moveStep = direction > 0 ? -150 : 150; LK.on('tick', function () { if (Math.abs(moveAmount) > 0) { card.y += moveStep; moveAmount -= moveStep; } else { card.destroy(); LK.off('tick'); } }); } var background = self.createAsset('background', 'Background Asset', 0.5, 0.5); background.x = 2048 / 2; background.y = 2732 / 2; self.addChild(background); var scoreTxt = new Text2('0', { size: 100, fill: "#ffffff", stroke: '#000000', strokeThickness: 4, anchor: { x: .5, y: .5 } }); scoreTxt.y = 100; scoreTxt.x = 70; LK.gui.topLeft.addChild(scoreTxt); var deck = []; var cardsLeftTxt = new Text2('Cards Left: ' + deck.length, { size: 100, fill: "#ffffff", stroke: '#000000', strokeThickness: 4, anchor: { x: 0, y: 0.5 } }); cardsLeftTxt.x = 20 + scoreTxt.width + 20 + 700; cardsLeftTxt.y = 100; LK.gui.topLeft.addChild(cardsLeftTxt); self.updateCardsLeftDisplay = function () { cardsLeftTxt.setText('Cards Left: ' + deck.length); }; self.updateCardsLeftDisplay(); self.updateScoreDisplay = function (score) { scoreTxt.setText('Score: ' + score.toString()); }; self.updateScoreDisplay(0); var deck = []; var currentCard = null; var nextCard = null; var suits = ['hearts', 'diamonds', 'clubs', 'spades']; for (var s = 0; s < suits.length; s++) { for (var i = 1; i <= 13; i++) { var card = new Card(); card.setValue(i); card.setSuit(suits[s]); deck.push(card); } } deck.sort(function () { return 0.5 - Math.random(); }); currentCard = deck[Math.floor(Math.random() * deck.length)]; var index = deck.indexOf(currentCard); deck.splice(index, 1); self.addChild(currentCard); currentCard.x = 2048 / 2 - currentCard.width - 10; currentCard.y = 2732 / 2; nextCard = new Card(); self.addChild(nextCard); nextCard.x = 2048 / 2 + 10; nextCard.y = 2732 / 2; var startY = null; var startMessage = new MessageDisplay(); self.addChild(startMessage); startMessage.showMessage('Swipe up for higher or down for lower'); startMessage.y = 2732 - startMessage.height - 100; stage.on('down', function (obj) { startY = obj.event.getLocalPosition(self).y; }); });
===================================================================
--- original.js
+++ change.js
@@ -199,10 +199,14 @@
currentCard = deck[Math.floor(Math.random() * deck.length)];
var index = deck.indexOf(currentCard);
deck.splice(index, 1);
self.addChild(currentCard);
- currentCard.x = 2048 / 2 - 90;
+ currentCard.x = 2048 / 2 - currentCard.width - 10;
currentCard.y = 2732 / 2;
+ nextCard = new Card();
+ self.addChild(nextCard);
+ nextCard.x = 2048 / 2 + 10;
+ nextCard.y = 2732 / 2;
var startY = null;
var startMessage = new MessageDisplay();
self.addChild(startMessage);
startMessage.showMessage('Swipe up for higher or down for lower');
Green casino baize. To be used as background. No shade. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white rectangle flat. rounded corners. no background. no shadow. card shape.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.