diff options
Diffstat (limited to 'Player.cpp')
| -rw-r--r-- | Player.cpp | 146 |
1 files changed, 96 insertions, 50 deletions
@@ -85,9 +85,13 @@ void Player::showHealth(uint8_t hp) char str[8]; + str[0] = 'H'; + str[1] = 'P'; + str[2] = '='; + GfxFillRectangle(0, Y_SCREEN_RESOLUTION - 5, X_SCREEN_RESOLUTION, 8, GFX_WHITE); - snprintf(str, sizeof(str), "HP=%u", hp); + Systemitoa(&str[3], sizeof(str) - 3, hp); GfxPrintTextFont(str, font3x3, HP_TEXT_X, HP_TEXT_Y); } @@ -123,7 +127,7 @@ void Player::DrawHandler(void) UnitDraw(u, &Camera, selected); - if ( (u->selected == true) && (bAnyoneSelected == false) ) + if ( (u->selected != false) && (bAnyoneSelected == false) ) { bAnyoneSelected = true; @@ -131,9 +135,9 @@ void Player::DrawHandler(void) } } - if (human == true) + if (human != false) { - if (bAnyoneSelected == true) + if (bAnyoneSelected != false) { GfxDrawRectangle(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_W, PROGRESS_BAR_H, GFX_BLACK); @@ -151,24 +155,47 @@ void Player::DrawHandler(void) void Player::ShowResources(void) { - char str[16]; + char str[8]; + uint8_t i; + + str[1] = '='; gb.display.setColor(GFX_GRAY); gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 8); - snprintf(str, sizeof(str), "W=%d", Resources.Wood); + str[0] = 'W'; + + Systemitoa(&str[2], 6, Resources.Wood); + + GfxPrintTextFont(str, font3x3, 8, 1); - GfxPrintTextFont(str, font3x3, 2, 1); + str[0] = 'G'; - snprintf(str, sizeof(str), "G=%d", Resources.Gold); + Systemitoa(&str[2], 6, Resources.Gold); GfxPrintTextFont(str, font3x3, 2, 5); - snprintf(str, sizeof(str), "F=%d", Resources.Food); + str[0] = 'F'; + + Systemitoa(&str[2], 6, Resources.Food); GfxPrintTextFont(str, font3x3, 42, 1); - snprintf(str, sizeof(str), "%d/%d", unit_i, PLAYER_MAX_UNITS_BUILDINGS); + Systemitoa(str, 3, unit_i); + + for (i = 0; i < 3; i++) + { + if (str[i] == '\0') + { + break; + } + } + + str[i++] = '/'; + + Systemitoa(&str[i], sizeof(str) - i, PLAYER_MAX_UNITS_BUILDINGS); + + //~ snprintf(str, sizeof(str), "%d/%d", unit_i, PLAYER_MAX_UNITS_BUILDINGS); GfxPrintTextFont(str, font3x3, 42, 5); } @@ -196,7 +223,7 @@ bool Player::checkNewBuildingPosition(TYPE_COLLISION_BLOCK * cb) bldgCB.w = UnitGetWidthFromID(ptrUnit->id); bldgCB.h = UnitGetHeightFromID(ptrUnit->id); - if (SystemCollisionCheck(cb, &bldgCB) == true) + if (SystemCollisionCheck(cb, &bldgCB) != false) { success = false; } @@ -260,15 +287,6 @@ void Player::createUnit(TYPE_UNIT_ID id, TYPE_COLLISION_BLOCK cb) Resources.Wood -= res.Wood; Resources.Gold -= res.Gold; Resources.Food -= res.Food; - - if (ptrNewUnit->building == true) - { - GfxPrintText_Flash(F("Building created")); - } - else - { - GfxPrintText_Flash(F("Unit created")); - } } else { @@ -300,7 +318,7 @@ void Player::UnitBuildingSelection(void) { TYPE_UNIT* u = &units[i]; - if ( (u->alive == false) || (u->selected == true) ) + if ( (u->alive == false) || (u->selected != false) ) { continue; } @@ -325,13 +343,13 @@ void Player::UnitBuildingSelection(void) void Player::ActionsMenu(void) { - if (showActionsMenu == true) + if (showActionsMenu != false) { for (uint8_t i = 0; i < PLAYER_MAX_UNITS_BUILDINGS; i++) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { uint8_t availableActions = UnitGetAvailableActions(ptrUnit); @@ -369,27 +387,27 @@ void Player::Handler(void) void Player::ButtonHandler(void) { - if (PadButtonPressed(PAD_A) == true) + if (PadButtonPressed(PAD_A) != false) { ButtonAPressed(); } - else if (PadButtonReleased(PAD_A) == true) + else if (PadButtonReleased(PAD_A) != false) { ButtonAReleased(); } - else if (PadButtonPressed(PAD_B) == true) + else if (PadButtonPressed(PAD_B) != false) { ButtonBPressed(); } - else if (PadButtonReleased(PAD_B) == true) + else if (PadButtonReleased(PAD_B) != false) { ButtonBReleased(); } - else if (PadButtonReleased(PAD_LEFT) == true) + else if (PadButtonReleased(PAD_LEFT) != false) { ButtonLeftReleased(); } - else if (PadButtonReleased(PAD_RIGHT) == true) + else if (PadButtonReleased(PAD_RIGHT) != false) { ButtonRightReleased(); } @@ -398,7 +416,7 @@ void Player::ButtonHandler(void) void Player::ButtonAPressed(void) { // Only increase progress bar when any unit has been previously selected - if (anyUnitSelected == true) + if (anyUnitSelected != false) { if (showActionsMenu == false) { @@ -428,7 +446,7 @@ void Player::ButtonAReleased(void) showActionsMenu_counter = 0; } - else if (showActionsMenu == true) + else if (showActionsMenu != false) { uint8_t i = 0; @@ -436,7 +454,7 @@ void Player::ButtonAReleased(void) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { showActionsMenu_counterLevel1 = 0; @@ -474,7 +492,7 @@ void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID unit) { uint8_t w = UnitGetWidthFromID(ptrUnit->id); uint8_t h = UnitGetHeightFromID(ptrUnit->id); - uint8_t new_pos_x = ptrUnit->x + SystemRand(w, w + (w >> 1)); + uint8_t new_pos_x = ptrUnit->x + SystemRand(0, w + (w >> 1)); uint8_t new_pos_y = ptrUnit->y + SystemRand(h, h + (h >> 1)); TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y}; @@ -485,6 +503,26 @@ void Player::ActionCreateBuilding(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID bldg) { TYPE_COLLISION_BLOCK cb = GetCursorPos(); + for (uint8_t i = 0; i < unit_i; i++) + { + TYPE_UNIT* ptrOtherUnit = &units[i]; + TYPE_COLLISION_BLOCK ocb = {.x = ptrOtherUnit->x, + .y = ptrOtherUnit->y, + .w = UnitGetWidthFromID(ptrOtherUnit->id), + .h = UnitGetHeightFromID(ptrOtherUnit->id)}; + + if (ptrOtherUnit->alive == false) + { + continue; + } + + if (SystemCollisionCheck(&cb, &ocb) != false) + { + GfxPrintText_Flash(F("Cannot build here")); + return; + } + } + createUnit(bldg, cb); } @@ -495,7 +533,7 @@ void Player::ButtonBPressed(void) CANCEL_SELECTION_FRAMES = 5 }; - if (anyUnitSelected == true) + if (anyUnitSelected != false) { if (unselectUnits_counter < CANCEL_SELECTION_FRAMES) { @@ -503,22 +541,22 @@ void Player::ButtonBPressed(void) } else { - if (anyUnitSelected == true) + if (anyUnitSelected != false) { uint8_t i; - // Cancel selection of all units + /* Cancel selection of all units */ for (i = 0; i < PLAYER_MAX_UNITS_BUILDINGS; i++) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { ptrUnit->selected = false; } } - // Reset accumulated counter and flags + /* Reset accumulated counter and flags */ unselectUnits_counter = 0; anyUnitSelected = false; showActionsMenu = false; @@ -530,7 +568,7 @@ void Player::ButtonBPressed(void) void Player::ButtonBReleased(void) { - if (anyUnitSelected == true) + if (anyUnitSelected != false) { TYPE_COLLISION_BLOCK cursor = GetCursorPos(); uint8_t i; @@ -539,21 +577,29 @@ void Player::ButtonBReleased(void) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { - UnitMoveTo(ptrUnit, cursor.x, cursor.y); + if (showActionsMenu == false) + { + UnitMoveTo(ptrUnit, cursor.x, cursor.y); + } + else + { + showActionsMenu = false; + showActionsMenu_counter = 0; + } } } } - // Reset accumulated counter + /* Reset accumulated counter */ unselectUnits_counter = 0; } void Player::ButtonLeftReleased(void) { - if (showActionsMenu == true) + if (showActionsMenu != false) { uint8_t i; @@ -561,10 +607,10 @@ void Player::ButtonLeftReleased(void) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { - // We need to iterate over all available actions - // for current unit. + /* We need to iterate over all available actions + * for current unit. */ uint8_t availableActions = UnitGetAvailableActions(ptrUnit); for (uint8_t j = showActionsMenu_index - 1; j != showActionsMenu_index ; j--) @@ -594,7 +640,7 @@ void Player::ButtonRightReleased(void) void Player::IncreaseShowActionsMenuIndex(void) { - if (showActionsMenu == true) + if (showActionsMenu != false) { uint8_t i; @@ -602,10 +648,10 @@ void Player::IncreaseShowActionsMenuIndex(void) { TYPE_UNIT* ptrUnit = &units[i]; - if (ptrUnit->selected == true) + if (ptrUnit->selected != false) { - // We need to iterate over all available actions - // for current unit. + /* We need to iterate over all available actions + * for current unit. */ uint8_t availableActions = UnitGetAvailableActions(ptrUnit); for (uint8_t j = showActionsMenu_index + 1; j != showActionsMenu_index ; j++) |
