From 14c12aeea30d59e9c811f1cc8c7019053d646033 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Tue, 10 Jul 2018 00:04:16 +0200 Subject: [PATCH] More work on Unit/BaseUnit concepts. --- BaseUnit.cpp | 16 +- BaseUnit.h | 12 +- Exe/POCKET.ELF | Bin 28184 -> 30272 bytes Exe/POCKET.HEX | 1576 ++++++++++++++++++++++--------------------- Exe/POCKET.MAP | 847 ++++++++++++----------- Game.cpp | 56 +- Game.h | 36 +- HumanPlayer.cpp | 51 +- HumanPlayer.h | 5 +- Makefile | 2 +- MouseSpr.i | 30 +- Player.cpp | 11 +- Player.h | 9 +- PocketEmpires.geany | 48 +- Sprite.cpp | 43 +- Sprite.h | 9 +- Unit.cpp | 102 +++ Unit.h | 53 ++ 18 files changed, 1673 insertions(+), 1233 deletions(-) create mode 100644 Unit.cpp create mode 100644 Unit.h diff --git a/BaseUnit.cpp b/BaseUnit.cpp index ff431b5..8de5a05 100644 --- a/BaseUnit.cpp +++ b/BaseUnit.cpp @@ -3,6 +3,8 @@ * ******************************************************************/ #include "BaseUnit.h" +#include +#include /* ******************************************************************* * Defines @@ -33,7 +35,19 @@ * \brief Constructor for BaseUnit class. * *********************************************************************/ -BaseUnit::BaseUnit(void) +BaseUnit::BaseUnit(void) : +_hp(0), +_bAlive(false), +_x(0), +_y(0) { } +/*****************************************************************//** + * + * \brief Periodical handler for BaseUnit class. + * + *********************************************************************/ +void BaseUnit::handler(void) +{ +} diff --git a/BaseUnit.h b/BaseUnit.h index 485ac94..4ce1186 100644 --- a/BaseUnit.h +++ b/BaseUnit.h @@ -5,7 +5,8 @@ * Includes * ******************************************************************/ -#include "BaseUnit.h" +#include +#include /* ******************************************************************* * Defines @@ -30,7 +31,14 @@ class BaseUnit { public: - explicit BaseUnit(void); + explicit BaseUnit(); + void handler(void); + + protected: + uint16_t _hp; /**< Health points. */ + bool _bAlive; /**< Alive flag. */ + uint8_t _x; /**< X coordinate inside map. */ + uint8_t _y; /**< Y coordinate inside map. */ }; #endif /* BASEUNIT_H__ */ diff --git a/Exe/POCKET.ELF b/Exe/POCKET.ELF index 85108c7c9559d7ec0093df64271d1144f30f31f6..0dfa63e1a771ffa1ad0a0a92f8ba7718d84975a1 100755 GIT binary patch delta 10135 zcma)?3tUuX`p3^XGb0yaZp<*;87?9sFo0%ehKiT86wu0AGhqw}5di^R+ijg0Mv|Mr z@D7+|mjB)S_%A*_D-6b}CCUHyo(qiZ{y)2i&zW<+&-=XZ z`#jJ4yq6h$?t8ZD3fmguzf{RElNpAYTJ4IBy)QX~Vd$-bgu~6^?gBHcU62>ymEL2h zNV*dyL5A`om&0gdxd8Ws|MJe#|Eq3((7($5wY?>URqNIiGK<%(s%DCra^|5`WlxnB znk!0)9~-CIz%(-3JJVSYr`V}@k;E$tY^9toKKgKX-`D)9BcC48@h|gx`739xo#nbz zt$}U3rtJ0k=0+U9>-=7x?TT#MGh?4m&ka3)l>eMpcExPH&8po;OkHUwe2(2vyC=du zLui1TVbty-PVN3c@oTq+M3ZjP#CGvF*&4@(rsoEdEouBQwobDxI>Qoc8=t7TC))0C zIclKEY}I+x?h9OZ-o@@`&%1cFd+yk}xD!7W@%A4nJ*upW`{r5}U+`lEFP1X_jx^Wx zZdbHRb9>yx#h$O& z-I~8dr?{rO&SYwSie_6q4nCzh@TEw<_OIEiu0fY>tG;84Yr89GYuZ-bfPF~SMXNRi zz6gy@cR*frPJG7!{;&G?$zuN?n{T^p8uhA$Yi4~{MCW{%dphSs@Lv^v&<`+0`W(GM zof0E8$gXwfJF}c|PD72c#2-?NxILU+wKg? zO9r3itJzKG#87Tz>-Y=m{s?=|4OZ9I(0=iTXwM4vX5XLHdn57@U~1Rz1-tx>;i|ni zjv7uV(>*hLa{2x2-%+Ltoz3U+rDxV+D7X&Nr8C$9+_yspS#6EJMpt8~391Q(+1h7K zHBR2KSsd0uR#!vIgHTQ-BSC3IlU0f+XQ0zN0PCHFlEchr^zYLHrw$CVwT=#lGtH%X zdw^!>Aj>~~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A*h<0B^$6kiJfkJ_HY%x8ktf!UM4t92h|62%Z97 ziZw_XpuIm2`~d1Eot}T>pcI03QGG!WxwYU^C>jcY_U_+<>4gq$Wcy}t4+2C?a)$l@ zjz@~sn%N63!F(c#vi*l(b!ViS_)=x`FBeG{1Z}WJAF{(s;FbUfBC<0``Nu&i4+H;K zK!9=J6LaMQ|1Z+6U;M zb$lMY7(83yAHZF3Pz@#r0$wP)kRi1wE#Q|>RO%|Rfg_+)^>>4luCD!dkqrvaVhB5efIyh>mSV0XZXDd0asuf?)bU(-JU2WIpHI5Z%jUeY`L z%YdWDqBzM;+Tsy9Ks=Wp;ipqU{HhXVfnt;m%T$W_Bi1lg0bJ=VvF3q>G zB3vfruzFk;handler(); + } + } +} + +/*****************************************************************//** + * + * \brief When C button is pressed, this function evaluates + * user actions to determine whether game must be exited. + * + *********************************************************************/ static enum tPauseMenuChoice GamePause(void) { if (gb.buttons.released(BTN_C) != false) { + /* Strings must be individually allocated into + * PROGMEM so they can be read correctly by gb.menu(). */ + static const char strPauseMenuOption_0[] PROGMEM = "Resume"; + static const char strPauseMenuOption_1[] PROGMEM = "Quit"; + static const char* const astrPauseMenuOptions[MAX_PAUSE_MENU_CHOICES] PROGMEM = { - [PAUSE_MENU_CHOICE_RESUME] = "Resume", - [PAUSE_MENU_CHOICE_QUIT] = "Quit" + [PAUSE_MENU_CHOICE_RESUME] = strPauseMenuOption_0, + [PAUSE_MENU_CHOICE_QUIT] = strPauseMenuOption_1 }; return (enum tPauseMenuChoice)gb.menu(astrPauseMenuOptions, MAX_PAUSE_MENU_CHOICES); diff --git a/Game.h b/Game.h index 5021c87..2f9760e 100644 --- a/Game.h +++ b/Game.h @@ -1,20 +1,20 @@ #ifndef GAMEPLAY_H__ #define GAMEPLAY_H__ -/* ************************************** - * Includes * - * **************************************/ +/* ******************************************************************* + * Includes + * ******************************************************************/ #include "HumanPlayer.h" #include -/* ************************************** - * Defines * - * **************************************/ +/* ******************************************************************* + * Defines + * ******************************************************************/ -/* ************************************** - * Structs and enums * - * **************************************/ +/* ******************************************************************* + * Global types definition + * ******************************************************************/ struct tGameConfig { @@ -22,14 +22,18 @@ struct tGameConfig uint8_t u8NHumanPlayers; }; -/* ************************************** - * Global prototypes * - * **************************************/ +/* ******************************************************************* + * Global variables declaration + * ******************************************************************/ -void Game(const struct tGameConfig& psGameConfig); +/* ******************************************************************* + * Global functions declaration + * ******************************************************************/ -/* ************************************** - * Global variables * - * **************************************/ +void Game(const struct tGameConfig& sGameConfig); + +/* ******************************************************************* + * Class definition + * ******************************************************************/ #endif /* GAMEPLAY_H__ */ diff --git a/HumanPlayer.cpp b/HumanPlayer.cpp index c9b60e4..ae16f97 100644 --- a/HumanPlayer.cpp +++ b/HumanPlayer.cpp @@ -39,6 +39,24 @@ HumanPlayer::HumanPlayer(const char* const strPlayerName) : Player(strPlayerName) { + _unitsMap[0].create(Unit::UNIT_ID_PEASANT); +} + +/*****************************************************************//** + * + * \brief Periodical event handler that calls HumanPlayer subtasks. + * + *********************************************************************/ +void HumanPlayer::handler(void) +{ + this->buttonHandler(); + + for (uint8_t i = 0; i < MAX_UNITS; i++) + { + Unit& unit = _unitsMap[i]; + + unit.handler(); + } } /*****************************************************************//** @@ -53,7 +71,7 @@ void HumanPlayer::buttonHandler(void) { /* This array of member functions lists * button pressed event handlers for each button. */ - void (HumanPlayer::*const apBtnHandlerTable[NUM_BTN])(void) = + static void (HumanPlayer::*const apBtnHandlerTable[NUM_BTN])(void) = { [BTN_LEFT] = NULL, [BTN_UP] = NULL, @@ -63,7 +81,7 @@ void HumanPlayer::buttonHandler(void) [BTN_B] = &HumanPlayer::onBBtnPressed }; - void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) = + static void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) = { [BTN_LEFT] = &Camera::onLeftBtnPressed, [BTN_UP] = NULL, @@ -71,7 +89,6 @@ void HumanPlayer::buttonHandler(void) [BTN_DOWN] = NULL }; - /* Member function pointer is valid. */ if (gb.buttons.pressed(u8Btn)) { /* Key has been pressed. Execute both @@ -105,26 +122,38 @@ void HumanPlayer::buttonHandler(void) /* Undefined callback for selected button. */ } } + else + { + /* Key has not been pressed. Exit. */ + } } } /*****************************************************************//** * * \brief Event handler executed when human player presses - * left arrow button. + * A button. * *********************************************************************/ -void HumanPlayer::onLeftBtnPressed(void) -{ - /* Also, send the event to Camera object. */ - _cam.onLeftBtnPressed(); -} - void HumanPlayer::onABtnPressed(void) { } +/*****************************************************************//** + * + * \brief Event handler executed when human player presses + * B button. + * + *********************************************************************/ +void HumanPlayer::onBBtnPressed(void) +{ +} + +/*****************************************************************//** + * + * \brief This function draws all units and player UI. + * + *********************************************************************/ void HumanPlayer::drawHandler(void) { - } diff --git a/HumanPlayer.h b/HumanPlayer.h index 17986ba..5f213c4 100644 --- a/HumanPlayer.h +++ b/HumanPlayer.h @@ -24,15 +24,14 @@ class HumanPlayer : public Player { public: explicit HumanPlayer(const char* const strPlayerName); - void drawHandler(void); + void handler(void); private: Camera _cam; void buttonHandler(void); + void drawHandler(void); /* Event handlers. */ - void onLeftBtnPressed(void); - void onRightBtnPressed(void); void onABtnPressed(void); void onBBtnPressed(void); }; diff --git a/Makefile b/Makefile index d047fd3..98922d9 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ OBJ_DIR = Obj SRC_DIR = . OBJECTS=$(addprefix $(OBJ_DIR)/,main.o Game.o System.o HumanPlayer.o Sprite.o \ - Player.o Camera.o Unit.o Menu.o ) + Player.o Camera.o BaseUnit.o Unit.o Menu.o ) DEPS = $(OBJECTS:.o=.d) diff --git a/MouseSpr.i b/MouseSpr.i index 91bc2ef..374e40d 100644 --- a/MouseSpr.i +++ b/MouseSpr.i @@ -1,11 +1,31 @@ #ifndef MOUSE_SPR_I__ #define MOUSE_SPR_I__ +/* ******************************************************************* + * Includes + * ******************************************************************/ + #include #include #include -const uint8_t PROGMEM MouseSprData[] = +/* ******************************************************************* + * Defines + * ******************************************************************/ + +/* ******************************************************************* + * Types definition + * ******************************************************************/ + +/* ******************************************************************* + * Global variables definition + * ******************************************************************/ + +/* ******************************************************************* + * Local variables definition + * ******************************************************************/ + +const uint8_t MouseSprData[] PROGMEM = { 8,8, //width and height B11111100, @@ -18,4 +38,12 @@ const uint8_t PROGMEM MouseSprData[] = B00000100 }; +/* ******************************************************************* + * Local prototypes declaration + * ******************************************************************/ + +/* ******************************************************************* + * Functions definition + * ******************************************************************/ + #endif /* MOUSE_SPR_I__ */ diff --git a/Player.cpp b/Player.cpp index b90e9fa..e8c6e86 100644 --- a/Player.cpp +++ b/Player.cpp @@ -34,8 +34,14 @@ * \brief Constructor for Player class. * *********************************************************************/ -Player::Player(const char* const strPlayerName) +Player::Player(const char* const strPlayerName): +_name{'\0'} { + enum + { + DEFAULT_RESOURCES = 300 + }; + if (strPlayerName != NULL) { strncpy(_name, strPlayerName, MAX_NAME_LENGTH); @@ -44,4 +50,7 @@ Player::Player(const char* const strPlayerName) { /* Undefined player name. */ } + + /* Set all resources to default value. */ + memset(_resourcesMap, DEFAULT_RESOURCES, sizeof(uint8_t) * MAX_RESOURCE_TYPES); } diff --git a/Player.h b/Player.h index 6e89052..b0a91c7 100644 --- a/Player.h +++ b/Player.h @@ -6,6 +6,7 @@ * **************************************/ #include +#include "Unit.h" /* ************************************** * Defines * @@ -39,11 +40,13 @@ class Player protected: enum { - MAX_NAME_LENGTH = 16 + MAX_NAME_LENGTH = 16, + MAX_UNITS = 32 }; - uint16_t _resourcesMap[MAX_RESOURCE_TYPES] = {0}; - char _name[MAX_NAME_LENGTH] = {0}; + uint16_t _resourcesMap[MAX_RESOURCE_TYPES]; + char _name[MAX_NAME_LENGTH]; + Unit _unitsMap[MAX_UNITS]; }; #endif /* PLAYER_H__ */ diff --git a/PocketEmpires.geany b/PocketEmpires.geany index 98143c2..082a8eb 100644 --- a/PocketEmpires.geany +++ b/PocketEmpires.geany @@ -28,34 +28,38 @@ long_line_behaviour=1 long_line_column=120 [files] -current_page=2 +current_page=30 FILE_NAME_0=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGfx.cpp;0;4 -FILE_NAME_1=889;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2Fmain.cpp;0;4 -FILE_NAME_2=1577;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMenu.cpp;0;4 +FILE_NAME_1=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2Fmain.cpp;0;4 +FILE_NAME_2=3361;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMenu.cpp;0;4 FILE_NAME_3=317;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPad.cpp;0;4 -FILE_NAME_4=874;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCamera.h;0;4 +FILE_NAME_4=772;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCamera.h;0;4 FILE_NAME_5=665;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGfx.h;0;4 FILE_NAME_6=314;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGlobal_Inc.h;0;4 FILE_NAME_7=299;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMenu.h;0;4 -FILE_NAME_8=651;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPad.h;0;4 -FILE_NAME_9=868;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.h;0;4 +FILE_NAME_8=611;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPad.h;0;4 +FILE_NAME_9=728;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.h;0;4 FILE_NAME_10=543;Make;0;EUTF-8;1;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMakefile;0;4 -FILE_NAME_11=1466;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSystem.cpp;0;4 -FILE_NAME_12=670;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.h;0;4 -FILE_NAME_13=1034;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.cpp;0;4 -FILE_NAME_14=164;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.cpp;0;4 -FILE_NAME_15=331;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMouseSpr.i;0;4 -FILE_NAME_16=2015;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.cpp;0;4 -FILE_NAME_17=725;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.h;0;4 -FILE_NAME_18=910;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCamera.cpp;0;4 -FILE_NAME_19=1377;C;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCameraOld.c;0;4 -FILE_NAME_20=476;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSprite.h;0;4 -FILE_NAME_21=854;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSprite.cpp;0;4 -FILE_NAME_22=818;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSystem.h;0;4 -FILE_NAME_23=486;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FUnit.h;0;4 -FILE_NAME_24=115;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FUnit.cpp;0;4 -FILE_NAME_25=2863;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FDisplay.h;0;4 -FILE_NAME_26=7382;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FGamebuino.cpp;0;4 +FILE_NAME_11=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSystem.cpp;0;4 +FILE_NAME_12=875;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.h;0;4 +FILE_NAME_13=4115;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.cpp;0;4 +FILE_NAME_14=1662;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.cpp;0;4 +FILE_NAME_15=3287;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.cpp;0;4 +FILE_NAME_16=1226;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.h;0;4 +FILE_NAME_17=1965;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCamera.cpp;0;4 +FILE_NAME_18=1377;C;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCameraOld.c;0;4 +FILE_NAME_19=586;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSprite.h;0;4 +FILE_NAME_20=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSprite.cpp;0;4 +FILE_NAME_21=818;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSystem.h;0;4 +FILE_NAME_22=5650;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FDisplay.h;0;4 +FILE_NAME_23=14993;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FGamebuino.cpp;0;4 +FILE_NAME_24=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FGamebuino.h;0;4 +FILE_NAME_25=833;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FButtons.cpp;0;4 +FILE_NAME_26=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FButtons.h;0;4 +FILE_NAME_27=3441;C;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2Fsettings.c;0;4 +FILE_NAME_28=22712;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FDisplay.cpp;0;4 +FILE_NAME_29=1190;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FBaseUnit.cpp;0;4 +FILE_NAME_30=1233;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FBaseUnit.h;0;4 [VTE] last_dir=/home/xavier/PocketEmpires/src diff --git a/Sprite.cpp b/Sprite.cpp index ea7f9d2..d948652 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -3,6 +3,7 @@ * ******************************************************************/ #include "Sprite.h" +#include "System.h" /* ******************************************************************* * Defines @@ -32,8 +33,46 @@ * * \brief Constructor for Sprite class. * + * \param pu8SprData + * Pointer to raw sprite data. + * + * \param u8Colour + * Sprite colour. Default value is BLACK. + * + * \param rotation + * Sprite rotation. Default value is NOROT. + * *********************************************************************/ -Sprite::Sprite(const uint8_t& pu8SprData) : -_pu8SprData(pu8SprData) +Sprite::Sprite(const uint8_t& pu8SprData, const uint8_t u8Colour, const uint8_t rotation) : +_pu8SprData(pu8SprData), +_colour(u8Colour), +_rotation(rotation), +_x(0), +_y(0) { } + +/*****************************************************************//** + * + * \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; +} + +void Sprite::draw(void) +{ + gb.display.setColor(_colour); + gb.display.drawBitmap(_x, _y, (const uint8_t*)&_pu8SprData); +} diff --git a/Sprite.h b/Sprite.h index d690ddd..c365735 100644 --- a/Sprite.h +++ b/Sprite.h @@ -5,6 +5,7 @@ * Includes * *************************************/ +#include #include /* ************************************* @@ -22,10 +23,16 @@ class Sprite { public: - Sprite(const uint8_t& pu8SprData); + Sprite(const uint8_t& pu8SprData, const uint8_t u8Colour = BLACK, const uint8_t rotation = NOFLIP); + void setPos(const uint8_t x, const uint8_t y); + void draw(void); private: const uint8_t& _pu8SprData; + uint8_t _colour; + uint8_t _rotation; + uint8_t _x; + uint8_t _y; }; #endif /* SPRITE_H__ */ diff --git a/Unit.cpp b/Unit.cpp new file mode 100644 index 0000000..38535e7 --- /dev/null +++ b/Unit.cpp @@ -0,0 +1,102 @@ +/* ******************************************************************* + * Includes + * ******************************************************************/ + +#include "BaseUnit.h" +#include "Unit.h" +#include "Sprite.h" +#include +#include +#include + +/* ******************************************************************* + * Defines + * ******************************************************************/ + +/* ******************************************************************* + * Types definition + * ******************************************************************/ + +/* ******************************************************************* + * Global variables definition + * ******************************************************************/ + +/* ******************************************************************* + * Local variables definition + * ******************************************************************/ + +/* ******************************************************************* + * Local prototypes declaration + * ******************************************************************/ + +/* ******************************************************************* + * Functions definition + * ******************************************************************/ + +/*****************************************************************//** + * + * \brief Constructor for Unit class. + * + *********************************************************************/ +Unit::Unit(const enum Unit::tUnitID eUnitID) : +BaseUnit(), +_eUnitID(eUnitID) +{ +} + +void Unit::create(const enum Unit::tUnitID eUnitID) +{ + _eUnitID = eUnitID; +} + +/*****************************************************************//** + * + * \brief Periodical handler for Unit class. + * + *********************************************************************/ +void Unit::handler(void) +{ + /* Execute base class handler. */ + BaseUnit::handler(); + + drawHandler(); +} + +void Unit::drawHandler(void) +{ + if (_eUnitID < MAX_UNIT_ID) + { + static const uint8_t au8PeasantSprData[] = + { + 8, + 8, + 0x00, + 0x3C, + 0x42, + 0x99, + 0xA5, + 0x66, + 0x18, + 0x00 + }; + + static const uint8_t* const apu8UnitSpriteDataTable[MAX_UNIT_ID] = + { + [UNIT_ID_NONE] = NULL, + [UNIT_ID_PEASANT] = au8PeasantSprData, + [UNIT_ID_SWORDMAN] = NULL + }; + + const uint8_t* const pu8UnitSpriteData = apu8UnitSpriteDataTable[_eUnitID]; + + Sprite spr(*pu8UnitSpriteData); + + spr.setPos(16, 16); + + spr.draw(); + } + else + { + /* Unit has an invalid ID. Exit. */ + } +} diff --git a/Unit.h b/Unit.h new file mode 100644 index 0000000..960154a --- /dev/null +++ b/Unit.h @@ -0,0 +1,53 @@ +#ifndef UNIT_H__ +#define UNIT_H__ + +/* ******************************************************************* + * Includes + * ******************************************************************/ + +#include "BaseUnit.h" +#include +#include + +/* ******************************************************************* + * Defines + * ******************************************************************/ + +/* ******************************************************************* + * Global types definition + * ******************************************************************/ + +/* ******************************************************************* + * Global variables declaration + * ******************************************************************/ + +/* ******************************************************************* + * Global functions declaration + * ******************************************************************/ + +/* ******************************************************************* + * Class definition + * ******************************************************************/ + +class Unit : public BaseUnit +{ + public: + enum tUnitID + { + UNIT_ID_NONE, + UNIT_ID_PEASANT, + UNIT_ID_SWORDMAN, + + MAX_UNIT_ID + }; + + explicit Unit(const Unit::tUnitID eUnitID = UNIT_ID_NONE); + void create(const enum Unit::tUnitID eUnitID); + void handler(void); + + private: + void drawHandler(void); + enum tUnitID _eUnitID; +}; + +#endif /* UNIT_H__ */