]> git.localhorst.tv Git - l2e.git/commitdiff
added tile ladder flag
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 23 Jan 2013 23:59:23 +0000 (17:59 -0600)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 24 Jan 2013 01:21:10 +0000 (19:21 -0600)
fixes #25

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

index d239844ea2ef420bd76fd5e47a57dbe7082359e0..6bce2adfde82b28d092cd08a03eae7fd39246f7e 100644 (file)
@@ -26,6 +26,7 @@ Entity::Entity()
 , partyLayout(0)
 , monsters(0)
 , numMonsters(0)
+, direction(ORIENTATION_NORTH)
 , orientation(ORIENTATION_NORTH)
 , speed(0)
 , flags(0) {
@@ -35,12 +36,17 @@ Entity::Entity()
 
 void Entity::SetOrientation(Orientation o) {
        orientation = o;
-       UpdateVelocity();
        if (CanTurn()) {
-               runner.SetColOffset(orientation);
+               runner.SetColOffset(o);
        }
 }
 
+void Entity::SetDirection(Orientation o) {
+       direction = o;
+       UpdateVelocity();
+       SetOrientation(o);
+}
+
 void Entity::SetSpeed(Fixed<8> s) {
        speed = s;
        UpdateVelocity();
@@ -103,7 +109,7 @@ void Entity::UpdateVelocity() {
                velocity = Vector<Fixed<8> >();
                return;
        }
-       switch (orientation) {
+       switch (direction) {
                case ORIENTATION_NORTH:
                        velocity = Vector<Fixed<8> >(0, -speed);
                        break;
index 13044880121569cfa54c1ef4f7ce34dbc6a64457..44ba00f682c8eff04e574be39141dfe89902393b 100644 (file)
@@ -80,12 +80,17 @@ public:
        /// west sprites at offsets (0,0), (1,0), (2,0), and (3,0) respectively.
        void SetSprite(const graphics::Sprite *s) { sprite = s; }
 
-       /// Change the entity's orientation to given one.
-       /// If the entity is moving, velocity is changed accordingly.
+       /// Change the entity's facing direction.
+       /// If the entity is moving, velocity is untouched.
        void SetOrientation(Orientation);
        Orientation GetOrientation() const { return orientation; }
+       /// Change the entity's orientation to given one.
+       /// If the entity is moving, velocity is changed accordingly.
+       /// Also changes the orientation to given direction.
+       void SetDirection(Orientation);
+       Orientation GetDirection() const { return direction; }
        /// Set the entity's speed in pixels per second.
-       /// This speed is then combined with the orientation to form a velocity.
+       /// This speed is then combined with the direction to form a velocity.
        void SetSpeed(math::Fixed<8>);
 
        /// Change to a natural, relaxed animation state (row offset 0).
@@ -157,6 +162,7 @@ private:
        math::Vector<int> tilePosition;
        math::Vector<math::Fixed<8> > position;
        math::Vector<math::Fixed<8> > velocity;
+       Orientation direction;
        Orientation orientation;
        math::Fixed<8> speed;
        int flags;
index baefdc5ef59c91e5095bc0999dcd14e95125549f..2ae4bb362082c00a62fb3c0a6f70404cd7d56a92 100644 (file)
@@ -118,17 +118,19 @@ void MapState::OnTileLock() {
                return;
        }
 
+       const Tile *tile(map->TileAt(nowLock));
+
        if (nextDirection >= 0) {
                if (afterLock) {
                        bool blocked(CheckBlocking());
                        OnMove(!blocked);
-                       controlled->SetOrientation(Entity::Orientation(nextDirection));
+                       controlled->SetDirection(Entity::Orientation(nextDirection));
                        if (!blocked) {
                                afterLock = false;
                                controlled->SetSpeed(walkingSpeed);
                                moveTimer.Clear();
                                if (pushed) {
-                                       pushed->SetOrientation(Entity::Orientation(nextDirection));
+                                       pushed->SetDirection(Entity::Orientation(nextDirection));
                                        pushed->SetSpeed(walkingSpeed);
                                        controlled->SetPushing();
                                } else {
@@ -138,7 +140,7 @@ void MapState::OnTileLock() {
                                controlled->SetSpeed(0);
                                StopFollowers(*controlled);
                                if (!moveTimer.Running()) {
-                                       int tileSize((controlled->GetOrientation() % 2) ? map->Tileset()->Width() : map->Tileset()->Height());
+                                       int tileSize((controlled->GetDirection() % 2) ? map->Tileset()->Width() : map->Tileset()->Height());
                                        Fixed<8> walkingInterval(tileSize);
                                        walkingInterval /= walkingSpeed;
                                        moveTimer = PhysicsTimers().StartInterval(walkingInterval.Int());
@@ -160,6 +162,11 @@ void MapState::OnTileLock() {
                }
        }
 
+       if (controlled->GetDirection() == Entity::ORIENTATION_SOUTH
+                       && tile && tile->IsLadder()) {
+               controlled->SetOrientation(Entity::ORIENTATION_NORTH);
+       }
+
        lastLock = nowLock;
 }
 
@@ -365,19 +372,19 @@ void MapState::UpdateFollower(Entity &e) {
        Vector<int> direction(coords - fCoords);
 
        if (direction.Y() < 0) {
-               f.SetOrientation(Entity::ORIENTATION_NORTH);
+               f.SetDirection(Entity::ORIENTATION_NORTH);
                f.SetSpeed(walkingSpeed);
                f.StartAnimation(*this);
        } else if (direction.X() > 0) {
-               f.SetOrientation(Entity::ORIENTATION_EAST);
+               f.SetDirection(Entity::ORIENTATION_EAST);
                f.SetSpeed(walkingSpeed);
                f.StartAnimation(*this);
        } else if (direction.Y() > 0) {
-               f.SetOrientation(Entity::ORIENTATION_SOUTH);
+               f.SetDirection(Entity::ORIENTATION_SOUTH);
                f.SetSpeed(walkingSpeed);
                f.StartAnimation(*this);
        } else if (direction.X() < 0) {
-               f.SetOrientation(Entity::ORIENTATION_WEST);
+               f.SetDirection(Entity::ORIENTATION_WEST);
                f.SetSpeed(walkingSpeed);
                f.StartAnimation(*this);
        } else {
@@ -399,7 +406,7 @@ void MapState::Transition(Map *newMap, const Vector<int> &coordinates) {
        Vector<int> position(coordinates * map->Tileset()->Size());
        for (Entity *e(controlled); e; e = e->Follower()) {
                e->Position() = position;
-               e->SetOrientation(controlled->GetOrientation());
+               e->SetDirection(controlled->GetDirection());
        }
        LoadMap(newMap);
        skipLock = true;
index f5afb246219e7d3e88faa3d06eb5980ff640076a..137da43c02b30faff6ec6b92b70b98e2ef072469 100644 (file)
@@ -22,6 +22,7 @@ public:
                BLOCK_EAST = 0x02,
                BLOCK_SOUTH = 0x04,
                BLOCK_WEST = 0x08,
+               LADDER = 0x10,
        };
 
        SDL_Surface *BattleBackground() { return battlebg; }
@@ -33,6 +34,8 @@ public:
        bool BlocksSouth() const { return flags & BLOCK_SOUTH; }
        bool BlocksWest() const { return flags & BLOCK_WEST; }
 
+       bool IsLadder() const { return flags & LADDER; }
+
        static void CreateTypeDescription();
        static void Construct(void *);