diff --git a/slangin.ino b/slangin.ino index 2b234e9..7105b70 100644 --- a/slangin.ino +++ b/slangin.ino @@ -87,7 +87,7 @@ int sCurrentDrug; long sCurrentQty; long sQtyMax; long sLastDebounce = 0; -short sDebounceCount = 0; +int sDebounceCount = 0; bool sAlreadyBorrowed; int sPigs = 0; @@ -103,11 +103,12 @@ int pCapacity; int pHealth; long pInventory[6]; -String menu[8]; +String menu[6]; int menuLength = 0; bool menuCols = false; bool menuSmall = false; int menuSelected = 0; +int menuBackOut = 0; String dialog[5]; int dialogLength; @@ -137,7 +138,8 @@ void loop() { if (!screenInitialized) { arduboy.clear(); - menuSelected = 0; + menuSelected = menuBackOut; + menuBackOut = 0; // if we're entering the turn menu on day 31 then game is over instead if (sGameState == STATE_TURN_MENU @@ -430,6 +432,7 @@ void loop() { sGameState == STATE_SHARK_MENU || sGameState == STATE_BANK_MENU) { screenInitialized = false; + menuBackOut = getMenuBackOut(); sGameState = STATE_TURN_MENU; } } @@ -524,10 +527,16 @@ void loop() { sGameState = sPreviousGameState; } else { const unsigned long currentMillis = millis(); - const int incAmount = sGameState == STATE_BUY_QTY_INPUT || + const long incAmount = sGameState == STATE_BUY_QTY_INPUT || sGameState == STATE_SELL_QTY_INPUT ? 1 : 10; - if (currentMillis - sLastDebounce > (sDebounceCount < 2 ? 500 : 100)) { - if (sDebounceCount < 2) sDebounceCount++; + if (currentMillis - sLastDebounce > (sDebounceCount < 2 ? 500 : sDebounceCount < 21 ? 100 : 0)) { + const long incMult = sDebounceCount < 100 + ? 1 : sDebounceCount < 125 + ? 10 : sDebounceCount < 150 + ? 100 : sDebounceCount < 175 + ? 1000 + : 10000; + if (sDebounceCount < 1000) sDebounceCount++; if (arduboy.pressed(UP_BUTTON)) { sLastDebounce = currentMillis; if (sCurrentQty <= sQtyMax - incAmount) sCurrentQty += incAmount; @@ -535,7 +544,8 @@ void loop() { drawQtyInputTotal(); } else if (arduboy.pressed(RIGHT_BUTTON)) { sLastDebounce = currentMillis; - if (sCurrentQty <= sQtyMax - incAmount * 10) sCurrentQty += incAmount * 10; + if (sCurrentQty + incAmount * 10 * incMult <= sQtyMax) + sCurrentQty += incAmount * 10 * incMult; else sCurrentQty = sQtyMax; drawQtyInputTotal(); } else if (arduboy.pressed(DOWN_BUTTON)) { @@ -545,7 +555,8 @@ void loop() { drawQtyInputTotal(); } else if (arduboy.pressed(LEFT_BUTTON)) { sLastDebounce = currentMillis; - if (sCurrentQty >= incAmount * 10) sCurrentQty -= incAmount * 10; + if (sCurrentQty >= incAmount * 10 * incMult) + sCurrentQty -= incAmount * 10 * incMult; else sCurrentQty = 0; drawQtyInputTotal(); } else { diff --git a/states.ino b/states.ino index 33269f1..9d8328f 100644 --- a/states.ino +++ b/states.ino @@ -192,6 +192,38 @@ void newDayRandomEvent() { } } +int getMenuBackOut() { + // this whole thing could have been done so much better :( + // i suck at C++ + switch (sGameState) { + case STATE_SELL_MENU: + case STATE_BORROW_INPUT: + case STATE_WITHDRAW_INPUT: + return 1; + case STATE_INVENTORY: + return 2; + case STATE_JET_MENU: + return 3; + case STATE_SHARK_MENU: + return 4; + case STATE_BANK_MENU: + return 5; + case STATE_BUY_QTY_INPUT: + case STATE_SELL_QTY_INPUT: + return sCurrentDrug; + case STATE_INFO_DIALOG: + switch (sPreviousGameState) { + case STATE_BUY_MENU: + case STATE_SELL_MENU: + return sCurrentDrug; + default: + return 0; + } + default: + return 0; + } +} + void handleMenuAction() { screenInitialized = false; switch (sGameState) { @@ -418,6 +450,7 @@ bool checkBackedOut(const bool eitherButton) { if (arduboy.justPressed(B_BUTTON) || (eitherButton && arduboy.justPressed(A_BUTTON))) { screenInitialized = false; + menuBackOut = getMenuBackOut(); sGameState = sPreviousGameState; return true; }