Camera is now an independent instance, and HumanPlayer only holds a reference to it.
This commit is contained in:
parent
14c12aeea3
commit
20936e9302
16
BaseUnit.cpp
16
BaseUnit.cpp
|
@ -37,12 +37,26 @@
|
|||
*********************************************************************/
|
||||
BaseUnit::BaseUnit(void) :
|
||||
_hp(0),
|
||||
_bAlive(false),
|
||||
_alive(false),
|
||||
_x(0),
|
||||
_y(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This function is executed when user wants to create
|
||||
* a new object derived from BaseUnit, and this function
|
||||
* sets default parameters for a BaseUnit abstract object.
|
||||
*
|
||||
*********************************************************************/
|
||||
void BaseUnit::create(const uint16_t x, const uint16_t y)
|
||||
{
|
||||
_alive = true;
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Periodical handler for BaseUnit class.
|
||||
|
|
|
@ -33,12 +33,13 @@ class BaseUnit
|
|||
public:
|
||||
explicit BaseUnit();
|
||||
void handler(void);
|
||||
void create(const uint16_t x, const uint16_t y);
|
||||
|
||||
protected:
|
||||
uint16_t _hp; /**< Health points. */
|
||||
bool _bAlive; /**< Alive flag. */
|
||||
uint8_t _x; /**< X coordinate inside map. */
|
||||
uint8_t _y; /**< Y coordinate inside map. */
|
||||
bool _alive; /**< Alive flag. */
|
||||
uint16_t _x; /**< X coordinate inside map. */
|
||||
uint16_t _y; /**< Y coordinate inside map. */
|
||||
};
|
||||
|
||||
#endif /* BASEUNIT_H__ */
|
||||
|
|
113
Camera.cpp
113
Camera.cpp
|
@ -9,7 +9,9 @@
|
|||
* Defines
|
||||
* ******************************************************************/
|
||||
|
||||
#define MAX_CAMERA_SPEED ((int8_t)3)
|
||||
#define SPEED_CALCULATION_TIME ((uint8_t)3)
|
||||
#define CAMERA_ACCELERATION ((int8_t)1)
|
||||
|
||||
/* *******************************************************************
|
||||
* Types definition
|
||||
|
@ -42,30 +44,85 @@ Camera::Camera(void) :
|
|||
_yOffset(0),
|
||||
_xSpeed(0),
|
||||
_ySpeed(0),
|
||||
_speedTimer(SPEED_CALCULATION_TIME)
|
||||
_speedTimer(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Camera::handler(void)
|
||||
{
|
||||
_xOffset += _xSpeed;
|
||||
_yOffset += _ySpeed;
|
||||
|
||||
if (++_speedTimer >= SPEED_CALCULATION_TIME)
|
||||
{
|
||||
_speedTimer = 0;
|
||||
|
||||
if (_ySpeed < 0)
|
||||
{
|
||||
_ySpeed += CAMERA_ACCELERATION;
|
||||
}
|
||||
else if (_ySpeed > 0)
|
||||
{
|
||||
_ySpeed -= CAMERA_ACCELERATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Y speed is already still. Continue. */
|
||||
}
|
||||
|
||||
if (_xSpeed < 0)
|
||||
{
|
||||
_xSpeed += CAMERA_ACCELERATION;
|
||||
}
|
||||
else if (_xSpeed > 0)
|
||||
{
|
||||
_xSpeed -= CAMERA_ACCELERATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* x speed is alreadx still. Continue. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This function transforms the coordinates for a given
|
||||
* \brief This function transforms X coordinates for a given
|
||||
* object to camera coordinates.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Camera::getCoordinates(int16_t* const x, int16_t* const y)
|
||||
uint8_t Camera::getX(const uint8_t x) const
|
||||
{
|
||||
*x += _xOffset;
|
||||
*y += _yOffset;
|
||||
return x + _xOffset;
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This function transforms Y coordinates for a given
|
||||
* object to camera coordinates.
|
||||
*
|
||||
*********************************************************************/
|
||||
uint8_t Camera::getY(const uint8_t y) const
|
||||
{
|
||||
return y + _yOffset;
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Event handler executed when human player presses
|
||||
* left button.
|
||||
* left arrow button.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Camera::onLeftBtnPressed(void)
|
||||
{
|
||||
if (_xSpeed < 0)
|
||||
{
|
||||
_xSpeed += CAMERA_ACCELERATION << 1;
|
||||
}
|
||||
else if (_xSpeed < MAX_CAMERA_SPEED)
|
||||
{
|
||||
_xSpeed += CAMERA_ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
|
@ -76,4 +133,48 @@ void Camera::onLeftBtnPressed(void)
|
|||
*********************************************************************/
|
||||
void Camera::onRightBtnPressed(void)
|
||||
{
|
||||
if (_xSpeed > 0)
|
||||
{
|
||||
_xSpeed -= CAMERA_ACCELERATION << 1;
|
||||
}
|
||||
else if (_xSpeed > -MAX_CAMERA_SPEED)
|
||||
{
|
||||
_xSpeed -= CAMERA_ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Event handler executed when human player presses
|
||||
* up arrow button.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Camera::onUpBtnPressed(void)
|
||||
{
|
||||
if (_ySpeed < 0)
|
||||
{
|
||||
_ySpeed += CAMERA_ACCELERATION << 1;
|
||||
}
|
||||
else if (_ySpeed < MAX_CAMERA_SPEED)
|
||||
{
|
||||
_ySpeed += CAMERA_ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Event handler executed when human player presses
|
||||
* down arrow button.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Camera::onDownBtnPressed(void)
|
||||
{
|
||||
if (_ySpeed > 0)
|
||||
{
|
||||
_ySpeed -= CAMERA_ACCELERATION << 1;
|
||||
}
|
||||
else if (_ySpeed < MAX_CAMERA_SPEED)
|
||||
{
|
||||
_ySpeed -= CAMERA_ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
|
6
Camera.h
6
Camera.h
|
@ -23,15 +23,19 @@ class Camera
|
|||
{
|
||||
public:
|
||||
Camera(void);
|
||||
void handler(void);
|
||||
void setLock(const bool bLock)
|
||||
{
|
||||
_bLocked = bLock;
|
||||
}
|
||||
void getCoordinates(int16_t* const x, int16_t* const y);
|
||||
uint8_t getX(const uint8_t x) const;
|
||||
uint8_t getY(const uint8_t y) const;
|
||||
|
||||
/* Event handlers. */
|
||||
void onLeftBtnPressed(void);
|
||||
void onRightBtnPressed(void);
|
||||
void onUpBtnPressed(void);
|
||||
void onDownBtnPressed(void);
|
||||
|
||||
private:
|
||||
bool _bLocked;
|
||||
|
|
BIN
Exe/POCKET.ELF
BIN
Exe/POCKET.ELF
Binary file not shown.
1659
Exe/POCKET.HEX
1659
Exe/POCKET.HEX
File diff suppressed because it is too large
Load Diff
863
Exe/POCKET.MAP
863
Exe/POCKET.MAP
File diff suppressed because it is too large
Load Diff
13
Game.cpp
13
Game.cpp
|
@ -60,15 +60,6 @@ static enum tPauseMenuChoice GamePause(void);
|
|||
*********************************************************************/
|
||||
void Game(const struct tGameConfig& sGameConfig)
|
||||
{
|
||||
#if 0
|
||||
Sprite MouseSpr( MouseSprData,
|
||||
INVERT,
|
||||
NOROT,
|
||||
NOFLIP,
|
||||
(X_SCREEN_RESOLUTION >> 1) - 4,
|
||||
(Y_SCREEN_RESOLUTION >> 1) - 4);
|
||||
#endif /* 0 */
|
||||
|
||||
do
|
||||
{
|
||||
/* Calculate next frame. */
|
||||
|
@ -100,6 +91,10 @@ static void GameNextFrame(const struct tGameConfig& sGameConfig)
|
|||
pHumanPlayerData->handler();
|
||||
}
|
||||
}
|
||||
|
||||
/* Update camera position according
|
||||
* to button pressed events. */
|
||||
sGameConfig.cam.handler();
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
|
|
1
Game.h
1
Game.h
|
@ -20,6 +20,7 @@ struct tGameConfig
|
|||
{
|
||||
HumanPlayer* pHumanPlayerData;
|
||||
uint8_t u8NHumanPlayers;
|
||||
Camera& cam;
|
||||
};
|
||||
|
||||
/* *******************************************************************
|
||||
|
|
|
@ -36,10 +36,11 @@
|
|||
* \brief Constructor for HumanPlayer class.
|
||||
*
|
||||
*********************************************************************/
|
||||
HumanPlayer::HumanPlayer(const char* const strPlayerName) :
|
||||
Player(strPlayerName)
|
||||
HumanPlayer::HumanPlayer(const char* const strPlayerName, const Camera& cam) :
|
||||
Player(strPlayerName),
|
||||
_cam(cam)
|
||||
{
|
||||
_unitsMap[0].create(Unit::UNIT_ID_PEASANT);
|
||||
_unitsMap[0].create(Unit::UNIT_ID_PEASANT, 16, 16);
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
|
@ -84,12 +85,12 @@ void HumanPlayer::buttonHandler(void)
|
|||
static void (Camera::*const apBtnCameraHandlerTable[NUM_BTN])(void) =
|
||||
{
|
||||
[BTN_LEFT] = &Camera::onLeftBtnPressed,
|
||||
[BTN_UP] = NULL,
|
||||
[BTN_UP] = &Camera::onUpBtnPressed,
|
||||
[BTN_RIGHT] = &Camera::onRightBtnPressed,
|
||||
[BTN_DOWN] = NULL
|
||||
[BTN_DOWN] = &Camera::onDownBtnPressed
|
||||
};
|
||||
|
||||
if (gb.buttons.pressed(u8Btn))
|
||||
if (gb.buttons.timeHeld(u8Btn) > 0)
|
||||
{
|
||||
/* Key has been pressed. Execute both
|
||||
* HumanPlayer and Camera handlers, if available. */
|
||||
|
@ -113,9 +114,12 @@ void HumanPlayer::buttonHandler(void)
|
|||
|
||||
if (pCameraBtnHandler != NULL)
|
||||
{
|
||||
/* Camera member function
|
||||
* pointer is available. Execute. */
|
||||
(_cam.*pCameraBtnHandler)();
|
||||
/* Camera member function pointer
|
||||
* is available.
|
||||
* Note: "const" qualifier must be
|
||||
* removed since camera button event
|
||||
* handler modifies Camera class members. */
|
||||
((Camera&)_cam.*pCameraBtnHandler)();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
class HumanPlayer : public Player
|
||||
{
|
||||
public:
|
||||
explicit HumanPlayer(const char* const strPlayerName);
|
||||
explicit HumanPlayer(const char* const strPlayerName, const Camera& cam);
|
||||
void handler(void);
|
||||
|
||||
private:
|
||||
Camera _cam;
|
||||
const Camera& _cam;
|
||||
void buttonHandler(void);
|
||||
void drawHandler(void);
|
||||
|
||||
|
|
11
Menu.cpp
11
Menu.cpp
|
@ -6,6 +6,7 @@
|
|||
#include "HumanPlayer.h"
|
||||
#include "Game.h"
|
||||
#include "System.h"
|
||||
#include "Sprite.h"
|
||||
#include <Gamebuino.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
|
@ -83,20 +84,26 @@ void MainMenu(void)
|
|||
GAMEBUINO_MAX_PLAYER_NAME = 10
|
||||
};
|
||||
|
||||
Camera cam;
|
||||
|
||||
char strName[GAMEBUINO_MAX_PLAYER_NAME] = {0};
|
||||
|
||||
/* Fill strName with default user name. */
|
||||
gb.getDefaultName(strName);
|
||||
|
||||
/* Declare 1 human player instance. */
|
||||
HumanPlayer h(strName);
|
||||
HumanPlayer h(strName, cam);
|
||||
|
||||
const struct tGameConfig c =
|
||||
{
|
||||
.pHumanPlayerData = &h,
|
||||
.u8NHumanPlayers = 1
|
||||
.u8NHumanPlayers = 1,
|
||||
.cam = cam
|
||||
};
|
||||
|
||||
/* Set global camera for sprites. */
|
||||
Sprite::setCamera(&c.cam);
|
||||
|
||||
/* Initialize game with defined configuration. */
|
||||
Game(c);
|
||||
}
|
||||
|
|
|
@ -28,28 +28,28 @@ long_line_behaviour=1
|
|||
long_line_column=120
|
||||
|
||||
[files]
|
||||
current_page=30
|
||||
current_page=13
|
||||
FILE_NAME_0=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGfx.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_2=3160;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=772;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FCamera.h;0;4
|
||||
FILE_NAME_4=663;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=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=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_9=1191;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.h;0;4
|
||||
FILE_NAME_10=412;Make;0;EUTF-8;1;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMakefile;0;4
|
||||
FILE_NAME_11=2168;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSystem.cpp;0;4
|
||||
FILE_NAME_12=731;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.h;0;4
|
||||
FILE_NAME_13=4068;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FHumanPlayer.cpp;0;4
|
||||
FILE_NAME_14=1460;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPlayer.cpp;0;4
|
||||
FILE_NAME_15=2083;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.cpp;0;4
|
||||
FILE_NAME_16=571;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FGame.h;0;4
|
||||
FILE_NAME_17=2241;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_19=768;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSprite.h;0;4
|
||||
FILE_NAME_20=2844;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
|
||||
|
@ -57,9 +57,17 @@ FILE_NAME_24=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%
|
|||
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
|
||||
FILE_NAME_28=19868;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FLibs%2Flibgamebuino%2FDisplay.cpp;0;4
|
||||
FILE_NAME_29=1853;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FBaseUnit.cpp;0;4
|
||||
FILE_NAME_30=1182;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FBaseUnit.h;0;4
|
||||
FILE_NAME_31=1373;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FUnit.h;0;4
|
||||
FILE_NAME_32=2363;C++;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FUnit.cpp;0;4
|
||||
FILE_NAME_33=0;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FBarracksSpr.i;0;4
|
||||
FILE_NAME_34=937;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FMouseSpr.i;0;4
|
||||
FILE_NAME_35=225;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FPeasantSpr.i;0;4
|
||||
FILE_NAME_36=0;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FSoldierSpr.i;0;4
|
||||
FILE_NAME_37=0;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FTowerSpr.i;0;4
|
||||
FILE_NAME_38=0;None;0;EUTF-8;0;1;0;%2Fhome%2Fxavier%2FPocketEmpires%2Fsrc%2FTownCentre.i;0;4
|
||||
|
||||
[VTE]
|
||||
last_dir=/home/xavier/PocketEmpires/src
|
||||
|
|
23
Sprite.cpp
23
Sprite.cpp
|
@ -17,6 +17,8 @@
|
|||
* Global variables definition
|
||||
* ******************************************************************/
|
||||
|
||||
const Camera* _cam;
|
||||
|
||||
/* *******************************************************************
|
||||
* Local variables definition
|
||||
* ******************************************************************/
|
||||
|
@ -36,6 +38,9 @@
|
|||
* \param pu8SprData
|
||||
* Pointer to raw sprite data.
|
||||
*
|
||||
* \param _followCam
|
||||
* Sprite is moved by camera. Default value is true.
|
||||
*
|
||||
* \param u8Colour
|
||||
* Sprite colour. Default value is BLACK.
|
||||
*
|
||||
|
@ -43,8 +48,9 @@
|
|||
* Sprite rotation. Default value is NOROT.
|
||||
*
|
||||
*********************************************************************/
|
||||
Sprite::Sprite(const uint8_t& pu8SprData, const uint8_t u8Colour, const uint8_t rotation) :
|
||||
Sprite::Sprite(const uint8_t* pu8SprData, const bool followCam, const uint8_t u8Colour, const uint8_t rotation) :
|
||||
_pu8SprData(pu8SprData),
|
||||
_followCam(followCam),
|
||||
_colour(u8Colour),
|
||||
_rotation(rotation),
|
||||
_x(0),
|
||||
|
@ -73,6 +79,17 @@ void Sprite::setPos(const uint8_t x, const uint8_t y)
|
|||
|
||||
void Sprite::draw(void)
|
||||
{
|
||||
gb.display.setColor(_colour);
|
||||
gb.display.drawBitmap(_x, _y, (const uint8_t*)&_pu8SprData);
|
||||
gb.display.setColor(_colour, WHITE);
|
||||
|
||||
if (_cam != NULL)
|
||||
{
|
||||
const uint8_t x = _followCam ? _cam->getX(_x) : _x;
|
||||
const uint8_t y = _followCam ? _cam->getY(_y) : _y;
|
||||
|
||||
gb.display.drawBitmap(x, y, _pu8SprData);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Error: uninitialized camera. */
|
||||
}
|
||||
}
|
||||
|
|
41
Sprite.h
41
Sprite.h
|
@ -1,34 +1,53 @@
|
|||
#ifndef SPRITE_H__
|
||||
#define SPRITE_H__
|
||||
|
||||
/* *************************************
|
||||
/* *******************************************************************
|
||||
* Includes
|
||||
* *************************************/
|
||||
* ******************************************************************/
|
||||
|
||||
#include "Camera.h"
|
||||
#include <Gamebuino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* *************************************
|
||||
/* *******************************************************************
|
||||
* Defines
|
||||
* *************************************/
|
||||
* ******************************************************************/
|
||||
|
||||
/* *************************************
|
||||
* Structs and enums
|
||||
* *************************************/
|
||||
/* *******************************************************************
|
||||
* Global types definition
|
||||
* ******************************************************************/
|
||||
|
||||
/* *************************************
|
||||
/* *******************************************************************
|
||||
* Global variables declaration
|
||||
* ******************************************************************/
|
||||
|
||||
extern const Camera* _cam;
|
||||
|
||||
/* *******************************************************************
|
||||
* Global functions declaration
|
||||
* ******************************************************************/
|
||||
|
||||
/* *******************************************************************
|
||||
* Class definition
|
||||
* *************************************/
|
||||
* ******************************************************************/
|
||||
|
||||
class Sprite
|
||||
{
|
||||
public:
|
||||
Sprite(const uint8_t& pu8SprData, const uint8_t u8Colour = BLACK, const uint8_t rotation = NOFLIP);
|
||||
Sprite( const uint8_t* pu8SprData,
|
||||
const bool followCam = true,
|
||||
const uint8_t u8Colour = BLACK,
|
||||
const uint8_t rotation = NOFLIP);
|
||||
void setPos(const uint8_t x, const uint8_t y);
|
||||
void draw(void);
|
||||
static void setCamera(const Camera* const cam)
|
||||
{
|
||||
_cam = cam;
|
||||
};
|
||||
|
||||
private:
|
||||
const uint8_t& _pu8SprData;
|
||||
const uint8_t* _pu8SprData;
|
||||
const bool _followCam;
|
||||
uint8_t _colour;
|
||||
uint8_t _rotation;
|
||||
uint8_t _x;
|
||||
|
|
72
Unit.cpp
72
Unit.cpp
|
@ -25,6 +25,25 @@
|
|||
* Local variables definition
|
||||
* ******************************************************************/
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Bitmap data for idle UNIT_ID_PEASANT.
|
||||
*
|
||||
*********************************************************************/
|
||||
static const PROGMEM uint8_t au8PeasantSprData[] =
|
||||
{
|
||||
8,
|
||||
8,
|
||||
0x00,
|
||||
0x3C,
|
||||
0x42,
|
||||
0x99,
|
||||
0xA5,
|
||||
0x66,
|
||||
0x18,
|
||||
0x00
|
||||
};
|
||||
|
||||
/* *******************************************************************
|
||||
* Local prototypes declaration
|
||||
* ******************************************************************/
|
||||
|
@ -44,9 +63,31 @@ _eUnitID(eUnitID)
|
|||
{
|
||||
}
|
||||
|
||||
void Unit::create(const enum Unit::tUnitID eUnitID)
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief Creates a Unit instance by setting default parameters
|
||||
* and X/Y coordinates.
|
||||
*
|
||||
*********************************************************************/
|
||||
void Unit::create(const enum Unit::tUnitID eUnitID, const uint16_t x, const uint16_t y)
|
||||
{
|
||||
/* Execute base class function first. */
|
||||
BaseUnit::create(x, y);
|
||||
|
||||
/* Assign new ID to selected Unit. */
|
||||
_eUnitID = eUnitID;
|
||||
|
||||
/* This table relates all available
|
||||
* unit IDs against a bitmap data table. */
|
||||
const uint8_t au8HpData[MAX_UNIT_ID] PROGMEM =
|
||||
{
|
||||
[UNIT_ID_NONE] = 0,
|
||||
[UNIT_ID_PEASANT] = 25,
|
||||
[UNIT_ID_SWORDMAN] = 35
|
||||
};
|
||||
|
||||
/* Assign health according to unit ID. */
|
||||
_hp = au8HpData[eUnitID];
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
|
@ -62,36 +103,31 @@ void Unit::handler(void)
|
|||
drawHandler();
|
||||
}
|
||||
|
||||
/*****************************************************************//**
|
||||
*
|
||||
* \brief This function checks whether unit is inside screen
|
||||
* boundaries and draws its associated bitmap.
|
||||
*
|
||||
*********************************************************************/
|
||||
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] =
|
||||
/* This table relates all available
|
||||
* unit IDs against a bitmap data table. */
|
||||
const uint8_t* const apu8UnitSpriteDataTable[MAX_UNIT_ID] PROGMEM =
|
||||
{
|
||||
[UNIT_ID_NONE] = NULL,
|
||||
[UNIT_ID_PEASANT] = au8PeasantSprData,
|
||||
[UNIT_ID_SWORDMAN] = NULL
|
||||
};
|
||||
|
||||
/* Point to appropiate bitmap data given unit ID. */
|
||||
const uint8_t* const pu8UnitSpriteData = apu8UnitSpriteDataTable[_eUnitID];
|
||||
|
||||
Sprite spr(*pu8UnitSpriteData);
|
||||
Sprite spr(pu8UnitSpriteData);
|
||||
|
||||
spr.setPos(16, 16);
|
||||
spr.setPos(_x, _y);
|
||||
|
||||
spr.draw();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue