implemented inventory screen
This commit is contained in:
parent
2f2ae4012e
commit
df2f32f1b1
15
Makefile
15
Makefile
|
@ -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
|
cp ./build/arduino.avr.leonardo/slangin.ino.hex ./slangin.hex
|
||||||
|
|
||||||
build:
|
run: slangin.hex
|
||||||
arduino-cli compile -b arduino:avr:leonardo -e .
|
sim_arduboy -k 1073741906,1073741905,1073741904,1073741903,104,116 -p 6 ./slangin.hex
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ./build ./slangin.hex
|
rm -rf ./build ./slangin.hex
|
||||||
|
|
||||||
run: slangin.hex
|
|
||||||
sim_arduboy -p 6 ./slangin.hex
|
|
||||||
|
|
159
slangin.ino
159
slangin.ino
|
@ -16,12 +16,12 @@ enum GameState {
|
||||||
STATE_TITLE = 0,
|
STATE_TITLE = 0,
|
||||||
STATE_TURN_MENU,
|
STATE_TURN_MENU,
|
||||||
STATE_JET_MENU,
|
STATE_JET_MENU,
|
||||||
STATE_INVENTORY,
|
|
||||||
STATE_BUY_MENU,
|
STATE_BUY_MENU,
|
||||||
STATE_SELL_MENU,
|
STATE_SELL_MENU,
|
||||||
STATE_FIGHT_MENU,
|
STATE_FIGHT_MENU,
|
||||||
STATE_SHARK_MENU,
|
STATE_SHARK_MENU,
|
||||||
STATE_BANK_MENU,
|
STATE_BANK_MENU,
|
||||||
|
STATE_INVENTORY,
|
||||||
STATE_INFO_DIALOG,
|
STATE_INFO_DIALOG,
|
||||||
STATE_QUESTION_DIALOG,
|
STATE_QUESTION_DIALOG,
|
||||||
STATE_AMOUNT_DIALOG,
|
STATE_AMOUNT_DIALOG,
|
||||||
|
@ -99,6 +99,8 @@ void loop() {
|
||||||
if (!(arduboy.nextFrame()))
|
if (!(arduboy.nextFrame()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
arduboy.pollButtons();
|
||||||
|
|
||||||
// draw screen if needed
|
// draw screen if needed
|
||||||
if (!screenInitialized) {
|
if (!screenInitialized) {
|
||||||
arduboy.clear();
|
arduboy.clear();
|
||||||
|
@ -138,15 +140,16 @@ void loop() {
|
||||||
case STATE_INVENTORY:
|
case STATE_INVENTORY:
|
||||||
drawStatusBar();
|
drawStatusBar();
|
||||||
drawTitle(F("Trenchcoat"));
|
drawTitle(F("Trenchcoat"));
|
||||||
|
buildDrugMenu(pInventory);
|
||||||
|
drawMenu(menuSmall, menuCols, menuLength, menu);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
screenInitialized = true;
|
screenInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle user input
|
// handle user input
|
||||||
arduboy.pollButtons();
|
// menu screens
|
||||||
switch (sGameState) {
|
switch (sGameState) {
|
||||||
// menu screens
|
|
||||||
case STATE_TITLE:
|
case STATE_TITLE:
|
||||||
case STATE_TURN_MENU:
|
case STATE_TURN_MENU:
|
||||||
case STATE_JET_MENU:
|
case STATE_JET_MENU:
|
||||||
|
@ -154,59 +157,67 @@ void loop() {
|
||||||
case STATE_SELL_MENU:
|
case STATE_SELL_MENU:
|
||||||
case STATE_FIGHT_MENU:
|
case STATE_FIGHT_MENU:
|
||||||
case STATE_SHARK_MENU:
|
case STATE_SHARK_MENU:
|
||||||
case STATE_BANK_MENU:
|
case STATE_BANK_MENU: {
|
||||||
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, true);
|
if (arduboy.justPressed(UP_BUTTON) ||
|
||||||
int col1Count = round(menuLength / 2.0);
|
arduboy.justPressed(DOWN_BUTTON) ||
|
||||||
int inCol = menuSelected < col1Count ? 1 : 2;
|
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)) {
|
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 {
|
|
||||||
menuSelected++;
|
menuSelected++;
|
||||||
}
|
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
|
||||||
if (menuSelected >= menuLength) menuSelected = menuLength - 1;
|
|
||||||
|
|
||||||
} else if (arduboy.justPressed(LEFT_BUTTON)) {
|
} else if (arduboy.justPressed(UP_BUTTON)) {
|
||||||
if (menuCols && inCol == 2) {
|
|
||||||
menuSelected -= col1Count;
|
|
||||||
} else {
|
|
||||||
menuSelected--;
|
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;
|
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
|
||||||
|
|
||||||
} 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);
|
|
||||||
break;
|
break;
|
||||||
case STATE_INVENTORY:
|
}
|
||||||
// TODO: not working
|
case STATE_INVENTORY: {
|
||||||
if (arduboy.justPressed(B_BUTTON)) {
|
if (arduboy.justPressed(B_BUTTON)) {
|
||||||
screenInitialized = false;
|
screenInitialized = false;
|
||||||
sGameState = STATE_TURN_MENU;
|
sGameState = STATE_TURN_MENU;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arduboy.display();
|
arduboy.display();
|
||||||
|
@ -216,19 +227,59 @@ void loop() {
|
||||||
/* screen draw heplers */
|
/* screen draw heplers */
|
||||||
/***********************/
|
/***********************/
|
||||||
void drawStatusBar() {
|
void drawStatusBar() {
|
||||||
const int chars = log10(pMoney);
|
if (sGameState == STATE_INVENTORY) {
|
||||||
const int x = 128 - (chars * 4);
|
const int chars = numberChars(pCapacity);
|
||||||
Sprites::drawOverwrite(x - 6, 1, spriteDollar, 0);
|
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);
|
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) {
|
void drawTitle(const String title) {
|
||||||
font4x6.setCursor(6, 11);
|
font4x6.setCursor(6, 12);
|
||||||
font4x6.print(title);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue