Hi everyone,
I bought my first Arduboy last week, and I have a lot of fun on playing and coding games ! Thanks for that amazing community, I have learned a lot from this forum.
So, I’m working on a program to “help” my 4 years old son to imagine adventures. It’s not really a game, but more some screens to go with its stories. For example, you have a radar screen that shows a scanner and some points are blinking and moving through the screen.
But I also have a screen which acts like a phone : you have a list of contacts (a monkey, a frog and a robot), you select one of them, an animation is displayed to represent the hanging call until the character picks up, and then you have the conversation.
My difficulty is that I handle this workflow with a switch case :
void display(Arduboy2 arduboy, ArduboyTones sound)
{
switch (screen) {
case 0:
controlsContactsList(arduboy);
contactList.displayConctactsListTitle(arduboy, selectedCharacter);
contactList.displayContactsList(arduboy, selectedCharacter);
break;
case 2:
displayConversation(arduboy);
break;
case 1:
// Intro has not finished playing
if (needToPlayHangingIntro) {
needToPlayHangingIntro = hangingCall.introIsPlaying(arduboy, selectedCharacter);
return;
}
// Hanging animation
bool hanging = hangingCall.hanging(
arduboy,
sound,
selectedCharacter
);
if (arduboy.justPressed(B_BUTTON)) {
screen = 0;
}
if (hanging) {
return;
}
// Animation finished, jump to last screen
screen = 2;
// Populates line buffer with random indexes of alphabet symbols
for (int i=0; i<108; i++) {
conversationLine[i] = random(0, 30);
}
animationTimer.updatePreviousTime();
break;
}
}
You can notice that i putted screen 2 before screen 1 in the switch cases order. In this order, everything works fine. But if I put the case 2
block after the case 1
, then the screen 2 won’t play.
Could you help me by giving me clues on where to start looking please ? I’m not familiar with C++ language, so I was wondering if that’s a recurrent issue on this language, because I’ve never had this kind of problem on other languages.
You can find the whole code on this branch : https://github.com/benoitjupille/exploration-tools/tree/bug-on-switchcase/tools/src/phone
The files concerned are Phone.h
and HangingCall.h
.
Thanks !