131 lines
4.1 KiB
C++
131 lines
4.1 KiB
C++
/* *******************************************************************
|
|
* Includes
|
|
* ******************************************************************/
|
|
|
|
#include "HumanPlayer.h"
|
|
#include "System.h"
|
|
#include <Buttons.h>
|
|
#include <Gamebuino.h>
|
|
|
|
/* *******************************************************************
|
|
* Defines
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Types definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Global variables definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Local variables definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Local prototypes declaration
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Functions definition
|
|
* ******************************************************************/
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Constructor for HumanPlayer class.
|
|
*
|
|
*********************************************************************/
|
|
HumanPlayer::HumanPlayer(const char* const strPlayerName) :
|
|
Player(strPlayerName)
|
|
{
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Event handler executed when human player presses
|
|
* left arrow button.
|
|
*
|
|
*********************************************************************/
|
|
void HumanPlayer::buttonHandler(void)
|
|
{
|
|
for (uint8_t u8Btn = 0; u8Btn < NUM_BTN; u8Btn++)
|
|
{
|
|
/* This array of member functions lists
|
|
* button pressed event handlers for each button. */
|
|
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
|
|
};
|
|
|
|
void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) =
|
|
{
|
|
[BTN_LEFT] = &Camera::onLeftBtnPressed,
|
|
[BTN_UP] = NULL,
|
|
[BTN_RIGHT] = &Camera::onRightBtnPressed,
|
|
[BTN_DOWN] = NULL
|
|
};
|
|
|
|
/* Member function pointer is valid. */
|
|
if (gb.buttons.pressed(u8Btn))
|
|
{
|
|
/* 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. Execute. */
|
|
(_cam.*pCameraBtnHandler)();
|
|
}
|
|
else
|
|
{
|
|
/* Undefined callback for selected button. */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Event handler executed when human player presses
|
|
* left arrow button.
|
|
*
|
|
*********************************************************************/
|
|
void HumanPlayer::onLeftBtnPressed(void)
|
|
{
|
|
/* Also, send the event to Camera object. */
|
|
_cam.onLeftBtnPressed();
|
|
}
|
|
|
|
void HumanPlayer::onABtnPressed(void)
|
|
{
|
|
}
|
|
|
|
void HumanPlayer::drawHandler(void)
|
|
{
|
|
|
|
}
|