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(int width, int height) const {
91 Vector<int> tilePosition(
92 position.X() - (width / 2),
94 return (tilePosition.X() % width == 0) && (tilePosition.Y() % height == 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.DrawCenter(dest, offset + position);
108 animation->GetSprite()->DrawCenter(dest, offset + position, orientation);