summary refs log tree commit diff stats
path: root/src/character_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-17 20:34:59 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-17 20:34:59 -0500
commitaac57db782718bf40a7adea15baf8d6b899ea925 (patch)
treec9f32563cdb9a06e6e24343946c5bb35dc254b76 /src/character_system.cpp
parentb3720c4a401f345c49eadabdb852968e273e7077 (diff)
downloadtanetane-aac57db782718bf40a7adea15baf8d6b899ea925.tar.gz
tanetane-aac57db782718bf40a7adea15baf8d6b899ea925.tar.bz2
tanetane-aac57db782718bf40a7adea15baf8d6b899ea925.zip
Made some sprites persist between map changes
The player party characters are now initialised at the start of the game and are no longer re-created after every map change. The script system takes care of moving the player into the correct position on the new map.

Deleted sprite IDs are now reused the next time a sprite is created, instead of throwing out everything between maps.
Diffstat (limited to 'src/character_system.cpp')
-rw-r--r--src/character_system.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/character_system.cpp b/src/character_system.cpp index d0c416e..7d456f6 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp
@@ -39,6 +39,32 @@ void CharacterSystem::addSpriteToParty(int leaderId, int followerId) {
39 game_.getSystem<AnimationSystem>().setSpriteAnimation(followerId, "still"); 39 game_.getSystem<AnimationSystem>().setSpriteAnimation(followerId, "still");
40} 40}
41 41
42void CharacterSystem::transplantParty(int leaderId, vec2i pos, Direction dir) {
43 Sprite& leader = game_.getSprite(leaderId);
44 CharacterState oldState = leader.characterState;
45
46 std::vector<int> followers = leader.followers;
47 leader.followers.clear();
48
49 game_.getSystem<TransformSystem>().moveSprite(leaderId, pos);
50 game_.getSystem<AnimationSystem>().setSpriteDirection(leaderId, dir);
51
52 for (int followerId : followers) {
53 Sprite& follower = game_.getSprite(followerId);
54 follower.trail.clear();
55
56 game_.getSystem<TransformSystem>().moveSprite(followerId, pos);
57 game_.getSystem<AnimationSystem>().setSpriteDirection(followerId, dir);
58 addSpriteToParty(leaderId, followerId);
59 }
60
61 if (oldState == CharacterState::Running) {
62 startRunning(leaderId);
63 } else {
64 setPartyState(leaderId, oldState);
65 }
66}
67
42void CharacterSystem::moveInDirection(int spriteId, Direction dir) { 68void CharacterSystem::moveInDirection(int spriteId, Direction dir) {
43 Sprite& sprite = game_.getSprite(spriteId); 69 Sprite& sprite = game_.getSprite(spriteId);
44 70
@@ -266,11 +292,3 @@ void CharacterSystem::destroySprite(int spriteId) {
266 stopRunningSound(sprite); 292 stopRunningSound(sprite);
267 } 293 }
268} 294}
269
270void CharacterSystem::clearSpriteCache() {
271 for (Sprite& sprite : game_.getSprites() | game_.spriteView()) {
272 if (sprite.runningSfxChannel != -1) {
273 stopRunningSound(sprite);
274 }
275 }
276}