| @@ -54,6 +54,53 @@ static int32_t NI_P1Score, NI_P2Score; · 53 unmodified lines |
| 54 | static nibbleCrd NI_P1[256], NI_P2[256]; | 54 | static nibbleCrd NI_P1[256], NI_P2[256]; |
| 55 | static nibbleBufferTyp nibblesBuffer[2]; | 55 | static nibbleBufferTyp nibblesBuffer[2]; |
| 56 | | 56 | |
| | 57 | /* Non-FT2 feature: Check if either the Desktop or Buttons palette color |
| | 58 | ** is so close to black that the player would have troubles seeing the walls |
| | 59 | ** when playing Nibbles. |
| | 60 | */ |
| | 61 | // ------------------------------------------------------------------------ |
| | 62 | // ------------------------------------------------------------------------ |
| | 63 | static uint8_t rgb24ToLuminosity(uint32_t rgb24) |
| | 64 | { |
| | 65 | const uint8_t R = RGB32_R(rgb24); |
| | 66 | const uint8_t G = RGB32_G(rgb24); |
| | 67 | const uint8_t B = RGB32_B(rgb24); |
| | 68 | |
| | 69 | // get highest channel value |
| | 70 | uint8_t hi = 0; |
| | 71 | if (hi < R) hi = R; |
| | 72 | if (hi < G) hi = G; |
| | 73 | if (hi < B) hi = B; |
| | 74 | |
| | 75 | // get lowest channel value |
| | 76 | uint8_t lo = 255; |
| | 77 | if (lo > R) lo = R; |
| | 78 | if (lo > G) lo = G; |
| | 79 | if (lo > B) lo = B; |
| | 80 | |
| | 81 | return (hi + lo) >> 1; // 0..255 |
| | 82 | } |
| | 83 | |
| | 84 | static bool wallColorsAreCloseToBlack(void) |
| | 85 | { |
| | 86 | #define LUMINOSITY_THRESHOLD 4 |
| | 87 | |
| | 88 | uint8_t wallColor1L = rgb24ToLuminosity(video.palette[PAL_DESKTOP]); |
| | 89 | uint8_t wallColor2L = rgb24ToLuminosity(video.palette[PAL_BUTTONS]); |
| | 90 | |
| | 91 | /* Since the rest of the wall colors are based on lower and higher |
| | 92 | ** contrast values from these two primary colors, we don't really |
| | 93 | ** need to check them all. |
| | 94 | */ |
| | 95 | |
| | 96 | if (wallColor1L <= LUMINOSITY_THRESHOLD || wallColor2L <= LUMINOSITY_THRESHOLD) |
| | 97 | return true; |
| | 98 | |
| | 99 | return false; |
| | 100 | } |
| | 101 | // ------------------------------------------------------------------------ |
| | 102 | // ------------------------------------------------------------------------ |
| | 103 | |
| 57 | static void redrawNibblesScreen(void) | 104 | static void redrawNibblesScreen(void) |
| 58 | { | 105 | { |
| 59 | uint8_t x, y, c; | 106 | uint8_t x, y, c; |
| @@ -409,6 +456,10 @@ static void nibblesDecLives(int16_t l1, int16_t l2) · 349 unmodified lines |
| 409 | editor.NI_Play = false; | 456 | editor.NI_Play = false; |
| 410 | okBox(0, "Nibbles message", "GAME OVER"); | 457 | okBox(0, "Nibbles message", "GAME OVER"); |
| 411 | | 458 | |
| | 459 | // prevent highscore table from showing overflowing level graphics |
| | 460 | if (NI_Level >= NI_MAXLEVEL) |
| | 461 | NI_Level = NI_MAXLEVEL - 1; |
| | 462 | |
| 412 | if (NI_P1Score > config.NI_HighScore[9].score) | 463 | if (NI_P1Score > config.NI_HighScore[9].score) |
| 413 | { | 464 | { |
| 414 | strcpy(name, "Unknown"); | 465 | strcpy(name, "Unknown"); |
| @@ -786,6 +837,9 @@ void nibblesPlay(void) · 371 unmodified lines |
| 786 | return; | 837 | return; |
| 787 | } | 838 | } |
| 788 | | 839 | |
| | 840 | if (wallColorsAreCloseToBlack()) |
| | 841 | okBox(0, "Nibbles warning", "The Desktop/Button colors are set to values that make the walls hard to see!"); |
| | 842 | |
| 789 | assert(config.NI_Speed < 4); | 843 | assert(config.NI_Speed < 4); |
| 790 | NI_CurSpeed = NI_Speeds[config.NI_Speed]; | 844 | NI_CurSpeed = NI_Speeds[config.NI_Speed]; |
| 791 | | 845 | |
| @@ -798,7 +852,7 @@ void nibblesPlay(void) · 6 unmodified lines |
| 798 | NI_P2Score = 0; | 852 | NI_P2Score = 0; |
| 799 | NI_P1Lives = 5; | 853 | NI_P1Lives = 5; |
| 800 | NI_P2Lives = 5; | 854 | NI_P2Lives = 5; |
| 801 | NI_Level = 0; | 855 | NI_Level = 1; |
| 802 | | 856 | |
| 803 | newNibblesGame(); | 857 | newNibblesGame(); |
| 804 | } | 858 | } |