From 54ea724c5d2f3a2c5bdf3cfe6f6807d43a5ae9d7 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Sat, 26 Aug 2017 11:13:20 +0200 Subject: + Added MouseSpr and Unit modules. * Unit actions, building actions. --- Player.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 19 deletions(-) (limited to 'Player.cpp') diff --git a/Player.cpp b/Player.cpp index 95f23e7..39886a9 100644 --- a/Player.cpp +++ b/Player.cpp @@ -9,6 +9,8 @@ * **************************************/ #define CANCEL_SELECTION_NO_FRAMES 5 +#define ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES 5 +#define MAX_SELECTION_DIST 400 /* ************************************** * Local variables * @@ -133,6 +135,11 @@ void Player::DrawHandler(void) UnitSelectedOptions(u); } } + + if(progress_bar != 0) + { + GfxDrawRectangle(X_SCREEN_RESOLUTION - 16, Y_SCREEN_RESOLUTION - 4, progress_bar, 2, GFX_BLACK); + } } bool Player::checkNewBuildingPosition(TYPE_COLLISION_BLOCK * cb) @@ -264,7 +271,7 @@ void Player::UnitBuildingSelection(void) { TYPE_UNIT * u = &units[i]; - if(u->alive == false) + if( (u->alive == false) || (u->selected == true) ) { continue; } @@ -291,7 +298,7 @@ void Player::UnitBuildingSelection(void) { TYPE_BUILDING * b = &buildings[i]; - if(b->built == false) + if( (b->built == false) || (b->selected == true) ) { continue; } @@ -322,9 +329,9 @@ void Player::UnitBuildingSelection(void) selectedBuilding = NULL; } - if( (nearest_unit_dist > 400) + if( (nearest_unit_dist > MAX_SELECTION_DIST) && - (nearest_building_dist > 400) ) + (nearest_building_dist > MAX_SELECTION_DIST) ) { selectedUnit = NULL; selectedBuilding = NULL; @@ -341,20 +348,68 @@ void Player::UnitBuildingSelection(void) GfxPrintText(buf, X_SCREEN_RESOLUTION - 32, 24);*/ } -void Player::Handler(void) +void Player::BuildingUnitActions(void) { - static bool bCancelSelection = false; + const char* pActionStr = NULL; + + for(uint8_t i = 0; i < PLAYER_MAX_BUILDINGS; i++) + { + if(buildings[i].selected == true) + { + BuildingSelectedOptions(selectedBuilding); + break; + } + } + + if(pActionStr == NULL) + { + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) + { + if(units[i].selected == true) + { + pActionStr = UnitSelectedOptions(selectedUnit); + break; + } + } + } + if(pActionStr != NULL) + { + GfxPrintTextFont(pActionStr, font3x3, 48, Y_SCREEN_RESOLUTION - 4); + } +} + +void Player::Handler(void) +{ CameraHandler(&Camera); UnitBuildingSelection(); - for(int i = 0; i < PLAYER_MAX_UNITS; i++) + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) { TYPE_UNIT * ptrUnit = &units[i]; UnitHandler(ptrUnit); } + + ButtonHandler(); + + BuildingUnitActions(); + + GfxShowResources(&Resources); +} + +void Player::ButtonHandler(void) +{ + static bool bCancelSelection = false; + + if(PadButtonPressed(PAD_A) == true) + { + if(progress_bar < ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES) + { + progress_bar++; + } + } if(PadButtonReleased(PAD_A) == true) { @@ -374,7 +429,7 @@ void Player::Handler(void) GfxPrintText_Flash(F("Building built!\0")); }*/ - for(int i = 0; i < PLAYER_MAX_UNITS; i++) + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) { TYPE_UNIT * u = &units[i]; @@ -384,7 +439,7 @@ void Player::Handler(void) } } - for(int i = 0; i < PLAYER_MAX_BUILDINGS; i++) + for(uint8_t i = 0; i < PLAYER_MAX_BUILDINGS; i++) { TYPE_BUILDING * b = &buildings[i]; @@ -394,18 +449,31 @@ void Player::Handler(void) } } } + else if(PadButtonPressedFrames(PAD_A, ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES) == true) + { + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) + { + TYPE_UNIT* u = &units[i]; + + if(u->selected == true) + { + UnitAcceptAction(u); + break; + } + } + } else if( (PadButtonPressedFrames(PAD_B, CANCEL_SELECTION_NO_FRAMES) == true) && (bCancelSelection == false) ) { - for(int i = 0; i < PLAYER_MAX_UNITS; i++) + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) { TYPE_UNIT * u = &units[i]; u->selected = false; } - for(int i = 0; i < PLAYER_MAX_BUILDINGS; i++) + for(uint8_t i = 0; i < PLAYER_MAX_BUILDINGS; i++) { TYPE_BUILDING * b = &buildings[i]; @@ -416,30 +484,42 @@ void Player::Handler(void) selectedBuilding = NULL; bCancelSelection = true; + showUnitBuildingOptions = true; + } + else + { + // Button A is not pressed. Reset progress bar. + progress_bar = 0; } if( (PadButtonReleased(PAD_B) == true) && (bCancelSelection == false) ) { - TYPE_COLLISION_BLOCK cursor = GetCursorPos(); - - for(int i = 0; i < PLAYER_MAX_UNITS; i++) + if(showUnitBuildingOptions == false) { - TYPE_UNIT * u = &units[i]; + TYPE_COLLISION_BLOCK cursor = GetCursorPos(); - if(u->selected == true) + for(uint8_t i = 0; i < PLAYER_MAX_UNITS; i++) { - UnitMoveTo(u, cursor.x, cursor.y); + TYPE_UNIT * u = &units[i]; + + if(u->selected == true) + { + UnitMoveTo(u, cursor.x, cursor.y); + } } } + else + { + showUnitBuildingOptions = false; + } } else if( (PadButtonReleased(PAD_B) == true) && (bCancelSelection == true) ) { bCancelSelection = false; + UnitResetMenuLevel(); } - - GfxShowResources(&Resources); } -- cgit v1.2.3