From 667e1d9c6a78d0b608b518a4e5b5c31bc30e4e89 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 23 Jan 2013 17:59:23 -0600 Subject: [PATCH] added tile ladder flag fixes #25 --- src/map/Entity.cpp | 12 +++++++++--- src/map/Entity.h | 12 +++++++++--- src/map/MapState.cpp | 23 +++++++++++++++-------- src/map/Tile.h | 3 +++ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index d239844..6bce2ad 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -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 >(); return; } - switch (orientation) { + switch (direction) { case ORIENTATION_NORTH: velocity = Vector >(0, -speed); break; diff --git a/src/map/Entity.h b/src/map/Entity.h index 1304488..44ba00f 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -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 tilePosition; math::Vector > position; math::Vector > velocity; + Orientation direction; Orientation orientation; math::Fixed<8> speed; int flags; diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index baefdc5..2ae4bb3 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -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 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 &coordinates) { Vector 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; diff --git a/src/map/Tile.h b/src/map/Tile.h index f5afb24..137da43 100644 --- a/src/map/Tile.h +++ b/src/map/Tile.h @@ -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 *); -- 2.39.2