From bfdc0b9f497ef10f6687abcc55d93405c611af11 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Thu, 26 Jul 2018 21:15:59 +0200 Subject: * Menu.cpp: actions for CHOICE_SINGLE_PLAYER_GAME have been moved to a new function called MainMenuSinglePlayer(). + BaseUnit.cpp, BaseUnit.h: new _selected flag. + Camera.cpp, Camera.h: linear movement has been taken over quadratic movement. Also, cursor now moves if dealing with screen borders. + Cursor.cpp, Cursor.h: new Cursor class holds cursor X/Y information. It is meant to be contained inside a HumanPlayer object. * Game.cpp: minor changes in casts and comments. + HumanPlayer.cpp: added callbacks for button release events. * HumanPlayer.cpp, HumanPlayerBtn.cpp: button handling has been transferred from HumanPlayer.cpp to HumanPlayerBtn.cpp in order to improve modularity. + Sprite.cpp: sprite data was not being checked against NULL. - Unit.cpp: drawHandler() is now executed by Player object. --- Sprite.cpp | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'Sprite.cpp') diff --git a/Sprite.cpp b/Sprite.cpp index 131a4f1..2a5c3dc 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -60,23 +60,12 @@ _y(0) /*****************************************************************//** * - * \brief Reportedly, this function updates X/Y coordinates for - * a Sprite object. + * \brief This function draws a \ref Sprite object on the screen. * - * \param x - * X position, relative to screen coordinates origin. - * - * \param y - * Y position, relative to screen coordinates origin. + * \remarks If \ref Sprite object must be followed by a \ref Camera + * object, X and Y coordinates are automatically adjusted. * *********************************************************************/ -void Sprite::setPos(const uint8_t x, const uint8_t y) -{ - /* Update coords according to input parameters. */ - _x = x; - _y = y; -} - void Sprite::draw(void) { gb.display.setColor(_colour, WHITE); @@ -86,10 +75,36 @@ void Sprite::draw(void) const uint8_t x = _followCam ? _cam->getX(_x) : _x; const uint8_t y = _followCam ? _cam->getY(_y) : _y; - gb.display.drawBitmap(x, y, _pu8SprData); + 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; +} -- cgit v1.2.3