menu indicator movement
This commit is contained in:
parent
6f2afc4734
commit
d3bc64781b
7
menu.ino
7
menu.ino
|
@ -74,7 +74,8 @@ void drawMenu(const bool small, const bool cols,
|
|||
}
|
||||
|
||||
void drawMenuIndicator(const int menuSelected, const bool small,
|
||||
const bool cols, const int itemCount, const String items[]) {
|
||||
const bool cols, const int itemCount, const String items[],
|
||||
const bool clear) {
|
||||
const int charWidth = small ? 4 : 5;
|
||||
const int charHeight = small ? 8 : 9;
|
||||
int x1, x2, y;
|
||||
|
@ -91,5 +92,9 @@ void drawMenuIndicator(const int menuSelected, const bool small,
|
|||
cx = x1;
|
||||
cy = menuSelected * charHeight + y;
|
||||
}
|
||||
if (clear) {
|
||||
arduboy.fillRect(cx - 4, cy + (small ? 1 : 2), 3, 5, BLACK);
|
||||
} else {
|
||||
Sprites::drawOverwrite(cx - 4, cy + (small ? 1 : 2), spriteMenuCursor, 0);
|
||||
}
|
||||
}
|
||||
|
|
71
slangin.ino
71
slangin.ino
|
@ -5,8 +5,8 @@ License: WTFPL
|
|||
*/
|
||||
|
||||
#include <Arduboy2.h>
|
||||
#include "src/fonts/Font3x5.h";
|
||||
#include "src/fonts/Font4x6.h";
|
||||
#include "src/fonts/Font3x5.h"
|
||||
#include "src/fonts/Font4x6.h"
|
||||
|
||||
Arduboy2 arduboy;
|
||||
Font4x6 font4x6 = Font4x6();
|
||||
|
@ -16,7 +16,6 @@ enum GameState {
|
|||
STATE_TITLE = 0,
|
||||
STATE_TURN_MENU,
|
||||
STATE_JET_MENU,
|
||||
STATE_PRICE_LIST,
|
||||
STATE_INVENTORY,
|
||||
STATE_BUY_MENU,
|
||||
STATE_SELL_MENU,
|
||||
|
@ -72,6 +71,12 @@ int pCapacity;
|
|||
int pHealth;
|
||||
int pInventory[6] = {0};
|
||||
|
||||
String menu[8];
|
||||
int menuLength = 0;
|
||||
bool menuCols = false;
|
||||
bool menuSmall = false;
|
||||
int menuSelected = 0;
|
||||
|
||||
/***********************/
|
||||
/* game setup and loop */
|
||||
/***********************/
|
||||
|
@ -86,12 +91,7 @@ void loop() {
|
|||
if (!(arduboy.nextFrame()))
|
||||
return;
|
||||
|
||||
String menu[8];
|
||||
int menuLength = 0;
|
||||
bool menuCols = false;
|
||||
bool menuSmall = false;
|
||||
int menuSelected = 0;
|
||||
|
||||
// draw screen if needed
|
||||
if (!screenInitialized) {
|
||||
menuSelected = 0;
|
||||
arduboy.clear();
|
||||
|
@ -99,16 +99,59 @@ void loop() {
|
|||
case STATE_TITLE:
|
||||
arduboy.setCursor(25, 10);
|
||||
arduboy.print(F("Slangin' v0.9"));
|
||||
menu[0] = F("New Game");
|
||||
menuLength = 1;
|
||||
menu[0] = F("Cocaine 00000");
|
||||
menu[1] = F("Heroine 00000");
|
||||
menu[2] = F("Acid 0000");
|
||||
menu[3] = F("Weed 000");
|
||||
menu[4] = F("Speed 000");
|
||||
menu[5] = F("Ludes 00");
|
||||
menuLength = 6;
|
||||
menuSmall = false;
|
||||
menuCols = false;
|
||||
menuCols = true;
|
||||
drawMenu(menuSmall, menuCols, menuLength, menu);
|
||||
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu);
|
||||
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
|
||||
break;
|
||||
}
|
||||
arduboy.display();
|
||||
screenInitialized = true;
|
||||
}
|
||||
|
||||
// handle user input
|
||||
|
||||
arduboy.pollButtons();
|
||||
switch (sGameState) {
|
||||
// menu screens
|
||||
case STATE_TITLE:
|
||||
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 {
|
||||
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)) {
|
||||
} else if (arduboy.justPressed(B_BUTTON)) {
|
||||
}
|
||||
drawMenuIndicator(menuSelected, menuSmall, menuCols, menuLength, menu, false);
|
||||
break;
|
||||
}
|
||||
|
||||
arduboy.display();
|
||||
}
|
||||
|
||||
/***********************/
|
||||
|
|
Loading…
Reference in New Issue