4 * Created on: Sep 29, 2012
10 using geometry::Vector;
17 , orientation(ORIENTATION_NORTH)
20 runner.SetFrameShift(1);
24 void Entity::SetOrientation(Orientation o) {
27 runner.SetColOffset(orientation);
30 void Entity::SetSpeed(float s) {
35 void Entity::StartAnimation(app::Application &ctrl) {
39 void Entity::StartAnimation(app::State &ctrl) {
43 void Entity::StopAnimation() {
47 void Entity::AddFollower(Entity *f) {
49 follower->AddFollower(f);
55 void Entity::RemoveFollower(Entity *f) {
57 follower = follower->follower;
58 } else if (follower) {
59 follower->RemoveFollower(f);
63 void Entity::SetAnimation(const graphics::Animation *a) {
65 runner.ChangeAnimation(animation);
69 void Entity::UpdateVelocity() {
71 velocity = Vector<float>();
74 switch (orientation) {
75 case ORIENTATION_NORTH:
76 velocity = Vector<float>(0.0f, -speed);
78 case ORIENTATION_EAST:
79 velocity = Vector<float>(speed, 0.0f);
81 case ORIENTATION_SOUTH:
82 velocity = Vector<float>(0.0f, speed);
84 case ORIENTATION_WEST:
85 velocity = Vector<float>(-speed, 0.0f);
91 bool Entity::TileLock(const geometry::Vector<int> &tileSize) const {
92 // TODO: change position to point to the top-left corner of a tile
93 Vector<int> tilePosition(position);
94 return (tilePosition.X() % tileSize.X() == 0) && (tilePosition.Y() % tileSize.Y() == 0);
98 void Entity::Update(float deltaT) {
99 position += velocity * deltaT;
103 void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
104 // TODO: configurable sprite offsets
105 if (runner.Running()) {
106 runner.Draw(dest, offset + position + spriteOffset);
108 animation->GetSprite()->Draw(dest, offset + position + spriteOffset, orientation);