blob: 766bf7de79e8c30b4bc3219690fe917c34f11b28 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* **************************************
* Includes *
* **************************************/
#include "HumanPlayer.h"
#include "System.h"
#include <Buttons.h>
#include <Gamebuino.h>
/* *******************************************************************
* Defines
* ******************************************************************/
/* *******************************************************************
* Types definition
* ******************************************************************/
/* *******************************************************************
* Global variables
* ******************************************************************/
/* *******************************************************************
* Local variables
* ******************************************************************/
/* *******************************************************************
* 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 btn = 0; btn < NUM_BTN; btn++)
{
/* 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(btn))
{
/* 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[btn];
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[btn];
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)
{
}
|