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();
switch (sGameState) {
// menu screens
switch (sGameState) {
case STATE_TITLE:
case STATE_TURN_MENU:
case STATE_JET_MENU:
@ -154,7 +157,13 @@ void loop() {
case STATE_SELL_MENU:
case STATE_FIGHT_MENU:
case STATE_SHARK_MENU:
case STATE_BANK_MENU:
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;
@ -199,15 +208,17 @@ void loop() {
}
}
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,10 +227,19 @@ void loop() {
/* screen draw heplers */
/***********************/
void drawStatusBar() {
const int chars = log10(pMoney);
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);
arduboy.fillRect(0, 8, 128, 1, WHITE);
font3x5.setCursor(1, 0);
font3x5.print("Day");
font3x5.setCursor(14, 0);
@ -227,8 +247,39 @@ void drawStatusBar() {
font3x5.setCursor(x, 0);
font3x5.print(pMoney);
}
arduboy.fillRect(0, 8, 128, 1, WHITE);
}
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;
}