diff options
| author | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-09 19:26:13 +0200 |
|---|---|---|
| committer | XaviDCR92 <xavi.dcr@gmail.com> | 2018-07-09 19:26:13 +0200 |
| commit | f0b654b9bf3bc2a93c1f89d4cc3edcf77b948555 (patch) | |
| tree | 91b7404dca0b6eb136cb7f9b144435419144b777 /Unit.h | |
| parent | d85464781580796bbcc744ae732e56d1920e3b0f (diff) | |
| download | pocketempires-f0b654b9bf3bc2a93c1f89d4cc3edcf77b948555.tar.gz | |
Game has been restructured in favor of OOP
Diffstat (limited to 'Unit.h')
| -rw-r--r-- | Unit.h | 135 |
1 files changed, 19 insertions, 116 deletions
@@ -1,123 +1,26 @@ -#ifndef __UNIT_HEADER__ -#define __UNIT_HEADER__ +#ifndef UNIT_H__ +#define UNIT_H__ -/* ************************************** - * Includes * - * **************************************/ +/* ************************************* + * Includes + * *************************************/ -#include "Global_Inc.h" -#include "Camera.h" -#include "Player.h" +/* ************************************* + * Defines + * *************************************/ -#ifdef __cplusplus -extern "C" -{ -#endif //__cplusplus - -/* ************************************** - * Defines * - * **************************************/ - - /* ************************************** - * Structs and enums * - * **************************************/ - -typedef enum t_unitdirection -{ - DIRECTION_LEFT = 0, - DIRECTION_RIGHT, - DIRECTION_UP, - DIRECTION_DOWN -}UNIT_DIRECTION; - -typedef enum t_unitid -{ - // Walking units - PEASANT, - SOLDIER, - - MAX_UNIT_ID, - - // Buildings - BARRACKS, - TOWER, - TOWN_CENTER, - - MAX_BUILDING_ID, - - MAX_UNITS_BUILDINGS, - - FIRST_UNIT_ID = PEASANT, - FIRST_BUILDING_ID = BARRACKS -}TYPE_UNIT_ID; +/* ************************************* + * Structs and enums + * *************************************/ -typedef struct t_Unit -{ - uint16_t x; - uint16_t y; - uint16_t target_x; - uint16_t target_y; - uint8_t hp; - TYPE_UNIT_ID id; - UNIT_DIRECTION dir; - bool mirror; // True = down or left; true = up or right - bool building; - bool walking; - bool alive; - bool selected; - bool selecting_attack; - bool attacking; - uint8_t walk_counter; -}TYPE_UNIT; - -typedef struct -{ - const char* str; - void (*pAction)(TYPE_UNIT*); -}TYPE_UNIT_ACTION; +/* ************************************* + * Class definition + * *************************************/ -typedef enum t_availableactions +class Unit { - ACTION_BUILD_BARRACKS, - ACTION_CREATE_PEASANT, - ACTION_CREATE_SOLDIER, - ACTION_BUILD_TOWER_CENTER, - MAX_ACTIONS -}UNIT_ACTION; - -typedef struct t_Camera TYPE_CAMERA; -typedef struct t_Resource TYPE_RESOURCES; - -/* ************************************** - * Global prototypes * - * **************************************/ - -// Initialization and handling -void UnitInit(void); -void UnitHandler(TYPE_UNIT* unitArray, size_t sz); - -// Unit information -uint8_t UnitGetHpFromID(TYPE_UNIT_ID id); -uint8_t UnitGetWidthFromID(TYPE_UNIT_ID id); -uint8_t UnitGetHeightFromID(TYPE_UNIT_ID id); -uint8_t UnitGetAvailableActions(TYPE_UNIT *ptrUnit); -TYPE_RESOURCES UnitNeededResourcesFromID(TYPE_UNIT_ID id); - -// Rendering -void UnitDraw(TYPE_UNIT *ptrUnit, TYPE_CAMERA* ptrCamera, bool bHighlighted); -void UnitDrawShadow(TYPE_UNIT *ptrUnit, TYPE_CAMERA *ptrCamera); - -// Movement -void UnitMoveTo(TYPE_UNIT *ptrUnit, uint16_t x, uint16_t y); - -// Collision cheking -bool UnitCheckCollisionAgainstOtherUnits(TYPE_COLLISION_BLOCK* cb, TYPE_UNIT *ptrUnitArray, TYPE_UNIT* ptrCurrentUnit); - -// Selection index -const char* UnitGetActionString(UNIT_ACTION action); - -#ifdef __cplusplus -} -#endif //__cplusplus + public: + Unit(void); +}; -#endif //__UNIT_HEADER__ +#endif /* UNIT_H__ */ |
