New style of display modes

pull/14/head
Dennis Bücker 1 year ago
parent cfb51dcdc2
commit f57c833d68
  1. 63
      src/DisplayModeLayouts.h
  2. 8
      src/EnterColorSequence.cpp
  3. 161
      src/SimonDisplay.cpp

@ -0,0 +1,63 @@
unsigned const int DisplayLayoutNoColor[25] =
{
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
};
unsigned const int DisplayLayoutOneColor[25] =
{
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
};
unsigned const int DisplayLayoutTwoColor[25] =
{
1, 1, 0, 2, 2,
1, 1, 0, 2, 2,
1, 1, 0, 2, 2,
1, 1, 0, 2, 2,
1, 1, 0, 2, 2,
};
unsigned const int DisplayLayoutThreeColor[25] =
{
1, 1, 1, 0, 0,
1, 1, 1, 2, 2,
0, 0, 0, 2, 2,
3, 3, 3, 2, 2,
3, 3, 3, 0, 0,
};
unsigned const int DisplayLayoutFourColor[25] =
{
1, 1, 0, 2, 2,
1, 1, 0, 2, 2,
0, 0, 0, 0, 0,
4, 4, 0, 3, 3,
4, 4, 0, 3, 3,
};
unsigned const int DisplayLayoutFiveColor[25] =
{
1, 1, 5, 2, 2,
1, 1, 5, 2, 2,
5, 5, 5, 5, 5,
4, 4, 5, 3, 3,
4, 4, 5, 3, 3,
};
unsigned const int DisplayLayoutSixColor[25] =
{
1, 5, 5, 6, 6,
1, 5, 5, 6, 6,
1, 1, 0, 4, 4,
2, 2, 3, 3, 4,
2, 2, 3, 3, 4,
};

@ -13,7 +13,7 @@ Mistake: Red screen. Game will restart with level one. Counter with failed games
Success: Nothing until final success: Show a green screen for a short time.
*/
/*
// qsort requires you to create a sort function
int sort_desc(const void *cmp1, const void *cmp2)
{
@ -25,7 +25,7 @@ int sort_desc(const void *cmp1, const void *cmp2)
// A simpler, probably faster way:
//return b - a;
}
*/
EnterColorSequence::EnterColorSequence() :
inputStarted{false},
@ -65,8 +65,8 @@ void EnterColorSequence::enter(SimonSays & simonSays){
*/
// Sort the array (high to low)
// qsort(activeSequenceColors, simonSays.currentSequenceLength, sizeof(activeSequenceColors[0]), sort_desc);
// Sorting is not necessary at this time
qsort(activeSequenceColors, simonSays.currentSequenceLength, sizeof(activeSequenceColors[0]), sort_desc);
// Sorting is not necessary at this time, but makes highlight sequence in good order
/*
// Debug sorted Array

@ -1,4 +1,5 @@
#include "SimonDisplay.h"
#include "DisplayModeLayouts.h"
namespace{
CustomDisplay customDisplay;
@ -28,7 +29,7 @@ SimonDisplay::SimonDisplay(M5Atom &_m5) :
void SimonDisplay::begin()
{
baseColors[0] = CRGB::DarkGreen;
baseColors[0] = CRGB(100,0,0);
baseColors[1] = CRGB::DarkBlue;
baseColors[2] = CRGB::DarkOrange;
baseColors[3] = CRGB::Gold;
@ -38,7 +39,7 @@ void SimonDisplay::begin()
baseColors[7] = CRGB::DarkTurquoise;
baseColors[8] = CRGB::DeepPink;
highlightColors[0] = CRGB::Green;
highlightColors[0] = CRGB(255,0,0);
highlightColors[1] = CRGB::Blue;
highlightColors[2] = CRGB::Orange;
highlightColors[3] = CRGB::Yellow;
@ -110,9 +111,30 @@ void CustomDisplay::update(SimonDisplay & simonDisplay)
}
void OneColorSelection::update(SimonDisplay &simonDisplay)
{
simonDisplay.displayOneColor(simonDisplay.activeColor);
simonDisplay.clearDisplay(); // clear display first
for (int i = 0; i <= 25; i++)
{
if (DisplayLayoutOneColor[i] == 0)
{
// if there is a zero, this will display black
simonDisplay.drawPixel(i, CRGB::Black);
}
else
{
if (DisplayLayoutOneColor[i] == simonDisplay.activeColor + 1)
{
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutOneColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else
{
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutOneColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
}
}
void TwoColorSelection::update(SimonDisplay &simonDisplay)
@ -123,40 +145,47 @@ void TwoColorSelection::update(SimonDisplay &simonDisplay)
for (int i = 0; i <= 25; i++)
{
if (((i-3) % 5 == 0) || ((i - 4) % 5 == 0))
if (DisplayLayoutTwoColor[i] == 0)
{
if (simonDisplay.colorsToDisplay[0] == simonDisplay.activeColor)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[1]]);
}
else {
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[1]]);
}
// if there is a zero, this will display black
simonDisplay.drawPixel(i, CRGB::Black);
}
if (((i - 0) % 5 == 0) || ((i - 1) % 5 == 0))
else
{
if (simonDisplay.colorsToDisplay[1] == simonDisplay.activeColor)
if (DisplayLayoutTwoColor[i] == simonDisplay.activeColor + 1)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[0]]);
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutTwoColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else
{
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[0]]);
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutTwoColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
}
}
void ThreeColorSelection::update(SimonDisplay &simonDisplay)
{
// Only test
simonDisplay.displayOneColorById(simonDisplay.activeColor);
// Serial.println("TwoColorSelectionUpdate");
// Serial.println("ThreeColorSelectionUpdate");
simonDisplay.clearDisplay(); // clear display first
for (int i = 0; i <= 25; i++)
{
if (DisplayLayoutThreeColor[i]==0) {
// if there is a zero, this will display black
simonDisplay.drawPixel(i,CRGB::Black);
}
else {
if (DisplayLayoutThreeColor[i]==simonDisplay.activeColor+1){
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutThreeColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else {
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutThreeColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
}
}
void FourColorSelection::update(SimonDisplay &simonDisplay)
@ -167,68 +196,74 @@ void FourColorSelection::update(SimonDisplay &simonDisplay)
for (int i = 0; i <= 25; i++)
{
if ((((i - 3) % 5 == 0) || ((i - 4) % 5 == 0)) && (i<10))
if (DisplayLayoutFourColor[i] == 0)
{
if (simonDisplay.colorsToDisplay[0] == simonDisplay.activeColor)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[1]]);
}
else
{
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[1]]);
}
// if there is a zero, this will display black
simonDisplay.drawPixel(i, CRGB::Black);
}
if ((((i - 3) % 5 == 0) || ((i - 4) % 5 == 0)) && (i > 14))
else
{
if (simonDisplay.colorsToDisplay[0] == simonDisplay.activeColor)
if (DisplayLayoutFourColor[i] == simonDisplay.activeColor + 1)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[2]]);
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutFourColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else
{
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[2]]);
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutFourColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
if ((((i - 0) % 5 == 0) || ((i - 1) % 5 == 0)) && (i<10))
}
}
void FiveColorSelection::update(SimonDisplay &simonDisplay)
{
// Serial.println("FiveColorSelectionUpdate");
simonDisplay.clearDisplay(); // clear display first
for (int i = 0; i <= 25; i++)
{
if (DisplayLayoutFiveColor[i] == 0)
{
// if there is a zero, this will display black
simonDisplay.drawPixel(i, CRGB::Black);
}
else
{
if (simonDisplay.colorsToDisplay[1] == simonDisplay.activeColor)
if (DisplayLayoutFiveColor[i] == simonDisplay.activeColor + 1)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[0]]);
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutFiveColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else
{
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[0]]);
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutFiveColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
if ((((i - 0) % 5 == 0) || ((i - 1) % 5 == 0)) && (i > 14))
}
}
void SixColorSelection::update(SimonDisplay &simonDisplay)
{
simonDisplay.clearDisplay(); // clear display first
for (int i = 0; i <= 25; i++)
{
if (DisplayLayoutSixColor[i] == 0)
{
// if there is a zero, this will display black
simonDisplay.drawPixel(i, CRGB::Black);
}
else
{
if (simonDisplay.colorsToDisplay[1] == simonDisplay.activeColor)
if (DisplayLayoutSixColor[i] == simonDisplay.activeColor + 1)
{
// Display highlight
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[3]]);
simonDisplay.drawPixel(i, simonDisplay.highlightColors[simonDisplay.colorsToDisplay[DisplayLayoutSixColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
else
{
// Display normal Color
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[3]]);
simonDisplay.drawPixel(i, simonDisplay.baseColors[simonDisplay.colorsToDisplay[DisplayLayoutSixColor[i] - 1]]); // show this color offset by one, bc display has zero as black
}
}
}
}
void FiveColorSelection::update(SimonDisplay &simonDisplay)
{
// Only test
simonDisplay.displayOneColorById(simonDisplay.activeColor);
// Serial.println("TwoColorSelectionUpdate");
}
void SixColorSelection::update(SimonDisplay &simonDisplay)
{
}
Loading…
Cancel
Save