summaryrefslogtreecommitdiff
path: root/Player.cpp
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-08-26 11:18:11 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-08-26 11:18:11 +0200
commite944ccbfc5df97da7e90a69d51c5534fa57322d0 (patch)
tree48dd3e8a81ced4396d1fac56108b9d9275cfc619 /Player.cpp
parent35937cb697b2d2fb7902a8473d6095816f602237 (diff)
parent54ea724c5d2f3a2c5bdf3cfe6f6807d43a5ae9d7 (diff)
downloadpocketempires-e944ccbfc5df97da7e90a69d51c5534fa57322d0.tar.gz
Merge branch 'master' of https://github.com/XaviDCR92/PocketEmpires
Diffstat (limited to 'Player.cpp')
-rw-r--r--Player.cpp118
1 files changed, 99 insertions, 19 deletions
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);
}