diff --git a/menu.ino b/menu.ino index c9f6720..22bea36 100644 --- a/menu.ino +++ b/menu.ino @@ -170,6 +170,7 @@ int getMenuBackOut() { case STATE_WITHDRAW_INPUT: return 1; case STATE_INVENTORY: + case STATE_HIGH_SCORES: return 2; case STATE_JET_MENU: return 3; diff --git a/slangin.ino b/slangin.ino index eaca547..bb53a93 100644 --- a/slangin.ino +++ b/slangin.ino @@ -5,6 +5,7 @@ License: WTFPL */ #include +#include #include "src/Font3x5.h" #include "src/Font4x6.h" @@ -14,6 +15,7 @@ Font3x5 font3x5 = Font3x5(); enum GameState { STATE_TITLE = 0, + STATE_HIGH_SCORES, STATE_TURN_MENU, STATE_JET_MENU, STATE_BUY_MENU, @@ -75,22 +77,27 @@ const uint8_t PROGMEM spriteWeed[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x22, 0x32, 0x2a, 0x24, 0x22, 0x10, 0x0a, 0x08, 0x0c, 0x08, 0x12, 0x21, 0x24, 0x2a, 0x32, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; +const uint8_t eepStart = EEPROM_STORAGE_SPACE_START + 1; + /**************/ /* game state */ /**************/ bool screenInitialized; GameState sGameState; GameState sPreviousGameState; -int sMaxDays; -int sCurrentDay; +short sMaxDays; +short sCurrentDay; long sDrugPrices[6]; -int sCurrentDrug; +short sCurrentDrug; long sCurrentQty; long sQtyMax; long sLastDebounce = 0; int sDebounceCount = 0; bool sAlreadyBorrowed; -int sPigs = 0; +short sPigs = 0; +// default high scores +long s30High = 100000; +long s60High = 200000; /****************/ /* player state */ @@ -120,11 +127,23 @@ bool dialogSmall = false; /***********************/ void setup() { arduboy.boot(); + arduboy.bootLogoSpritesOverwrite(); arduboy.setFrameRate(15); arduboy.initRandomSeed(); sGameState = STATE_TITLE; screenInitialized = false; - arduboy.begin(); + + // read high scores from eeprom + char check[5]; + EEPROM.get(eepStart, check); + if (strcmp(check, "slng") == 0) { + EEPROM.get(eepStart + 5, s30High); + EEPROM.get(eepStart + 9, s60High); + } else { + EEPROM.put(eepStart, "slng"); + EEPROM.put(eepStart + 5, s30High); + EEPROM.put(eepStart + 9, s60High); + } } void loop() { @@ -158,14 +177,21 @@ void loop() { font3x5.print(F("v1.1.1")); menu[0] = F("Hit the Streets"); menu[1] = F("Extended Game"); - // menu[2] = F("High Scores"); - menuLength = 2; + menu[2] = F("High Scores"); + menuLength = 3; menuSmall = true; menuCols = false; drawMenu(menuSmall, menuCols, menuLength, menu); drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false); break; + case STATE_HIGH_SCORES: + drawDialog(); + drawMoney(10, 19, s30High); + drawMoney(10, 39, s60High); + sPreviousGameState = STATE_TITLE; + break; + case STATE_TURN_MENU: drawStatusBar(); drawTitle(lookupLocation(pLocation)); @@ -353,9 +379,8 @@ void loop() { break; case STATE_GAME_OVER: { - dialog[0] = "Game over! Score:"; dialogSmall = false; - dialogLength = 1; + dialogLength = 3; sPreviousGameState = STATE_TITLE; pMoney += pSavingsAmount - pLoanAmount; for (int i = 0; i < 6; i++) { @@ -364,8 +389,23 @@ void loop() { if (pMoney < 0) { pMoney = 0; } + bool newHigh = sMaxDays == 31 ? pMoney > s30High : pMoney > s60High; + dialog[0] = F("Game over! Score:"); + dialog[1] = F(""); + dialog[2] = newHigh ? F("Old ") : F(""); + dialog[2] += F("High Score:"); drawDialog(); - drawMoney(10, 20, pMoney); + drawMoney(10, 19, pMoney); + drawMoney(10, 39, sMaxDays == 31 ? s30High : s60High); + if (newHigh) { + if (sMaxDays == 31) { + s30High = pMoney; + EEPROM.put(eepStart + 5, s30High); + } else { + s60High = pMoney; + EEPROM.put(eepStart + 9, s60High); + } + } break; } @@ -450,6 +490,7 @@ void loop() { break; } case STATE_INVENTORY: + case STATE_HIGH_SCORES: case STATE_INFO_DIALOG: case STATE_DID_WEED_DIALOG_1: case STATE_DID_WEED_DIALOG_2: diff --git a/states.ino b/states.ino index 2ea82b8..3dc2170 100644 --- a/states.ino +++ b/states.ino @@ -204,6 +204,14 @@ void handleMenuAction() { case 1: // extended game initializeNewGame(60); break; + case 2: // high scores + dialog[0] = F("Normal Game:"); + dialog[1] = F(""); + dialog[2] = F("Extended Game:"); + dialogSmall = false; + dialogLength = 3; + sGameState = STATE_HIGH_SCORES; + break; } break;