diff options
Diffstat (limited to 'Player.cpp')
| -rw-r--r-- | Player.cpp | 47 |
1 files changed, 28 insertions, 19 deletions
@@ -5,7 +5,7 @@ #include "Player.h" #include "Pad.h" #include "Unit.h" -#include <limits.h> +#include "Gameplay.h" /* ************************************** * Defines * @@ -53,7 +53,7 @@ void Player::Init(void) cb.x = SystemRand(0, 20); cb.y = SystemRand(0, 20); - if (createUnit(BARRACKS, cb) == false) + if (createUnit(TOWN_CENTER, cb) == false) { GfxPrintText_Flash(F("Failed to create building!")); } @@ -104,8 +104,6 @@ void Player::DrawHandler(void) uint8_t i; bool bAnyoneSelected = false; - //GfxRenderTiles(&Camera); - for (i = 0; i < PLAYER_MAX_UNITS_BUILDINGS; i++) { TYPE_UNIT* u = &units[i]; @@ -318,7 +316,7 @@ void Player::ActionsMenu(void) IncreaseShowActionsMenuIndex(); } - UNIT_ACTION action = (UNIT_ACTION) (showActionsMenu_index); + UNIT_ACTION action = (UNIT_ACTION)(showActionsMenu_index); const char* str = UnitGetActionString(action); @@ -371,8 +369,6 @@ void Player::ButtonHandler(void) { ButtonRightReleased(); } - - } void Player::ButtonAPressed(void) @@ -418,10 +414,19 @@ void Player::ButtonAReleased(void) if (ptrUnit->selected == true) { + showActionsMenu_counterLevel1 = 0; + switch (showActionsMenu_index) { - case ACTION_CREATE_UNIT: - ActionCreateUnit(ptrUnit); + case ACTION_CREATE_PEASANT: + ActionCreateUnit(ptrUnit, PEASANT); + break; + + case ACTION_BUILD_BARRACKS: + ActionCreateBuilding(ptrUnit, BARRACKS); + break; + + default: break; } @@ -433,18 +438,22 @@ void Player::ButtonAReleased(void) showActionsMenu = (showActionsMenu_counter < ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES)? false: true; } -void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit) +void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID unit) { - if (showActionsMenu_index == ACTION_CREATE_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_y = ptrUnit->y + SystemRand(h, h + (h >> 1)); - TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y}; + 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_y = ptrUnit->y + SystemRand(h, h + (h >> 1)); + TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y}; - createUnit(PEASANT, cb); - } + createUnit(unit, cb); +} + +void Player::ActionCreateBuilding(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID bldg) +{ + TYPE_COLLISION_BLOCK cb = GetCursorPos(); + + createUnit(bldg, cb); } void Player::ButtonBPressed(void) |
