question about something like a game loop
in
Programming Questions
•
2 months ago
What is the best way to loop through, I guess like a game loop, and move through different levels based on certain events.
So I think I should use a boolean, something like levelcomplete, and some other variable called level? but I'm wondering if
anyone perhaps has a good skeleton or example, because I'm not so good at it :)
So in this code for example, what would be the best way to move to question 2 if question one has been answered?
What I tried to do first was change evaluateAnswer()
like while(level = 1) if (saved.equals(answer1))
level = level 2, etc... but i couldn't get that working and I don't think its right
any advice?
- void draw() {
background(background);
- //image(normal, 185, -140);
image(normal, 210, 200, normal.width/2, normal.height/2);
textFont(f);
textSize(60);
text(question1, 50, 50);
// has user text been entered and sent?
if (!saved.equals(""))
{
// answer has been given now
evaluateAnswer();
}
else
{
// wait till answer is complete
text(typing, 50, 100);
//text(saved, 50, 150);
}
}
void evaluateAnswer() {
text(saved, 50, 100);
if (saved.equals(answer1)) {
image(happy, 210, 200, normal.width/2, normal.height/2);
//correct
fill(#F258E3);
text("cool!", 50, 150);
//fill(255);
text("Press return \nto play again", 50, 350);
// player.play();
}
else
{
image(sad, 210, 200, normal.width/2, normal.height/2);
//wrong
fill(255, 2, 2);
text("wrong", 50, 150);
//fill(255);
text("Press return \nto play again", 50, 350);
//player2.play();
}
}
Thanks for any help!
:)
:)
1