diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-26 21:15:59 +0200 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-26 21:15:59 +0200 |
| commit | bfdc0b9f497ef10f6687abcc55d93405c611af11 (patch) | |
| tree | 43914b2eada0bf5fb09093d61a250d4930b57a5d /HumanPlayer.cpp | |
| parent | 853c6cddaa2713a9eb0c1f1c55e3f61592f04a46 (diff) | |
| download | pocketempires-bfdc0b9f497ef10f6687abcc55d93405c611af11.tar.gz | |
* Menu.cpp: actions for CHOICE_SINGLE_PLAYER_GAME have been moved to a new function called MainMenuSinglePlayer().
+ BaseUnit.cpp, BaseUnit.h: new _selected flag.
+ Camera.cpp, Camera.h: linear movement has been taken over quadratic movement. Also, cursor now moves if dealing with screen borders.
+ Cursor.cpp, Cursor.h: new Cursor class holds cursor X/Y information. It is meant to be contained inside a HumanPlayer object.
* Game.cpp: minor changes in casts and comments.
+ HumanPlayer.cpp: added callbacks for button release events.
* HumanPlayer.cpp, HumanPlayerBtn.cpp: button handling has been transferred from HumanPlayer.cpp to HumanPlayerBtn.cpp in order to improve modularity.
+ Sprite.cpp: sprite data was not being checked against NULL.
- Unit.cpp: drawHandler() is now executed by Player object.
Diffstat (limited to 'HumanPlayer.cpp')
| -rw-r--r-- | HumanPlayer.cpp | 143 |
1 files changed, 53 insertions, 90 deletions
diff --git a/HumanPlayer.cpp b/HumanPlayer.cpp index e83d4e6..d13bc6b 100644 --- a/HumanPlayer.cpp +++ b/HumanPlayer.cpp @@ -4,8 +4,12 @@ #include "HumanPlayer.h" #include "System.h" +#include "Sprite.h" +#include "Cursor.h" #include <Buttons.h> #include <Gamebuino.h> +#include <stdint.h> +#include <string.h> /* ******************************************************************* * Defines @@ -23,6 +27,25 @@ * Local variables definition * ******************************************************************/ +/*****************************************************************//** + * + * \brief Bitmap data for idle UNIT_ID_PEASANT. + * + *********************************************************************/ +static const PROGMEM uint8_t au8MouseSprData[] = +{ + 8, + 8, + 0xFC, + 0x84, + 0x88, + 0x84, + 0xA2, + 0xD1, + 0x0A, + 0x04 +}; + /* ******************************************************************* * Local prototypes declaration * ******************************************************************/ @@ -38,7 +61,9 @@ *********************************************************************/ HumanPlayer::HumanPlayer(const char* const strPlayerName, const Camera& cam) : Player(strPlayerName), -_cam(cam) +_cam(cam), +_ABtnFrames(0), +_eState(PLAYER_STATE_IDLE) { _unitsMap[0].create(Unit::UNIT_ID_PEASANT, 16, 16); } @@ -50,114 +75,52 @@ _cam(cam) *********************************************************************/ void HumanPlayer::handler(void) { - this->buttonHandler(); + /* Execute HumanPlayerBtn submodule. */ + buttonHandler(); - for (uint8_t i = 0; i < MAX_UNITS; i++) - { - Unit& unit = _unitsMap[i]; + /* Execute parent class unit handler. */ + Player::handleUnits(); - unit.handler(); - } + drawHandler(); } /*****************************************************************//** * - * \brief Event handler executed when human player presses - * left arrow button. + * \brief This function draws all units and player UI. * *********************************************************************/ -void HumanPlayer::buttonHandler(void) +void HumanPlayer::drawHandler(void) { - for (uint8_t u8Btn = 0; u8Btn < NUM_BTN; u8Btn++) + /* Execute base class Unit drawHandler. */ + Player::drawUnits(); + + if (_eState == PLAYER_STATE_UNIT_MENU) { - /* This array of member functions lists - * button pressed event handlers for each button. */ - static void (HumanPlayer::*const apBtnHandlerTable[NUM_BTN])(void) = - { - [BTN_LEFT] = NULL, - [BTN_UP] = NULL, - [BTN_RIGHT] = NULL, - [BTN_DOWN] = NULL, - [BTN_A] = &HumanPlayer::onABtnPressed, - [BTN_B] = &HumanPlayer::onBBtnPressed - }; - - static void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) = - { - [BTN_LEFT] = &Camera::onLeftBtnPressed, - [BTN_UP] = &Camera::onUpBtnPressed, - [BTN_RIGHT] = &Camera::onRightBtnPressed, - [BTN_DOWN] = &Camera::onDownBtnPressed - }; - - if (gb.buttons.timeHeld(u8Btn) > 0) - { - /* Key has been pressed. Execute both - * HumanPlayer and Camera handlers, if available. */ - - /* Get pointer to HumanPlayer member function for selected button. */ - void (HumanPlayer::*const pBtnHandler)(void) = apBtnHandlerTable[u8Btn]; - - if (pBtnHandler != NULL) - { - /* HumanPlayer member function - * pointer is available. Execute. */ - (this->*pBtnHandler)(); - } - else - { - /* Undefined callback for selected button. */ - } - - /* Get pointer to Camera member function for selected button. */ - void (Camera::*const pCameraBtnHandler)(void) = apBtnCameraHandlerTable[u8Btn]; - - if (pCameraBtnHandler != NULL) - { - /* Camera member function pointer - * is available. - * Note: "const" qualifier must be - * removed since camera button event - * handler modifies Camera class members. */ - ((Camera&)_cam.*pCameraBtnHandler)(); - } - else - { - /* Undefined callback for selected button. */ - } - } - else - { - /* Key has not been pressed. Exit. */ - } + gb.display.setColor(BLACK); + gb.display.drawRect(0, 40, 84, 8); } -} -/*****************************************************************//** - * - * \brief Event handler executed when human player presses - * A button. - * - *********************************************************************/ -void HumanPlayer::onABtnPressed(void) -{ + /* Configure cursor sprite object. */ + Sprite cursorSpr(au8MouseSprData, false, INVERT); + + /* Transfer Cursor to Sprite coordinates. */ + cursorSpr.setPos(_cursor.getX(), _cursor.getY()); + + /* Draw cursor sprite. */ + cursorSpr.draw(); } /*****************************************************************//** * - * \brief Event handler executed when human player presses - * B button. + * \brief This function looks for units nearby and selects them. + * If no units can be selected, player state remains + * unchanged. * - *********************************************************************/ -void HumanPlayer::onBBtnPressed(void) -{ -} - -/*****************************************************************//** + * \return New player state. * - * \brief This function draws all units and player UI. + * \see \ref tPlayerState. * *********************************************************************/ -void HumanPlayer::drawHandler(void) +enum tPlayerState HumanPlayer::selectUnit(void) { } |
