#include "StateDefault.h" #include "NerfStatTrekConfig.h" #include "Globals.h" #include "StateLoseTheGame.h" #include "StateUserUnknown.h" bool DefaultState::ShowHits = true; void DefaultState::setup() { introStart = currentTime; } void DefaultState::loop() { if (buttonA->pressed() && buttonB->pressed()) { // A + B setCurrentState(new UserUnknownState()); return; } if (buttonA->changed() && !buttonA->pressed()) { // A (triggered on release) hits++; if (!DefaultState::ShowHits) setShowHits(true); } // B short (triggered on release) if (buttonB->changed() && !buttonB->pressed() && buttonB->pressedMillis(currentTime) <= NerfButtonLongPressThreshold) { setShowHits(!DefaultState::ShowHits); } // B long if (buttonB->pressed() && buttonB->pressedMillis(currentTime) > NerfButtonLongPressThreshold) { setCurrentState(new LoseTheGameState()); return; } if (showIntro) { if (currentTime - introStart >= NerfDefaultIntroTime) showIntro = false; if (DefaultState::ShowHits) { // Prevents warning: deprecated conversion from string constant to 'char*' char text[] = "Hits"; display->writeTextLeft(text); } else { char text[] = "Shots"; display->writeTextLeft(text); } } else { if (DefaultState::ShowHits) display->writeNumber(hits); else display->writeNumber(shots); } } void DefaultState::setShowHits(bool value) { showIntro = true; introStart = currentTime; DefaultState::ShowHits = value; }