diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-10 00:04:16 +0200 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-10 00:04:16 +0200 |
| commit | 14c12aeea30d59e9c811f1cc8c7019053d646033 (patch) | |
| tree | 7bff078a702a1b2949c37930adfc6fd2fc45c3cb /HumanPlayer.cpp | |
| parent | 188d74cb789f33967daf6daa5af17d41b6f59d4e (diff) | |
More work on Unit/BaseUnit concepts.
Diffstat (limited to 'HumanPlayer.cpp')
| -rw-r--r-- | HumanPlayer.cpp | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/HumanPlayer.cpp b/HumanPlayer.cpp index c9b60e4..ae16f97 100644 --- a/HumanPlayer.cpp +++ b/HumanPlayer.cpp @@ -39,6 +39,24 @@ HumanPlayer::HumanPlayer(const char* const strPlayerName) : Player(strPlayerName) { + _unitsMap[0].create(Unit::UNIT_ID_PEASANT); +} + +/*****************************************************************//** + * + * \brief Periodical event handler that calls HumanPlayer subtasks. + * + *********************************************************************/ +void HumanPlayer::handler(void) +{ + this->buttonHandler(); + + for (uint8_t i = 0; i < MAX_UNITS; i++) + { + Unit& unit = _unitsMap[i]; + + unit.handler(); + } } /*****************************************************************//** @@ -53,7 +71,7 @@ void HumanPlayer::buttonHandler(void) { /* This array of member functions lists * button pressed event handlers for each button. */ - void (HumanPlayer::*const apBtnHandlerTable[NUM_BTN])(void) = + static void (HumanPlayer::*const apBtnHandlerTable[NUM_BTN])(void) = { [BTN_LEFT] = NULL, [BTN_UP] = NULL, @@ -63,7 +81,7 @@ void HumanPlayer::buttonHandler(void) [BTN_B] = &HumanPlayer::onBBtnPressed }; - void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) = + static void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) = { [BTN_LEFT] = &Camera::onLeftBtnPressed, [BTN_UP] = NULL, @@ -71,7 +89,6 @@ void HumanPlayer::buttonHandler(void) [BTN_DOWN] = NULL }; - /* Member function pointer is valid. */ if (gb.buttons.pressed(u8Btn)) { /* Key has been pressed. Execute both @@ -105,26 +122,38 @@ void HumanPlayer::buttonHandler(void) /* Undefined callback for selected button. */ } } + else + { + /* Key has not been pressed. Exit. */ + } } } /*****************************************************************//** * * \brief Event handler executed when human player presses - * left arrow button. + * A button. * *********************************************************************/ -void HumanPlayer::onLeftBtnPressed(void) +void HumanPlayer::onABtnPressed(void) { - /* Also, send the event to Camera object. */ - _cam.onLeftBtnPressed(); } -void HumanPlayer::onABtnPressed(void) +/*****************************************************************//** + * + * \brief Event handler executed when human player presses + * B button. + * + *********************************************************************/ +void HumanPlayer::onBBtnPressed(void) { } +/*****************************************************************//** + * + * \brief This function draws all units and player UI. + * + *********************************************************************/ void HumanPlayer::drawHandler(void) { - } |
