v1.0 candidate

This commit is contained in:
Rudis Muiznieks 2022-06-19 12:51:58 -05:00
parent 8841c3a25e
commit b40277bdc5
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 158 additions and 13 deletions

View File

@ -21,6 +21,7 @@ enum GameState {
STATE_SHARK_MENU, STATE_SHARK_MENU,
STATE_BANK_MENU, STATE_BANK_MENU,
STATE_FIGHT_MENU, STATE_FIGHT_MENU,
STATE_FIGHT_DAMAGE,
STATE_INVENTORY, STATE_INVENTORY,
STATE_INFO_DIALOG, STATE_INFO_DIALOG,
STATE_BUY_GUN_DIALOG, STATE_BUY_GUN_DIALOG,
@ -80,6 +81,7 @@ long sQtyMax;
long sLastDebounce = 0; long sLastDebounce = 0;
short sDebounceCount = 0; short sDebounceCount = 0;
bool sAlreadyBorrowed; bool sAlreadyBorrowed;
int sPigs = 0;
/****************/ /****************/
/* player state */ /* player state */
@ -107,11 +109,12 @@ bool dialogSmall = false;
/* game setup and loop */ /* game setup and loop */
/***********************/ /***********************/
void setup() { void setup() {
arduboy.boot();
arduboy.setFrameRate(15);
arduboy.initRandomSeed();
sGameState = STATE_TITLE; sGameState = STATE_TITLE;
screenInitialized = false; screenInitialized = false;
arduboy.begin(); arduboy.begin();
arduboy.setFrameRate(15);
arduboy.initRandomSeed();
} }
void loop() { void loop() {
@ -127,6 +130,13 @@ void loop() {
if (!screenInitialized) { if (!screenInitialized) {
arduboy.clear(); arduboy.clear();
menuSelected = 0; menuSelected = 0;
// if we're entering the turn menu on day 31 then game is over instead
if (sGameState == STATE_TURN_MENU
&& sCurrentDay >= 31) {
sGameState = STATE_GAME_OVER;
}
switch (sGameState) { switch (sGameState) {
case STATE_TITLE: case STATE_TITLE:
arduboy.setCursor(25, 10); arduboy.setCursor(25, 10);
@ -217,11 +227,40 @@ void loop() {
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false); drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
break; break;
case STATE_FIGHT_MENU:
dialog[0] = F("Being chased!!");
dialog[1] = F("There are ");
dialog[1] += String(sPigs);
dialog[1] += F(" pigs");
dialog[2] = F("still after you!");
dialog[3] = F("Your health: ");
dialog[3] += String(pHealth);
dialogLength = 4;
dialogSmall = false;
drawDialog();
drawFightPrompt();
break;
case STATE_FIGHT_DAMAGE:
handleFightDamage();
drawDialog();
break;
case STATE_HEAL_DIALOG:
dialog[0] = F("Will you pay 1000");
dialog[1] = F("dollars for a");
dialog[2] = F("doctor to sew you");
dialog[3] = F("up?");
dialogLength = 4;
dialogSmall = false;
drawDialog();
drawYesNoPrompt();
break;
case STATE_INFO_DIALOG: case STATE_INFO_DIALOG:
case STATE_BUY_GUN_DIALOG: case STATE_BUY_GUN_DIALOG:
case STATE_BUY_COAT_DIALOG: case STATE_BUY_COAT_DIALOG:
case STATE_DO_WEED_DIALOG: case STATE_DO_WEED_DIALOG:
case STATE_HEAL_DIALOG:
drawDialog(); drawDialog();
if (sGameState != STATE_INFO_DIALOG) drawYesNoPrompt(); if (sGameState != STATE_INFO_DIALOG) drawYesNoPrompt();
break; break;
@ -311,6 +350,12 @@ void loop() {
drawDialog(); drawDialog();
break; break;
} }
default:
arduboy.setCursor(5, 5);
arduboy.print(F("ERROR "));
arduboy.print(sGameState);
break;
} }
screenInitialized = true; screenInitialized = true;
} }
@ -326,7 +371,6 @@ void loop() {
case STATE_JET_MENU: case STATE_JET_MENU:
case STATE_BUY_MENU: case STATE_BUY_MENU:
case STATE_SELL_MENU: case STATE_SELL_MENU:
case STATE_FIGHT_MENU:
case STATE_SHARK_MENU: case STATE_SHARK_MENU:
case STATE_BANK_MENU: { case STATE_BANK_MENU: {
if (arduboy.justPressed(UP_BUTTON) || if (arduboy.justPressed(UP_BUTTON) ||
@ -387,6 +431,7 @@ void loop() {
case STATE_INFO_DIALOG: case STATE_INFO_DIALOG:
case STATE_DID_WEED_DIALOG_1: case STATE_DID_WEED_DIALOG_1:
case STATE_DID_WEED_DIALOG_2: case STATE_DID_WEED_DIALOG_2:
case STATE_FIGHT_DAMAGE:
case STATE_GAME_OVER: case STATE_GAME_OVER:
checkBackedOut(true); checkBackedOut(true);
break; break;
@ -426,6 +471,10 @@ void loop() {
} }
break; break;
case STATE_FIGHT_MENU:
handleFightMenuInput();
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_PAY_LOAN_INPUT:
@ -498,7 +547,6 @@ void loop() {
} }
break; break;
} }
arduboy.display(); arduboy.display();
} }
@ -593,3 +641,10 @@ void drawYesNoPrompt() {
arduboy.drawCircle(75, 58, 5, WHITE); arduboy.drawCircle(75, 58, 5, WHITE);
arduboy.drawCircle(103, 58, 5, WHITE); arduboy.drawCircle(103, 58, 5, WHITE);
} }
void drawFightPrompt() {
font3x5.setCursor(66, 55);
font3x5.print(F("A Fight B Run"));
arduboy.drawCircle(67, 58, 5, WHITE);
arduboy.drawCircle(103, 58, 5, WHITE);
}

View File

@ -40,10 +40,12 @@ void incrementDay(const bool withInterest) {
pLoanAmount = floor(pLoanAmount * 1.1); pLoanAmount = floor(pLoanAmount * 1.1);
pSavingsAmount = floor(pSavingsAmount * 1.06); pSavingsAmount = floor(pSavingsAmount * 1.06);
} }
screenInitialized = false;
} }
void newDayRandomEvent() { void newDayRandomEvent() {
const int eventId = 6; //random(20); const int eventId = random(20);
sPreviousGameState = STATE_TURN_MENU; sPreviousGameState = STATE_TURN_MENU;
dialogSmall = false; dialogSmall = false;
switch (eventId) { switch (eventId) {
@ -101,12 +103,14 @@ void newDayRandomEvent() {
case 10: case 10:
case 11: { case 11: {
if (playerDrugInventoryCount() >= 50) { if (playerDrugInventoryCount() >= 50) {
const int pigs = eventId == 9 ? 1 : eventId == 10 ? 3 : 4; sPigs = eventId == 9 ? 2 : eventId == 10 ? 4 : 5;
dialog[0] = F("Officer Hardass and"); dialog[0] = F("Officer Hardass");
dialog[1] = String(pigs); dialog[1] = F("and ");
dialog[1] += F(" of his deputies"); dialog[1] += String(sPigs - 1);
dialog[2] = F("are after you!"); dialog[1] += F(" of his");
dialogLength = 3; dialog[2] = F("deputies are");
dialog[3] = F("after you!");
dialogLength = 4;
sPreviousGameState = STATE_FIGHT_MENU; sPreviousGameState = STATE_FIGHT_MENU;
sGameState = STATE_INFO_DIALOG; sGameState = STATE_INFO_DIALOG;
} else { } else {
@ -224,8 +228,8 @@ void handleMenuAction() {
break; break;
case STATE_JET_MENU: case STATE_JET_MENU:
incrementDay(true);
pLocation = menuSelected < pLocation ? menuSelected : menuSelected + 1; pLocation = menuSelected < pLocation ? menuSelected : menuSelected + 1;
incrementDay(true);
newDayRandomEvent(); newDayRandomEvent();
break; break;
@ -323,6 +327,92 @@ void handleMenuAction() {
} }
} }
void handleFightMenuInput() {
if (arduboy.justPressed(B_BUTTON)) { // run
screenInitialized = false;
if (random(2) == 0) {
dialog[0] = F("You lost them in");
dialog[1] = F("an alley!!");
dialogLength = 2;
dialogSmall = false;
sPreviousGameState = STATE_TURN_MENU;
sGameState = STATE_INFO_DIALOG;
} else {
dialog[0] = F("You can't shake");
dialog[1] = F("them!");
dialogLength = 2;
dialogSmall = false;
sPreviousGameState = STATE_FIGHT_DAMAGE;
sGameState = STATE_INFO_DIALOG;
}
} else if (arduboy.justPressed(A_BUTTON)) { // fight
screenInitialized = false;
if (pGuns == 0) {
dialog[0] = F("You don't have");
dialog[1] = F("any guns! You");
dialog[2] = F("have to run!");
dialogLength = 3;
dialogSmall = false;
sPreviousGameState = STATE_FIGHT_MENU;
sGameState = STATE_INFO_DIALOG;
} else {
if (random(2) == 0) {
dialog[0] = F("");
dialog[1] = F(" You missed!!!");
dialogLength = 2;
dialogSmall = false;
sPreviousGameState = STATE_FIGHT_DAMAGE;
sGameState = STATE_INFO_DIALOG;
} else {
sPigs--;
if (sPigs > 0) {
dialog[0] = F("");
dialog[1] = F("You killed one!!");
dialogLength = 2;
dialogSmall = false;
sPreviousGameState = STATE_FIGHT_DAMAGE;
sGameState = STATE_INFO_DIALOG;
} else {
const int found = random(1251) + 750;
dialog[0] = F("You killed all of");
dialog[1] = F("them! You found ");
dialog[1] += String(found);
dialog[2] = F("dollars on Officer");
dialog[3] = F("Hardass' carcass!!");
dialogLength = 4;
dialogSmall = true;
pMoney += found;
sPreviousGameState = pMoney >= 1200
? STATE_HEAL_DIALOG : STATE_TURN_MENU;
sGameState = STATE_INFO_DIALOG;
}
}
}
}
}
void handleFightDamage() {
const int x = random(2);
dialog[0] = F("They're firing at");
dialog[1] = F("you!! ");
sPreviousGameState = STATE_FIGHT_MENU;
dialogLength = 3;
dialogSmall = false;
if (x == 0) { // missed
dialog[1] += F("They");
dialog[2] = F("missed!!");
} else { // hit
dialog[1] += F("You've");
dialog[2] = F("been hit!");
pHealth -= 3;
if (pHealth <= 0) { // dead
dialog[3] = F("You're dead!!");
dialogLength = 4;
sPreviousGameState = STATE_GAME_OVER;
}
}
}
bool checkBackedOut(const bool eitherButton) { bool checkBackedOut(const bool eitherButton) {
if (arduboy.justPressed(B_BUTTON) || if (arduboy.justPressed(B_BUTTON) ||
(eitherButton && arduboy.justPressed(A_BUTTON))) { (eitherButton && arduboy.justPressed(A_BUTTON))) {