diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2017-11-05 05:38:31 +0100 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2017-11-05 05:38:31 +0100 |
| commit | 8fba2176bc34aa7e507f0b9d983427bb5e522e17 (patch) | |
| tree | d5e1c7d5560f30581fc5a1957121fc0a198b62f7 /Player.cpp | |
| parent | 2cf2d608af862e812e7fd3ac580f869141a96fa7 (diff) | |
* Modified shadows for Town centre.
* Bugfixes in unit movement and collision detection. Now it should work fine.
* Added include guards to all *.i files.
* Other minor changes
Diffstat (limited to 'Player.cpp')
| -rw-r--r-- | Player.cpp | 82 |
1 files changed, 57 insertions, 25 deletions
@@ -30,6 +30,13 @@ Player::~Player(void) void Player::Init(void) { + enum + { + DEFAULT_WOOD = 1000, + DEFAULT_GOLD = 1000, + DEFAULT_FOOD = 1000 + }; + uint8_t i; unit_i = 0; @@ -46,17 +53,14 @@ void Player::Init(void) TYPE_COLLISION_BLOCK cb; - Resources.Wood = 25; - Resources.Gold = 50; - Resources.Food = 75; + Resources.Wood = DEFAULT_WOOD; + Resources.Gold = DEFAULT_GOLD; + Resources.Food = DEFAULT_FOOD; - cb.x = SystemRand(0, 20); - cb.y = SystemRand(0, 20); + cb.x = SystemRand(0, 24); + cb.y = SystemRand(0, 24); - if (createUnit(TOWN_CENTER, cb) == false) - { - GfxPrintText_Flash(F("Failed to create building!")); - } + createUnit(TOWN_CENTER, cb); cb.x = SystemRand(48, 56); cb.y = SystemRand(48, 56); @@ -68,10 +72,7 @@ void Player::Init(void) showActionsMenu = false; anyUnitSelected = false; - if (createUnit(PEASANT, cb) == false) - { - GfxPrintText_Flash(F("Failed to create unit!")); - } + createUnit(PEASANT, cb); } void Player::showHealth(uint8_t hp) @@ -152,8 +153,8 @@ void Player::ShowResources(void) { char str[16]; - gb.display.setColor(GFX_WHITE); - gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 5); + gb.display.setColor(GFX_GRAY); + gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 8); snprintf(str, sizeof(str), "W=%d", Resources.Wood); @@ -161,11 +162,15 @@ void Player::ShowResources(void) snprintf(str, sizeof(str), "G=%d", Resources.Gold); - GfxPrintTextFont(str, font3x3, 22, 1); + GfxPrintTextFont(str, font3x3, 2, 5); snprintf(str, sizeof(str), "F=%d", Resources.Food); GfxPrintTextFont(str, font3x3, 42, 1); + + snprintf(str, sizeof(str), "%d/%d", unit_i, PLAYER_MAX_UNITS_BUILDINGS); + + GfxPrintTextFont(str, font3x3, 42, 5); } @@ -191,7 +196,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) == true) { success = false; } @@ -227,29 +232,48 @@ bool Player::checkNewBuildingPosition(TYPE_COLLISION_BLOCK * cb) return true; } -bool Player::createUnit(TYPE_UNIT_ID id, TYPE_COLLISION_BLOCK cb) +void Player::createUnit(TYPE_UNIT_ID id, TYPE_COLLISION_BLOCK cb) { + TYPE_RESOURCES res = UnitNeededResourcesFromID(id); + + if ( (Resources.Food < res.Food) + || + (Resources.Wood < res.Wood) + || + (Resources.Gold < res.Gold) ) + { + GfxPrintText_Flash(F("Insuff. resources")); + return; + } + if (unit_i < PLAYER_MAX_UNITS_BUILDINGS) { - TYPE_UNIT* ptrNewUnit = &units[unit_i]; + TYPE_UNIT* ptrNewUnit = &units[unit_i++]; ptrNewUnit->id = id; ptrNewUnit->x = cb.x; ptrNewUnit->y = cb.y; ptrNewUnit->hp = UnitGetHpFromID(id); ptrNewUnit->alive = true; - ptrNewUnit->building = (id > MAX_UNIT_ID); - unit_i++; + /* Substract resources from player */ + Resources.Wood -= res.Wood; + Resources.Gold -= res.Gold; + Resources.Food -= res.Food; - return true; + if (ptrNewUnit->building == true) + { + GfxPrintText_Flash(F("Building created")); + } + else + { + GfxPrintText_Flash(F("Unit created")); + } } else { - return false; + GfxPrintText_Flash(F("Popul. limit")); } - - return false; } TYPE_COLLISION_BLOCK Player::GetCursorPos(void) @@ -422,10 +446,18 @@ void Player::ButtonAReleased(void) ActionCreateUnit(ptrUnit, PEASANT); break; + case ACTION_CREATE_SOLDIER: + ActionCreateUnit(ptrUnit, SOLDIER); + break; + case ACTION_BUILD_BARRACKS: ActionCreateBuilding(ptrUnit, BARRACKS); break; + case ACTION_BUILD_TOWER_CENTER: + ActionCreateBuilding(ptrUnit, TOWN_CENTER); + break; + default: break; } |
