Hola Snake.
No es sencillo hacer mejoras para una clase de la que no se conoce a fondo su funcionalidad, pero revisa estos pequeños cambios:
Código PHP:
#include <grids.hpp>
TColor ACTOR_Color;
class Actor {
private:
int mapWidth_;
int mapHeight_;
int maxActors_;
TPoint pt_;
char nDisplayChar_;
TColor nColorCode_;
TPoint getPos( void );
void setPos( const TPoint& pt );
bool IsPassable( const TPoint& pt );
public:
Actor( void );
void SetAppearance( const char &nDisplayChar, TColor nDisplayColor );
void Draw( TStringGrid* grd );
void Update( void );
const int mapWidth( void ) { return mapWidth_; }
const int mapHeight( void ) { return mapHeight_; }
const int maxActors( void ) { return maxActors_; }
__property TPoint Position = { read = getPos, write = setPos };
};
/* ------------------------- PUBLIC ------------------------- */
Actor::Actor( void )
{
mapWidth_ = 48;
mapHeight_ = 30;
maxActors_ = 20;
pt_ = Point( 0, 0);
nDisplayChar_ = '@';
nColorCode_ = clRed;
}
void Actor::SetAppearance( const char &nDisplayChar, TColor nDisplayColor )
{
nDisplayChar_ = nDisplayChar;
nColorCode_ = nDisplayColor;
}
void Actor::Draw( TStringGrid* grd )
{
if( pt_.x < 0 || pt_.x >= mapWidth() ||
pt_.y < 0 || pt_.y >= mapHeight() || grd->Cells[pt_.x][pt_.y] == '#' )
return;
ACTOR_Color = nColorCode_;
grd->Cells[pt_.x][pt_.y] = nDisplayChar_;
}
bool Actor::IsPassable( const TPoint& pt )
{
if( pt.x < 0 || pt.x >= mapWidth() || pt.y < 0 || pt.y >= mapHeight() )
return false;
return true;
// nMapArray ????
// int nTileValue = nMapArray[y][x];
// return sTileIndex[nTileValue].bPassable;
}
void Actor::Update( void )
{
int iDeltaX = (rand() % 3) - 1;
int iDeltaY = (rand() % 3) - 1;
if( IsPassable( Point(pt_.x + iDeltaX, pt_.y + iDeltaY) ) ) {
pt_.x += iDeltaX;
pt_.y += iDeltaY;
}
}
/* ------------------------- PRIVATE ------------------------- */
TPoint Actor::getPos( void )
{
return pt_;
}
void Actor::setPos( const TPoint& pt )
{
if( ( pt.x < 0 ) || ( pt.x >= mapWidth() ) ||
( pt.y < 0 ) || ( pt.y >= mapHeight() ) )
return;
pt_ = pt;
}
...
Puse las partes del código afectadas por las modificaciones en la definición de la clase.
Un ejemplo de llamada podría ser:
Código PHP:
...
{
Actor a;
a.Position = Point( 3, 2 );
a.Draw( StringGrid1 );
...
}
Saludos
