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. --- Cursor.cpp | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Cursor.cpp (limited to 'Cursor.cpp') diff --git a/Cursor.cpp b/Cursor.cpp new file mode 100644 index 0000000..2b02ad6 --- /dev/null +++ b/Cursor.cpp @@ -0,0 +1,126 @@ +/* ******************************************************************* + * Includes + * ******************************************************************/ + +#include "Cursor.h" +#include + +/* ******************************************************************* + * Defines + * ******************************************************************/ + +#define CURSOR_DEFAULT_X (static_cast(80 >> 1)) +#define CURSOR_DEFAULT_Y (static_cast(44 >> 1)) + +/* ******************************************************************* + * Types definition + * ******************************************************************/ + +/* ******************************************************************* + * Global variables definition + * ******************************************************************/ + +/* ******************************************************************* + * Local variables definition + * ******************************************************************/ + +/* ******************************************************************* + * Local prototypes declaration + * ******************************************************************/ + +/* ******************************************************************* + * Functions definition + * ******************************************************************/ + +/*****************************************************************//** + * + * \brief Constructor for Cursor class. + * + *********************************************************************/ +Cursor::Cursor(void) : +_x(CURSOR_DEFAULT_X), +_y(CURSOR_DEFAULT_Y) +{ +} + +/*****************************************************************//** + * + * \brief This function moves the cursor to a given position, + * as long as X coordinates are between {0, CURSOR_DEFAULT_X} + * and Y coordinates are between {0, CURSOR_DEFAULT_Y}. + * + * \param x + * X position diff. + * + * \param y + * Y position diff. + * + *********************************************************************/ +void Cursor::move(const int8_t x, const int8_t y) +{ + if ((static_cast(_x) + x >= 0) + && + (static_cast(_x) + x <= CURSOR_DEFAULT_X)) + { + _x += x; + } + + if ((static_cast(_y) + y >= 0) + && + (static_cast(_y) + y <= CURSOR_DEFAULT_Y)) + { + _y += y; + } +} + +/*****************************************************************//** + * + * \brief This function simply returns cursor X position. + * + * \return Returns cursor X position. + * + *********************************************************************/ +uint8_t Cursor::getX(void) +{ + return _x; +} + +/*****************************************************************//** + * + * \brief This function simply returns cursor Y position. + * + * \return Returns cursor Y position. + * + *********************************************************************/ +uint8_t Cursor::getY(void) +{ + return _y; +} + +/*****************************************************************//** + * + * \brief This function returns whether cursor is on its initial + * X position. + * + * \return True if \ref Cursor object is on its initial X position, + * false otherwise. + * + *********************************************************************/ +bool Cursor::isXCentered(void) +{ + return _x == CURSOR_DEFAULT_X; +} + +/*****************************************************************//** + * + * \brief This function returns whether cursor is on its initial + * Y position. + * + * \return True if \ref Cursor object is on its initial Y position, + * false otherwise. + * + *********************************************************************/ +bool Cursor::isYCentered(void) +{ + return _y == CURSOR_DEFAULT_Y; +} -- cgit v1.2.3