Instantly share code, notes, and snippets.
Created
November 8, 2018 05:43
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save jbobrow/87b321fa0d3621c4fe219badb5261b35 to your computer and use it in GitHub Desktop.
A start for the kind of "attract screen" that whackamole should have...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mole waiting animation | |
*/ | |
uint32_t pixelSetTime[6]; | |
uint32_t timeOfPlayerSelection; | |
Timer popUpTimer; | |
// number of players | |
byte numPlayers = 1; | |
void setup() { | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if (buttonPressed()) { | |
// increase our number of players (1-3) | |
numPlayers++; | |
if (numPlayers > 3) { | |
numPlayers = 1; | |
} | |
timeOfPlayerSelection = millis(); | |
} | |
// animate the intro | |
uint32_t timeSincePlayerSelection = millis() - timeOfPlayerSelection; | |
if (timeSincePlayerSelection < 3000) { | |
setColor(GREEN); // draw the grass | |
if (numPlayers == 1) { | |
// present player | |
// then fade out | |
// fade back in the grass | |
byte bri; | |
if ( timeSincePlayerSelection < 255 ) { | |
bri = timeSincePlayerSelection; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
} else if ( timeSincePlayerSelection < 1500 ) { | |
bri = 255; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
} else if (timeSincePlayerSelection < 2750) { | |
bri = (timeSincePlayerSelection - 1500) / 5; | |
bri = bri * bri / 255; | |
bri = bri * bri / 255; | |
setColorOnFace(dim(ORANGE, 255 - bri), 0); | |
} else { | |
bri = timeSincePlayerSelection - 2750; | |
setColorOnFace(dim(GREEN, bri), 0); | |
} | |
} | |
else if (numPlayers == 2) { | |
byte bri; | |
if ( timeSincePlayerSelection < 255 ) { | |
bri = timeSincePlayerSelection; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
setColorOnFace(dim(YELLOW, bri), 1); | |
} else if ( timeSincePlayerSelection < 1500 ) { | |
bri = 255; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
setColorOnFace(dim(YELLOW, bri), 1); | |
} else if (timeSincePlayerSelection < 2750) { | |
bri = (timeSincePlayerSelection - 1500) / 5; | |
bri = bri * bri / 255; | |
bri = bri * bri / 255; | |
setColorOnFace(dim(ORANGE, 255 - bri), 0); | |
setColorOnFace(dim(YELLOW, 255 - bri), 1); | |
} else { | |
bri = timeSincePlayerSelection - 2750; | |
setColorOnFace(dim(GREEN, bri), 0); | |
setColorOnFace(dim(GREEN, bri), 1); | |
} | |
} | |
else { // 3 | |
byte bri; | |
if ( timeSincePlayerSelection < 255 ) { | |
bri = timeSincePlayerSelection; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
setColorOnFace(dim(YELLOW, bri), 1); | |
setColorOnFace(dim(MAGENTA, bri), 2); | |
} else if ( timeSincePlayerSelection < 1500 ) { | |
bri = 255; | |
setColorOnFace(dim(ORANGE, bri), 0); | |
setColorOnFace(dim(YELLOW, bri), 1); | |
setColorOnFace(dim(MAGENTA, bri), 2); | |
} else if (timeSincePlayerSelection < 2750) { | |
bri = (timeSincePlayerSelection - 1500) / 5; | |
bri = bri * bri / 255; | |
bri = bri * bri / 255; | |
setColorOnFace(dim(ORANGE, 255 - bri), 0); | |
setColorOnFace(dim(YELLOW, 255 - bri), 1); | |
setColorOnFace(dim(MAGENTA, 255 - bri), 2); | |
} else { | |
bri = timeSincePlayerSelection - 2750; | |
setColorOnFace(dim(GREEN, bri), 0); | |
setColorOnFace(dim(GREEN, bri), 1); | |
setColorOnFace(dim(GREEN, bri), 2); | |
} | |
} | |
} | |
else if (timeSincePlayerSelection < 4500) { | |
// hang tight before showing moles | |
setColor(GREEN); // draw the grass | |
} | |
else { | |
// attract animation with the correct number of players | |
if (popUpTimer.isExpired()) { | |
popUpTimer.set(500 + rand(7 - numPlayers) * 250); | |
// choose an open space to pop up into: | |
getSpotToPopUp(); | |
} | |
setColor(GREEN); // draw the grass | |
if (numPlayers == 1) { | |
FOREACH_FACE(f) { | |
if (millis() - pixelSetTime[f] < 500) { | |
setColorOnFace(ORANGE, f); | |
} | |
} | |
} | |
else if (numPlayers == 2) { | |
FOREACH_FACE(f) { | |
if (millis() - pixelSetTime[f] < 500) { | |
setColorOnFace(YELLOW, f); | |
} | |
} | |
} | |
else { // 3 | |
FOREACH_FACE(f) { | |
if (millis() - pixelSetTime[f] < 500) { | |
setColorOnFace(MAGENTA, f); | |
} | |
} | |
} | |
} | |
} | |
byte getSpotToPopUp() { | |
byte f = rand(5); | |
while (millis() - pixelSetTime[f] < 1500 ) { | |
f = rand(5); | |
} | |
pixelSetTime[f] = millis(); | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment