127 lines
3.6 KiB
C++
127 lines
3.6 KiB
C++
/* *******************************************************************
|
|
* Includes
|
|
* ******************************************************************/
|
|
|
|
#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
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Types definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Global variables definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* 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
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Functions definition
|
|
* ******************************************************************/
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Constructor for HumanPlayer class.
|
|
*
|
|
*********************************************************************/
|
|
HumanPlayer::HumanPlayer(const char* const strPlayerName, const Camera& cam) :
|
|
Player(strPlayerName),
|
|
_cam(cam),
|
|
_ABtnFrames(0),
|
|
_eState(PLAYER_STATE_IDLE)
|
|
{
|
|
_unitsMap[0].create(Unit::UNIT_ID_PEASANT, 16, 16);
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Periodical event handler that calls HumanPlayer subtasks.
|
|
*
|
|
*********************************************************************/
|
|
void HumanPlayer::handler(void)
|
|
{
|
|
/* Execute HumanPlayerBtn submodule. */
|
|
buttonHandler();
|
|
|
|
/* Execute parent class unit handler. */
|
|
Player::handleUnits();
|
|
|
|
drawHandler();
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief This function draws all units and player UI.
|
|
*
|
|
*********************************************************************/
|
|
void HumanPlayer::drawHandler(void)
|
|
{
|
|
/* Execute base class Unit drawHandler. */
|
|
Player::drawUnits();
|
|
|
|
if (_eState == PLAYER_STATE_UNIT_MENU)
|
|
{
|
|
gb.display.setColor(BLACK);
|
|
gb.display.drawRect(0, 40, 84, 8);
|
|
}
|
|
|
|
/* 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 This function looks for units nearby and selects them.
|
|
* If no units can be selected, player state remains
|
|
* unchanged.
|
|
*
|
|
* \return New player state.
|
|
*
|
|
* \see \ref tPlayerState.
|
|
*
|
|
*********************************************************************/
|
|
enum tPlayerState HumanPlayer::selectUnit(void)
|
|
{
|
|
}
|