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
|
/* *******************************************************************
* Includes
* ******************************************************************/
#include "Sprite.h"
#include "System.h"
/* *******************************************************************
* Defines
* ******************************************************************/
/* *******************************************************************
* Types definition
* ******************************************************************/
/* *******************************************************************
* Global variables definition
* ******************************************************************/
const Camera* _cam;
/* *******************************************************************
* Local variables definition
* ******************************************************************/
/* *******************************************************************
* Local prototypes declaration
* ******************************************************************/
/* *******************************************************************
* Functions definition
* ******************************************************************/
/*****************************************************************//**
*
* \brief Constructor for Sprite class.
*
* \param pu8SprData
* Pointer to raw sprite data.
*
* \param _followCam
* Sprite is moved by camera. Default value is true.
*
* \param u8Colour
* Sprite colour. Default value is BLACK.
*
* \param rotation
* Sprite rotation. Default value is NOROT.
*
*********************************************************************/
Sprite::Sprite(const uint8_t* pu8SprData, const bool followCam, const uint8_t u8Colour, const uint8_t rotation) :
_pu8SprData(pu8SprData),
_followCam(followCam),
_colour(u8Colour),
_rotation(rotation),
_x(0),
_y(0)
{
}
/*****************************************************************//**
*
* \brief This function draws a \ref Sprite object on the screen.
*
* \remarks If \ref Sprite object must be followed by a \ref Camera
* object, X and Y coordinates are automatically adjusted.
*
*********************************************************************/
void Sprite::draw(void)
{
gb.display.setColor(_colour, WHITE);
if (_cam != NULL)
{
const uint8_t x = _followCam ? _cam->getX(_x) : _x;
const uint8_t y = _followCam ? _cam->getY(_y) : _y;
if (_pu8SprData != NULL)
{
gb.display.drawBitmap(x, y, _pu8SprData);
}
else
{
/* Undefined sprite data. */
}
}
else
{
/* Error: uninitialized camera. */
}
}
/*****************************************************************//**
*
* \brief Reportedly, this function updates X/Y coordinates for
* a Sprite object.
*
* \param x
* X position, relative to screen coordinates origin.
*
* \param y
* Y position, relative to screen coordinates origin.
*
*********************************************************************/
void Sprite::setPos(const uint8_t x, const uint8_t y)
{
/* Update coords according to input parameters. */
_x = x;
_y = y;
}
|