changing Areas and door tiles implemented
[Tsunagari.git] / src / entity.cpp
blob412e2698867546ef3c6884227f4cca7af0c6684a
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** entity.cpp **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #define TILE_SIZE 64
9 #include "area.h"
10 #include "entity.h"
11 #include "sprite.h"
13 Entity::Entity(Resourcer* rc,
14 Area* area,
15 const std::string descriptor,
16 const std::string spriteDescriptor)
17 : rc(rc),
18 sprite(NULL),
19 area(area),
20 redraw(true),
21 descriptor(descriptor),
22 spriteDescriptor(spriteDescriptor)
26 Entity::~Entity()
28 delete sprite;
31 bool Entity::init()
33 sprite = new Sprite(rc, spriteDescriptor);
34 return sprite->init();
37 void Entity::draw()
39 redraw = false;
40 sprite->draw();
43 bool Entity::needsRedraw() const
45 return redraw;
48 coord_t Entity::getCoordsByPixel()
50 return sprite->getCoordsByPixel();
53 coord_t Entity::getCoordsByTile()
55 return sprite->getCoordsByTile();
58 void Entity::moveByTile(coord_t delta)
60 coord_t newCoord = sprite->getCoordsByTile();
61 newCoord.x += delta.x;
62 newCoord.y += delta.y;
63 newCoord.z += delta.z;
64 Area::Tile* dest = area->getTile(newCoord);
65 if ((dest->flags & Area::nowalk) != 0 ||
66 (dest->type->flags & Area::nowalk) != 0) {
67 // The tile we're trying to move onto is set as nowalk.
68 // Stop here.
69 return;
71 sprite->moveByTile(delta);
72 redraw = true;
75 void Entity::setCoordsByTile(coord_t pos)
77 sprite->setCoordsByTile(pos);
78 redraw = true;
81 void Entity::setArea(Area* area)
83 this->area = area;