NerfStatTrak/StateDefault.cpp
Mark van Renswoude ba58eb93c0 Moved away from proof of concepts, started prototyping for the final software
- Button library
- State handling and transitions
- Default state: dual counter display
- User unknown state: static for now
- Lost the game state: static for now
2016-12-04 19:53:43 +01:00

82 lines
1.5 KiB
C++

#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 LoseTheGameState());
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 UserUnknownState());
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;
}