implemented loan shark and bank
This commit is contained in:
parent
6a66f47488
commit
042f41df71
121
slangin.ino
121
slangin.ino
|
@ -79,17 +79,18 @@ int sCurrentDay;
|
|||
int sDrugPrices[6];
|
||||
int sRandomEvent;
|
||||
int sCurrentDrug;
|
||||
unsigned long sCurrentQty;
|
||||
unsigned long sQtyMax;
|
||||
unsigned long sLastDebounce = 0;
|
||||
long sCurrentQty;
|
||||
long sQtyMax;
|
||||
long sLastDebounce = 0;
|
||||
short sDebounceCount = 0;
|
||||
bool sAlreadyBorrowed;
|
||||
|
||||
/****************/
|
||||
/* player state */
|
||||
/****************/
|
||||
unsigned long pMoney;
|
||||
unsigned long pLoanAmount;
|
||||
unsigned long pSavingsAmount;
|
||||
long pMoney;
|
||||
long pLoanAmount;
|
||||
long pSavingsAmount;
|
||||
GameLocation pLocation;
|
||||
int pGuns;
|
||||
int pCapacity;
|
||||
|
@ -244,6 +245,31 @@ void loop() {
|
|||
drawQtyInputTotal();
|
||||
drawQtySelector(F("Qty"));
|
||||
break;
|
||||
|
||||
case STATE_PAY_LOAN_INPUT:
|
||||
case STATE_BORROW_INPUT:
|
||||
case STATE_DEPOSIT_INPUT:
|
||||
case STATE_WITHDRAW_INPUT:
|
||||
dialog[0] = sGameState == STATE_PAY_LOAN_INPUT
|
||||
? F("Pay Loan")
|
||||
: sGameState == STATE_BORROW_INPUT
|
||||
? F("Borrow Money")
|
||||
: sGameState == STATE_DEPOSIT_INPUT
|
||||
? F("Deposit Money")
|
||||
: F("Withdraw Money");
|
||||
dialog[1] = F("");
|
||||
dialog[2] = F("");
|
||||
dialog[3] = sPreviousGameState == STATE_SHARK_MENU
|
||||
? F("You owe") : F("Savings");
|
||||
dialog[4] = F("You have");
|
||||
dialogLength = 5;
|
||||
dialogSmall = true;
|
||||
drawDialog();
|
||||
drawMoney(50, 37, sPreviousGameState == STATE_SHARK_MENU
|
||||
? pLoanAmount : pSavingsAmount);
|
||||
drawMoney(55, 46, pMoney);
|
||||
drawQtySelector(F("Amt"));
|
||||
break;
|
||||
}
|
||||
screenInitialized = true;
|
||||
}
|
||||
|
@ -310,12 +336,6 @@ void loop() {
|
|||
sGameState == STATE_BANK_MENU) {
|
||||
screenInitialized = false;
|
||||
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);
|
||||
|
@ -328,37 +348,65 @@ void loop() {
|
|||
break;
|
||||
case STATE_SELL_QTY_INPUT:
|
||||
case STATE_BUY_QTY_INPUT:
|
||||
case STATE_PAY_LOAN_INPUT:
|
||||
case STATE_BORROW_INPUT:
|
||||
case STATE_WITHDRAW_INPUT:
|
||||
case STATE_DEPOSIT_INPUT:
|
||||
if (!checkBackedOut(false)) {
|
||||
if (arduboy.justPressed(A_BUTTON)) {
|
||||
if (sGameState == STATE_SELL_QTY_INPUT) {
|
||||
pInventory[sCurrentDrug] -= sCurrentQty;
|
||||
pMoney += sCurrentQty * sDrugPrices[sCurrentDrug];
|
||||
} else {
|
||||
pInventory[sCurrentDrug] += sCurrentQty;
|
||||
pMoney -= sCurrentQty * sDrugPrices[sCurrentDrug];
|
||||
switch (sGameState) {
|
||||
case STATE_SELL_QTY_INPUT:
|
||||
pInventory[sCurrentDrug] -= sCurrentQty;
|
||||
pMoney += sCurrentQty * sDrugPrices[sCurrentDrug];
|
||||
break;
|
||||
case STATE_BUY_QTY_INPUT:
|
||||
pInventory[sCurrentDrug] += sCurrentQty;
|
||||
pMoney -= sCurrentQty * sDrugPrices[sCurrentDrug];
|
||||
break;
|
||||
case STATE_PAY_LOAN_INPUT:
|
||||
pLoanAmount -= sCurrentQty;
|
||||
pMoney -= sCurrentQty;
|
||||
break;
|
||||
case STATE_BORROW_INPUT:
|
||||
pLoanAmount += sCurrentQty;
|
||||
pMoney += sCurrentQty;
|
||||
sAlreadyBorrowed = true;
|
||||
break;
|
||||
case STATE_WITHDRAW_INPUT:
|
||||
pSavingsAmount -= sCurrentQty;
|
||||
pMoney += sCurrentQty;
|
||||
break;
|
||||
case STATE_DEPOSIT_INPUT:
|
||||
pSavingsAmount += sCurrentQty;
|
||||
pMoney -= sCurrentQty;
|
||||
break;
|
||||
}
|
||||
screenInitialized = false;
|
||||
sGameState = sPreviousGameState;
|
||||
} else {
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - sLastDebounce > (sDebounceCount < 2 ? 300 : 100)) {
|
||||
const unsigned long currentMillis = millis();
|
||||
const int 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 (arduboy.pressed(UP_BUTTON)) {
|
||||
sLastDebounce = currentMillis;
|
||||
if (sCurrentQty <= sQtyMax - 1) sCurrentQty++;
|
||||
if (sCurrentQty <= sQtyMax - incAmount) sCurrentQty += incAmount;
|
||||
else sCurrentQty = sQtyMax;
|
||||
drawQtyInputTotal();
|
||||
} else if (arduboy.pressed(RIGHT_BUTTON)) {
|
||||
sLastDebounce = currentMillis;
|
||||
if (sCurrentQty <= sQtyMax - 10) sCurrentQty += 10;
|
||||
if (sCurrentQty <= sQtyMax - incAmount * 10) sCurrentQty += incAmount * 10;
|
||||
else sCurrentQty = sQtyMax;
|
||||
drawQtyInputTotal();
|
||||
} else if (arduboy.pressed(DOWN_BUTTON)) {
|
||||
sLastDebounce = currentMillis;
|
||||
if (sCurrentQty > 0) sCurrentQty--;
|
||||
if (sCurrentQty >= incAmount) sCurrentQty -= incAmount;
|
||||
else sCurrentQty = 0;
|
||||
drawQtyInputTotal();
|
||||
} else if (arduboy.pressed(LEFT_BUTTON)) {
|
||||
sLastDebounce = currentMillis;
|
||||
if (sCurrentQty > 10) sCurrentQty -= 10;
|
||||
if (sCurrentQty >= incAmount * 10) sCurrentQty -= incAmount * 10;
|
||||
else sCurrentQty = 0;
|
||||
drawQtyInputTotal();
|
||||
} else {
|
||||
|
@ -438,7 +486,7 @@ void buildDrugMenu(int extra[6]) {
|
|||
menuSmall = col1Max + col2Max > 22;
|
||||
}
|
||||
|
||||
int numberChars(unsigned long num) {
|
||||
int numberChars(long num) {
|
||||
int length = 1;
|
||||
while (num /= 10) length++;
|
||||
return length;
|
||||
|
@ -459,7 +507,7 @@ void drawDialog() {
|
|||
}
|
||||
}
|
||||
|
||||
void drawMoney(const int x, const int y, const unsigned long amount) {
|
||||
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);
|
||||
|
@ -468,21 +516,22 @@ void drawMoney(const int x, const int y, const unsigned long 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);
|
||||
drawQtySelectorAmount(label);
|
||||
arduboy.drawRect(30, 22, 88, 12, WHITE);
|
||||
drawQtySelectorAmount();
|
||||
Sprites::drawOverwrite(111, 24, spriteAdjust, 0);
|
||||
}
|
||||
|
||||
void drawQtySelectorAmount(String label) {
|
||||
const int labelLength = label.length() * 5;
|
||||
arduboy.fillRect(labelLength + 16, 23, 95 - labelLength, 10, BLACK);
|
||||
font4x6.setCursor(labelLength + 19, 24);
|
||||
void drawQtySelectorAmount() {
|
||||
arduboy.fillRect(31, 23, 80, 10, BLACK);
|
||||
font4x6.setCursor(35, 24);
|
||||
font4x6.print(sCurrentQty);
|
||||
}
|
||||
|
||||
void drawQtyInputTotal() {
|
||||
arduboy.fillRect(40, 37, 91, 7, BLACK);
|
||||
drawMoney(40, 37, sCurrentQty * sDrugPrices[sCurrentDrug]);
|
||||
drawQtySelectorAmount(F("Qty"));
|
||||
if (sGameState == STATE_SELL_QTY_INPUT ||
|
||||
sGameState == STATE_BUY_QTY_INPUT) {
|
||||
arduboy.fillRect(40, 37, 87, 7, BLACK);
|
||||
drawMoney(40, 37, sCurrentQty * sDrugPrices[sCurrentDrug]);
|
||||
}
|
||||
drawQtySelectorAmount();
|
||||
}
|
||||
|
|
39
states.ino
39
states.ino
|
@ -7,7 +7,7 @@ License: WTFPL
|
|||
|
||||
void initializeNewGame() {
|
||||
sGameState = STATE_TURN_MENU;
|
||||
pMoney = 10000000; // 2000
|
||||
pMoney = 2000;
|
||||
pLoanAmount = 5000;
|
||||
pSavingsAmount = 0;
|
||||
pLocation = LOC_BRONX;
|
||||
|
@ -29,6 +29,7 @@ void incrementDay() {
|
|||
sCurrentDay++;
|
||||
|
||||
// TODO: check for game over
|
||||
sAlreadyBorrowed = false;
|
||||
|
||||
// generate new drug prices
|
||||
sDrugPrices[DRUG_COCAINE] = random(12001) + 16000;
|
||||
|
@ -77,6 +78,7 @@ void handleMenuAction() {
|
|||
|
||||
case STATE_JET_MENU:
|
||||
break;
|
||||
|
||||
case STATE_BUY_MENU: {
|
||||
int remaining = playerCapacityRemaining();
|
||||
sPreviousGameState = STATE_BUY_MENU;
|
||||
|
@ -109,6 +111,7 @@ void handleMenuAction() {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case STATE_SELL_MENU:
|
||||
sPreviousGameState = STATE_SELL_MENU;
|
||||
sCurrentDrug = menuSelected;
|
||||
|
@ -127,8 +130,42 @@ void handleMenuAction() {
|
|||
sGameState = STATE_INFO_DIALOG;
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE_SHARK_MENU:
|
||||
sPreviousGameState = STATE_SHARK_MENU;
|
||||
sCurrentQty = 0;
|
||||
switch (menuSelected) {
|
||||
case 0: // repay loan
|
||||
sGameState = STATE_PAY_LOAN_INPUT;
|
||||
sQtyMax = pLoanAmount > pMoney ? pMoney : pLoanAmount;
|
||||
break;
|
||||
case 1: // borrow money
|
||||
if (sAlreadyBorrowed) {
|
||||
dialog[0] = F("You already");
|
||||
dialog[1] = F("borrowed money");
|
||||
dialog[2] = F("today!");
|
||||
dialogLength = 3;
|
||||
dialogSmall = false;
|
||||
sGameState = STATE_INFO_DIALOG;
|
||||
} else {
|
||||
sGameState = STATE_BORROW_INPUT;
|
||||
sQtyMax = 5000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case STATE_BANK_MENU:
|
||||
sPreviousGameState = STATE_BANK_MENU;
|
||||
switch (menuSelected) {
|
||||
case 0: // deposit money
|
||||
sGameState = STATE_DEPOSIT_INPUT;
|
||||
sQtyMax = pMoney;
|
||||
break;
|
||||
case 1: // withdraw money
|
||||
sGameState = STATE_WITHDRAW_INPUT;
|
||||
sQtyMax = pSavingsAmount;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue