implemented inventory screen

This commit is contained in:
Rudis Muiznieks 2022-06-18 12:24:23 -05:00
parent 2f2ae4012e
commit df2f32f1b1
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 114 additions and 60 deletions

View File

@ -1,11 +1,14 @@
slangin.hex: build
SOURCE=$(wildcard *.ino)
BIN=./build/aurdino.avr.leonardo/slangin.ino.hex
$(BIN): $(SOURCE)
arduino-cli compile -b arduino:avr:leonardo -e .
slangin.hex: $(BIN)
cp ./build/arduino.avr.leonardo/slangin.ino.hex ./slangin.hex
build:
arduino-cli compile -b arduino:avr:leonardo -e .
run: slangin.hex
sim_arduboy -k 1073741906,1073741905,1073741904,1073741903,104,116 -p 6 ./slangin.hex
clean:
rm -rf ./build ./slangin.hex
run: slangin.hex
sim_arduboy -p 6 ./slangin.hex

View File

@ -16,12 +16,12 @@ enum GameState {
STATE_TITLE = 0,
STATE_TURN_MENU,
STATE_JET_MENU,
STATE_INVENTORY,
STATE_BUY_MENU,
STATE_SELL_MENU,
STATE_FIGHT_MENU,
STATE_SHARK_MENU,
STATE_BANK_MENU,
STATE_INVENTORY,
STATE_INFO_DIALOG,
STATE_QUESTION_DIALOG,
STATE_AMOUNT_DIALOG,
@ -99,6 +99,8 @@ void loop() {
if (!(arduboy.nextFrame()))
return;
arduboy.pollButtons();
// draw screen if needed
if (!screenInitialized) {
arduboy.clear();
@ -138,15 +140,16 @@ void loop() {
case STATE_INVENTORY:
drawStatusBar();
drawTitle(F("Trenchcoat"));
buildDrugMenu(pInventory);
drawMenu(menuSmall, menuCols, menuLength, menu);
break;
}
screenInitialized = true;
}
// handle user input
arduboy.pollButtons();
// menu screens
switch (sGameState) {
// menu screens
case STATE_TITLE:
case STATE_TURN_MENU:
case STATE_JET_MENU:
@ -154,59 +157,67 @@ void loop() {
case STATE_SELL_MENU:
case STATE_FIGHT_MENU:
case STATE_SHARK_MENU:
case STATE_BANK_MENU:
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, true);
int col1Count = round(menuLength / 2.0);
int inCol = menuSelected < col1Count ? 1 : 2;
case STATE_BANK_MENU: {
if (arduboy.justPressed(UP_BUTTON) ||
arduboy.justPressed(DOWN_BUTTON) ||
arduboy.justPressed(LEFT_BUTTON) ||
arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.justPressed(A_BUTTON) ||
arduboy.justPressed(B_BUTTON)) {
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, true);
int col1Count = round(menuLength / 2.0);
int inCol = menuSelected < col1Count ? 1 : 2;
if (arduboy.justPressed(DOWN_BUTTON)) {
menuSelected++;
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
} else if (arduboy.justPressed(UP_BUTTON)) {
menuSelected--;
if (menuSelected < 0) menuSelected = 0;
} else if (arduboy.justPressed(RIGHT_BUTTON)) {
if (menuCols && inCol == 1) {
menuSelected += col1Count;
} else {
if (arduboy.justPressed(DOWN_BUTTON)) {
menuSelected++;
}
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
} else if (arduboy.justPressed(LEFT_BUTTON)) {
if (menuCols && inCol == 2) {
menuSelected -= col1Count;
} else {
} else if (arduboy.justPressed(UP_BUTTON)) {
menuSelected--;
if (menuSelected < 0) menuSelected = 0;
} else if (arduboy.justPressed(RIGHT_BUTTON)) {
if (menuCols && inCol == 1) {
menuSelected += col1Count;
} else {
menuSelected++;
}
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
} else if (arduboy.justPressed(LEFT_BUTTON)) {
if (menuCols && inCol == 2) {
menuSelected -= col1Count;
} else {
menuSelected--;
}
if (menuSelected < 0) menuSelected = 0;
} else if (arduboy.justPressed(A_BUTTON)) {
// advance to next state
handleMenuAction();
} else if (arduboy.justPressed(B_BUTTON)) {
// return to turn menu from the other menus
if (sGameState == STATE_JET_MENU ||
sGameState == STATE_BUY_MENU ||
sGameState == STATE_SELL_MENU ||
sGameState == STATE_SHARK_MENU ||
sGameState == STATE_BANK_MENU) {
sGameState = STATE_TURN_MENU;
}
}
if (menuSelected < 0) menuSelected = 0;
} else if (arduboy.justPressed(A_BUTTON)) {
// advance to next state
handleMenuAction();
} else if (arduboy.justPressed(B_BUTTON)) {
// return to turn menu from the other menus
if (sGameState == STATE_JET_MENU ||
sGameState == STATE_BUY_MENU ||
sGameState == STATE_SELL_MENU ||
sGameState == STATE_SHARK_MENU ||
sGameState == STATE_BANK_MENU) {
sGameState = STATE_TURN_MENU;
}
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
}
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
break;
case STATE_INVENTORY:
// TODO: not working
}
case STATE_INVENTORY: {
if (arduboy.justPressed(B_BUTTON)) {
screenInitialized = false;
sGameState = STATE_TURN_MENU;
}
break;
}
}
arduboy.display();
@ -216,19 +227,59 @@ void loop() {
/* screen draw heplers */
/***********************/
void drawStatusBar() {
const int chars = log10(pMoney);
const int x = 128 - (chars * 4);
Sprites::drawOverwrite(x - 6, 1, spriteDollar, 0);
if (sGameState == STATE_INVENTORY) {
const int chars = numberChars(pCapacity);
const int x = 128 - ((chars + 9) * 4);
font3x5.setCursor(1, 0);
font3x5.print("Guns ");
font3x5.print(pGuns);
font3x5.setCursor(x, 0);
font3x5.print("Capacity ");
font3x5.print(pCapacity);
} else {
const int chars = numberChars(pMoney);
const int x = 128 - (chars * 4);
Sprites::drawOverwrite(x - 6, 1, spriteDollar, 0);
font3x5.setCursor(1, 0);
font3x5.print("Day");
font3x5.setCursor(14, 0);
font3x5.print(sCurrentDay);
font3x5.setCursor(x, 0);
font3x5.print(pMoney);
}
arduboy.fillRect(0, 8, 128, 1, WHITE);
font3x5.setCursor(1, 0);
font3x5.print("Day");
font3x5.setCursor(14, 0);
font3x5.print(sCurrentDay);
font3x5.setCursor(x, 0);
font3x5.print(pMoney);
}
void drawTitle(const String title) {
font4x6.setCursor(6, 11);
font4x6.setCursor(6, 12);
font4x6.print(title);
}
void buildDrugMenu(int extra[6]) {
int lengths[6];
int col1Max = 0;
int col2Max = 0;
for (int i = 0; i < 6; i++) {
int extraLen = numberChars(extra[i]);
lengths[i] = lookupDrug(i).length() + 1 + extraLen;
if (i < 3 && lengths[i] > col1Max) col1Max = lengths[i];
if (i >= 3 && lengths[i] > col2Max) col2Max = lengths[i];
}
for (int i = 0; i < 6; i++) {
int colMax = i < 3 ? col1Max : col2Max;
menu[i] = lookupDrug(i) + F(" ");
for (int s = 0; s < colMax - lengths[i]; s++) {
menu[i] = menu[i] + F(" ");
}
menu[i] = menu[i] + extra[i];
}
menuLength = 6;
menuCols = true;
menuSmall = col1Max + col2Max > 22;
}
int numberChars(int num) {
int length = 1;
while (num /= 10) length++;
return length;
}