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-23 22:22:49 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-02-24 16:00:53 -0500
commitb06b259c54e09f1a4026191d6eec9684599bd370 (patch)
treef31b241c3da5559d388d97bf9e65c2104f4652e8 /src/character_system.cpp
parentae654356f843bb42a3c72d57b528d87aa63cf66d (diff)
downloadtanetane-b06b259c54e09f1a4026191d6eec9684599bd370.tar.gz
tanetane-b06b259c54e09f1a4026191d6eec9684599bd370.tar.bz2
tanetane-b06b259c54e09f1a4026191d6eec9684599bd370.zip
Started working on ladders
TODO:
* all the animations are weird. we will need to have an adjustable framerate bc the climbing animation does not look right at the current rate. (also remove the manual animation stuff ig)
* does the medium stuff seem good and right? i am kinda not satisfied with it.
* running onto a ladder causes the characters to bunch up bc the movement speed is slowed down but the trails are not doubled
* no ladder running sound
* shadows should vanish while on a ladder
* uhh if you end a cutscene while on a ladder it resets the animation to "still" which is wrong. will this ever happen? idk
* adding a sprite to your party while you are on a ladder??
Diffstat (limited to 'src/character_system.cpp')
-rw-r--r--src/character_system.cpp122
1 files changed, 93 insertions, 29 deletions
diff --git a/src/character_system.cpp b/src/character_system.cpp index 99b6929..27c2280 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp
@@ -34,7 +34,7 @@ void CharacterSystem::addSpriteToParty(int leaderId, int followerId) {
34 34
35 for (int i=0; i<truePartyDelay; i++) { 35 for (int i=0; i<truePartyDelay; i++) {
36 vec2i tween = ((follower.loc - targetPos) * i) / static_cast<double>(truePartyDelay) + targetPos; 36 vec2i tween = ((follower.loc - targetPos) * i) / static_cast<double>(truePartyDelay) + targetPos;
37 follower.trail.push_front({.pos = tween, .dir = toFace}); 37 follower.trail.push_front({.pos = tween, .dir = toFace, .medium = CharacterMedium::Normal});
38 } 38 }
39 39
40 leader.followers.push_back(followerId); 40 leader.followers.push_back(followerId);
@@ -70,14 +70,31 @@ void CharacterSystem::transplantParty(int leaderId, vec2i pos, Direction dir) {
70 70
71void CharacterSystem::moveInDirection(int spriteId, Direction dir) { 71void CharacterSystem::moveInDirection(int spriteId, Direction dir) {
72 Sprite& sprite = game_.getSprite(spriteId); 72 Sprite& sprite = game_.getSprite(spriteId);
73 sprite.movementDir = dir;
73 74
74 game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, dir); 75 switch (sprite.characterMedium) {
76 case CharacterMedium::Normal: {
77 game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, dir);
78 break;
79 }
80 case CharacterMedium::Ladder: {
81 if (dirHasDir(dir, Direction::up)) {
82 game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, Direction::up);
83 } else if (dirHasDir(dir, Direction::down)) {
84 game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, Direction::down);
85 }
86 break;
87 }
88 }
75 89
76 if (sprite.characterState == CharacterState::Still) { 90 if (sprite.characterState == CharacterState::Still) {
77 setPartyState(spriteId, CharacterState::Walking); 91 setPartyState(spriteId, CharacterState::Walking);
78 } else if (sprite.characterState == CharacterState::Crouching) { 92 } else if (sprite.characterState == CharacterState::Crouching) {
79 for (int followerId : sprite.followers) { 93 for (int followerId : sprite.followers) {
80 game_.getSystem<AnimationSystem>().setSpriteDirection(followerId, dir); 94 Sprite& follower = game_.getSprite(followerId);
95 if (follower.characterMedium == CharacterMedium::Normal) {
96 game_.getSystem<AnimationSystem>().setSpriteDirection(followerId, dir);
97 }
81 } 98 }
82 } 99 }
83} 100}
@@ -107,14 +124,18 @@ void CharacterSystem::tick(double dt) {
107 } 124 }
108 125
109 int speed = sprite.movementSpeed; 126 int speed = sprite.movementSpeed;
110 if (sprite.characterState == CharacterState::Running) { 127 if (sprite.characterState == CharacterState::Running && sprite.characterMedium == CharacterMedium::Normal) {
111 speed *= 2; 128 speed *= 2;
112 } 129 }
113 130
114 pLoc += (unitVecInDirection(sprite.dir) * speed); 131 if (sprite.characterMedium == CharacterMedium::Ladder) {
132 //game_.getSystem<AnimationSystem>().advanceAnimation(spriteId);
133 }
134
135 pLoc += (unitVecInDirection(sprite.movementDir) * speed);
115 136
116 // Check collision. 137 // Check collision.
117 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, pLoc, sprite.dir); 138 CollisionResult collision = game_.getSystem<TransformSystem>().checkCollision(spriteId, pLoc, sprite.movementDir);
118 bool blocked = collision.horiz.blocked || collision.vert.blocked; 139 bool blocked = collision.horiz.blocked || collision.vert.blocked;
119 140
120 if (collision.horiz.blocked && !sprite.clipping) { 141 if (collision.horiz.blocked && !sprite.clipping) {
@@ -146,6 +167,12 @@ void CharacterSystem::tick(double dt) {
146 if (pLoc != sprite.loc) { 167 if (pLoc != sprite.loc) {
147 game_.getSystem<TransformSystem>().moveSprite(spriteId, pLoc); 168 game_.getSystem<TransformSystem>().moveSprite(spriteId, pLoc);
148 169
170 CharacterMedium newMedium = game_.getSystem<TransformSystem>().getMediumAtPosition(spriteId, pLoc);
171 if (newMedium != sprite.characterMedium) {
172 sprite.characterMedium = newMedium;
173 setAnimationFor(spriteId, sprite.characterState);
174 }
175
149 if (sprite.characterState == CharacterState::Running) { 176 if (sprite.characterState == CharacterState::Running) {
150 const Map& map = game_.getMap(); 177 const Map& map = game_.getMap();
151 178
@@ -164,12 +191,20 @@ void CharacterSystem::tick(double dt) {
164 191
165 for (int followerId : sprite.followers) { 192 for (int followerId : sprite.followers) {
166 Sprite& pNext = game_.getSprite(followerId); 193 Sprite& pNext = game_.getSprite(followerId);
194 if (pNext.characterMedium == CharacterMedium::Ladder) {
195 //game_.getSystem<AnimationSystem>().advanceAnimation(followerId);
196 }
197
167 const Movement& posdir = pNext.trail.front(); 198 const Movement& posdir = pNext.trail.front();
168 game_.getSystem<TransformSystem>().moveSprite(followerId, posdir.pos); 199 game_.getSystem<TransformSystem>().moveSprite(followerId, posdir.pos);
169 game_.getSystem<AnimationSystem>().setSpriteDirection(followerId, posdir.dir); 200 game_.getSystem<AnimationSystem>().setSpriteDirection(followerId, posdir.dir);
201 if (posdir.medium != pNext.characterMedium) {
202 pNext.characterMedium = posdir.medium;
203 setAnimationFor(followerId, sprite.characterState);
204 }
170 205
171 pNext.trail.pop_front(); 206 pNext.trail.pop_front();
172 pNext.trail.push_back({.pos = pLoc, .dir = sprite.dir}); 207 pNext.trail.push_back({.pos = pLoc, .dir = sprite.dir, .medium = sprite.characterMedium});
173 } 208 }
174 } 209 }
175 } 210 }
@@ -180,6 +215,10 @@ void CharacterSystem::tick(double dt) {
180void CharacterSystem::beginCrouch(int spriteId) { 215void CharacterSystem::beginCrouch(int spriteId) {
181 Sprite& sprite = game_.getSprite(spriteId); 216 Sprite& sprite = game_.getSprite(spriteId);
182 217
218 if (sprite.characterMedium == CharacterMedium::Ladder) {
219 return;
220 }
221
183 if (sprite.characterState == CharacterState::Running) { 222 if (sprite.characterState == CharacterState::Running) {
184 stopRunning(spriteId); 223 stopRunning(spriteId);
185 } else { 224 } else {
@@ -242,32 +281,12 @@ void CharacterSystem::stopRunning(int spriteId) {
242} 281}
243 282
244void CharacterSystem::setPartyState(int spriteId, CharacterState state) { 283void CharacterSystem::setPartyState(int spriteId, CharacterState state) {
245 std::string animName;
246 switch (state) {
247 case CharacterState::Still: {
248 animName = "still";
249 break;
250 }
251 case CharacterState::Walking: {
252 animName = "walk";
253 break;
254 }
255 case CharacterState::Crouching: {
256 animName = "crouch";
257 break;
258 }
259 case CharacterState::Running: {
260 animName = "run";
261 break;
262 }
263 }
264
265 Sprite& sprite = game_.getSprite(spriteId); 284 Sprite& sprite = game_.getSprite(spriteId);
266 sprite.characterState = state; 285 sprite.characterState = state;
267 286
268 game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName); 287 setAnimationFor(spriteId, state);
269 for (int followerId : sprite.followers) { 288 for (int followerId : sprite.followers) {
270 game_.getSystem<AnimationSystem>().setSpriteAnimation(followerId, animName); 289 setAnimationFor(followerId, state);
271 } 290 }
272} 291}
273 292
@@ -297,3 +316,48 @@ void CharacterSystem::destroySprite(int spriteId) {
297 stopRunningSound(sprite); 316 stopRunningSound(sprite);
298 } 317 }
299} 318}
319
320void CharacterSystem::setAnimationFor(int spriteId, CharacterState state) {
321 Sprite& sprite = game_.getSprite(spriteId);
322 std::string animName;
323
324 switch (sprite.characterMedium) {
325 case CharacterMedium::Normal: {
326 std::string animName;
327
328 switch (state) {
329 case CharacterState::Still: {
330 animName = "still";
331 break;
332 }
333 case CharacterState::Walking: {
334 animName = "walk";
335 break;
336 }
337 case CharacterState::Crouching: {
338 animName = "crouch";
339 break;
340 }
341 case CharacterState::Running: {
342 animName = "run";
343 break;
344 }
345 }
346
347 game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName);
348
349 break;
350 }
351 case CharacterMedium::Ladder: {
352 game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, "climb.");
353
354 if (state == CharacterState::Still || state == CharacterState::Crouching) {
355 sprite.animPaused = true;
356 } else {
357 sprite.animPaused = false;
358 }
359
360 break;
361 }
362 }
363}