]> git.localhorst.tv Git - l2e.git/commitdiff
added entity follower list
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 3 Oct 2012 15:23:31 +0000 (17:23 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 3 Oct 2012 15:23:31 +0000 (17:23 +0200)
still unfinished due to movement detection bugs

refs #17
refs #20

src/main.cpp
src/map/Entity.cpp
src/map/Entity.h
src/map/MapState.cpp
src/map/MapState.h

index 745ec4bcdda5ddce953ad513f6f15dfd28ca80e7..951eccc4c311220612748565e88b52f63d079692 100644 (file)
@@ -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<float>(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<float>(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<float>(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;
index b9fba9797acc17246783793dac4cc4dfdf8ed1d1..08be97b96c93208ab95774ed4168377e02cc007d 100644 (file)
@@ -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);
index 926c360fef144d740c4cc7f460372aadb3644b87..94090a1e547806790f3bf7331303749bfc1a7568 100644 (file)
@@ -39,15 +39,20 @@ public:
        const geometry::Vector<float> &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<int> &offset) const;
 
 private:
-       void UpdateVelocity();
+       void UpdateVelocity();;
 
 private:
+       Entity *follower;
        const graphics::Animation *animation;
        graphics::AnimationRunner runner;
        geometry::Vector<float> position;
index 3be5a4592f5d16b636c3fb2d8a33d1df7a8277f6..b529e216541ac3894ee574bb4460cee4a8e06595 100644 (file)
@@ -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
 }
 
 
index 2b530698ea48211fc5c08ed51e208a47bf45f4ea..b753ccfd61201aa1e2decb13f586c6bda05ef64d 100644 (file)
@@ -47,6 +47,8 @@ private:
        void OnGridLock();
        void OnMove();
 
+       void UpdateFollower(Entity *);
+
 private:
        Map *map;
        Entity *controlled;