Add screen before color sequence is displayed to resolve #3
parent
5b9acf8475
commit
151f62a147
|
@ -7,6 +7,33 @@ static unsigned const int DisplayLayoutNoColor[25] =
|
|||
0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static unsigned const int DisplayLayoutX[25] =
|
||||
{
|
||||
1, 0, 0, 0, 1,
|
||||
0, 1, 0, 1, 0,
|
||||
0, 0, 1, 0, 0,
|
||||
0, 1, 0, 1, 0,
|
||||
1, 0, 0, 0, 1,
|
||||
};
|
||||
|
||||
static unsigned const int DisplayLayoutPlayButton[25] =
|
||||
{
|
||||
1, 0, 1, 0, 0,
|
||||
1, 0, 1, 1, 0,
|
||||
1, 0, 1, 1, 1,
|
||||
1, 0, 1, 1, 0,
|
||||
1, 0, 1, 0, 0,
|
||||
};
|
||||
|
||||
static unsigned const int DisplayLayoutPlayButtonSmall[25] =
|
||||
{
|
||||
0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 1,
|
||||
0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static unsigned const int DisplayLayoutOneColor[25] =
|
||||
{
|
||||
1, 1, 1, 1, 1,
|
||||
|
|
|
@ -41,9 +41,6 @@ void EnterColorSequence::enter(SimonSays & simonSays){
|
|||
inputSequencePosition = 0;
|
||||
inputActiveColor = 0;
|
||||
|
||||
// To display inital green screen
|
||||
simonSays.simonDisplay.setDisplayMode(0);
|
||||
|
||||
// Determine the number of unique
|
||||
|
||||
// Generate array with only active colors
|
||||
|
@ -122,8 +119,36 @@ void EnterColorSequence::enter(SimonSays & simonSays){
|
|||
Serial.print("Number of unique elements: ");
|
||||
Serial.println(numberOfUniqueColors);
|
||||
|
||||
// Switch to correct color selection state
|
||||
switch (numberOfUniqueColors)
|
||||
{
|
||||
case 1:
|
||||
simonSays.simonDisplay.setDisplayMode(1);
|
||||
break;
|
||||
case 2:
|
||||
simonSays.simonDisplay.setDisplayMode(2);
|
||||
break;
|
||||
case 3:
|
||||
simonSays.simonDisplay.setDisplayMode(3);
|
||||
break;
|
||||
case 4:
|
||||
simonSays.simonDisplay.setDisplayMode(4);
|
||||
break;
|
||||
case 5:
|
||||
simonSays.simonDisplay.setDisplayMode(5);
|
||||
break;
|
||||
case 6:
|
||||
simonSays.simonDisplay.setDisplayMode(6);
|
||||
break;
|
||||
|
||||
default:
|
||||
simonSays.simonDisplay.setDisplayMode(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// give information to display module
|
||||
simonSays.simonDisplay.setNumberColors(numberOfUniqueColors);
|
||||
simonSays.simonDisplay.setActiveColor(inputActiveColor);
|
||||
simonSays.simonDisplay.setColorsToDisplay(arrayOfUniqueColors);
|
||||
}
|
||||
|
||||
|
@ -133,46 +158,19 @@ void EnterColorSequence::leave(SimonSays &simonSays)
|
|||
|
||||
void EnterColorSequence::update(SimonSays &simonSays)
|
||||
{
|
||||
if (!inputStarted) {
|
||||
// Only start,
|
||||
simonSays.simonDisplay.displayOneColor(CRGB::Green);
|
||||
//Serial.println("Game not started condition.");
|
||||
if (M5.Btn.wasPressed())
|
||||
{
|
||||
inputStarted = true;
|
||||
|
||||
// Switch to correct color selection state
|
||||
switch (numberOfUniqueColors)
|
||||
{
|
||||
case 2:
|
||||
simonSays.simonDisplay.setDisplayMode(2);
|
||||
break;
|
||||
case 3:
|
||||
simonSays.simonDisplay.setDisplayMode(3);
|
||||
break;
|
||||
case 4:
|
||||
simonSays.simonDisplay.setDisplayMode(4);
|
||||
break;
|
||||
case 5:
|
||||
simonSays.simonDisplay.setDisplayMode(5);
|
||||
break;
|
||||
case 6:
|
||||
simonSays.simonDisplay.setDisplayMode(6);
|
||||
break;
|
||||
|
||||
default:
|
||||
simonSays.simonDisplay.setDisplayMode(0);
|
||||
break;
|
||||
}
|
||||
simonSays.simonDisplay.setNumberColors(numberOfUniqueColors);
|
||||
simonSays.simonDisplay.setColorsToDisplay(arrayOfUniqueColors);
|
||||
simonSays.simonDisplay.setActiveColor(inputActiveColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if (!inputStarted) {
|
||||
// // Only start,
|
||||
// simonSays.simonDisplay.displayOneColor(CRGB::Green);
|
||||
// //Serial.println("Game not started condition.");
|
||||
// if (M5.Btn.wasPressed())
|
||||
// {
|
||||
// inputStarted = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// check for short press
|
||||
if (M5.Btn.wasReleased())
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#include "SimonSays.h"
|
||||
|
||||
#include "DisplayModeLayouts.h"
|
||||
|
||||
ShowColorSequence::ShowColorSequence():
|
||||
positionDisplay{0},
|
||||
speed{10},
|
||||
ticksTillNextColor{100},
|
||||
lastDisplayWasColor{false}
|
||||
ticksTillNextColor{0},
|
||||
lastDisplayWasColor{false},
|
||||
sequenceDisplayHasStartedBool{false}
|
||||
{}
|
||||
|
||||
void ShowColorSequence::enter(SimonSays & simonSays)
|
||||
|
@ -12,10 +15,26 @@ void ShowColorSequence::enter(SimonSays & simonSays)
|
|||
positionDisplay = 0;
|
||||
simonSays.simonDisplay.setActiveColor(simonSays.currentSequence[positionDisplay]);
|
||||
simonSays.simonDisplay.setDisplayMode(0);
|
||||
sequenceDisplayHasStartedBool = false; // reset to not start showing anything
|
||||
}
|
||||
|
||||
void ShowColorSequence::update(SimonSays & simonSays)
|
||||
{
|
||||
// Check if button was pressed once to start sequence display. if not: show red x
|
||||
if (!sequenceDisplayHasStartedBool)
|
||||
{
|
||||
// Display x
|
||||
simonSays.simonDisplay.displayDisplayLayout(DisplayLayoutPlayButtonSmall, true, 2, 10, 9); // highlight colors, 9: white, 10:black
|
||||
|
||||
if (M5.Btn.wasPressed())
|
||||
{
|
||||
// Leave this mode when button was pressed.
|
||||
sequenceDisplayHasStartedBool=true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ticksTillNextColor > 0)
|
||||
{
|
||||
--ticksTillNextColor;
|
||||
|
|
|
@ -38,16 +38,20 @@ void SimonDisplay::begin()
|
|||
baseColors[6] = CRGB::Black;
|
||||
baseColors[7] = CRGB::Black;
|
||||
baseColors[8] = CRGB::Black;
|
||||
baseColors[9] = CRGB(100,100,100); // not so bright withe
|
||||
baseColors[10] = CRGB::Black; // always black
|
||||
|
||||
highlightColors[0] = CRGB(255,0,0);
|
||||
highlightColors[1] = CRGB(0,255,0);
|
||||
highlightColors[2] = CRGB(0,80,255);
|
||||
highlightColors[3] = CRGB(255,255,0);
|
||||
highlightColors[4] = CRGB(255, 0, 255);
|
||||
highlightColors[5] = CRGB(255, 127, 0);
|
||||
highlightColors[0] = CRGB(255,0,0); // red
|
||||
highlightColors[1] = CRGB(0,255,0); // green
|
||||
highlightColors[2] = CRGB(0,80,255); // blue
|
||||
highlightColors[3] = CRGB(255,255,0); // yellow?
|
||||
highlightColors[4] = CRGB(255, 0, 255); // violett?
|
||||
highlightColors[5] = CRGB(255, 127, 0); // orange
|
||||
highlightColors[6] = CRGB::Black;
|
||||
highlightColors[7] = CRGB::Black;
|
||||
highlightColors[8] = CRGB::Black;
|
||||
highlightColors[9] = CRGB(255,255,255); // bright white
|
||||
highlightColors[10] = CRGB::Black; // always black
|
||||
}
|
||||
|
||||
void SimonDisplay::update()
|
||||
|
@ -116,8 +120,53 @@ void SimonDisplay::displayOneColorById(int colorId, bool highlightBool)
|
|||
}
|
||||
}
|
||||
|
||||
void SimonDisplay::displayDisplayLayout(unsigned const int DisplayLayout[25], bool useHighlightColors, int numColors, ...)
|
||||
{
|
||||
// max input of 10 colors
|
||||
va_list valist; // va_list item that will handle the multiple input
|
||||
|
||||
void CustomDisplay::update(SimonDisplay & simonDisplay)
|
||||
va_start(valist,numColors); // connect the colorIds input with the list item
|
||||
|
||||
int colors[10]; // define this array with a max of 10 entries
|
||||
|
||||
for (int colorsIdx = 0; colorsIdx < numColors; colorsIdx++)
|
||||
{
|
||||
// Get colorIds from input
|
||||
colors[colorsIdx]=va_arg(valist,int);
|
||||
//Serial.println(colors[colorsIdx]);
|
||||
}
|
||||
|
||||
va_end(valist); // clear memory of va_list
|
||||
|
||||
// Display the colors
|
||||
|
||||
clearDisplay(); // clear display first
|
||||
|
||||
for (int pixelIdx = 0; pixelIdx < 25; pixelIdx++)
|
||||
{
|
||||
if (DisplayLayout[pixelIdx] > numColors)
|
||||
{
|
||||
// This is an exception. Will be handled by just doing nothing
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (useHighlightColors)
|
||||
{
|
||||
drawPixel(pixelIdx, highlightColors[colors[DisplayLayout[pixelIdx]]]); // show the color defined in colors array
|
||||
}
|
||||
else
|
||||
{
|
||||
drawPixel(pixelIdx, baseColors[colors[DisplayLayout[pixelIdx]]]); // show the color defined in colors array
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Possible improvement: include a switch for a highlighed color
|
||||
|
||||
}
|
||||
|
||||
void CustomDisplay::update(SimonDisplay &simonDisplay)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ class SimonDisplay {
|
|||
void setColors();
|
||||
void displayOneColor(CRGB color);
|
||||
void displayOneColorById(int colorId, bool highlightBool);
|
||||
void displayDisplayLayout(unsigned const int DisplayLayout[25], bool useHighlightColors, int numColors, ...);
|
||||
void drawPixel(int i, CRGB color);
|
||||
void clearDisplay();
|
||||
|
||||
|
@ -80,8 +81,8 @@ class SimonDisplay {
|
|||
M5Atom m5;
|
||||
|
||||
CRGB currentColors[9];
|
||||
CRGB baseColors[9];
|
||||
CRGB highlightColors[9];
|
||||
CRGB baseColors[11];
|
||||
CRGB highlightColors[11];
|
||||
|
||||
int numberOfColors;
|
||||
int activeColor; // idx of color id in array colorsToDisplay.
|
||||
|
|
|
@ -30,6 +30,7 @@ class ShowColorSequence final : public GameState {
|
|||
int speed;
|
||||
int ticksTillNextColor;
|
||||
bool lastDisplayWasColor;
|
||||
bool sequenceDisplayHasStartedBool;
|
||||
};
|
||||
|
||||
class EnterColorSequence final : public GameState {
|
||||
|
|
Loading…
Reference in New Issue