4 * Created on: Sep 29, 2012
10 using geometry::Vector;
17 , orientation(ORIENTATION_NORTH)
19 runner.SetFrameShift(1);
23 void Entity::SetOrientation(Orientation o) {
26 runner.SetColOffset(orientation);
29 void Entity::SetSpeed(float s) {
34 void Entity::StartAnimation(app::Application &ctrl) {
38 void Entity::StartAnimation(app::State &ctrl) {
42 void Entity::StopAnimation() {
46 void Entity::AddFollower(Entity *f) {
48 follower->AddFollower(f);
54 void Entity::RemoveFollower(Entity *f) {
56 follower = follower->follower;
57 } else if (follower) {
58 follower->RemoveFollower(f);
62 void Entity::SetAnimation(const graphics::Animation *a) {
64 runner.ChangeAnimation(animation);
68 void Entity::UpdateVelocity() {
70 velocity = Vector<float>();
73 switch (orientation) {
74 case ORIENTATION_NORTH:
75 velocity = Vector<float>(0.0f, -speed);
77 case ORIENTATION_EAST:
78 velocity = Vector<float>(speed, 0.0f);
80 case ORIENTATION_SOUTH:
81 velocity = Vector<float>(0.0f, speed);
83 case ORIENTATION_WEST:
84 velocity = Vector<float>(-speed, 0.0f);
90 bool Entity::TileLock(const geometry::Vector<int> &tileSize) const {
91 // TODO: change position to point to the top-left corner of a tile
92 Vector<int> tilePosition(position);
93 return (tilePosition.X() % tileSize.X() == 0) && (tilePosition.Y() % tileSize.Y() == 0);
97 void Entity::Update(float deltaT) {
98 position += velocity * deltaT;
102 void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
103 // TODO: configurable sprite offsets
104 if (runner.Running()) {
105 runner.Draw(dest, offset + position + spriteOffset);
107 animation->GetSprite()->Draw(dest, offset + position + spriteOffset, orientation);