4 * Created on: Sep 29, 2012
10 using geometry::Vector;
16 , orientation(ORIENTATION_NORTH)
22 void Entity::SetOrientation(Orientation o) {
25 runner.SetColOffset(orientation);
28 void Entity::SetSpeed(float s) {
33 void Entity::SetAnimation(const graphics::Animation *a) {
35 runner.ChangeAnimation(animation);
39 void Entity::UpdateVelocity() {
41 velocity = Vector<float>();
44 switch (orientation) {
45 case ORIENTATION_NORTH:
46 velocity = Vector<float>(0.0f, -speed);
48 case ORIENTATION_EAST:
49 velocity = Vector<float>(speed, 0.0f);
51 case ORIENTATION_SOUTH:
52 velocity = Vector<float>(0.0f, speed);
54 case ORIENTATION_WEST:
55 velocity = Vector<float>(-speed, 0.0f);
61 bool Entity::TileLock(int width, int height) const {
62 Vector<int> tilePosition(
63 position.X() - (width / 2),
65 return (tilePosition.X() % width == 0) && (tilePosition.Y() % height == 0);
69 void Entity::Update(float deltaT) {
70 position += velocity * deltaT;
74 void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
75 // TODO: configurable sprite offsets
76 if (runner.Running()) {
77 runner.DrawCenter(dest, offset + position);
79 animation->GetSprite()->DrawCenter(dest, offset + position, orientation);