From d525f4eae5e0799ae61509cff845faf70caa8a04 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Tue, 12 Jul 2016 09:44:48 -0400 Subject: [PATCH 1/4] Use Arduboy2 library instead of custom library --- ArduboyCustom.cpp | 752 ---------------------------------------------- ArduboyCustom.h | 217 ------------- Globals.cpp | 2 +- Globals.h | 6 +- StarHonor.ino | 6 +- Vector2d.cpp | 2 +- coreCustom.cpp | 337 --------------------- coreCustom.h | 298 ------------------ 8 files changed, 8 insertions(+), 1612 deletions(-) delete mode 100644 ArduboyCustom.cpp delete mode 100644 ArduboyCustom.h delete mode 100644 coreCustom.cpp delete mode 100644 coreCustom.h diff --git a/ArduboyCustom.cpp b/ArduboyCustom.cpp deleted file mode 100644 index 2ff41b1..0000000 --- a/ArduboyCustom.cpp +++ /dev/null @@ -1,752 +0,0 @@ -#include "ArduboyCustom.h" -#include "glcdfont.c" -#include "ab_logo.c" - -ArduboyCustom::ArduboyCustom() -{ - // frame management - setFrameRate(60); - frameCount = 0; - nextFrameStart = 0; - post_render = false; - - // init not necessary, will be reset after first use - // lastFrameStart - // lastFrameDurationMs -} - -void ArduboyCustom::start() // deprecated -{ - begin(); -} - -// functions called here should be public so users can create their -// own init functions if they need different behavior than `begin` -// provides by default -void ArduboyCustom::begin() -{ - boot(); // raw hardware - - // utils -// if(pressed(UP_BUTTON)) { -// flashlight(); -// } - -// bootLogo(); - -// audio.begin(); -} - -void ArduboyCustom::flashlight() -{ - // sendLCDCommand(OLED_ALL_PIXELS_ON); // smaller than allPixelsOn() - blank(); - setRGBled(255,255,255); - while(!pressed(DOWN_BUTTON)) { - idle(); - } - setRGBled(0,0,0); -} - -void ArduboyCustom::bootLogo() -{ - // setRGBled(10,0,0); - for(int8_t y = -18; y<=24; y++) { - setRGBled(24-y, 0, 0); - - clear(); - drawBitmap(20,y, arduboy_logo, 88, 16, WHITE); - display(); - delay(27); - // longer delay post boot, we put it inside the loop to - // save the flash calling clear/delay again outside the loop - if (y==-16) { - delay(250); - } - } - - delay(750); - setRGBled(0,0,0); -} - -/* Frame management */ - -void ArduboyCustom::setFrameRate(uint8_t rate) -{ - frameRate = rate; - eachFrameMillis = 1000/rate; -} - -bool ArduboyCustom::everyXFrames(uint8_t frames) -{ - return frameCount % frames == 0; -} - -bool ArduboyCustom::nextFrame() -{ - long now = millis(); - uint8_t remaining; - - // post render - if (post_render) { - lastFrameDurationMs = now - lastFrameStart; - frameCount++; - post_render = false; - } - - // if it's not time for the next frame yet - if (now < nextFrameStart) { - remaining = nextFrameStart - now; - // if we have more than 1ms to spare, lets sleep - // we should be woken up by timer0 every 1ms, so this should be ok - if (remaining > 1) - idle(); - return false; - } - - // pre-render - - // next frame should start from last frame start + frame duration - nextFrameStart = lastFrameStart + eachFrameMillis; - // If we're running CPU at 100%+ (too slow to complete each loop within - // the frame duration) then it's possible that we get "behind"... Say we - // took 5ms too long, resulting in nextFrameStart being 5ms in the PAST. - // In that case we simply schedule the next frame to start immediately. - // - // If we were to let the nextFrameStart slide further and further into - // the past AND eventually the CPU usage dropped then frame management - // would try to "catch up" (by speeding up the game) to make up for all - // that lost time. That would not be good. We allow frames to take too - // long (what choice do we have?), but we do not allow super-fast frames - // to make up for slow frames in the past. - if (nextFrameStart < now) { - nextFrameStart = now; - } - - lastFrameStart = now; - - post_render = true; - return post_render; -} - -int ArduboyCustom::cpuLoad() -{ - return lastFrameDurationMs*100 / eachFrameMillis; -} - -void ArduboyCustom::initRandomSeed() -{ - power_adc_enable(); // ADC on - randomSeed(~rawADC(ADC_TEMP) * ~rawADC(ADC_VOLTAGE) * ~micros() + micros()); - power_adc_disable(); // ADC off -} - -uint16_t ArduboyCustom::rawADC(byte adc_bits) -{ - ADMUX = adc_bits; - // we also need MUX5 for temperature check - if (adc_bits == ADC_TEMP) { - ADCSRB = _BV(MUX5); - } - - delay(2); // Wait for ADMUX setting to settle - ADCSRA |= _BV(ADSC); // Start conversion - while (bit_is_set(ADCSRA,ADSC)); // measuring - - return ADC; -} - -/* Graphics */ - -void ArduboyCustom::clearDisplay() // deprecated -{ - clear(); -} - -void ArduboyCustom::clear() -{ - fillScreen(BLACK); -} - -void ArduboyCustom::drawPixel(int x, int y, uint8_t color) -{ - #ifdef PIXEL_SAFE_MODE - if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1)) - { - return; - } - #endif - - uint8_t row = (uint8_t)y / 8; - if (color) - { - sBuffer[(row*WIDTH) + (uint8_t)x] |= _BV((uint8_t)y % 8); - } - else - { - sBuffer[(row*WIDTH) + (uint8_t)x] &= ~ _BV((uint8_t)y % 8); - } -} - -uint8_t ArduboyCustom::getPixel(uint8_t x, uint8_t y) -{ - uint8_t row = y / 8; - uint8_t bit_position = y % 8; - return (sBuffer[(row*WIDTH) + x] & _BV(bit_position)) >> bit_position; -} - -void ArduboyCustom::drawCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color) -{ - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - drawPixel(x0, y0+r, color); - drawPixel(x0, y0-r, color); - drawPixel(x0+r, y0, color); - drawPixel(x0-r, y0, color); - - while (x= 0) - { - y--; - ddF_y += 2; - f += ddF_y; - } - - x++; - ddF_x += 2; - f += ddF_x; - - drawPixel(x0 + x, y0 + y, color); - drawPixel(x0 - x, y0 + y, color); - drawPixel(x0 + x, y0 - y, color); - drawPixel(x0 - x, y0 - y, color); - drawPixel(x0 + y, y0 + x, color); - drawPixel(x0 - y, y0 + x, color); - drawPixel(x0 + y, y0 - x, color); - drawPixel(x0 - y, y0 - x, color); - } -} - -void ArduboyCustom::drawCircleHelper -(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, uint8_t color) -{ - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - while (x= 0) - { - y--; - ddF_y += 2; - f += ddF_y; - } - - x++; - ddF_x += 2; - f += ddF_x; - - if (cornername & 0x4) - { - drawPixel(x0 + x, y0 + y, color); - drawPixel(x0 + y, y0 + x, color); - } - if (cornername & 0x2) - { - drawPixel(x0 + x, y0 - y, color); - drawPixel(x0 + y, y0 - x, color); - } - if (cornername & 0x8) - { - drawPixel(x0 - y, y0 + x, color); - drawPixel(x0 - x, y0 + y, color); - } - if (cornername & 0x1) - { - drawPixel(x0 - y, y0 - x, color); - drawPixel(x0 - x, y0 - y, color); - } - } -} - -void ArduboyCustom::fillCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color) -{ - drawFastVLine(x0, y0-r, 2*r+1, color); - fillCircleHelper(x0, y0, r, 3, 0, color); -} - -void ArduboyCustom::fillCircleHelper -(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, int16_t delta, - uint8_t color) -{ - // used to do circles and roundrects! - int16_t f = 1 - r; - int16_t ddF_x = 1; - int16_t ddF_y = -2 * r; - int16_t x = 0; - int16_t y = r; - - while (x < y) - { - if (f >= 0) - { - y--; - ddF_y += 2; - f += ddF_y; - } - - x++; - ddF_x += 2; - f += ddF_x; - - if (cornername & 0x1) - { - drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); - drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); - } - - if (cornername & 0x2) - { - drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); - drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); - } - } -} - -void ArduboyCustom::drawLine -(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color) -{ - // bresenham's algorithm - thx wikpedia - boolean steep = abs(y1 - y0) > abs(x1 - x0); - if (steep) { - swap(x0, y0); - swap(x1, y1); - } - - if (x0 > x1) { - swap(x0, x1); - swap(y0, y1); - } - - int16_t dx, dy; - dx = x1 - x0; - dy = abs(y1 - y0); - - int16_t err = dx / 2; - int8_t ystep; - - if (y0 < y1) - { - ystep = 1; - } - else - { - ystep = -1; - } - - for (; x0 <= x1; x0++) - { - if (steep) - { - drawPixel(y0, x0, color); - } - else - { - drawPixel(x0, y0, color); - } - - err -= dy; - if (err < 0) - { - y0 += ystep; - err += dx; - } - } -} - -void ArduboyCustom::drawRect -(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color) -{ - drawFastHLine(x, y, w, color); - drawFastHLine(x, y+h-1, w, color); - drawFastVLine(x, y, h, color); - drawFastVLine(x+w-1, y, h, color); -} - -void ArduboyCustom::drawFastVLine -(int16_t x, int16_t y, uint8_t h, uint8_t color) -{ - int end = y+h; - for (int a = max(0,y); a < min(end,HEIGHT); a++) - { - drawPixel(x,a,color); - } -} - -void ArduboyCustom::drawFastHLine -(int16_t x, int16_t y, uint8_t w, uint8_t color) -{ - // Do bounds/limit checks - if (y < 0 || y >= HEIGHT) { - return; - } - - // make sure we don't try to draw below 0 - if (x < 0) { - w += x; - x = 0; - } - - // make sure we don't go off the edge of the display - if ((x + w) > WIDTH) { - w = (WIDTH - x); - } - - // if our width is now negative, punt - if (w <= 0) { - return; - } - - // buffer pointer plus row offset + x offset - register uint8_t *pBuf = sBuffer + ((y/8) * WIDTH) + x; - - // pixel mask - register uint8_t mask = 1 << (y&7); - - switch (color) - { - case WHITE: - while(w--) { - *pBuf++ |= mask; - }; - break; - - case BLACK: - mask = ~mask; - while(w--) { - *pBuf++ &= mask; - }; - break; - } -} - -void ArduboyCustom::fillRect -(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color) -{ - // stupidest version - update in subclasses if desired! - for (int16_t i=x; i= y1 >= y0) - if (y0 > y1) - { - swap(y0, y1); swap(x0, x1); - } - if (y1 > y2) - { - swap(y2, y1); swap(x2, x1); - } - if (y0 > y1) - { - swap(y0, y1); swap(x0, x1); - } - - if(y0 == y2) - { // Handle awkward all-on-same-line case as its own thing - a = b = x0; - if(x1 < a) - { - a = x1; - } - else if(x1 > b) - { - b = x1; - } - if(x2 < a) - { - a = x2; - } - else if(x2 > b) - { - b = x2; - } - drawFastHLine(a, y0, b-a+1, color); - return; - } - - int16_t dx01 = x1 - x0, - dy01 = y1 - y0, - dx02 = x2 - x0, - dy02 = y2 - y0, - dx12 = x2 - x1, - dy12 = y2 - y1, - sa = 0, - sb = 0; - - // For upper part of triangle, find scanline crossings for segments - // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 - // is included here (and second loop will be skipped, avoiding a /0 - // error there), otherwise scanline y1 is skipped here and handled - // in the second loop...which also avoids a /0 error here if y0=y1 - // (flat-topped triangle). - if (y1 == y2) - { - last = y1; // Include y1 scanline - } - else - { - last = y1-1; // Skip it - } - - - for(y = y0; y <= last; y++) - { - a = x0 + sa / dy01; - b = x0 + sb / dy02; - sa += dx01; - sb += dx02; - - if(a > b) - { - swap(a,b); - } - - drawFastHLine(a, y, b-a+1, color); - } - - // For lower part of triangle, find scanline crossings for segments - // 0-2 and 1-2. This loop is skipped if y1=y2. - sa = dx12 * (y - y1); - sb = dx02 * (y - y0); - - for(; y <= y2; y++) - { - a = x1 + sa / dy12; - b = x0 + sb / dy02; - sa += dx12; - sb += dx02; - - if(a > b) - { - swap(a,b); - } - - drawFastHLine(a, y, b-a+1, color); - } -} - -void ArduboyCustom::drawBitmap -(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, - uint8_t color) -{ - // no need to dar at all of we're offscreen - if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1) - return; - - int yOffset = abs(y) % 8; - int sRow = y / 8; - if (y < 0) { - sRow--; - yOffset = 8 - yOffset; - } - int rows = h/8; - if (h%8!=0) rows++; - for (int a = 0; a < rows; a++) { - int bRow = sRow + a; - if (bRow > (HEIGHT/8)-1) break; - if (bRow > -2) { - for (int iCol = 0; iCol (WIDTH-1)) break; - if (iCol + x >= 0) { - if (bRow >= 0) { - if (color == WHITE) this->sBuffer[ (bRow*WIDTH) + x + iCol ] |= pgm_read_byte(bitmap+(a*w)+iCol) << yOffset; - else if (color == BLACK) this->sBuffer[ (bRow*WIDTH) + x + iCol ] &= ~(pgm_read_byte(bitmap+(a*w)+iCol) << yOffset); - else this->sBuffer[ (bRow*WIDTH) + x + iCol ] ^= pgm_read_byte(bitmap+(a*w)+iCol) << yOffset; - } - if (yOffset && bRow<(HEIGHT/8)-1 && bRow > -2) { - if (color == WHITE) this->sBuffer[ ((bRow+1)*WIDTH) + x + iCol ] |= pgm_read_byte(bitmap+(a*w)+iCol) >> (8-yOffset); - else if (color == BLACK) this->sBuffer[ ((bRow+1)*WIDTH) + x + iCol ] &= ~(pgm_read_byte(bitmap+(a*w)+iCol) >> (8-yOffset)); - else this->sBuffer[ ((bRow+1)*WIDTH) + x + iCol ] ^= pgm_read_byte(bitmap+(a*w)+iCol) >> (8-yOffset); - } - } - } - } - } -} - - -void ArduboyCustom::drawSlowXYBitmap -(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color) -{ - // no need to dar at all of we're offscreen - if (x+w < 0 || x > WIDTH-1 || y+h < 0 || y > HEIGHT-1) - return; - - int16_t xi, yi, byteWidth = (w + 7) / 8; - for(yi = 0; yi < h; yi++) { - for(xi = 0; xi < w; xi++ ) { - if(pgm_read_byte(bitmap + yi * byteWidth + xi / 8) & (128 >> (xi & 7))) { - drawPixel(x + xi, y + yi, color); - } - } - } -} - - -void ArduboyCustom::drawChar -(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size) -{ - boolean draw_background = bg != color; - - if ((x >= WIDTH) || // Clip right - (y >= HEIGHT) || // Clip bottom - ((x + 5 * size - 1) < 0) || // Clip left - ((y + 8 * size - 1) < 0) // Clip top - ) - { - return; - } - - for (int8_t i=0; i<6; i++ ) - { - uint8_t line; - if (i == 5) - { - line = 0x0; - } - else - { - line = pgm_read_byte(font+(c*5)+i); - } - - for (int8_t j = 0; j<8; j++) - { - uint8_t draw_color = (line & 0x1) ? color : bg; - - if (draw_color || draw_background) { - for (uint8_t a = 0; a < size; a++ ) { - for (uint8_t b = 0; b < size; b++ ) { - drawPixel(x + (i * size) + a, y + (j * size) + b, draw_color); - } - } - } - line >>= 1; - } - } -} - -void ArduboyCustom::display() -{ - this->paintScreen(sBuffer); -} - -unsigned char* ArduboyCustom::getBuffer() -{ - return sBuffer; -} - -boolean ArduboyCustom::pressed(uint8_t buttons) -{ - return (buttonsState() & buttons) == buttons; -} - -boolean ArduboyCustom::notPressed(uint8_t buttons) -{ - return (buttonsState() & buttons) == 0; -} - -void ArduboyCustom::swap(int16_t& a, int16_t& b) -{ - int temp = a; - a = b; - b = temp; -} - diff --git a/ArduboyCustom.h b/ArduboyCustom.h deleted file mode 100644 index e569fd2..0000000 --- a/ArduboyCustom.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef Arduboy_h -#define Arduboy_h - -#include "coreCustom.h" -#include "ab_printer.h" -#include -#include - -// Library version. -// For a version number in the form of x.y.z the value of the define will be -// ((x * 10000) + (y * 100) + (z)) as a decimal number. -// So, it will read as xxxyyzz, with no leading zeros on x. -#define ARDUBOY_LIB_VER 10200 - -// EEPROM settings -#define EEPROM_VERSION 0 -#define EEPROM_BRIGHTNESS 1 -#define EEPROM_AUDIO_ON_OFF 2 - -// we reserve the first 16 byte of EEPROM for system use -#define EEPROM_STORAGE_SPACE_START 16 // and onward - -// eeprom settings above are neded for audio -#include "audio/audio.h" - -#define PIXEL_SAFE_MODE - -// pixel colors -#define INVERT 2 //< lit/unlit pixel -#define WHITE 1 //< lit pixel -#define BLACK 0 //< unlit pixel - -// compare Vcc to 1.1 bandgap -#define ADC_VOLTAGE (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1)) -// compare temperature to 2.5 internal reference and _BV(MUX5) -#define ADC_TEMP (_BV(REFS0) | _BV(REFS1) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)) - - -class ArduboyCustom : public ArduboyCoreCustom -{ -public: - ArduboyCustom(); - - /// Returns true if the button mask passed in is pressed. - /** - * if (pressed(LEFT_BUTTON + A_BUTTON)) - */ - boolean pressed(uint8_t buttons); - - /// Returns true if the button mask passed in not pressed. - /** - * if (notPressed(LEFT_BUTTON)) - */ - boolean notPressed(uint8_t buttons); - - /// Initialize hardware, boot logo, boot utilities, etc. - void begin(); - - /// Init just hardware, no logo, no boot utilities. - /** - * Look at the source for `begin()` and just rip out what you do not - * need and start there. Calling just `boot()` might work also - * depending on your requirements. - * - * The minimum recommended `begin` replacement: - * - * arduboy.boot() // raw hardware init - * arduboy.audio.begin() // if you need audio - */ - // void boot(); // defined in core.cpp - - void start() __attribute__((deprecated, warning("use begin() instead"))); - - /// Scrolls in the Arduboy logo - void bootLogo(); - - /// Flashlight mode - /** - * Hold up key when booting to enable, press down key to exit - * or simply turn off your Arduboy. Your sketches can also - * call this at any time. It goes into a tight loop until the - * down buttn is pressed. - */ - void flashlight(); - - /// Clears display. - void clear(); - void clearDisplay() __attribute__((deprecated, warning("use clear() instead"))); - - /// Copies the contents of the screen buffer to the screen. - /** - * X and Y positions on the display are from the top left corner, thus a Y of 64 - * is the bottom of the screen and an X of 128 is the right side of the screen. - * "Color" or "value" means choosing whether a pixel is lit or not - if color is - * 0, the pixel is off (black), if color is 1, the pixel is on (white). - */ - void display(); - - /// Sets a single pixel on the screen buffer to white or black. - void drawPixel(int x, int y, uint8_t color); - - uint8_t getPixel(uint8_t x, uint8_t y); - - /// Draw a circle of a defined radius. - /** - * Draws a circle in white or black. X and Y are the center point of the circle. - */ - void drawCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color); - - /// Draws one or more "corners" of a circle. - void drawCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, uint8_t color); - - /// Draws a filled-in circle. - void fillCircle(int16_t x0, int16_t y0, uint8_t r, uint8_t color); - - /// Draws one or both vertical halves of a filled-in circle. - void fillCircleHelper(int16_t x0, int16_t y0, uint8_t r, uint8_t cornername, int16_t delta, uint8_t color); - - /// Draws a line between two points. - /** - * Uses Bresenham's algorithm. - */ - void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t color); - - /// Draws a rectangle of a width and height. - void drawRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color); - - /// Draws vertical line. - void drawFastVLine(int16_t x, int16_t y, uint8_t h, uint8_t color); - - /// Draws a horizontal line. - void drawFastHLine(int16_t x, int16_t y, uint8_t w, uint8_t color); - - /// Draws a filled-in rectangle. - void fillRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color); - - /// Fills the screen buffer with white or black. - void fillScreen(uint8_t color); - - /// Draws a rectangle with rounded edges. - void drawRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color); - - /// Draws a filled-in rectangle with rounded edges. - void fillRoundRect(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color); - - /// Draws the outline of a triangle. - void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); - - /// Draws a filled-in triangle. - void fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); - - /// Draws a bitmap from program memory to a specific X/Y - void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color); - - /// Draws images that are bit-oriented horizontally. - /** - * This requires a lot of additional CPU power and will draw images slower - * than drawBitmap, where the images are stored in a format that - * allows them to be directly written to the screen. It is - * recommended you use drawBitmap when possible. - */ - void drawSlowXYBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t w, uint8_t h, uint8_t color); - - /// Draws an ASCII character at a point. - void drawChar(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size); - - unsigned char* getBuffer(); - - - /// Seeds the random number generator with entropy from the temperature, voltage reading, and microseconds since boot. - /** - * This method is still most effective when called semi-randomly such - * as after a user hits a button to start a game or other semi-random - * events - */ - void initRandomSeed(); - - /// Swap the references of two pointers. - void swap(int16_t& a, int16_t& b); - - ArduboyAudio audio; - - void setFrameRate(uint8_t rate); - bool nextFrame(); - bool everyXFrames(uint8_t frames); - - /// Returns the load on the CPU as a percentage. - /** - * This is based on how much of the time your app is spends rendering - * frames. This number can be higher than 100 if your app is rendering - * really slowly. - */ - int cpuLoad(); - - uint8_t frameRate; - uint16_t frameCount; - uint8_t eachFrameMillis; - long lastFrameStart; - long nextFrameStart; - bool post_render; - uint8_t lastFrameDurationMs; - - /// useful for getting raw approximate voltage values - uint16_t rawADC(byte adc_bits); - -protected: - unsigned char sBuffer[(HEIGHT*WIDTH)/8]; - - -protected: - int16_t cursor_x; - int16_t cursor_y; - uint8_t textsize; - boolean wrap; // If set, 'wrap' text at right edge of display -}; - -#endif diff --git a/Globals.cpp b/Globals.cpp index d18fb38..c7fb726 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -1,6 +1,6 @@ #include "Globals.h" -ArduboyCustom arduboy; +Arduboy2Base arduboy; //int FPS = 60; float LastUpdateTime = 0; diff --git a/Globals.h b/Globals.h index fb014c3..7b9f0a9 100644 --- a/Globals.h +++ b/Globals.h @@ -3,13 +3,13 @@ #pragma once -#include "ArduboyCustom.h" +#include #include "bitmaps.h" #include "Vector2d.h" -#define PI 3.14159265 +//#define PI 3.14159265 -extern ArduboyCustom arduboy; +extern Arduboy2Base arduboy; //extern int FPS; extern float LastUpdateTime; diff --git a/StarHonor.ino b/StarHonor.ino index bd9af5e..5dd11f8 100644 --- a/StarHonor.ino +++ b/StarHonor.ino @@ -1,7 +1,7 @@ #include #include -#include "ArduboyCustom.h" +#include #include "Globals.h" #include "GUI.h" #include "StarField.h" @@ -22,7 +22,7 @@ void setup() { #endif MilliPerFrame = 1000.0f / 60.0f; - arduboy.start(); + arduboy.boot(); arduboy.display(); arduboy.initRandomSeed(); @@ -63,7 +63,7 @@ void loop() DeltaTime = ( millis() - LastUpdateTime ) / 1000.0f; LastUpdateTime = millis(); - arduboy.clearDisplay(); + arduboy.clear(); // AbPrinter text(arduboy); // text.print("Hello"); GetInput(); diff --git a/Vector2d.cpp b/Vector2d.cpp index 24f7d43..ceae683 100644 --- a/Vector2d.cpp +++ b/Vector2d.cpp @@ -1,5 +1,5 @@ #include "Vector2d.h" -#include "ArduboyCustom.h" +#include //#define Deg2Rad( Deg ) { Deg * PI / 180 }; diff --git a/coreCustom.cpp b/coreCustom.cpp deleted file mode 100644 index 6e44011..0000000 --- a/coreCustom.cpp +++ /dev/null @@ -1,337 +0,0 @@ -#include "coreCustom.h" - -// need to redeclare these here since we declare them static in .h -volatile uint8_t *ArduboyCoreCustom::csport, *ArduboyCoreCustom::dcport; -uint8_t ArduboyCoreCustom::cspinmask, ArduboyCoreCustom::dcpinmask; - -const uint8_t PROGMEM pinBootProgram[] = { - // buttons - PIN_LEFT_BUTTON, INPUT_PULLUP, - PIN_RIGHT_BUTTON, INPUT_PULLUP, - PIN_UP_BUTTON, INPUT_PULLUP, - PIN_DOWN_BUTTON, INPUT_PULLUP, - PIN_A_BUTTON, INPUT_PULLUP, - PIN_B_BUTTON, INPUT_PULLUP, - - // audio is specifically not included here as those pins are handled - // separately by `audio.begin()`, `audio.on()` and `audio.off()` in order - // to respect the EEPROM audio settings - - // OLED SPI - DC, OUTPUT, - CS, OUTPUT, - RST, OUTPUT, - 0 -}; - -const uint8_t PROGMEM lcdBootProgram[] = { - // boot defaults are commented out but left here incase they - // might prove useful for reference - // - // Further reading: https://www.adafruit.com/datasheets/SSD1306.pdf - // - // Display Off - // 0xAE, - - // Set Display Clock Divisor v = 0xF0 - // default is 0x80 - 0xD5, 0xF0, - - // Set Multiplex Ratio v = 0x3F - // 0xA8, 0x3F, - - // Set Display Offset v = 0 - // 0xD3, 0x00, - - // Set Start Line (0) - // 0x40, - - // Charge Pump Setting v = enable (0x14) - // default is disabled - 0x8D, 0x14, - - // Set Segment Re-map (A0) | (b0001) - // default is (b0000) - 0xA1, - - // Set COM Output Scan Direction - 0xC8, - - // Set COM Pins v - // 0xDA, 0x12, - - // Set Contrast v = 0xCF - 0x81, 0xCF, - - // Set Precharge = 0xF1 - 0xD9, 0xF1, - - // Set VCom Detect - // 0xDB, 0x40, - - // Entire Display ON - // 0xA4, - - // Set normal/inverse display - // 0xA6, - - // Display On - 0xAF, - - // set display mode = horizontal addressing mode (0x00) - 0x20, 0x00, - - // set col address range - // 0x21, 0x00, COLUMN_ADDRESS_END, - - // set page address range - // 0x22, 0x00, PAGE_ADDRESS_END -}; - - -ArduboyCoreCustom::ArduboyCoreCustom() {} - -void ArduboyCoreCustom::boot() -{ - #ifdef ARDUBOY_SET_CPU_8MHZ - // ARDUBOY_SET_CPU_8MHZ will be set by the IDE using boards.txt - setCPUSpeed8MHz(); - #endif - - SPI.begin(); - bootPins(); - bootOLED(); - - #ifdef SAFE_MODE - if (buttonsState() == (LEFT_BUTTON | UP_BUTTON)) - safeMode(); - #endif - - bootPowerSaving(); -} - -#ifdef ARDUBOY_SET_CPU_8MHZ -// If we're compiling for 8MHz we need to slow the CPU down because the -// hardware clock on the Arduboy is 16MHz. -// We also need to readjust the PLL prescaler because the Arduino USB code -// likely will have incorrectly set it for an 8MHz hardware clock. -void ArduboyCoreCustom::setCPUSpeed8MHz() -{ - uint8_t oldSREG = SREG; - cli(); // suspend interrupts - PLLCSR = _BV(PINDIV); // dissable the PLL and set prescale for 16MHz) - CLKPR = _BV(CLKPCE); // allow reprogramming clock - CLKPR = 1; // set clock divisor to 2 (0b0001) - PLLCSR = _BV(PLLE) | _BV(PINDIV); // enable the PLL (with 16MHz prescale) - SREG = oldSREG; // restore interrupts -} -#endif - -void ArduboyCoreCustom::bootPins() -{ - uint8_t pin, mode; - const uint8_t *i = pinBootProgram; - - while(true) { - pin = pgm_read_byte(i++); - mode = pgm_read_byte(i++); - if (pin==0) break; - pinMode(pin, mode); - } - - digitalWrite(RST, HIGH); - delay(1); // VDD (3.3V) goes high at start, lets just chill for a ms - digitalWrite(RST, LOW); // bring reset low - delay(10); // wait 10ms - digitalWrite(RST, HIGH); // bring out of reset -} - -void ArduboyCoreCustom::bootOLED() -{ - // setup the ports we need to talk to the OLED - csport = portOutputRegister(digitalPinToPort(CS)); - cspinmask = digitalPinToBitMask(CS); - dcport = portOutputRegister(digitalPinToPort(DC)); - dcpinmask = digitalPinToBitMask(DC); - - SPI.setClockDivider(SPI_CLOCK_DIV2); - - LCDCommandMode(); - // run our customized boot-up command sequence against the - // OLED to initialize it properly for Arduboy - for (int8_t i=0; i < sizeof(lcdBootProgram); i++) { - SPI.transfer(pgm_read_byte(lcdBootProgram + i)); - } - LCDDataMode(); -} - -void ArduboyCoreCustom::LCDDataMode() -{ - *dcport |= dcpinmask; - *csport &= ~cspinmask; -} - -void ArduboyCoreCustom::LCDCommandMode() -{ - *csport |= cspinmask; - *dcport &= ~dcpinmask; - *csport &= ~cspinmask; -} - - - -void ArduboyCoreCustom::safeMode() -{ - blank(); // too avoid random gibberish - while (true) { - asm volatile("nop \n"); - } -} - - -/* Power Management */ - -void ArduboyCoreCustom::idle() -{ - set_sleep_mode(SLEEP_MODE_IDLE); - sleep_mode(); -} - -void ArduboyCoreCustom::bootPowerSaving() -{ - power_adc_disable(); - power_usart0_disable(); - power_twi_disable(); - // timer 0 is for millis() - // timers 1 and 3 are for music and sounds - power_timer2_disable(); - power_usart1_disable(); - // we need USB, for now (to allow triggered reboots to reprogram) - // power_usb_disable() -} - -uint8_t ArduboyCoreCustom::width() { return WIDTH; } - -uint8_t ArduboyCoreCustom::height() { return HEIGHT; } - - -/* Drawing */ - -void ArduboyCoreCustom::paint8Pixels(uint8_t pixels) -{ - SPI.transfer(pixels); -} - -void ArduboyCoreCustom::paintScreen(const unsigned char *image) -{ - for (int i = 0; i < (HEIGHT*WIDTH)/8; i++) - { - SPI.transfer(pgm_read_byte(image + i)); - } -} - -// paint from a memory buffer, this should be FAST as it's likely what -// will be used by any buffer based subclass -void ArduboyCoreCustom::paintScreen(unsigned char image[]) -{ - for (int i = 0; i < (HEIGHT*WIDTH)/8; i++) - { - // SPI.transfer(image[i]); - - // we need to burn 18 cycles between sets of SPDR - // 4 clock cycles - SPDR = image[i]; - // 7 clock cycles - asm volatile( - "mul __zero_reg__, __zero_reg__ \n" // 2 cycles - "mul __zero_reg__, __zero_reg__ \n" // 2 cycles - "mul __zero_reg__, __zero_reg__ \n" // 2 cycles - ); - } -} - -void ArduboyCoreCustom::blank() -{ - for (int i = 0; i < (HEIGHT*WIDTH)/8; i++) - SPI.transfer(0x00); -} - -void ArduboyCoreCustom::sendLCDCommand(uint8_t command) -{ - LCDCommandMode(); - SPI.transfer(command); - LCDDataMode(); -} - -// invert the display or set to normal -// when inverted, a pixel set to 0 will be on -void ArduboyCoreCustom::invert(bool inverse) -{ - sendLCDCommand(inverse ? OLED_PIXELS_INVERTED : OLED_PIXELS_NORMAL); -} - -// turn all display pixels on, ignoring buffer contents -// or set to normal buffer display -void ArduboyCoreCustom::allPixelsOn(bool on) -{ - sendLCDCommand(on ? OLED_ALL_PIXELS_ON : OLED_PIXELS_FROM_RAM); -} - -// flip the display vertically or set to normal -void ArduboyCoreCustom::flipVertical(bool flipped) -{ - sendLCDCommand(flipped ? OLED_VERTICAL_FLIPPED : OLED_VERTICAL_NORMAL); -} - -// flip the display horizontally or set to normal -void ArduboyCoreCustom::flipHorizontal(bool flipped) -{ - sendLCDCommand(flipped ? OLED_HORIZ_FLIPPED : OLED_HORIZ_NORMAL); -} - -/* RGB LED */ - -void ArduboyCoreCustom::setRGBled(uint8_t red, uint8_t green, uint8_t blue) -{ -#ifdef ARDUBOY_10 // RGB, all the pretty colors - // inversion is necessary because these are common annode LEDs - analogWrite(RED_LED, 255 - red); - analogWrite(GREEN_LED, 255 - green); - analogWrite(BLUE_LED, 255 - blue); -#elif defined(AB_DEVKIT) - // only blue on devkit - digitalWrite(BLUE_LED, ~blue); -#endif -} - -/* Buttons */ - -uint8_t ArduboyCoreCustom::getInput() -{ - return buttonsState(); -} - - -uint8_t ArduboyCoreCustom::buttonsState() -{ - uint8_t buttons; - - // using ports here is ~100 bytes smaller than digitalRead() -#ifdef AB_DEVKIT - // down, left, up - buttons = ((~PINB) & B01110000); - // right button - buttons = buttons | (((~PINC) & B01000000) >> 4); - // A and B - buttons = buttons | (((~PINF) & B11000000) >> 6); -#elif defined(ARDUBOY_10) - // down, up, left right - buttons = ((~PINF) & B11110000); - // A (left) - buttons = buttons | (((~PINE) & B01000000) >> 3); - // B (right) - buttons = buttons | (((~PINB) & B00010000) >> 2); -#endif - - return buttons; -} diff --git a/coreCustom.h b/coreCustom.h deleted file mode 100644 index 9485890..0000000 --- a/coreCustom.h +++ /dev/null @@ -1,298 +0,0 @@ -#ifndef ArduboyCoreCustom_h -#define ArduboyCoreCustom_h - -#include -#include -#include -#include - - -// main hardware compile flags - -#if !defined(ARDUBOY_10) && !defined(AB_DEVKIT) -/// defaults to Arduboy Release 1.0 if not using a boards.txt file -/** - * we default to Arduboy Release 1.0 if a compile flag has not been - * passed to us from a boards.txt file - * - * if you wish to compile for the devkit without using a boards.txt - * file simply comment out the ARDUBOY_10 define and uncomment - * the AB_DEVKIT define like this: - * - * // #define ARDUBOY_10 - * #define AB_DEVKIT - */ -#define ARDUBOY_10 //< compile for the production Arduboy v1.0 -// #define AB_DEVKIT //< compile for the official dev kit -#endif - - -#ifdef AB_DEVKIT -#define DEVKIT //< for compatibilty with older sketches -#define SAFE_MODE //< include safe mode (44 bytes) -#endif - - -#ifdef ARDUBOY_10 - -#define CS 12 -#define DC 4 -#define RST 6 - -#define RED_LED 10 -#define GREEN_LED 11 -#define BLUE_LED 9 -#define TX_LED 30 -#define RX_LED 17 - -// pin values for buttons, probably shouldn't use these -#define PIN_LEFT_BUTTON A2 -#define PIN_RIGHT_BUTTON A1 -#define PIN_UP_BUTTON A0 -#define PIN_DOWN_BUTTON A3 -#define PIN_A_BUTTON 7 -#define PIN_B_BUTTON 8 - -// bit values for button states -#define LEFT_BUTTON _BV(5) -#define RIGHT_BUTTON _BV(6) -#define UP_BUTTON _BV(7) -#define DOWN_BUTTON _BV(4) -#define A_BUTTON _BV(3) -#define B_BUTTON _BV(2) - -#define PIN_SPEAKER_1 5 -#define PIN_SPEAKER_2 13 - -#define PIN_SPEAKER_1_PORT &PORTC -#define PIN_SPEAKER_2_PORT &PORTC - -#define PIN_SPEAKER_1_BITMASK _BV(6) -#define PIN_SPEAKER_2_BITMASK _BV(7) - -#elif defined(AB_DEVKIT) - -#define CS 6 -#define DC 4 -#define RST 12 - -// map all LEDs to the single TX LED on DEVKIT -#define RED_LED 17 -#define GREEN_LED 17 -#define BLUE_LED 17 -#define TX_LED 17 -#define RX_LED 17 - -// pin values for buttons, probably shouldn't use these -#define PIN_LEFT_BUTTON 9 -#define PIN_RIGHT_BUTTON 5 -#define PIN_UP_BUTTON 8 -#define PIN_DOWN_BUTTON 10 -#define PIN_A_BUTTON A0 -#define PIN_B_BUTTON A1 - -// bit values for button states -#define LEFT_BUTTON _BV(5) -#define RIGHT_BUTTON _BV(2) -#define UP_BUTTON _BV(4) -#define DOWN_BUTTON _BV(6) -#define A_BUTTON _BV(1) -#define B_BUTTON _BV(0) - -#define PIN_SPEAKER_1 A2 -#define PIN_SPEAKER_1_PORT &PORTF -#define PIN_SPEAKER_1_BITMASK _BV(5) -// SPEAKER_2 is purposely not defined for DEVKIT as it could potentially -// be dangerous and fry your hardware (because of the devkit wiring). -// -// Reference: https://github.com/Arduboy/Arduboy/issues/108 - -#endif - -// OLED hardware (SSD1306) - -#define OLED_PIXELS_INVERTED 0xA7 // All pixels inverted -#define OLED_PIXELS_NORMAL 0xA6 // All pixels normal - -#define OLED_ALL_PIXELS_ON 0xA5 // all pixels on -#define OLED_PIXELS_FROM_RAM 0xA4 // pixels mapped to display RAM contents - -#define OLED_VERTICAL_FLIPPED 0xC0 // reversed COM scan direction -#define OLED_VERTICAL_NORMAL 0xC8 // normal COM scan direction - -#define OLED_HORIZ_FLIPPED 0xA0 // reversed segment re-map -#define OLED_HORIZ_NORMAL 0xA1 // normal segment re-map - -// ----- - -#define WIDTH 128 -#define HEIGHT 64 - -#define COLUMN_ADDRESS_END (WIDTH - 1) & 127 // 128 pixels wide -#define PAGE_ADDRESS_END ((HEIGHT/8)-1) & 7 // 8 pages high - - -class ArduboyCoreCustom -{ -public: - ArduboyCoreCustom(); - - /// allows the CPU to idle between frames - /** - * This puts the CPU in "Idle" sleep mode. You should call this as often - * as you can for the best power savings. The timer 0 overflow interrupt - * will wake up the chip every 1ms - so even at 60 FPS a well written - * app should be able to sleep maybe half the time in between rendering - * it's own frames. - * - * See the Arduboy class nextFrame() for an example of how to use idle() - * in a frame loop. - */ - void static idle(); - - void static LCDDataMode(); //< put the display in data mode - - /// put the display in command mode - /** - * See SSD1306 documents for available commands and command sequences. - * - * Links: - * - https://www.adafruit.com/datasheets/SSD1306.pdf - * - http://www.eimodule.com/download/SSD1306-OLED-Controller.pdf - */ - void static LCDCommandMode(); - - uint8_t static width(); //< return display width - uint8_t static height(); // < return display height - - /// get current state of all buttons (bitmask) - /** - * Bit mask that is returned: - * - * Hi Low - * DevKit 00000000 - reserved - * -DLU-RAB D down - * U up - * 1.0 00000000 L left - * URLDAB-- R right - * - * Of course you shouldn't worry about bits (they may change with future - * hardware revisions) and should instead use the button defines: - * LEFT_BUTTON, A_BUTTON, UP_BUTTON, etc. - */ - - uint8_t static getInput() __attribute__((deprecated, warning("use buttonsState() instead"))); - uint8_t static buttonsState(); - - // paints 8 pixels (vertically) from a single byte - // - 1 is lit, 0 is unlit - // - // NOTE: You probably wouldn't actually use this, you'd build something - // higher level that does it's own calls to SPI.transfer(). It's - // included for completeness since it seems there should be some very - // rudimentary low-level draw function in the core that supports the - // minimum unit that the hardware allows (which is a strip of 8 pixels) - // - // This routine starts in the top left and then across the screen. - // After each "page" (row) of 8 pixels is drawn it will shift down - // to start drawing the next page. To paint the full screen you call - // this function 1,024 times. - // - // Example: - // - // X = painted pixels, . = unpainted - // - // blank() paint8Pixels() 0xFF, 0, 0x0F, 0, 0xF0 - // v TOP LEFT corner (8x9) v TOP LEFT corner - // ........ (page 1) X...X... (page 1) - // ........ X...X... - // ........ X...X... - // ........ X...X... - // ........ X.X..... - // ........ X.X..... - // ........ X.X..... - // ........ (end of page 1) X.X..... (end of page 1) - // ........ (page 2) ........ (page 2) - void static paint8Pixels(uint8_t pixels); - - /// paints an entire image directly to hardware (from PROGMEM) - /* - * Each byte will be 8 vertical pixels, painted in the same order as - * explained above in paint8Pixels. - */ - void static paintScreen(const unsigned char *image); - - /// paints an entire image directly to hardware (from RAM) - /* - * Each byte will be 8 vertical pixels, painted in the same order as - * explained above in paint8Pixels. - */ - void static paintScreen(unsigned char image[]); - - /// paints a blank (black) screen to hardware - void static blank(); - - /// invert the display or set to normal - /** - * when inverted, a pixel set to 0 will be on - */ - void static invert(bool inverse); - - /// turn all display pixels on, or display the buffer contents - /** - * when set to all pixels on, the display buffer will be - * ignored but not altered - */ - void static allPixelsOn(bool on); - - /// flip the display vertically or set to normal - void static flipVertical(bool flipped); - - /// flip the display horizontally or set to normal - void static flipHorizontal(bool flipped); - - /// send a single byte command to the OLED - void static sendLCDCommand(uint8_t command); - - /// set the light output of the RGB LEB - void setRGBled(uint8_t red, uint8_t green, uint8_t blue); - - /// boots the hardware - /** - * - sets input/output/pullup mode for pins - * - powers up the OLED screen and initializes it properly - * - sets up power saving - * - kicks CPU down to 8Mhz if needed - * - allows Safe mode to be entered - */ - void static boot(); - -protected: - - /// Safe mode - /** - * Safe Mode is engaged by holding down both the LEFT button and UP button - * when plugging the device into USB. It puts your device into a tight - * loop and allows it to be reprogrammed even if you have uploaded a very - * broken sketch that interferes with the normal USB triggered auto-reboot - * functionality of the device. - * - * This is most useful on Devkits because they lack a built-in reset - * button. - */ - void static inline safeMode() __attribute__((always_inline)); - - // internals - void static inline setCPUSpeed8MHz() __attribute__((always_inline)); - void static inline bootOLED() __attribute__((always_inline)); - void static inline bootPins() __attribute__((always_inline)); - void static inline bootPowerSaving() __attribute__((always_inline)); - - -private: - volatile static uint8_t *csport, *dcport; - uint8_t static cspinmask, dcpinmask; - -}; - -#endif From 57e9b60843c74083dc512734d89da37f7980e261 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Wed, 30 Nov 2016 13:51:57 -0500 Subject: [PATCH 2/4] Add changes made to origial code --- GUI.cpp | 5 - GUI.h | 1 - Globals.cpp | 5 +- Globals.h | 13 --- Map.cpp | 56 ----------- Map.h | 1 - SelectionArrow.cpp | 15 --- SelectionArrow.h | 3 - Ship.cpp | 45 +-------- Ship.h | 18 +--- StarHonor.ino | 240 ++++++++++++++++----------------------------- 11 files changed, 92 insertions(+), 310 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index 3ed56c3..bc61551 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -1,15 +1,10 @@ #include "GUI.h" -//int _OverviewXPos = 0; -//int _OverviewYPos = 6; Vector2d** OverviewLocations; Vector2d** CombatLocations; -//int _StatusBarIndent = 60; - bool AcceptMenuInput; SelectionArrow* RepairSelectionArrow; -//SelectionArrow* AuxSelectionArrow; SelectionArrow* CurrentSelectionArrow; SelectionArrow* CombatSelectionArrow; diff --git a/GUI.h b/GUI.h index 2c838c6..41a2680 100644 --- a/GUI.h +++ b/GUI.h @@ -12,7 +12,6 @@ extern Vector2d** CombatLocations; extern int _StatusBarIndent; extern SelectionArrow* RepairSelectionArrow; -//extern SelectionArrow* AuxSelectionArrow; extern SelectionArrow* CurrentSelectionArrow; extern SelectionArrow* CombatSelectionArrow; diff --git a/Globals.cpp b/Globals.cpp index c7fb726..98b3d34 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -2,7 +2,6 @@ Arduboy2Base arduboy; -//int FPS = 60; float LastUpdateTime = 0; float MilliPerFrame = 0; float DeltaTime = 0; @@ -11,7 +10,7 @@ int StatusBlinkTime = 60; State GameState; State PreviousGameState; -//StatusScreen CurrentStatusScreen; + int MenuWaitTime; int SequenceStage = 0; int CurrentSector = 1; @@ -44,5 +43,3 @@ float seconds = 60; int minutes = 9; float TimeToNextRandomEncounter; - -//RandomShipEncounter* ShipEncountered; diff --git a/Globals.h b/Globals.h index 7b9f0a9..943c77a 100644 --- a/Globals.h +++ b/Globals.h @@ -7,11 +7,9 @@ #include "bitmaps.h" #include "Vector2d.h" -//#define PI 3.14159265 extern Arduboy2Base arduboy; -//extern int FPS; extern float LastUpdateTime; extern float MilliPerFrame; extern float DeltaTime; @@ -32,7 +30,6 @@ extern bool CanHail; extern bool RunningAway; typedef enum { Overview, Repair, Auxilary } StatusScreen; -//extern StatusScreen CurrentStatusScreen; typedef enum { Up, UpRight, Right, DownRight, Down, DownLeft, Left, UpLeft, None } Direction; extern Direction DPad; @@ -67,14 +64,4 @@ extern int BattleRepairsMax; extern float seconds; extern int minutes; -//extern float TimeToNextRandomEncounter; -//struct RandomShipEncounter -//{ -// int Attack; -// int Defense; -// Loot Prize; -//}; -// -//extern RandomShipEncounter* ShipEncountered; - #endif diff --git a/Map.cpp b/Map.cpp index 33e0c81..5896b5d 100644 --- a/Map.cpp +++ b/Map.cpp @@ -3,18 +3,7 @@ Planetoid** Planets; Planetoid* LatestPlanetEncountered; const int PROGMEM PlanetsPerMap = 10; -//int ShipsPerMap = 1; -//const unsigned char* PlanetArt1 = Planet_1_16_16; -//const unsigned char* PlanetArt2 = Planet_2_16_16; -//const unsigned char* PlanetArt3 = Planet_3_16_16; -//const unsigned char* PlanetArt4 = Planet_4_16_16; -//const unsigned char* PlanetArt5 = Planet_5_16_16; -//const unsigned char* PlanetArt6 = Planet_6_16_16; -//const unsigned char* PlanetArt7 = Planet_7_16_16; -//const unsigned char* PlanetArt8 = Planet_8_16_16; -//const unsigned char* PlanetArt9 = Planet_9_16_16; -//const unsigned char* PlanetArt10 = Planet_10_16_16; const unsigned char* PlanetArt[] { Planet_1_16_16, Planet_2_16_16, Planet_3_16_16, Planet_4_16_16, Planet_5_16_16, Planet_6_16_16, Planet_7_16_16, Planet_8_16_16, Planet_9_16_16 , Planet_10_16_16 }; void InitializePlanetsArray() @@ -34,7 +23,6 @@ void NewMap() for ( int i(0); i < PlanetsPerMap; i++ ) { -// Planets[i] = new Planetoid(); Vector2d randPos = RandomMapPosition(); Planets[i]->MapPosition->x = randPos.x; Planets[i]->MapPosition->y = randPos.y; @@ -50,7 +38,6 @@ void NewMap() Planets[i]->Attack = CurrentSector + random( 1, 3 ) + 3; Planets[i]->Defense = CurrentSector + random( 3, 5 ) + 3; -// if ( fuel > 0 && Planets[i]->Alignment > 0 ) if ( fuel > 0 ) { Planets[i]->Prize = LootFuel; @@ -60,41 +47,15 @@ void NewMap() Planets[i]->Prize = static_cast( rand() % 7 ); Planets[i]->Contacted = false; } - - //CreateEnemyShips( ShipsPerMap ); } void DeleteMap() { LatestPlanetEncountered = NULL; -// for ( int i( PlanetsPerMap - 1 ); i >= 0; i-- ) - for ( int i( 0 ); i < PlanetsPerMap; i++ ) - { -// delete(Planets[i]->MapPosition); -// delete(Planets[i]); - } } -//void CreateEnemyShips( int count ) -//{ -// if ( EnemyShips != NULL ) -// { -// for ( int i( count - 1 ); i >= 0; i-- ) -// delete(EnemyShips[i]); -// delete(EnemyShips); -// } -// EnemyShips = new Ship*[count]; -// for ( int i(0); i < count; i++ ) -// { -// EnemyShips[i] = new Ship(); -// Ship::SetupShip( EnemyShips[i], false ); -// EnemyShips[i]->MapPosition = RandomMapPosition(); -// } -//} - Vector2d RandomMapPosition() { -// return new Vector2d( random( MapUpperBounds->x + 16, MapLowerBounds->x - 16), random ( MapUpperBounds->y + 16, MapLowerBounds->y - 16 ) ); Vector2d pos; pos.x = random( MapUpperBounds->x + 16, MapLowerBounds->x - 16); pos.y = random ( MapUpperBounds->y + 16, MapLowerBounds->y - 16 ); @@ -103,21 +64,6 @@ Vector2d RandomMapPosition() void MapLoop() { -// for ( int i(0); i < ShipsPerMap; i++ ) -// { -// EnemyShips[i]->Update(); -// EnemyShips[i]->DrawOnMap(); -// if ( EnemyShips[i]->IsAlive ) -// NextSector = false; -// } -// -// if ( NextSector ) -// { -//// ShipsPerMap++; -// NewMap(); -// return; -// } - if ( AButton ) { ChangeGameState( Status ); @@ -156,8 +102,6 @@ void DrawMap() } } } - -// DrawMarkers(); } void DrawMarkers() diff --git a/Map.h b/Map.h index fec94b6..6965e60 100644 --- a/Map.h +++ b/Map.h @@ -23,7 +23,6 @@ extern Planetoid* LatestPlanetEncountered; void InitializePlanetsArray(); void NewMap(); void DeleteMap(); -//void CreateEnemyShips( int count ); Vector2d RandomMapPosition(); void MapLoop(); void DrawMap(); diff --git a/SelectionArrow.cpp b/SelectionArrow.cpp index 91114a1..a61f592 100644 --- a/SelectionArrow.cpp +++ b/SelectionArrow.cpp @@ -20,7 +20,6 @@ SelectionArrow::SelectionArrow( Vector2d** array, int size ) { NumberOfPositions = size; Position = 0; -// Type = ArrowSelection; SelectionLocation* tmp; for ( int i(0); i < size; i ++ ) @@ -57,10 +56,7 @@ SelectionArrow::~SelectionArrow() void SelectionArrow::Draw() { -// if ( Type == ArrowSelection ) arduboy.drawBitmap( CurrentSelection->Location->x, CurrentSelection->Location->y, SelectionArrow_8_8, 8, 8, 1); -// else if ( Type == BoxSelection ) -// arduboy.drawRect( CurrentSelection->Location->x, CurrentSelection->Location->y, 29, 9, 1 ); } void SelectionArrow::SelectionMoveUp() @@ -81,14 +77,3 @@ void SelectionArrow::Enable( bool e ) { _Enabled = e; } - -//void SelectionArrow::SetBoxType() -//{ -// this->Type = BoxSelection; -//} -// -//void SelectionArrow::SetArrowType() -//{ -// this->Type = ArrowSelection; -//} - diff --git a/SelectionArrow.h b/SelectionArrow.h index e9337a8..8f5b27c 100644 --- a/SelectionArrow.h +++ b/SelectionArrow.h @@ -23,7 +23,6 @@ class SelectionArrow public: int NumberOfPositions; int Position; -// SelectionType Type; SelectionLocation* CurrentSelection; SelectionLocation* FirstLocation; @@ -37,8 +36,6 @@ class SelectionArrow void SelectionMoveDown(); void Enable( bool e ); -// void SetBoxType(); -// void SetArrowType(); // private: bool _Enabled; diff --git a/Ship.cpp b/Ship.cpp index fab77a3..0581139 100644 --- a/Ship.cpp +++ b/Ship.cpp @@ -1,7 +1,6 @@ #include "Ship.h" Ship* PlayerShip; -//Ship** EnemyShips; float DiagonalVelocity = 1.41421f; @@ -12,21 +11,17 @@ const unsigned char* PlayerBitMaps[] { ArduShip_TD_Up_16_16, ArduShip_TD_UpRight Ship::Ship() { IsAlive = true; -// ShipRotation = 90; Velocity = new Vector2d( 0, 0 ); MapPosition = new Vector2d( 0, 0 ); -// NavFocus = new Vector2d( 0, 0 ); } Ship::~Ship() { -// delete( NavFocus ); delete( MapPosition ); delete( Velocity ); delete[] crewCharArray; delete[] fuelCharArray; delete[] maxCrewCharArray; -// delete[] goodsCharArray; } void Ship::SetupShip( Ship* s ) @@ -41,10 +36,7 @@ void Ship::SetupShip( Ship* s ) s->HP_Engine = 5; s->MaxVelocity = s->HP_Engine + 5; s->Fuel = 0; -// s->Food = 5; -// s->Fuel = 300; s->Crew = 33; -// s->Inv_Goods = 0; s->BitMap = ArduShip_TD_Right_16_16; s->Max_Hull = s->HP_Hull; @@ -53,19 +45,12 @@ void Ship::SetupShip( Ship* s ) s->Max_Shields = s->HP_Shields; s->Max_Crew = s->Crew; s->Max_Fuel = 25; -// s->Max_Food = s->Food; s->Velocity->x = s->Velocity->y = 0; s->MapPosition->x = s->MapPosition->y = 0; -// RepairTarget = Crew; RepairTarget = NoTarget; } -//float Ship::NextRandomFireTime() -//{ -// return random(3.0f, 6.0f); -//} - // Applies damage to a ship, returns the system damaged SystemTarget Ship::TakeDamage( int Damage ) { @@ -117,10 +102,7 @@ void Ship::DrawOnMap() void Ship::Update() { -// if ( IsPlayerShip ) - PlayerUpdate(); -// else -// AIUpdate(); + PlayerUpdate(); } Vector2d Ship::GetVelocity() @@ -130,11 +112,7 @@ Vector2d Ship::GetVelocity() //typedef enum { Up, UpRight, Right, DownRight, Down, DownLeft, Left, UpLeft, None } Direction; void Ship::PlayerUpdate() -{ -// byte input = 1 << DPad; -// byte left = 1 << UpLeft | 1 << Left | 1 << DownLeft; -// byte right = 1 << UpRight | 1 << Right | 1 << DownRight; - +{ // Be clever and arrange the enums so you can do a bit mask? if ( DPad == UpLeft || DPad == Left || DPad == DownLeft ) { @@ -176,14 +154,7 @@ void Ship::PlayerUpdate() TimeUntilNextRepair = RepairTime;// + ( RepairTime * 10 - RepairTime * 10 * Crew / Max_Crew ); RepairSystem(); } -// TimeToNextRandomEncounter -= DeltaTime; } - -// AbPrinter text(arduboy); -// text.setCursor(0, 24); -// text.print(this->MapPosition->x); -// text.setCursor(32, 24); -// text.print(this->MapPosition->y); } void Ship::UpdateMovement( Vector2d thrust ) @@ -223,8 +194,6 @@ Vector2d Ship::CalcThrust( Direction dir ) { Vector2d thrust; thrust.x = 0; -// thrust.y = -1; -// thrust.y = -0.5f - ( HP_Engine / 10.0f ); thrust.y = -0.2f - HP_Engine / 3.0f; int rotation = static_cast( dir ) * 45; thrust.Rotate( rotation ); @@ -277,14 +246,8 @@ int Ship::Upgrade( Loot Upgrade ) case LootFuel: UpgradeAmount = 1; Fuel += UpgradeAmount; -// Fuel = min( Max_Fuel, Fuel ); return UpgradeAmount; break; -// case LootGoods: -// UpgradeAmount *= 2; -// Inv_Goods += UpgradeAmount; -// return UpgradeAmount; -// break; } return 0; } @@ -295,7 +258,7 @@ void Ship::RepairSystem() bool existingUpdate = StatusUpdateAvailable; SystemTarget systemTargeted = RepairTarget; - //typedef enum SystemTarget { Crew, Hull, Weapons, Engines, Shields }; + switch (RepairTarget) { @@ -354,8 +317,6 @@ void Ship::RepairSystem() if ( !existingUpdate && StatusUpdateAvailable ) { StatusUpdateTime = 240; - //typedef enum SystemTarget { Crew, Hull, Weapons, Engines, Shields }; - //const char* RepairedText[] { RedShirtsRepaired, HullRepaired, WeaponsRepaired, EnginesRepaired, ShieldsRepaired }; Status_Update = (char *) RepairedText[systemTargeted]; StatusUpdateFromProgMem = true; } diff --git a/Ship.h b/Ship.h index 91b5cbe..1232c6a 100644 --- a/Ship.h +++ b/Ship.h @@ -31,8 +31,6 @@ class Ship int HP_Shields; int Crew; int Fuel; -// int Food; -// int Inv_Goods; uint8_t Max_Hull; uint8_t Max_Weapons; @@ -40,18 +38,15 @@ class Ship uint8_t Max_Shields; uint8_t Max_Crew; uint8_t Max_Fuel; -// uint8_t Max_Food; char crewCharArray[4]; char maxCrewCharArray[4]; char fuelCharArray[4]; -// char goodsCharArray[4]; Direction ShipFacing = Up; const unsigned char* BitMap; // AIState State; -// Vector2d* NavFocus; Vector2d* MapPosition; SystemTarget TakeDamage( int Damage ); @@ -62,25 +57,16 @@ class Ship void PlayerUpdate(); void UpdateMovement( Vector2d thrust ); -// void AIUpdate(); -// void ChooseNavLocation(); + Vector2d CalcThrust( Direction dir ); -// void AINavLoop(); -// bool ArrivedAtDestination(); -// static float NextRandomFireTime(); -// float DistanceToPlayerShip(); + int Upgrade( Loot Upgrade ); void RepairSystem(); void CalculateBattleRepairs(); float ShipRotation; Vector2d* Velocity; -// float timeUntilNextFire; }; -//void FireWeapon( Ship* owner, Ship* Target, WeaponType wt ); // Defined in Combat.cpp - extern Ship* PlayerShip; -//extern Ship** EnemyShips; - #endif diff --git a/StarHonor.ino b/StarHonor.ino index 5dd11f8..1cf05f0 100644 --- a/StarHonor.ino +++ b/StarHonor.ino @@ -11,12 +11,12 @@ #define Debug 0 +// To decompile the elf and sort by function size: // avr-nm --size-sort -C -r ./VoyageHome.ino.elf > ~/output.txt StarField* _StarField; void setup() { - // put your setup code here, to run once: #if Debug Serial.begin(9600); #endif @@ -32,20 +32,16 @@ void setup() { MapUpperBounds = new Vector2d(-32, -128); MapLowerBounds = new Vector2d(512, 128); -// MapUpperBounds = new Vector2d(-128, -128); -// MapLowerBounds = new Vector2d(128, 128); TextManager = new Text(); + #if !Debug CreateStatusSelectionArrow(); CreateCombatSelectionArrow(); #endif -// CurrentStatusScreen = Overview; -// ChangeGameState( WinGame ); - ChangeGameState( TitleLoop ); -// ChangeGameState( Map ); + ChangeGameState( TitleLoop ); MenuWaitTime = 15; // Order is important to prevent Heap Fragmentation @@ -58,14 +54,11 @@ void setup() { void loop() { -// Serial.println(MilliPerFrame); if ( millis() < (LastUpdateTime + MilliPerFrame) ) return; DeltaTime = ( millis() - LastUpdateTime ) / 1000.0f; LastUpdateTime = millis(); arduboy.clear(); -// AbPrinter text(arduboy); -// text.print("Hello"); GetInput(); switch ( GameState ) @@ -136,18 +129,14 @@ void loop() StatusUpdateTime = 0; Status_Update = NULL; CanHail = false; -// DeleteMap(); LatestPlanetEncountered = NULL; ResetPlayer(); NewMap(); ChangeGameState( TitleLoop ); minutes = 9; - seconds = 59.99; + seconds = 59.99f; break; case Warping: -// Vector2d warpVelocity; -// warpVelocity.x = -10; -// warpVelocity.y = 0; _StarField->Move(Vector2d(-60,0)); _StarField->Draw(); PlayerShip->DrawOnMap(); @@ -256,16 +245,13 @@ void ChangeGameState( State newState ) case Prologue: SequenceStage = 1; TextManager->NewDisplayTextOverTime(); -// GenerateRandomEncounter(); break; case Map: -// SequenceStage = 1; break; case Status: Text::ConvertIntToChar( PlayerShip->Crew, PlayerShip->crewCharArray ); Text::ConvertIntToChar( PlayerShip->Max_Crew, PlayerShip->maxCrewCharArray ); Text::ConvertIntToChar( PlayerShip->Fuel, PlayerShip->fuelCharArray ); -// Text::ConvertIntToChar( PlayerShip->Inv_Goods, PlayerShip->goodsCharArray ); break; case Encounter: SetupEncounter(); @@ -287,7 +273,7 @@ void ChangeGameState( State newState ) PlayerShip->Velocity->y = 0; PlayerShip->PlayerUpdate(); PlayerShip->Fuel -= 3; - WaitTime = 240; // 240 frames. Changed from float to get under 28,672 + WaitTime = 240; // 240 frames break; case WinGame: SequenceStage = 1; @@ -337,10 +323,6 @@ void ShipStatusLoop() CurrentSelectionArrow->SelectionMoveDown(); AcceptMenuInput = false; } -// else if ( DPad == Right || DPad == Left ) -// { -// AcceptMenuInput = false; -// } // Status Menu if ( AButton ) { @@ -351,21 +333,6 @@ void ShipStatusLoop() { } } - -// if ( DPad == Up && AcceptMenuInput ) -// { -// CurrentSelectionArrow->SelectionMoveUp(); -// AcceptMenuInput = false; -// } -// else if ( DPad == Down && AcceptMenuInput ) -// { -// CurrentSelectionArrow->SelectionMoveDown(); -// AcceptMenuInput = false; -// } -// else if ( ( DPad == Right || DPad == Left ) && AcceptMenuInput ) -// { -// AcceptMenuInput = false; -// } DrawShipStatusScreen(); CurrentSelectionArrow->Draw(); @@ -375,100 +342,94 @@ void DrawShipStatusScreen() { int StatusBarX = 66; int TextXPos = 10; -// switch ( CurrentStatusScreen ) + + Text::DisplayText(ShipStatus, 42, 0, true); + Text::DisplayText(TCrew, TextXPos, 8, true); + Text::DisplayText(THull, TextXPos, 15, true); + Text::DisplayText(TWeapons, TextXPos, 22, true); + Text::DisplayText(TShields, TextXPos, 29, true); + Text::DisplayText(TEngines, TextXPos, 36, true); + Text::DisplayText(TFuel, TextXPos, 43, true); + + if ( RepairTarget != NoTarget && StatusBlinkTime > 30) { -// case Overview: - Text::DisplayText(ShipStatus, 42, 0, true); - Text::DisplayText(TCrew, TextXPos, 8, true); - Text::DisplayText(THull, TextXPos, 15, true); - Text::DisplayText(TWeapons, TextXPos, 22, true); - Text::DisplayText(TShields, TextXPos, 29, true); - Text::DisplayText(TEngines, TextXPos, 36, true); - Text::DisplayText(TFuel, TextXPos, 43, true); -// Text::DisplayText(TGoods, 72, 8, true); - - if ( RepairTarget != NoTarget && StatusBlinkTime > 30) - { - arduboy.fillRect( TextXPos, 8 + 7 * RepairTarget, 40, 6, 0 ); - } - else if (StatusBlinkTime < 0) - StatusBlinkTime = 60; - StatusBlinkTime -= 1; + arduboy.fillRect( TextXPos, 8 + 7 * RepairTarget, 40, 6, 0 ); + } + else if (StatusBlinkTime < 0) + StatusBlinkTime = 60; + StatusBlinkTime -= 1; -// DrawStatusBar( int x, int y, int length, int height, float fill ) - // 27,600 -> 27,322 ...wow Just removing the array reference with the arithmetic offset "OverviewLocation[0].y + 2" - Text::DisplayText( PlayerShip->crewCharArray, 66, 8, false); - Text::DisplayText( "/", 80, 8, false ); - Text::DisplayText( PlayerShip->maxCrewCharArray, 86, 8, false ); -// DrawStatusBar( StatusBarX, 15, PlayerShip->Max_Hull, 4, (float) PlayerShip->HP_Hull / PlayerShip->Max_Hull ); - DrawStatusBar( StatusBarX, 15, PlayerShip->Max_Hull, 4, 100 * PlayerShip->HP_Hull / PlayerShip->Max_Hull ); - DrawStatusBar( StatusBarX, 22, PlayerShip->Max_Weapons, 4, 100 * PlayerShip->HP_Weapons / PlayerShip->Max_Weapons ); - DrawStatusBar( StatusBarX, 29, PlayerShip->Max_Shields, 4, 100 * PlayerShip->HP_Shields / PlayerShip->Max_Shields ); - DrawStatusBar( StatusBarX, 36, PlayerShip->Max_Engine, 4, 100 * PlayerShip->HP_Engine / PlayerShip->Max_Engine ); -// DrawStatusBar( StatusBarX, 43, PlayerShip->Max_Fuel, 4, (float) PlayerShip->Fuel / PlayerShip->Max_Fuel ); - Text::DisplayText( PlayerShip->fuelCharArray, StatusBarX, 43, false ); -// Text::DisplayText( PlayerShip->goodsCharArray, 114, 8, false); - - if ( PreviousGameState == Map ) + // DrawStatusBar( int x, int y, int length, int height, float fill ) + // 27,600 -> 27,322 ...wow Just removing the array reference with the arithmetic offset "OverviewLocation[0].y + 2" + Text::DisplayText( PlayerShip->crewCharArray, 66, 8, false); + Text::DisplayText( "/", 80, 8, false ); + Text::DisplayText( PlayerShip->maxCrewCharArray, 86, 8, false ); + + DrawStatusBar( StatusBarX, 15, PlayerShip->Max_Hull, 4, 100 * PlayerShip->HP_Hull / PlayerShip->Max_Hull ); + DrawStatusBar( StatusBarX, 22, PlayerShip->Max_Weapons, 4, 100 * PlayerShip->HP_Weapons / PlayerShip->Max_Weapons ); + DrawStatusBar( StatusBarX, 29, PlayerShip->Max_Shields, 4, 100 * PlayerShip->HP_Shields / PlayerShip->Max_Shields ); + DrawStatusBar( StatusBarX, 36, PlayerShip->Max_Engine, 4, 100 * PlayerShip->HP_Engine / PlayerShip->Max_Engine ); + + Text::DisplayText( PlayerShip->fuelCharArray, StatusBarX, 43, false ); + + if ( PreviousGameState == Map ) + { + if ( CurrentSelectionArrow->Position == 0 ) + { + Text::DisplayText( StatusHelp2, 0, 50, true ); + if (BButton) // Triage { - if ( CurrentSelectionArrow->Position == 0 ) - { - Text::DisplayText( StatusHelp2, 0, 50, true ); - if (BButton) // Triage - { - RepairTarget = static_cast( CurrentSelectionArrow->Position ); - } - } - if ( CurrentSelectionArrow->Position > 0 && CurrentSelectionArrow->Position <= 4 ) - { - Text::DisplayText( StatusHelp, 0, 50, true ); - if (BButton) // Repair - { - RepairTarget = static_cast( CurrentSelectionArrow->Position ); - } - } - else if ( CurrentSelectionArrow->Position == 5 ) - { - Text::DisplayText( StatusHelp4, 0, 50, true ); - } + RepairTarget = static_cast( CurrentSelectionArrow->Position ); } - else if ( PreviousGameState == Encounter ) + } + if ( CurrentSelectionArrow->Position > 0 && CurrentSelectionArrow->Position <= 4 ) + { + Text::DisplayText( StatusHelp, 0, 50, true ); + if (BButton) // Repair + { + RepairTarget = static_cast( CurrentSelectionArrow->Position ); + } + } + else if ( CurrentSelectionArrow->Position == 5 ) + { + Text::DisplayText( StatusHelp4, 0, 50, true ); + } + } + else if ( PreviousGameState == Encounter ) + { + if ( CurrentSelectionArrow->Position > 0 && CurrentSelectionArrow->Position <= 4 ) + { + Text::DisplayText( SpendEmergencyRepairs, 0, 50, true ); + if (BButton && BattleRepairs > 0) // Repair { - if ( CurrentSelectionArrow->Position > 0 && CurrentSelectionArrow->Position <= 4 ) + RepairTarget = static_cast( CurrentSelectionArrow->Position ); + int randomRepairs = random(2, 6); + while ( randomRepairs > 0 ) { - Text::DisplayText( SpendEmergencyRepairs, 0, 50, true ); - if (BButton && BattleRepairs > 0) // Repair - { - RepairTarget = static_cast( CurrentSelectionArrow->Position ); - int randomRepairs = random(2, 6); - while ( randomRepairs > 0 ) - { - PlayerShip->RepairSystem(); - randomRepairs--; - } - BattleRepairs--; - } + PlayerShip->RepairSystem(); + randomRepairs--; } - - // Bubbles - if ( BattleRepairsMax > 2 ) - arduboy.drawBitmap(106, 58, Bubble_Empty_8_8, 8, 8, 1); - if ( BattleRepairsMax > 1 ) - arduboy.drawBitmap(94, 58, Bubble_Empty_8_8, 8, 8, 1); - if ( BattleRepairsMax > 0 ) - arduboy.drawBitmap(82, 58, Bubble_Empty_8_8, 8, 8, 1); - - Text::DisplayText( EmergencyRepairs, 0, 58, true ); - - if ( BattleRepairs > 2 ) - arduboy.drawBitmap(106, 58, Bubble_8_8, 8, 8, 1); - if ( BattleRepairs > 1 ) - arduboy.drawBitmap(94, 58, Bubble_8_8, 8, 8, 1); - if ( BattleRepairs > 0 ) - arduboy.drawBitmap(82, 58, Bubble_8_8, 8, 8, 1); + BattleRepairs--; } -// break; + } + + // Bubbles + if ( BattleRepairsMax > 2 ) + arduboy.drawBitmap(106, 58, Bubble_Empty_8_8, 8, 8, 1); + if ( BattleRepairsMax > 1 ) + arduboy.drawBitmap(94, 58, Bubble_Empty_8_8, 8, 8, 1); + if ( BattleRepairsMax > 0 ) + arduboy.drawBitmap(82, 58, Bubble_Empty_8_8, 8, 8, 1); + + Text::DisplayText( EmergencyRepairs, 0, 58, true ); + + if ( BattleRepairs > 2 ) + arduboy.drawBitmap(106, 58, Bubble_8_8, 8, 8, 1); + if ( BattleRepairs > 1 ) + arduboy.drawBitmap(94, 58, Bubble_8_8, 8, 8, 1); + if ( BattleRepairs > 0 ) + arduboy.drawBitmap(82, 58, Bubble_8_8, 8, 8, 1); } } @@ -522,14 +483,6 @@ void EncouterUpdate() } break; -// case 2: // Intro -// TextManager->DisplayTextClear( Comm_A_1, 0, 0, true, true ); -// if ( TextManager->DisplayTextOverTime( Comm_B_1, 0, 55 ) || ( AButton || BButton ) ) -// { -// SequenceStage++; -// } -// break; - case 3: // Combat Choice DrawCombatScreen( true ); @@ -712,8 +665,6 @@ void DrawCombatScreen( bool DrawCommands ) // Left Side arduboy.fillRect( 0, 16, 35, 24, 0 ); arduboy.drawRect(0, 18, 35, 21, 1); - // static int DisplayText( char* text, int x, int y, bool fromProgMem ); - //static int DisplayTextClear( char* text, int x, int y, bool fromProgMem, bool withBorder ); Text::DisplayText(CombatMenu_Atk, 2, 20, true); Text::ConvertIntToChar( PlayerShip->HP_Weapons ); @@ -816,10 +767,6 @@ void GenerateReward( Loot reward ) case LootFuel: index += Text::CopyIntoBuffer( TFuel, index, 7 ); break; -// case LootGoods: -// -// index += Text::CopyIntoBuffer( TGoods, index, 4 ); -// break; } typeBuffer[index] = '\0'; } @@ -829,9 +776,8 @@ void GenerateReward( Loot reward ) static void DrawStatusBar( int x, int y, int length, int height, int fill ) { length *= 2; -// int fillTo = x + ceil( fill * length ); - int fillTo = x + floor( fill * length / 100.0f ); -// int fillTo = x + floor( length / fill ); + int fillTo = x + floor( fill * length / 100.0f ); + for ( int i(0); i < height; i++ ) { int xOffset = abs( height - ( ceil( height / 2.0f ) + i ) ); @@ -856,8 +802,6 @@ static void DrawStatusBar( int x, int y, int length, int height, int fill ) void ResetPlayer() { -// delete( PlayerShip ); -// PlayerShip = new Ship(); Ship::SetupShip( PlayerShip ); TimeUntilNextRepair = RepairTime; } @@ -962,24 +906,13 @@ void GameOverLoop( int ending ) } } -//void GenerateRandomEncounter() -//{ -// TimeToNextRandomEncounter = random( 10, 20 ); -// ShipEncountered->Attack = 1; -// ShipEncountered->Defense = 1; -// ShipEncountered->Prize = static_cast( rand() % 7 ); -//} - void SetupSectorReachedText() { StatusUpdateTime = 240; -// int index = 0; StatusUpdateAvailable = true; StatusUpdateFromProgMem = false; Text::CopyIntoBuffer( SectorReachedA, 0, 16 ); -// index = 15; Text::ConvertIntToChar( 60 + random( 1, 10 ) - ( CurrentSector * 10 ), typeBuffer, 16 ); -// index = 17; typeBuffer[18] = '\0'; Status_Update = typeBuffer; } @@ -1025,7 +958,6 @@ void ClockUpdate( bool runnning ) * Random encounters * Random space debris * Not all Planets are encounters - * Crew for emergency repairs * * Note: It would be cool to render wreckage so you can see where you've been */ From 6c0a4c1213ab39d1eb8e432ff60e5ef5aeacfccf Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Wed, 30 Nov 2016 13:56:54 -0500 Subject: [PATCH 3/4] Add flashlight and boot logo to startup --- StarHonor.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StarHonor.ino b/StarHonor.ino index 1cf05f0..f76048a 100644 --- a/StarHonor.ino +++ b/StarHonor.ino @@ -23,7 +23,8 @@ void setup() { MilliPerFrame = 1000.0f / 60.0f; arduboy.boot(); - arduboy.display(); + arduboy.flashlight(); + arduboy.bootLogo(); arduboy.initRandomSeed(); #if !Debug From 549f954f5242588529f3c23eb8e788155ba33fb5 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Wed, 30 Nov 2016 14:00:08 -0500 Subject: [PATCH 4/4] Fix function DisplayTextOverTime() --- Text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Text.cpp b/Text.cpp index d1c3574..690b5e8 100644 --- a/Text.cpp +++ b/Text.cpp @@ -136,7 +136,7 @@ bool Text::DisplayTextOverTime( char* text, int x, int y ) bool Text::DisplayTextOverTime( char const* text, int x, int y ) { - Text::DisplayTextOverTime( (char *) text, x, y ); + return Text::DisplayTextOverTime( (char *) text, x, y ); } bool Text::DisplayTextOverTimeClear( char* text, int x, int y )