slangin/slangin.ino

170 lines
3.6 KiB
C++

/*
Slangin'
Author: Rudis Muiznieks
License: WTFPL
*/
#include <Arduboy2.h>
#include "src/Font4x6.h";
Arduboy2 arduboy;
Font4x6 font4x6 = Font4x6();
enum GameState {
STATE_TITLE = 0,
STATE_TURN_MENU,
STATE_JET_MENU,
STATE_PRICE_LIST,
STATE_INVENTORY,
STATE_BUY_MENU,
STATE_SELL_MENU,
STATE_FIGHT_MENU,
STATE_SHARK_MENU,
STATE_BANK_MENU,
STATE_INFO_DIALOG,
STATE_QUESTION_DIALOG,
STATE_AMOUNT_DIALOG,
STATE_SUBWAY
};
enum GameLocation {
LOC_BRONX = 0,
LOC_GHETTO,
LOC_CENTRAL_PARK,
LOC_MANHATTEN,
LOC_CONEY_ISLAND,
LOC_BROOKLYN
};
enum Drug {
DRUG_COCAINE = 0,
DRUG_HEROINE,
DRUG_ACID,
DRUG_WEED,
DRUG_SPEED,
DRUG_LUDES
};
enum DialogType {
DIALOG_INFO = 0,
DIALOG_YESNO,
DIALOG_AMOUNT
};
/**************/
/* game state */
/**************/
bool screenInitialized;
GameState sGameState;
int sCurrentDay;
/****************/
/* player state */
/****************/
int pMoney;
int pLoanAmount;
int pSavingsAmount;
GameLocation pLocation;
int pGuns;
int pCapacity;
int pHealth;
int pInventory[6] = {0};
/***********************/
/* game setup and loop */
/***********************/
void setup() {
sGameState = STATE_TITLE;
screenInitialized = false;
arduboy.begin();
arduboy.setFrameRate(15);
}
void loop() {
if (!(arduboy.nextFrame()))
return;
String menu[8];
int menuLength = 0;
bool menuSmall = false;
if (!screenInitialized) {
arduboy.clear();
switch (sGameState) {
case STATE_TITLE:
drawTitle(F("Slangin'"));
menu[0] = F("New Game");
menu[1] = F("Continue");
menuLength = 2;
menuSmall = true;
draw1ColMenu(menuSmall, menuLength, menu);
break;
}
arduboy.display();
}
}
/***********************/
/* screen draw heplers */
/***********************/
void drawTitle(const String title) {
arduboy.setCursor(6, 8);
arduboy.print(title);
}
void draw1ColMenu(const bool small, const int itemCount, const String items[]) {
int colWidth = 0;
for (int i = 0; i < itemCount; i++) {
const int newLen = items[i].length();
if (newLen > colWidth) colWidth = newLen;
}
const int charWidth = small ? 5 : 6;
const int charHeight = small ? 9 : 10;
int x = 66 - round(colWidth * (charWidth / 2.0));
int y = 18 - round(itemCount * (charHeight / 2.0));
for (int i = 0; i < itemCount; i++) {
const int cy = i * charHeight + 22 + y;
if (small) {
font4x6.setCursor(x, cy);
font4x6.print(items[i]);
} else {
arduboy.setCursor(x, cy);
arduboy.print(items[i]);
}
}
}
void draw2ColMenu(const bool small, const int itemCount, const String items[]) {
const int col1Count = round(itemCount / 2.0);
const int col2Count = itemCount - col1Count;
int col1Width = 0;
int col2Width = 0;
for (int i = 0; i < col1Count; i++) {
const int newLen = items[i].length();
if (newLen > col1Width) col1Width = newLen;
}
for (int i = 0; i < col2Count; i++) {
const int newLen = items[i].length();
if (newLen > col2Width) col2Width = newLen;
}
const int charWidth = small ? 5 : 6;
const int charHeight = small ? 9 : 10;
int x = 66 - round((col1Width + col2Width + 2) * (charWidth / 2.0));
int y = 18 - round(col1Count * (charHeight / 2.0));
for (int i = 0; i < itemCount; i++) {
const int cx = (i < col1Count)
? x
: x + (col1Width + 2) * charWidth;
const int cy = (i < col1Count)
? i * charHeight + 22 + y
: (i - col1Count) * charHeight + 22 + y;
if (small) {
font4x6.setCursor(cx, cy);
font4x6.print(items[i]);
} else {
arduboy.setCursor(cx, cy);
arduboy.print(items[i]);
}
}
}