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. --- Building.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'Building.c') diff --git a/Building.c b/Building.c index 368f791..f2955e0 100644 --- a/Building.c +++ b/Building.c @@ -47,13 +47,7 @@ uint8_t BuildingGetHpFromID(uint8_t id) void BuildingSelectedOptions(TYPE_BUILDING * ptrBuilding) { - char str[8]; - GfxDrawRectangle(0, Y_SCREEN_RESOLUTION - 8, X_SCREEN_RESOLUTION, 8, GFX_WHITE); - - snprintf(str, 8, "HP=%d", ptrBuilding->hp); - - GfxPrintTextFont(str, font3x3, 4, Y_SCREEN_RESOLUTION - 4); } @@ -79,21 +73,29 @@ void BuildingDraw(TYPE_CAMERA * ptrCamera, TYPE_BUILDING * ptrBuilding, bool bSe GfxDrawSprite(BuildingSprTable[id]); + int8_t color = GFX_WHITE; + if( (bSelected == true) && (ptrBuilding->selected == false) ) { - TYPE_COLLISION_BLOCK cb; - - cb = CameraApplyCoordinatesToCoordinates(ptrCamera, ptrBuilding->x, ptrBuilding->y); - - GfxDrawCircle(cb.x + 3, cb.y + 3, BuildingGetWidthFromID(ptrBuilding->id) >> 2, GFX_GRAY); + color = GFX_GRAY; } else if(ptrBuilding->selected == true) { - TYPE_COLLISION_BLOCK cb; + color = GFX_BLACK; + } + + if(color != GFX_WHITE) + { + TYPE_COLLISION_BLOCK cb = CameraApplyCoordinatesToCoordinates(ptrCamera, ptrBuilding->x, ptrBuilding->y); - cb = CameraApplyCoordinatesToCoordinates(ptrCamera, ptrBuilding->x, ptrBuilding->y); + cb.w = BuildingGetWidthFromID(ptrBuilding->id); + cb.h = BuildingGetWidthFromID(ptrBuilding->id); - GfxDrawCircle(cb.x + 3, cb.y + 3, BuildingGetWidthFromID(ptrBuilding->id) >> 2, GFX_BLACK); + GfxDrawRectangle( cb.x - (cb.w / 10), + cb.y - (cb.h / 10), + BuildingGetWidthFromID(ptrBuilding->id) + (cb.w / 5), + BuildingGetHeightFromID(ptrBuilding->id) + (cb.h / 5), + color ); } } -- cgit v1.2.3