From 6628e7de58425b3e93da9ae6fcb7347137d96096 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Sun, 12 Mar 2017 21:09:29 +0100 Subject: * Player can now select nearest unit or building. Multiple buildings and units can be selected at the same time. * Unit module moved from C++ to C (only extension change - and compiler - was needed). * GfxGetHeightFromSpriteData and GfxGetWidthFromSpriteData were getting incorrect data! Incorrect memory address was being read when calling pgm_read_byte, and caused unexpected behaviour under real hw. --- Gfx.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'Gfx.cpp') diff --git a/Gfx.cpp b/Gfx.cpp index e291213..ff58551 100644 --- a/Gfx.cpp +++ b/Gfx.cpp @@ -91,14 +91,14 @@ bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE * spr) uint8_t GfxGetWidthFromSpriteData(const uint8_t * sprData) { - // On Gamebuino bitmaps, width is always stored on first byte. - return pgm_read_byte_near(sprData[0]) << 1; + // On Gamebuino bitmaps, width is always stored on first byte. + return pgm_read_byte_near(&sprData[0]); } uint8_t GfxGetHeightFromSpriteData(const uint8_t * sprData) { // On Gamebuino bitmaps, height is always stored on second byte. - return pgm_read_byte_near(sprData[1]) << 1; + return pgm_read_byte_near(&sprData[1]); } void GfxPrintText_Flash(const __FlashStringHelper * str) @@ -187,11 +187,26 @@ void GfxDrawCircle(uint16_t x, uint16_t y, uint8_t radius, int8_t color) void GfxDrawRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color) { - int8_t orig_color = gb.display.getColor(); - - gb.display.setColor(color); - gb.display.fillRect(x, y, w, h); - gb.display.setColor(orig_color); + if(GfxIsInsideScreenArea(x, y, w, h) == true) + { + int8_t orig_color = gb.display.getColor(); + + gb.display.setColor(color); + gb.display.drawRect(x, y, w, h); + gb.display.setColor(orig_color); + } +} + +void GfxFillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color) +{ + if(GfxIsInsideScreenArea(x, y, w, h) == true) + { + int8_t orig_color = gb.display.getColor(); + + gb.display.setColor(color); + gb.display.fillRect(x, y, w, h); + gb.display.setColor(orig_color); + } } void GfxShowResources(TYPE_RESOURCES * ptrResources) @@ -199,17 +214,17 @@ void GfxShowResources(TYPE_RESOURCES * ptrResources) char str[8]; gb.display.setColor(GFX_WHITE); - gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 8); + gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 5); snprintf(str, 8, "W=%d", ptrResources->Wood); - GfxPrintTextFont(str, font3x3, 4, 4); + GfxPrintTextFont(str, font3x3, 4, 1); snprintf(str, 8, "G=%d", ptrResources->Gold); - GfxPrintTextFont(str, font3x3, 24, 4); + GfxPrintTextFont(str, font3x3, 24, 1); snprintf(str, 8, "F=%d", ptrResources->Food); - GfxPrintTextFont(str, font3x3, 48, 4); + GfxPrintTextFont(str, font3x3, 48, 1); } -- cgit v1.2.3