More work on Unit/BaseUnit concepts.
This commit is contained in:
parent
188d74cb78
commit
14c12aeea3
16
BaseUnit.cpp
16
BaseUnit.cpp
|
@ -3,6 +3,8 @@
|
|||
* ******************************************************************/
|
||||
|
||||
#include "BaseUnit.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* *******************************************************************
|
||||
* 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)
|
||||
{
|
||||
}
|
||||
|
|
12
BaseUnit.h
12
BaseUnit.h
|
@ -5,7 +5,8 @@
|
|||
* Includes
|
||||
* ******************************************************************/
|
||||
|
||||
#include "BaseUnit.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* *******************************************************************
|
||||
* 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__ */
|
||||
|
|
BIN
Exe/POCKET.ELF
BIN
Exe/POCKET.ELF
Binary file not shown.
1576
Exe/POCKET.HEX
1576
Exe/POCKET.HEX
File diff suppressed because it is too large
Load Diff
847
Exe/POCKET.MAP
847
Exe/POCKET.MAP
File diff suppressed because it is too large
Load Diff
56
Game.cpp
56
Game.cpp
|
@ -17,10 +17,16 @@
|
|||
* Types definition
|
||||
* ******************************************************************/
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This enum holds different options to be selected
|
||||
* under pause menu.
|
||||
*
|
||||
*********************************************************************/
|
||||
enum tPauseMenuChoice
|
||||
{
|
||||
PAUSE_MENU_CHOICE_RESUME,
|
||||
PAUSE_MENU_CHOICE_QUIT,
|
||||
PAUSE_MENU_CHOICE_RESUME, /**< Resumes the game. */
|
||||
PAUSE_MENU_CHOICE_QUIT, /**< Exits the game. */
|
||||
|
||||
MAX_PAUSE_MENU_CHOICES,
|
||||
};
|
||||
|
@ -37,6 +43,7 @@ enum tPauseMenuChoice
|
|||
* Local prototypes declaration
|
||||
* ******************************************************************/
|
||||
|
||||
static void GameNextFrame(const struct tGameConfig& sGameConfig);
|
||||
static enum tPauseMenuChoice GamePause(void);
|
||||
|
||||
/* *******************************************************************
|
||||
|
@ -47,8 +54,11 @@ static enum tPauseMenuChoice GamePause(void);
|
|||
*
|
||||
* \brief Entry point for gameplay logic.
|
||||
*
|
||||
* \param sGameConfig
|
||||
* Game configuration structure.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Game(const struct tGameConfig& psGameConfig)
|
||||
void Game(const struct tGameConfig& sGameConfig)
|
||||
{
|
||||
#if 0
|
||||
Sprite MouseSpr( MouseSprData,
|
||||
|
@ -61,20 +71,56 @@ void Game(const struct tGameConfig& psGameConfig)
|
|||
|
||||
do
|
||||
{
|
||||
/* Calculate next frame. */
|
||||
GameNextFrame(sGameConfig);
|
||||
|
||||
/* Do not calculate a new frame
|
||||
* until refresh flag is set. */
|
||||
while (gb.update() == false);
|
||||
} while (GamePause() != PAUSE_MENU_CHOICE_QUIT);
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This function calculates a new frame by calling
|
||||
* all handlers.
|
||||
*
|
||||
* \param sGameConfig
|
||||
* Game configuration structure.
|
||||
*
|
||||
*********************************************************************/
|
||||
static void GameNextFrame(const struct tGameConfig& sGameConfig)
|
||||
{
|
||||
for (uint8_t i = 0; i < sGameConfig.u8NHumanPlayers; i++)
|
||||
{
|
||||
HumanPlayer* pHumanPlayerData = &sGameConfig.pHumanPlayerData[i];
|
||||
|
||||
if (pHumanPlayerData != NULL)
|
||||
{
|
||||
pHumanPlayerData->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);
|
||||
|
|
36
Game.h
36
Game.h
|
@ -1,20 +1,20 @@
|
|||
#ifndef GAMEPLAY_H__
|
||||
#define GAMEPLAY_H__
|
||||
|
||||
/* **************************************
|
||||
* Includes *
|
||||
* **************************************/
|
||||
/* *******************************************************************
|
||||
* Includes
|
||||
* ******************************************************************/
|
||||
|
||||
#include "HumanPlayer.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* **************************************
|
||||
* 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__ */
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
2
Makefile
2
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)
|
||||
|
||||
|
|
30
MouseSpr.i
30
MouseSpr.i
|
@ -1,11 +1,31 @@
|
|||
#ifndef MOUSE_SPR_I__
|
||||
#define MOUSE_SPR_I__
|
||||
|
||||
/* *******************************************************************
|
||||
* Includes
|
||||
* ******************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
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__ */
|
||||
|
|
11
Player.cpp
11
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);
|
||||
}
|
||||
|
|
9
Player.h
9
Player.h
|
@ -6,6 +6,7 @@
|
|||
* **************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#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__ */
|
||||
|
|
|
@ -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
|
||||
|
|
43
Sprite.cpp
43
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);
|
||||
}
|
||||
|
|
9
Sprite.h
9
Sprite.h
|
@ -5,6 +5,7 @@
|
|||
* Includes
|
||||
* *************************************/
|
||||
|
||||
#include <Gamebuino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* *************************************
|
||||
|
@ -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__ */
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/* *******************************************************************
|
||||
* Includes
|
||||
* ******************************************************************/
|
||||
|
||||
#include "BaseUnit.h"
|
||||
#include "Unit.h"
|
||||
#include "Sprite.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* *******************************************************************
|
||||
* 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. */
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef UNIT_H__
|
||||
#define UNIT_H__
|
||||
|
||||
/* *******************************************************************
|
||||
* Includes
|
||||
* ******************************************************************/
|
||||
|
||||
#include "BaseUnit.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* *******************************************************************
|
||||
* 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__ */
|
Loading…
Reference in New Issue