diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-12 22:46:32 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-12 22:46:32 -0400 |
| commit | 47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e (patch) | |
| tree | 14acad810f6ef199d7fc669fc1abe91972eb7f6a /src/components.cpp | |
| parent | cc75196b1baca28a142e66c69cd51200649d252a (diff) | |
| download | therapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.tar.gz therapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.tar.bz2 therapy-47d9d7884c57c2c14dd363b4ccb0df1dcbb5375e.zip | |
Fixed bug that would prevent player from continuing to move after dying, and also refactored collisions and dying a bit
Diffstat (limited to 'src/components.cpp')
| -rw-r--r-- | src/components.cpp | 52 |
1 files changed, 28 insertions, 24 deletions
| diff --git a/src/components.cpp b/src/components.cpp index 5925d14..ad0f501 100644 --- a/src/components.cpp +++ b/src/components.cpp | |||
| @@ -157,6 +157,11 @@ void PlayerSpriteComponent::render(Game&, Entity& entity, Texture& buffer) | |||
| 157 | 157 | ||
| 158 | void PlayerSpriteComponent::receive(Game&, Entity&, const Message& msg) | 158 | void PlayerSpriteComponent::receive(Game&, Entity&, const Message& msg) |
| 159 | { | 159 | { |
| 160 | if (msg.type == Message::Type::stopDying) | ||
| 161 | { | ||
| 162 | dying = false; | ||
| 163 | } | ||
| 164 | |||
| 160 | if (dying) | 165 | if (dying) |
| 161 | { | 166 | { |
| 162 | return; | 167 | return; |
| @@ -216,7 +221,10 @@ void PlayerPhysicsComponent::receive(Game&, Entity& entity, const Message& msg) | |||
| 216 | velocity.second = 0.0; | 221 | velocity.second = 0.0; |
| 217 | } else if (msg.type == Message::Type::jump) | 222 | } else if (msg.type == Message::Type::jump) |
| 218 | { | 223 | { |
| 219 | playSound("../res/Randomize87.wav", 0.25); | 224 | if (!frozen) |
| 225 | { | ||
| 226 | playSound("../res/Randomize87.wav", 0.25); | ||
| 227 | } | ||
| 220 | 228 | ||
| 221 | velocity.second = jump_velocity; | 229 | velocity.second = jump_velocity; |
| 222 | accel.second = jump_gravity; | 230 | accel.second = jump_gravity; |
| @@ -241,6 +249,9 @@ void PlayerPhysicsComponent::receive(Game&, Entity& entity, const Message& msg) | |||
| 241 | } else if (msg.type == Message::Type::die) | 249 | } else if (msg.type == Message::Type::die) |
| 242 | { | 250 | { |
| 243 | frozen = true; | 251 | frozen = true; |
| 252 | } else if (msg.type == Message::Type::stopDying) | ||
| 253 | { | ||
| 254 | frozen = false; | ||
| 244 | } | 255 | } |
| 245 | } | 256 | } |
| 246 | 257 | ||
| @@ -331,8 +342,8 @@ void MapRenderComponent::render(Game&, Entity&, Texture& buffer) | |||
| 331 | 342 | ||
| 332 | MapCollisionComponent::MapCollisionComponent(const Map& map) : map(map) | 343 | MapCollisionComponent::MapCollisionComponent(const Map& map) : map(map) |
| 333 | { | 344 | { |
| 334 | addCollision(-6, 0, GAME_WIDTH, Direction::left, (map.getLeftMap() == nullptr) ? 1 : 2); | 345 | addCollision(-6, 0, GAME_WIDTH, Direction::left, (map.getLeftMap() == nullptr) ? Collision::Type::wrap : Collision::Type::teleport); |
| 335 | addCollision(GAME_WIDTH+6, 0, GAME_WIDTH, Direction::right, (map.getRightMap() == nullptr) ? 3 : 2); | 346 | addCollision(GAME_WIDTH+6, 0, GAME_WIDTH, Direction::right, (map.getRightMap() == nullptr) ? Collision::Type::reverse : Collision::Type::teleport); |
| 336 | 347 | ||
| 337 | for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++) | 348 | for (int i=0; i<MAP_WIDTH*(MAP_HEIGHT-1); i++) |
| 338 | { | 349 | { |
| @@ -342,21 +353,21 @@ MapCollisionComponent::MapCollisionComponent(const Map& map) : map(map) | |||
| 342 | 353 | ||
| 343 | if ((tile > 0) && (tile < 28) && (!((tile >= 5) && (tile <= 7)))) | 354 | if ((tile > 0) && (tile < 28) && (!((tile >= 5) && (tile <= 7)))) |
| 344 | { | 355 | { |
| 345 | addCollision(x*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, Direction::right, 0); | 356 | addCollision(x*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, Direction::right, Collision::Type::wall); |
| 346 | addCollision((x+1)*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, Direction::left, 0); | 357 | addCollision((x+1)*TILE_WIDTH, y*TILE_HEIGHT, (y+1)*TILE_HEIGHT, Direction::left, Collision::Type::wall); |
| 347 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, 0); | 358 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, Collision::Type::wall); |
| 348 | addCollision((y+1)*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::up, 0); | 359 | addCollision((y+1)*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::up, Collision::Type::wall); |
| 349 | } else if ((tile >= 5) && (tile <= 7)) | 360 | } else if ((tile >= 5) && (tile <= 7)) |
| 350 | { | 361 | { |
| 351 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, 4); | 362 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, Collision::Type::platform); |
| 352 | } else if (tile == 42) | 363 | } else if (tile == 42) |
| 353 | { | 364 | { |
| 354 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, 5); | 365 | addCollision(y*TILE_HEIGHT, x*TILE_WIDTH, (x+1)*TILE_WIDTH, Direction::down, Collision::Type::danger); |
| 355 | } | 366 | } |
| 356 | } | 367 | } |
| 357 | } | 368 | } |
| 358 | 369 | ||
| 359 | void MapCollisionComponent::addCollision(int axis, int lower, int upper, Direction dir, int type) | 370 | void MapCollisionComponent::addCollision(int axis, int lower, int upper, Direction dir, Collision::Type type) |
| 360 | { | 371 | { |
| 361 | std::list<Collision>::iterator it; | 372 | std::list<Collision>::iterator it; |
| 362 | 373 | ||
| @@ -498,7 +509,7 @@ void MapCollisionComponent::detectCollision(Game& game, Entity&, Entity& collide | |||
| 498 | 509 | ||
| 499 | bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir) | 510 | bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Collision collision, Direction dir) |
| 500 | { | 511 | { |
| 501 | if (collision.type == 0) | 512 | if (collision.type == Collision::Type::wall) |
| 502 | { | 513 | { |
| 503 | if (dir == Direction::left) | 514 | if (dir == Direction::left) |
| 504 | { | 515 | { |
| @@ -525,7 +536,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli | |||
| 525 | Message msg(Message::Type::stopMovingVertically); | 536 | Message msg(Message::Type::stopMovingVertically); |
| 526 | collider.send(game, msg); | 537 | collider.send(game, msg); |
| 527 | } | 538 | } |
| 528 | } else if (collision.type == 1) | 539 | } else if (collision.type == Collision::Type::wrap) |
| 529 | { | 540 | { |
| 530 | if (dir == Direction::left) | 541 | if (dir == Direction::left) |
| 531 | { | 542 | { |
| @@ -540,7 +551,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli | |||
| 540 | { | 551 | { |
| 541 | collider.position.second = -collider.size.second/2; | 552 | collider.position.second = -collider.size.second/2; |
| 542 | } | 553 | } |
| 543 | } else if (collision.type == 2) | 554 | } else if (collision.type == Collision::Type::teleport) |
| 544 | { | 555 | { |
| 545 | if (dir == Direction::left) | 556 | if (dir == Direction::left) |
| 546 | { | 557 | { |
| @@ -553,7 +564,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli | |||
| 553 | } | 564 | } |
| 554 | 565 | ||
| 555 | return true; | 566 | return true; |
| 556 | } else if (collision.type == 3) | 567 | } else if (collision.type == Collision::Type::reverse) |
| 557 | { | 568 | { |
| 558 | if (dir == Direction::right) | 569 | if (dir == Direction::right) |
| 559 | { | 570 | { |
| @@ -562,22 +573,15 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli | |||
| 562 | Message msg(Message::Type::walkLeft); | 573 | Message msg(Message::Type::walkLeft); |
| 563 | collider.send(game, msg); | 574 | collider.send(game, msg); |
| 564 | } | 575 | } |
| 565 | } else if (collision.type == 4) | 576 | } else if (collision.type == Collision::Type::platform) |
| 566 | { | 577 | { |
| 567 | Message msg(Message::Type::drop); | 578 | Message msg(Message::Type::drop); |
| 568 | msg.dropAxis = collision.axis; | 579 | msg.dropAxis = collision.axis; |
| 569 | 580 | ||
| 570 | collider.send(game, msg); | 581 | collider.send(game, msg); |
| 571 | } else if (collision.type == 5) | 582 | } else if (collision.type == Collision::Type::danger) |
| 572 | { | 583 | { |
| 573 | Message msg(Message::Type::die); | 584 | game.playerDie(collider, map); |
| 574 | collider.send(game, msg); | ||
| 575 | |||
| 576 | playSound("../res/Hit_Hurt5.wav", 0.25); | ||
| 577 | |||
| 578 | game.schedule(FRAMES_PER_SECOND * 0.75, [&] () { | ||
| 579 | game.loadGame(map); | ||
| 580 | }); | ||
| 581 | } | 585 | } |
| 582 | 586 | ||
| 583 | return false; | 587 | return false; |
