X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmap%2FEntity.cpp;h=99295344dbd52127a2f58c6e9f17ed27161d5a2c;hb=2ccc2369d32fb680a3047519d79c17de34c4e10a;hp=01a8e9c384012a81ce15d5fc872c4342f4fab893;hpb=0ad5ca97b5df217329bc319d62564a9f46ba11d7;p=l2e.git diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index 01a8e9c..9929534 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -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 &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); } } @@ -122,7 +143,9 @@ void Entity::CreateTypeDescription() { int animationId(TypeDescription::GetTypeId("Animation")); int monsterId(TypeDescription::GetTypeId("Monster")); + int numberId(TypeDescription::GetTypeId("Number")); int partyLayoutId(TypeDescription::GetTypeId("PartyLayout")); + int spriteId(TypeDescription::GetTypeId("Sprite")); int vectorId(TypeDescription::GetTypeId("Vector")); TypeDescription &td(TypeDescription::CreateOrGet("Entity")); @@ -131,9 +154,12 @@ void Entity::CreateTypeDescription() { td.SetSize(sizeof(Entity)); td.AddField("animation", FieldDescription(((char *)&e.animation) - ((char *)&e), animationId).SetReferenced()); + td.AddField("sprite", FieldDescription(((char *)&e.sprite) - ((char *)&e), spriteId).SetReferenced()); td.AddField("partyLayout", FieldDescription(((char *)&e.partyLayout) - ((char *)&e), partyLayoutId).SetReferenced()); td.AddField("monsters", FieldDescription(((char *)&e.monsters) - ((char *)&e), monsterId).SetReferenced().SetAggregate()); td.AddField("spriteOffset", FieldDescription(((char *)&e.spriteOffset) - ((char *)&e), vectorId)); + td.AddField("position", FieldDescription(((char *)&e.tilePosition) - ((char *)&e), vectorId)); + td.AddField("flags", FieldDescription(((char *)&e.flags) - ((char *)&e), numberId)); } void Entity::Construct(void *data) { @@ -142,7 +168,12 @@ void Entity::Construct(void *data) { void Entity::Load(void *data) { Entity *entity(reinterpret_cast(data)); - entity->runner.ChangeAnimation(entity->animation); + if (entity->animation) { + entity->runner.ChangeAnimation(entity->animation); + if (!entity->sprite) { + entity->sprite = entity->animation->GetSprite(); + } + } } }