User prompt
Make the answer of these questions "Cows can fly." and "The earth is flat" false.
User prompt
Add green flash color for true and red flash color for false when swiping on the screen.
User prompt
Add a gesture of swiping for the true or false question.
User prompt
Remove the buttons
User prompt
Fix Bug: 'TypeError: trueButton.containsPoint is not a function' in this line: 'if (trueButton.containsPoint(pos)) {' Line Number: 154
User prompt
Add a hill background.
User prompt
Fix Bug: 'ReferenceError: swipeGesture is not defined' in this line: 'swipeGesture.startSwipe(obj.event);' Line Number: 140
User prompt
Add buttons to choose an option (1st button: True; 2nd button: False.) (Button colors: Green (1st) and Red (2nd).)
User prompt
Add questions to become trivia.
User prompt
Fix Bug: 'Uncaught TypeError: this.text.setText is not a function' in this line: 'this.text.setText(question);' Line Number: 14
Initial prompt
True or False
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,25 @@
/****
* Classes
****/
+var Button = Container.expand(function () {
+ var self = Container.call(this);
+ this.text = new Text2('', {
+ size: 100,
+ fill: '#ffffff',
+ anchor: {
+ x: 0.5,
+ y: 0.5
+ }
+ });
+ self.addChild(this.text);
+ this.setLabel = function (label) {
+ this.text.setText(label);
+ };
+ this.setColor = function (color) {
+ self.tint = color;
+ };
+});
// Class for the trivia question
var TriviaQuestion = Container.expand(function () {
var self = Container.call(this);
this.text = new Text2('', {
@@ -100,39 +118,55 @@
// Initialize the trivia question
var triviaQuestion = game.addChild(new TriviaQuestion());
triviaQuestion.setQuestion("True or False?");
-// Initialize the swipe gesture
-var swipeGesture = new SwipeGesture();
+// Initialize the True button
+var trueButton = game.addChild(new Button());
+trueButton.setLabel('True');
+trueButton.setColor(0x00ff00); // Green
+trueButton.x = 2048 / 2 - 200;
+trueButton.y = 2732 / 2 + 200;
+// Initialize the False button
+var falseButton = game.addChild(new Button());
+falseButton.setLabel('False');
+falseButton.setColor(0xff0000); // Red
+falseButton.x = 2048 / 2 + 200;
+falseButton.y = 2732 / 2 + 200;
+
// Event listener for starting the swipe
game.on('down', function (obj) {
swipeGesture.startSwipe(obj.event);
});
-// Event listener for ending the swipe
-game.on('up', function (obj) {
- var direction = swipeGesture.endSwipe(obj.event);
- if (direction === 'right') {
- // Swipe right for true
+// Event listener for True button
+game.on('down', function (obj) {
+ var pos = obj.event.getLocalPosition(game);
+ if (trueButton.containsPoint(pos)) {
if (triviaQuestion.checkAnswer(true)) {
// Correct answer
LK.effects.flashScreen(0x00ff00, 500); // Flash green
} else {
// Incorrect answer
LK.effects.flashScreen(0xff0000, 500); // Flash red
}
- } else if (direction === 'left') {
- // Swipe left for false
+ triviaQuestion.nextQuestion();
+ }
+});
+
+// Event listener for False button
+game.on('down', function (obj) {
+ var pos = obj.event.getLocalPosition(game);
+ if (falseButton.containsPoint(pos)) {
if (triviaQuestion.checkAnswer(false)) {
// Correct answer
LK.effects.flashScreen(0x00ff00, 500); // Flash green
} else {
// Incorrect answer
LK.effects.flashScreen(0xff0000, 500); // Flash red
}
+ triviaQuestion.nextQuestion();
}
- // Load next question or end game
});
// Main game loop
LK.on('tick', function () {