diff options
Diffstat (limited to 'src/party.cpp')
| -rw-r--r-- | src/party.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
| diff --git a/src/party.cpp b/src/party.cpp index 1ff4bb4..19b9557 100644 --- a/src/party.cpp +++ b/src/party.cpp | |||
| @@ -12,6 +12,7 @@ void Party::addMember(Game& game, int spriteId) { | |||
| 12 | 12 | ||
| 13 | for (int i = 0; i < PARTY_FRAME_DELAY * index; i++) { | 13 | for (int i = 0; i < PARTY_FRAME_DELAY * index; i++) { |
| 14 | newMember.nextPosition.push_back(sprite.loc()); | 14 | newMember.nextPosition.push_back(sprite.loc()); |
| 15 | newMember.nextDirection.push_back(sprite.getDirection()); | ||
| 15 | } | 16 | } |
| 16 | } | 17 | } |
| 17 | 18 | ||
| @@ -25,35 +26,67 @@ void Party::move(Game& game, const Input& keystate) { | |||
| 25 | 26 | ||
| 26 | const Sprite& p1 = game.getSprite(members_[0].spriteId); | 27 | const Sprite& p1 = game.getSprite(members_[0].spriteId); |
| 27 | vec2i pLoc = p1.loc(); | 28 | vec2i pLoc = p1.loc(); |
| 29 | Direction dir = Direction::left; | ||
| 28 | 30 | ||
| 29 | if (keystate.up) | 31 | if (keystate.up) |
| 30 | { | 32 | { |
| 31 | pLoc.y() -= MOVEMENT_SPEED; | 33 | pLoc.y() -= MOVEMENT_SPEED; |
| 34 | dir = Direction::up; | ||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | if (keystate.down) | 37 | if (keystate.down) |
| 35 | { | 38 | { |
| 36 | pLoc.y() += MOVEMENT_SPEED; | 39 | pLoc.y() += MOVEMENT_SPEED; |
| 40 | dir = Direction::down; | ||
| 37 | } | 41 | } |
| 38 | 42 | ||
| 39 | if (keystate.left) | 43 | if (keystate.left) |
| 40 | { | 44 | { |
| 41 | pLoc.x() -= MOVEMENT_SPEED; | 45 | pLoc.x() -= MOVEMENT_SPEED; |
| 46 | |||
| 47 | if (dir == Direction::up) { | ||
| 48 | dir = Direction::up_left; | ||
| 49 | } else if (dir == Direction::down) { | ||
| 50 | dir = Direction::down_left; | ||
| 51 | } else { | ||
| 52 | dir = Direction::left; | ||
| 53 | } | ||
| 42 | } | 54 | } |
| 43 | 55 | ||
| 44 | if (keystate.right) | 56 | if (keystate.right) |
| 45 | { | 57 | { |
| 46 | pLoc.x() += MOVEMENT_SPEED; | 58 | pLoc.x() += MOVEMENT_SPEED; |
| 59 | |||
| 60 | if (dir == Direction::up) { | ||
| 61 | dir = Direction::up_right; | ||
| 62 | } else if (dir == Direction::down) { | ||
| 63 | dir = Direction::down_right; | ||
| 64 | } else { | ||
| 65 | dir = Direction::right; | ||
| 66 | } | ||
| 47 | } | 67 | } |
| 48 | 68 | ||
| 49 | if (keystate.up || keystate.down || keystate.left || keystate.right) { | 69 | if (keystate.up || keystate.down || keystate.left || keystate.right) { |
| 70 | for (int i = 0; i < members_.size(); i++) { | ||
| 71 | game.setSpriteWalking(members_[i].spriteId, true); | ||
| 72 | } | ||
| 73 | |||
| 50 | game.moveSprite(members_[0].spriteId, pLoc); | 74 | game.moveSprite(members_[0].spriteId, pLoc); |
| 75 | game.setSpriteDirection(members_[0].spriteId, dir); | ||
| 51 | 76 | ||
| 52 | for (int i = 1; i < members_.size(); i++) { | 77 | for (int i = 1; i < members_.size(); i++) { |
| 53 | const Sprite& pNext = game.getSprite(members_[i].spriteId); | 78 | const Sprite& pNext = game.getSprite(members_[i].spriteId); |
| 54 | members_[i].nextPosition.push_back(pLoc); | 79 | members_[i].nextPosition.push_back(pLoc); |
| 55 | game.moveSprite(members_[i].spriteId, members_[i].nextPosition.front()); | 80 | game.moveSprite(members_[i].spriteId, members_[i].nextPosition.front()); |
| 56 | members_[i].nextPosition.pop_front(); | 81 | members_[i].nextPosition.pop_front(); |
| 82 | |||
| 83 | members_[i].nextDirection.push_back(dir); | ||
| 84 | game.setSpriteDirection(members_[i].spriteId, members_[i].nextDirection.front()); | ||
| 85 | members_[i].nextDirection.pop_front(); | ||
| 86 | } | ||
| 87 | } else { | ||
| 88 | for (int i = 0; i < members_.size(); i++) { | ||
| 89 | game.setSpriteWalking(members_[i].spriteId, false); | ||
| 57 | } | 90 | } |
| 58 | } | 91 | } |
| 59 | } \ No newline at end of file | 92 | } \ No newline at end of file |
