User prompt
fix the issue
User prompt
play wrong answer sound whenever the player clicks the wrong button
User prompt
Little bit more
User prompt
Move little bit more
User prompt
move the "i am" text little bit above.
User prompt
Show Text "I AM" Above the Shape
User prompt
reset timer to 3 sec when any button is pressed.
User prompt
Add a sound for the Wrong Answer.
User prompt
Play Sound On Button Clicks
User prompt
Change the Color of True And False Text to White
User prompt
when player press the wrong button flash screen red
User prompt
but when i timer counts down and ends the lives are not reducing instead it just gameover, fix that
Code edit (1 edits merged)
Please save this source code
User prompt
in timer update, check whether lives are 0 or not instead of livesDiplay.length
User prompt
still issue persists
User prompt
game is getting over when i have lives and timer ends, i don't want that
User prompt
do not game over when timer ends, instead game only end when the lives are finished.
User prompt
show three lives on the top left corner with heart image representation, and reduce the lives by 1 each time the player press the wrong button, and timer gets finished
User prompt
also change the updation of the time when buttons are clicked
User prompt
instead of using string to track the time, use integer to track the time and update.
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'getText')' in or related to this line: 'var timeLeft = parseInt(timerTxt.text.getText().split(' ')[1]);' Line Number: 180
User prompt
print the timeLeft on console
User prompt
Please fix the bug: 'Timeout.tick error: timerTxt.getText is not a function' in or related to this line: 'var timeLeft = parseInt(timerTxt.getText().split(' ')[1]);' Line Number: 180
User prompt
debug the timer text update
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Shape class to represent the shapes in the game
var Shape = Container.expand(function () {
var self = Container.call(this);
self.shapeType = null;
self.shapeGraphics = null;
self.setShape = function (type) {
self.shapeType = type;
if (self.shapeGraphics) {
self.removeChild(self.shapeGraphics);
}
self.shapeGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
};
});
// Text class to represent the shape names in the game
var ShapeText = Container.expand(function () {
var self = Container.call(this);
self.text = new Text2('', {
size: 100,
fill: "#ffffff"
});
self.text.anchor.set(0.5, 0.5);
self.addChild(self.text);
self.setText = function (text) {
self.text.setText(text.toUpperCase());
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Function to handle game over
function gameOver() {
LK.clearTimeout(timer);
LK.showGameOver();
}
// Initialize variables
var shapes = ['circle', 'square', 'triangle', 'hexagon', 'octagon', 'oval', 'pentagon', 'rectangle', 'rhombus'];
var currentShape = null;
var currentShapeText = null;
var score = 0;
var timer = null;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var timerTxt = new Text2('Time: 3', {
size: 100,
fill: "#ffffff"
});
timerTxt.anchor.set(0.5, 0);
timerTxt.x = 2048 / 2;
timerTxt.y = 2732 * 3 / 4 - 200;
game.addChild(timerTxt);
// Create shape and text objects
var shape = new Shape();
shape.x = 2048 / 2;
shape.y = 2732 / 3;
game.addChild(shape);
var shapeText = new ShapeText();
shapeText.x = 2048 / 2;
shapeText.y = 2732 / 2;
game.addChild(shapeText);
// Function to update the shape and text
function updateShapeAndText() {
var randomShape = shapes[Math.floor(Math.random() * shapes.length)];
var randomText = shapes[Math.floor(Math.random() * shapes.length)];
shape.setShape(randomShape);
shapeText.setText(randomText);
currentShape = randomShape;
currentShapeText = randomText;
if (timer) {
LK.clearTimeout(timer);
}
timer = LK.setTimeout(gameOver, 3000);
timerTxt.setText('Time: 3');
}
// Function to handle True button press
function handleTruePress() {
if (currentShape === currentShapeText) {
score++;
scoreTxt.setText('Score: ' + score);
LK.clearTimeout(timer);
updateShapeAndText();
} else {
gameOver();
}
}
// Function to handle False button press
function handleFalsePress() {
if (currentShape !== currentShapeText) {
score++;
scoreTxt.setText('Score: ' + score);
LK.clearTimeout(timer);
updateShapeAndText();
} else {
gameOver();
}
}
// Create True and False buttons
var trueButtonBackground = LK.getAsset('trueButtonBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
game.addChild(trueButtonBackground);
trueButtonBackground.x = 2048 / 4;
trueButtonBackground.y = 2732 * 3 / 4;
var trueButton = new Text2('True', {
size: 200,
fill: "#00ff00"
});
trueButtonBackground.addChild(trueButton);
trueButton.anchor.set(0.5, 0.5);
trueButton.x = 2048 / 4;
trueButton.y = 2732 * 3 / 4;
game.addChild(trueButton);
var falseButtonBackground = LK.getAsset('falseButtonBackground', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
game.addChild(falseButtonBackground);
falseButtonBackground.x = 2048 * 3 / 4;
falseButtonBackground.y = 2732 * 3 / 4;
var falseButton = new Text2('False', {
size: 200,
fill: "#ff0000"
});
falseButtonBackground.addChild(falseButton);
falseButton.anchor.set(0.5, 0.5);
falseButton.x = 2048 * 3 / 4;
falseButton.y = 2732 * 3 / 4;
game.addChild(falseButton);
// Add event listeners for buttons
trueButton.down = function (x, y, obj) {
handleTruePress();
timerTxt.setText('Time: 3');
};
falseButton.down = function (x, y, obj) {
handleFalsePress();
timerTxt.setText('Time: 3');
};
// Initialize the game with the first shape and text
updateShapeAndText();
// Update the timer text every second
var timerInterval = LK.setInterval(function () {
var timeLeft = parseInt(timerTxt.getText().split(' ')[1]);
if (timeLeft > 0) {
timerTxt.setText('Time: ' + (timeLeft - 1));
} else {
gameOver();
}
}, 1000);
// Clear the timer interval when game over