started on quantity dialogs

This commit is contained in:
Rudis Muiznieks 2022-06-18 16:54:40 -05:00
parent a7eafdd1e0
commit b9f2beec6a
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 170 additions and 14 deletions

View File

@ -23,9 +23,16 @@ enum GameState {
STATE_FIGHT_MENU, STATE_FIGHT_MENU,
STATE_INVENTORY, STATE_INVENTORY,
STATE_INFO_DIALOG, STATE_INFO_DIALOG,
STATE_QUESTION_DIALOG, STATE_BUY_GUN_DIALOG,
STATE_AMOUNT_DIALOG, STATE_BUY_COAT_DIALOG,
STATE_SUBWAY STATE_DO_WEED_DIALOG,
STATE_HEAL_DIALOG,
STATE_BUY_QTY_INPUT,
STATE_SELL_QTY_INPUT,
STATE_PAY_LOAN_INPUT,
STATE_BORROW_INPUT,
STATE_DEPOSIT_INPUT,
STATE_WITHDRAW_INPUT
}; };
enum GameLocation { enum GameLocation {
@ -57,6 +64,11 @@ const uint8_t PROGMEM spriteDollar[] = {
0x12, 0x15, 0x1f, 0x15, 0x09, 0x12, 0x15, 0x1f, 0x15, 0x09,
}; };
const uint8_t PROGMEM spriteAdjust[] = {
5, 8,
0x24, 0x66, 0xe7, 0x66, 0x24,
};
/**************/ /**************/
/* game state */ /* game state */
/**************/ /**************/
@ -66,13 +78,16 @@ GameState sPreviousGameState;
int sCurrentDay; int sCurrentDay;
int sDrugPrices[6]; int sDrugPrices[6];
int sRandomEvent; int sRandomEvent;
int sCurrentDrug;
long sCurrentQty;
long sQtyMax;
/****************/ /****************/
/* player state */ /* player state */
/****************/ /****************/
int pMoney; long pMoney;
int pLoanAmount; long pLoanAmount;
int pSavingsAmount; long pSavingsAmount;
GameLocation pLocation; GameLocation pLocation;
int pGuns; int pGuns;
int pCapacity; int pCapacity;
@ -85,6 +100,10 @@ bool menuCols = false;
bool menuSmall = false; bool menuSmall = false;
int menuSelected = 0; int menuSelected = 0;
String dialog[5];
int dialogLength;
bool dialogSmall = false;
/***********************/ /***********************/
/* game setup and loop */ /* game setup and loop */
/***********************/ /***********************/
@ -195,6 +214,27 @@ void loop() {
drawMenu(menuSmall, menuCols, menuLength, menu); drawMenu(menuSmall, menuCols, menuLength, menu);
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false); drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
break; break;
case STATE_INFO_DIALOG:
drawDialog();
break;
case STATE_BUY_QTY_INPUT:
case STATE_SELL_QTY_INPUT:
dialog[0] = sGameState == STATE_BUY_QTY_INPUT ? F("Buy ") : F("Sell ");
dialog[0] += lookupDrug(sCurrentDrug);
dialog[1] = F("");
dialog[2] = F("");
dialog[3] = F("Cost");
dialog[4] = F("You have");
dialogLength = 5;
dialogSmall = true;
drawDialog();
drawMoney(dialog[0].length() * 5 + 15, 10, sDrugPrices[sCurrentDrug]);
drawMoney(35, 37, sCurrentQty * sDrugPrices[sCurrentDrug]);
drawMoney(55, 46, pMoney);
drawQtySelector(F("Qty"));
break;
} }
screenInitialized = true; screenInitialized = true;
} }
@ -258,19 +298,41 @@ void loop() {
sGameState == STATE_BANK_MENU) { sGameState == STATE_BANK_MENU) {
screenInitialized = false; screenInitialized = false;
sGameState = STATE_TURN_MENU; sGameState = STATE_TURN_MENU;
} else if (sGameState == STATE_BUY_QTY_INPUT) {
screenInitialized = false;
sGameState = STATE_BUY_MENU;
} else if (sGameState == STATE_SELL_QTY_INPUT) {
screenInitialized = false;
sGameState = STATE_SELL_MENU;
} }
} }
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false); drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
} }
break; break;
} }
case STATE_INVENTORY: { case STATE_INVENTORY:
if (arduboy.justPressed(B_BUTTON)) { case STATE_INFO_DIALOG:
screenInitialized = false; checkBackedOut();
sGameState = STATE_TURN_MENU; break;
} case STATE_SELL_QTY_INPUT:
case STATE_BUY_QTY_INPUT:
checkBackedOut();
if (arduboy.pressed(UP_BUTTON)) {
screenInitialized = false;
sCurrentQty++;
} else if (arduboy.pressed(RIGHT_BUTTON)) {
screenInitialized = false;
sCurrentQty += 10;
} else if (arduboy.pressed(DOWN_BUTTON)) {
screenInitialized = false;
sCurrentQty--;
} else if (arduboy.pressed(LEFT_BUTTON)) {
screenInitialized = false;
sCurrentQty -= 10;
}
if (sCurrentQty > sQtyMax) sCurrentQty = sQtyMax;
if (sCurrentQty < 0) sCurrentQty = 0;
break; break;
}
} }
arduboy.display(); arduboy.display();
@ -339,8 +401,39 @@ void buildDrugMenu(int extra[6]) {
menuSmall = col1Max + col2Max > 22; menuSmall = col1Max + col2Max > 22;
} }
int numberChars(int num) { int numberChars(long num) {
int length = 1; int length = 1;
while (num /= 10) length++; while (num /= 10) length++;
return length; return length;
} }
void drawDialog() {
arduboy.drawRoundRect(0, 0, 128, 64, 5, WHITE);
if (dialogSmall) {
for (int i = 0; i < dialogLength; i++) {
font4x6.setCursor(10, i * 9 + 10);
font4x6.print(dialog[i]);
}
} else {
for (int i = 0; i < dialogLength; i++) {
arduboy.setCursor(10, i * 10 + 10);
arduboy.print(dialog[i]);
}
}
}
void drawMoney(const int x, const int y, const long amount) {
Sprites::drawOverwrite(x, y + 2, spriteDollar, 0);
font4x6.setCursor(x + 6, y);
font4x6.print(amount);
}
void drawQtySelector(String label) {
font4x6.setCursor(10, 24);
font4x6.print(label);
const int labelLength = label.length() * 5;
arduboy.drawRect(labelLength + 15, 22, 103 - labelLength, 12, WHITE);
font4x6.setCursor(labelLength + 19, 24);
font4x6.print(sCurrentQty);
Sprites::drawOverwrite(111, 24, spriteAdjust, 0);
}

View File

@ -1,6 +1,13 @@
/*
Slangin'
State Management
Author: Rudis Muiznieks
License: WTFPL
*/
void initializeNewGame() { void initializeNewGame() {
sGameState = STATE_TURN_MENU; sGameState = STATE_TURN_MENU;
pMoney = 2000; pMoney = 10000000; // 2000
pLoanAmount = 5000; pLoanAmount = 5000;
pSavingsAmount = 0; pSavingsAmount = 0;
pLocation = LOC_BRONX; pLocation = LOC_BRONX;
@ -45,6 +52,7 @@ void handleMenuAction() {
break; break;
case STATE_TURN_MENU: case STATE_TURN_MENU:
sPreviousGameState = STATE_TURN_MENU;
switch (menuSelected) { switch (menuSelected) {
case 0: // trenchcoat case 0: // trenchcoat
sGameState = STATE_INVENTORY; sGameState = STATE_INVENTORY;
@ -68,10 +76,65 @@ void handleMenuAction() {
break; break;
case STATE_JET_MENU: case STATE_JET_MENU:
break;
case STATE_BUY_MENU: case STATE_BUY_MENU:
sPreviousGameState = STATE_BUY_MENU;
sCurrentDrug = menuSelected;
if (pCapacity <= 0) {
dialog[0] = F("Oops!");
dialog[1] = F("");
dialog[2] = F("You can't carry any");
dialog[3] = F("more ");
dialog[3] += lookupDrug(sCurrentDrug);
dialog[3] += F("!");
dialogLength = 4;
dialogSmall = false;
sPreviousGameState = sGameState;
sGameState = STATE_INFO_DIALOG;
} else if (pMoney < sDrugPrices[sCurrentDrug]) {
dialog[0] = F("Oops!");
dialog[1] = F("");
dialog[2] = F("You can't afford");
dialog[3] = lookupDrug(sCurrentDrug) + F("!");
dialogLength = 4;
dialogSmall = false;
sPreviousGameState = sGameState;
sGameState = STATE_INFO_DIALOG;
} else {
sGameState = STATE_BUY_QTY_INPUT;
sCurrentQty = 0;
sQtyMax = floor(pMoney / (float)sDrugPrices[sCurrentDrug]);
}
break;
case STATE_SELL_MENU: case STATE_SELL_MENU:
sPreviousGameState = STATE_SELL_MENU;
sCurrentDrug = menuSelected;
if (pInventory[sCurrentDrug] > 0) {
sGameState = STATE_SELL_QTY_INPUT;
sCurrentQty = 0;
sQtyMax = pInventory[sCurrentDrug];
} else {
dialog[0] = F("Oops!");
dialog[1] = F("");
dialog[2] = F("You don't have any");
dialog[3] = lookupDrug(sCurrentDrug) + F("!");
dialogLength = 4;
dialogSmall = false;
sPreviousGameState = sGameState;
sGameState = STATE_INFO_DIALOG;
}
break;
case STATE_SHARK_MENU: case STATE_SHARK_MENU:
case STATE_BANK_MENU: case STATE_BANK_MENU:
break; break;
} }
} }
bool checkBackedOut() {
if (arduboy.justPressed(B_BUTTON)) {
screenInitialized = false;
sGameState = sPreviousGameState;
return true;
}
return false;
}