forked from NattyBumppo/Simon-Clone-for-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttractMode.cpp
87 lines (70 loc) · 2.17 KB
/
AttractMode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Modes.h"
#include "gameplay.h"
#include "SNESPad.h"
#include "Input.h"
#include "Output.h"
const int easterEggCheatCode[] = {
SNES_UP, SNES_UP, SNES_DOWN, SNES_DOWN, SNES_LEFT, SNES_RIGHT, SNES_LEFT, SNES_RIGHT, SNES_B, SNES_A, SNES_START };
const int easterEggCheatCodeLength = sizeof(easterEggCheatCode) / sizeof(easterEggCheatCode[0]);
const int attractLEDDisplayTime = 120; // Time to show LED in ms during attract mode
const Color attractModeColors[] = {
BLUE, GREEN, YELLOW, RED,
BLUE, GREEN, YELLOW, RED,
BLUE, GREEN, YELLOW, RED,
BLUE, BLUE, BLUE, BLUE,
RED, YELLOW, GREEN, BLUE,
RED, YELLOW, GREEN, BLUE,
RED, YELLOW, GREEN, BLUE,
BLUE, BLUE };
const int attractModeColorsLength = sizeof(attractModeColors) / sizeof(attractModeColors[0]);
AttractMode::AttractMode() :
easterEggPos(0),
time(0)
{
}
// Loop through an attract mode light pattern until the user hits
// the start button (also an easter egg)
Mode* AttractMode::Update(int dT)
{
int pressed = Input::Get().Pressed();
if(CheckEasterEggCode(pressed))
return new MelodyMode(SECRET, new GameMode(SUPERHARD));
UpdateLights(dT);
if(pressed & SNES_START)
{
Difficulty difficulty = Input::Get().GetDifficulty();
return new DelayMode(200, new GameMode(difficulty));
}
return this;
}
boolean AttractMode::CheckEasterEggCode(int pressed)
{
if (pressed == easterEggCheatCode[easterEggPos])
{
// The correct button was just pressed, so advance the state
easterEggPos++;
}
else if (pressed)
{
// User just pressed a wrong button, so reset the cheat code state
easterEggPos = 0;
}
// If the user's done with the cheat code, trigger the easter egg
return (easterEggPos == easterEggCheatCodeLength);
}
void AttractMode::UpdateLights(int dT)
{
time += dT;
if(attractLEDDisplayTime * attractLightPos < time)
{
// enough time has passed, we should start the next light in the sequence:
Output::Get().LightOn(attractModeColors[attractLightPos], attractLEDDisplayTime);
}
attractLightPos++;
if(attractLightPos == attractModeColorsLength)
{
// hit the end of the sequence, reset and start over:
attractLightPos = 0;
time = 0;
}
}