From: Daniel Karbach Date: Wed, 3 Oct 2012 15:23:31 +0000 (+0200) Subject: added entity follower list X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=a1c89e41e38eca790e168b8acd3beee974685fcd;p=l2e.git added entity follower list still unfinished due to movement detection bugs refs #17 refs #20 --- diff --git a/src/main.cpp b/src/main.cpp index 745ec4b..951eccc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -341,18 +341,24 @@ int main(int argc, char **argv) { SimpleAnimation mapSelanAnimation(&mapSelanSprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true); Entity mapSelan; mapSelan.SetAnimation(&mapSelanAnimation); + mapSelan.Position() = Vector(80, 128); + mapMaxim.AddFollower(&mapSelan); SDL_Surface *mapGuyImg(IMG_Load("test-data/guy-map.png")); Sprite mapGuySprite(mapGuyImg, 32, 64); SimpleAnimation mapGuyAnimation(&mapGuySprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true); Entity mapGuy; mapGuy.SetAnimation(&mapGuyAnimation); + mapGuy.Position() = Vector(80, 128); + mapSelan.AddFollower(&mapGuy); SDL_Surface *mapDekarImg(IMG_Load("test-data/dekar-map.png")); Sprite mapDekarSprite(mapDekarImg, 32, 64); SimpleAnimation mapDekarAnimation(&mapDekarSprite, (tileSize/walkSpeed) / 2 * 1000, 2, 0, 0, true); Entity mapDekar; mapDekar.SetAnimation(&mapDekarAnimation); + mapDekar.Position() = Vector(80, 128); + mapGuy.AddFollower(&mapDekar); InitScreen screen(width, height); @@ -372,6 +378,9 @@ int main(int argc, char **argv) { } else { MapState *mapState(new MapState(&map)); mapState->AddEntity(&mapMaxim); +// mapState->AddEntity(&mapSelan); +// mapState->AddEntity(&mapGuy); +// mapState->AddEntity(&mapDekar); mapState->ControlEntity(&mapMaxim); mapState->SetWalkingSpeed(walkSpeed); state = mapState; diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index b9fba97..08be97b 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -12,7 +12,8 @@ using geometry::Vector; namespace map { Entity::Entity() -: animation(0) +: follower(0) +, animation(0) , orientation(ORIENTATION_NORTH) , speed(0) { runner.SetFrameShift(1); @@ -30,6 +31,34 @@ void Entity::SetSpeed(float s) { UpdateVelocity(); } +void Entity::StartAnimation(app::Application &ctrl) { + runner.Start(ctrl); +} + +void Entity::StartAnimation(app::State &ctrl) { + runner.Start(ctrl); +} + +void Entity::StopAnimation() { + runner.Stop(); +} + +void Entity::AddFollower(Entity *f) { + if (follower) { + follower->AddFollower(f); + } else { + follower = f; + } +} + +void Entity::RemoveFollower(Entity *f) { + if (follower == f) { + follower = follower->follower; + } else if (follower) { + follower->RemoveFollower(f); + } +} + void Entity::SetAnimation(const graphics::Animation *a) { animation = a; runner.ChangeAnimation(animation); diff --git a/src/map/Entity.h b/src/map/Entity.h index 926c360..94090a1 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -39,15 +39,20 @@ public: const geometry::Vector &Velocity() const { return velocity; } void SetAnimation(const graphics::Animation *a); - void StartAnimation(app::Application &ctrl) { runner.Start(ctrl); } - void StartAnimation(app::State &ctrl) { runner.Start(ctrl); } - void StopAnimation() { runner.Stop(); } + void StartAnimation(app::Application &ctrl); + void StartAnimation(app::State &ctrl); + void StopAnimation(); bool AnimationRunning() const { return runner.Running(); } void SetOrientation(Orientation); Orientation GetOrientation() const { return orientation; } void SetSpeed(float); + Entity *Follower() { return follower; } + const Entity *Follower() const { return follower; } + void AddFollower(Entity *); + void RemoveFollower(Entity *); + bool TileLock(int width, int height) const; void Update(float deltaT); @@ -55,9 +60,10 @@ public: void Render(SDL_Surface *, const geometry::Vector &offset) const; private: - void UpdateVelocity(); + void UpdateVelocity();; private: + Entity *follower; const graphics::Animation *animation; graphics::AnimationRunner runner; geometry::Vector position; diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 3be5a45..b529e21 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -77,6 +77,7 @@ void MapState::UpdateWorld(float deltaT) { } if (nextDirection >= 0) { if (afterLock) { + // FIXME: this check is unreliable, see #21 OnMove(); afterLock = false; } @@ -130,6 +131,15 @@ void MapState::OnGridLock() { void MapState::OnMove() { // TODO: evaluate monster movements + UpdateFollower(controlled); +} + +void MapState::UpdateFollower(Entity *e) { + if (!e->Follower()) return; + UpdateFollower(e->Follower()); + + e->Follower()->SetOrientation(e->GetOrientation()); + // TODO: set follower speed } diff --git a/src/map/MapState.h b/src/map/MapState.h index 2b53069..b753ccf 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -47,6 +47,8 @@ private: void OnGridLock(); void OnMove(); + void UpdateFollower(Entity *); + private: Map *map; Entity *controlled;