111 lines
3.3 KiB
C++
111 lines
3.3 KiB
C++
/* *******************************************************************
|
|
* 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;
|
|
}
|