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 sDrugPrices[6];
|
||||||
int sRandomEvent;
|
int sRandomEvent;
|
||||||
int sCurrentDrug;
|
int sCurrentDrug;
|
||||||
unsigned long sCurrentQty;
|
long sCurrentQty;
|
||||||
unsigned long sQtyMax;
|
long sQtyMax;
|
||||||
unsigned long sLastDebounce = 0;
|
long sLastDebounce = 0;
|
||||||
short sDebounceCount = 0;
|
short sDebounceCount = 0;
|
||||||
|
bool sAlreadyBorrowed;
|
||||||
|
|
||||||
/****************/
|
/****************/
|
||||||
/* player state */
|
/* player state */
|
||||||
/****************/
|
/****************/
|
||||||
unsigned long pMoney;
|
long pMoney;
|
||||||
unsigned long pLoanAmount;
|
long pLoanAmount;
|
||||||
unsigned long pSavingsAmount;
|
long pSavingsAmount;
|
||||||
GameLocation pLocation;
|
GameLocation pLocation;
|
||||||
int pGuns;
|
int pGuns;
|
||||||
int pCapacity;
|
int pCapacity;
|
||||||
|
@ -244,6 +245,31 @@ void loop() {
|
||||||
drawQtyInputTotal();
|
drawQtyInputTotal();
|
||||||
drawQtySelector(F("Qty"));
|
drawQtySelector(F("Qty"));
|
||||||
break;
|
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;
|
screenInitialized = true;
|
||||||
}
|
}
|
||||||
|
@ -310,12 +336,6 @@ 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);
|
||||||
|
@ -328,37 +348,65 @@ void loop() {
|
||||||
break;
|
break;
|
||||||
case STATE_SELL_QTY_INPUT:
|
case STATE_SELL_QTY_INPUT:
|
||||||
case STATE_BUY_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 (!checkBackedOut(false)) {
|
||||||
if (arduboy.justPressed(A_BUTTON)) {
|
if (arduboy.justPressed(A_BUTTON)) {
|
||||||
if (sGameState == STATE_SELL_QTY_INPUT) {
|
switch (sGameState) {
|
||||||
pInventory[sCurrentDrug] -= sCurrentQty;
|
case STATE_SELL_QTY_INPUT:
|
||||||
pMoney += sCurrentQty * sDrugPrices[sCurrentDrug];
|
pInventory[sCurrentDrug] -= sCurrentQty;
|
||||||
} else {
|
pMoney += sCurrentQty * sDrugPrices[sCurrentDrug];
|
||||||
pInventory[sCurrentDrug] += sCurrentQty;
|
break;
|
||||||
pMoney -= sCurrentQty * sDrugPrices[sCurrentDrug];
|
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;
|
screenInitialized = false;
|
||||||
sGameState = sPreviousGameState;
|
sGameState = sPreviousGameState;
|
||||||
} else {
|
} else {
|
||||||
unsigned long currentMillis = millis();
|
const unsigned long currentMillis = millis();
|
||||||
if (currentMillis - sLastDebounce > (sDebounceCount < 2 ? 300 : 100)) {
|
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 (sDebounceCount < 2) sDebounceCount++;
|
||||||
if (arduboy.pressed(UP_BUTTON)) {
|
if (arduboy.pressed(UP_BUTTON)) {
|
||||||
sLastDebounce = currentMillis;
|
sLastDebounce = currentMillis;
|
||||||
if (sCurrentQty <= sQtyMax - 1) sCurrentQty++;
|
if (sCurrentQty <= sQtyMax - incAmount) sCurrentQty += incAmount;
|
||||||
|
else sCurrentQty = sQtyMax;
|
||||||
drawQtyInputTotal();
|
drawQtyInputTotal();
|
||||||
} else if (arduboy.pressed(RIGHT_BUTTON)) {
|
} else if (arduboy.pressed(RIGHT_BUTTON)) {
|
||||||
sLastDebounce = currentMillis;
|
sLastDebounce = currentMillis;
|
||||||
if (sCurrentQty <= sQtyMax - 10) sCurrentQty += 10;
|
if (sCurrentQty <= sQtyMax - incAmount * 10) sCurrentQty += incAmount * 10;
|
||||||
else sCurrentQty = sQtyMax;
|
else sCurrentQty = sQtyMax;
|
||||||
drawQtyInputTotal();
|
drawQtyInputTotal();
|
||||||
} else if (arduboy.pressed(DOWN_BUTTON)) {
|
} else if (arduboy.pressed(DOWN_BUTTON)) {
|
||||||
sLastDebounce = currentMillis;
|
sLastDebounce = currentMillis;
|
||||||
if (sCurrentQty > 0) sCurrentQty--;
|
if (sCurrentQty >= incAmount) sCurrentQty -= incAmount;
|
||||||
|
else sCurrentQty = 0;
|
||||||
drawQtyInputTotal();
|
drawQtyInputTotal();
|
||||||
} else if (arduboy.pressed(LEFT_BUTTON)) {
|
} else if (arduboy.pressed(LEFT_BUTTON)) {
|
||||||
sLastDebounce = currentMillis;
|
sLastDebounce = currentMillis;
|
||||||
if (sCurrentQty > 10) sCurrentQty -= 10;
|
if (sCurrentQty >= incAmount * 10) sCurrentQty -= incAmount * 10;
|
||||||
else sCurrentQty = 0;
|
else sCurrentQty = 0;
|
||||||
drawQtyInputTotal();
|
drawQtyInputTotal();
|
||||||
} else {
|
} else {
|
||||||
|
@ -438,7 +486,7 @@ void buildDrugMenu(int extra[6]) {
|
||||||
menuSmall = col1Max + col2Max > 22;
|
menuSmall = col1Max + col2Max > 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
int numberChars(unsigned long num) {
|
int numberChars(long num) {
|
||||||
int length = 1;
|
int length = 1;
|
||||||
while (num /= 10) length++;
|
while (num /= 10) length++;
|
||||||
return 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);
|
Sprites::drawOverwrite(x, y + 2, spriteDollar, 0);
|
||||||
font4x6.setCursor(x + 6, y);
|
font4x6.setCursor(x + 6, y);
|
||||||
font4x6.print(amount);
|
font4x6.print(amount);
|
||||||
|
@ -468,21 +516,22 @@ void drawMoney(const int x, const int y, const unsigned long amount) {
|
||||||
void drawQtySelector(String label) {
|
void drawQtySelector(String label) {
|
||||||
font4x6.setCursor(10, 24);
|
font4x6.setCursor(10, 24);
|
||||||
font4x6.print(label);
|
font4x6.print(label);
|
||||||
const int labelLength = label.length() * 5;
|
arduboy.drawRect(30, 22, 88, 12, WHITE);
|
||||||
arduboy.drawRect(labelLength + 15, 22, 103 - labelLength, 12, WHITE);
|
drawQtySelectorAmount();
|
||||||
drawQtySelectorAmount(label);
|
|
||||||
Sprites::drawOverwrite(111, 24, spriteAdjust, 0);
|
Sprites::drawOverwrite(111, 24, spriteAdjust, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawQtySelectorAmount(String label) {
|
void drawQtySelectorAmount() {
|
||||||
const int labelLength = label.length() * 5;
|
arduboy.fillRect(31, 23, 80, 10, BLACK);
|
||||||
arduboy.fillRect(labelLength + 16, 23, 95 - labelLength, 10, BLACK);
|
font4x6.setCursor(35, 24);
|
||||||
font4x6.setCursor(labelLength + 19, 24);
|
|
||||||
font4x6.print(sCurrentQty);
|
font4x6.print(sCurrentQty);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawQtyInputTotal() {
|
void drawQtyInputTotal() {
|
||||||
arduboy.fillRect(40, 37, 91, 7, BLACK);
|
if (sGameState == STATE_SELL_QTY_INPUT ||
|
||||||
drawMoney(40, 37, sCurrentQty * sDrugPrices[sCurrentDrug]);
|
sGameState == STATE_BUY_QTY_INPUT) {
|
||||||
drawQtySelectorAmount(F("Qty"));
|
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() {
|
void initializeNewGame() {
|
||||||
sGameState = STATE_TURN_MENU;
|
sGameState = STATE_TURN_MENU;
|
||||||
pMoney = 10000000; // 2000
|
pMoney = 2000;
|
||||||
pLoanAmount = 5000;
|
pLoanAmount = 5000;
|
||||||
pSavingsAmount = 0;
|
pSavingsAmount = 0;
|
||||||
pLocation = LOC_BRONX;
|
pLocation = LOC_BRONX;
|
||||||
|
@ -29,6 +29,7 @@ void incrementDay() {
|
||||||
sCurrentDay++;
|
sCurrentDay++;
|
||||||
|
|
||||||
// TODO: check for game over
|
// TODO: check for game over
|
||||||
|
sAlreadyBorrowed = false;
|
||||||
|
|
||||||
// generate new drug prices
|
// generate new drug prices
|
||||||
sDrugPrices[DRUG_COCAINE] = random(12001) + 16000;
|
sDrugPrices[DRUG_COCAINE] = random(12001) + 16000;
|
||||||
|
@ -77,6 +78,7 @@ void handleMenuAction() {
|
||||||
|
|
||||||
case STATE_JET_MENU:
|
case STATE_JET_MENU:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_BUY_MENU: {
|
case STATE_BUY_MENU: {
|
||||||
int remaining = playerCapacityRemaining();
|
int remaining = playerCapacityRemaining();
|
||||||
sPreviousGameState = STATE_BUY_MENU;
|
sPreviousGameState = STATE_BUY_MENU;
|
||||||
|
@ -109,6 +111,7 @@ void handleMenuAction() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case STATE_SELL_MENU:
|
case STATE_SELL_MENU:
|
||||||
sPreviousGameState = STATE_SELL_MENU;
|
sPreviousGameState = STATE_SELL_MENU;
|
||||||
sCurrentDrug = menuSelected;
|
sCurrentDrug = menuSelected;
|
||||||
|
@ -127,8 +130,42 @@ void handleMenuAction() {
|
||||||
sGameState = STATE_INFO_DIALOG;
|
sGameState = STATE_INFO_DIALOG;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_SHARK_MENU:
|
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:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue