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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* *******************************************************************
* Includes
* ******************************************************************/
#include "BaseUnit.h"
#include "Camera.h"
#include "System.h"
#include "Sprite.h"
#include <stdbool.h>
#include <stdint.h>
#include <Gamebuino.h>
/* *******************************************************************
* Defines
* ******************************************************************/
/* *******************************************************************
* Types definition
* ******************************************************************/
/* *******************************************************************
* Global variables definition
* ******************************************************************/
/* *******************************************************************
* Local variables definition
* ******************************************************************/
static const Camera* cam;
/* *******************************************************************
* Local prototypes declaration
* ******************************************************************/
/* *******************************************************************
* Functions definition
* ******************************************************************/
/*****************************************************************//**
*
* \brief Constructor for BaseUnit class.
*
*********************************************************************/
BaseUnit::BaseUnit(void) :
_hp(0),
_alive(false),
_selected(false),
_x(0),
_y(0)
{
}
/*****************************************************************//**
*
* \brief This function is executed when user wants to create
* a new object derived from BaseUnit, and this function
* sets default parameters for a BaseUnit abstract object.
*
*********************************************************************/
void BaseUnit::create(const uint16_t x, const uint16_t y)
{
_alive = true;
_x = x;
_y = y;
}
/*****************************************************************//**
*
* \brief Periodical handler for BaseUnit class.
*
*********************************************************************/
void BaseUnit::handler(void)
{
}
/*****************************************************************//**
*
* \brief This function sets global camera for all BaseUnit
* instances.
*
*********************************************************************/
void BaseUnit::setCamera(const Camera* const c)
{
cam = c;
}
/*****************************************************************//**
*
* \brief Periodical draw handler for BaseUnit class.
*
*********************************************************************/
void BaseUnit::drawHandler(const uint8_t* const pu8SprData)
{
if (isSelected())
{
/* Retrieve unit width from sprite data. */
const uint8_t w = Sprite::getWidth(pu8SprData);
/* Retrieve unit height from sprite data. */
const uint8_t h = Sprite::getHeight(pu8SprData);
if (cam != NULL)
{
const uint8_t x = cam->getX(_x - w);
const uint8_t y = cam->getY(_y - h);
gb.display.drawRoundRect(x, y, w << 1, h << 1, 2);
}
}
else
{
/* BaseUnit object is not selected. Exit. */
}
}
/*****************************************************************//**
*
* \brief Returns Unit alive flag.
*
* \return Returns true if Unit object is alive, false otherwise.
*
*********************************************************************/
bool BaseUnit::isAlive(void)
{
return _alive;
}
/*****************************************************************//**
*
* \brief Returns Unit selected flag.
*
* \return Returns true if Unit object is selected, false otherwise.
*
*********************************************************************/
bool BaseUnit::isSelected(void)
{
return _selected;
}
/*****************************************************************//**
*
* \brief This function selects/deselects a \ref BaseUnit object
* according to requested state.
*
* \param bSelect
* If true, unit must be selected. Otherwise, unit
* must be deselected.
*
*********************************************************************/
void BaseUnit::setSelected(const bool bSelect)
{
_selected = bSelect;
}
/*****************************************************************//**
*
* \brief Returns Unit X coordinates.
*
* \return Returns Unit X coordinates.
*
*********************************************************************/
uint16_t BaseUnit::getX(void)
{
return _x;
}
/*****************************************************************//**
*
* \brief Returns Unit Y coordinates.
*
* \return Returns Unit Y coordinates.
*
*********************************************************************/
uint16_t BaseUnit::getY(void)
{
return _y;
}
|