]> git.localhorst.tv Git - l2e.git/blobdiff - src/map/Entity.cpp
implemented pushable entities and pushing
[l2e.git] / src / map / Entity.cpp
index 01a8e9c384012a81ce15d5fc872c4342f4fab893..e922e54c74c1d5deefe18122afc4a8fc6b546d14 100644 (file)
@@ -18,6 +18,7 @@ namespace map {
 Entity::Entity()
 : follower(0)
 , animation(0)
+, sprite(0)
 , partyLayout(0)
 , monsters(0)
 , numMonsters(0)
@@ -31,7 +32,9 @@ Entity::Entity()
 void Entity::SetOrientation(Orientation o) {
        orientation = o;
        UpdateVelocity();
-       runner.SetColOffset(orientation);
+       if (CanTurn()) {
+               runner.SetColOffset(orientation);
+       }
 }
 
 void Entity::SetSpeed(float s) {
@@ -39,6 +42,7 @@ void Entity::SetSpeed(float s) {
        UpdateVelocity();
 }
 
+
 void Entity::StartAnimation(app::Application &ctrl) {
        runner.Start(ctrl);
 }
@@ -51,6 +55,20 @@ void Entity::StopAnimation() {
        runner.Stop();
 }
 
+
+void Entity::SetHandsFree() {
+       runner.SetRowOffset(0);
+}
+
+void Entity::SetCarrying() {
+       runner.SetRowOffset(2);
+}
+
+void Entity::SetPushing() {
+       runner.SetRowOffset(4);
+}
+
+
 void Entity::AddFollower(Entity *f) {
        if (follower) {
                follower->AddFollower(f);
@@ -70,6 +88,9 @@ void Entity::RemoveFollower(Entity *f) {
 void Entity::SetAnimation(const graphics::Animation *a) {
        animation = a;
        runner.ChangeAnimation(animation);
+       if (!sprite) {
+               sprite = animation->GetSprite();
+       }
 }
 
 
@@ -112,7 +133,7 @@ void Entity::Render(SDL_Surface *dest, const Vector<int> &offset) const {
        if (runner.Running()) {
                runner.Draw(dest, offset + position + spriteOffset);
        } else {
-               animation->GetSprite()->Draw(dest, offset + position + spriteOffset, orientation);
+               sprite->Draw(dest, offset + position + spriteOffset, CanTurn() ? orientation : 0);
        }
 }
 
@@ -142,7 +163,12 @@ void Entity::Construct(void *data) {
 
 void Entity::Load(void *data) {
        Entity *entity(reinterpret_cast<Entity *>(data));
-       entity->runner.ChangeAnimation(entity->animation);
+       if (entity->animation) {
+               entity->runner.ChangeAnimation(entity->animation);
+               if (!entity->sprite) {
+                       entity->sprite = entity->animation->GetSprite();
+               }
+       }
 }
 
 }