summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 17:43:20 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-03-14 17:43:20 -0400
commit2ca593c5f09ee59a39733856cdb1f7191dc87216 (patch)
treedf7c51c2b707d1838b492f739b554230bba1c4be
parent25855f327a0b2b1386a3fd8c568817bb7782cac2 (diff)
downloadtherapy-2ca593c5f09ee59a39733856cdb1f7191dc87216.tar.gz
therapy-2ca593c5f09ee59a39733856cdb1f7191dc87216.tar.bz2
therapy-2ca593c5f09ee59a39733856cdb1f7191dc87216.zip
Fixed how movement while dying works
Also removed some unnecessary Message objects
-rw-r--r--src/components.cpp121
-rw-r--r--src/components.h2
-rw-r--r--src/game.cpp7
3 files changed, 72 insertions, 58 deletions
diff --git a/src/components.cpp b/src/components.cpp index d5261ef..954ac57 100644 --- a/src/components.cpp +++ b/src/components.cpp
@@ -13,22 +13,30 @@ void UserMovementComponent::input(Game& game, Entity& entity, int key, int actio
13 { 13 {
14 holdingLeft = true; 14 holdingLeft = true;
15 15
16 Message msg(Message::Type::walkLeft); 16 if (!frozen)
17 entity.send(game, msg); 17 {
18 entity.send(game, Message::Type::walkLeft);
19 }
18 } else if (key == GLFW_KEY_RIGHT) 20 } else if (key == GLFW_KEY_RIGHT)
19 { 21 {
20 holdingRight = true; 22 holdingRight = true;
21 23
22 Message msg(Message::Type::walkRight); 24 if (!frozen)
23 entity.send(game, msg); 25 {
26 entity.send(game, Message::Type::walkRight);
27 }
24 } else if (key == GLFW_KEY_UP) 28 } else if (key == GLFW_KEY_UP)
25 { 29 {
26 Message msg(Message::Type::jump); 30 if (!frozen)
27 entity.send(game, msg); 31 {
32 entity.send(game, Message::Type::jump);
33 }
28 } else if (key == GLFW_KEY_DOWN) 34 } else if (key == GLFW_KEY_DOWN)
29 { 35 {
30 Message msg(Message::Type::canDrop); 36 if (!frozen)
31 entity.send(game, msg); 37 {
38 entity.send(game, Message::Type::canDrop);
39 }
32 } 40 }
33 } else if (action == GLFW_RELEASE) 41 } else if (action == GLFW_RELEASE)
34 { 42 {
@@ -36,34 +44,61 @@ void UserMovementComponent::input(Game& game, Entity& entity, int key, int actio
36 { 44 {
37 holdingLeft = false; 45 holdingLeft = false;
38 46
39 if (holdingRight) 47 if (!frozen)
40 { 48 {
41 Message msg(Message::Type::walkRight); 49 if (holdingRight)
42 entity.send(game, msg); 50 {
43 } else { 51 entity.send(game, Message::Type::walkRight);
44 Message msg(Message::Type::stopWalking); 52 } else {
45 entity.send(game, msg); 53 entity.send(game, Message::Type::stopWalking);
54 }
46 } 55 }
47 } else if (key == GLFW_KEY_RIGHT) 56 } else if (key == GLFW_KEY_RIGHT)
48 { 57 {
49 holdingRight = false; 58 holdingRight = false;
50 59
51 if (holdingLeft) 60 if (!frozen)
52 { 61 {
53 Message msg(Message::Type::walkLeft); 62 if (holdingLeft)
54 entity.send(game, msg); 63 {
55 } else { 64 entity.send(game, Message::Type::walkLeft);
56 Message msg(Message::Type::stopWalking); 65 } else {
57 entity.send(game, msg); 66 entity.send(game, Message::Type::stopWalking);
67 }
58 } 68 }
59 } else if (key == GLFW_KEY_DOWN) 69 } else if (key == GLFW_KEY_DOWN)
60 { 70 {
61 Message msg(Message::Type::cantDrop); 71 if (!frozen)
62 entity.send(game, msg); 72 {
73 entity.send(game, Message::Type::cantDrop);
74 }
63 } else if (key == GLFW_KEY_UP) 75 } else if (key == GLFW_KEY_UP)
64 { 76 {
65 Message msg(Message::Type::stopJump); 77 if (!frozen)
66 entity.send(game, msg); 78 {
79 entity.send(game, Message::Type::stopJump);
80 }
81 }
82 }
83}
84
85void UserMovementComponent::receive(Game& game, Entity& entity, const Message& msg)
86{
87 if (msg.type == Message::Type::die)
88 {
89 frozen = true;
90
91 entity.send(game, Message::Type::stopWalking);
92 } else if (msg.type == Message::Type::stopDying)
93 {
94 frozen = false;
95
96 if (holdingLeft)
97 {
98 entity.send(game, Message::Type::walkLeft);
99 } else if (holdingRight)
100 {
101 entity.send(game, Message::Type::walkRight);
67 } 102 }
68 } 103 }
69} 104}
@@ -168,16 +203,6 @@ void PlayerSpriteComponent::render(Game&, Entity& entity, Texture& buffer)
168 203
169void PlayerSpriteComponent::receive(Game&, Entity&, const Message& msg) 204void PlayerSpriteComponent::receive(Game&, Entity&, const Message& msg)
170{ 205{
171 if (msg.type == Message::Type::stopDying)
172 {
173 dying = false;
174 }
175
176 if (dying)
177 {
178 return;
179 }
180
181 if (msg.type == Message::Type::walkLeft) 206 if (msg.type == Message::Type::walkLeft)
182 { 207 {
183 facingLeft = true; 208 facingLeft = true;
@@ -193,6 +218,9 @@ void PlayerSpriteComponent::receive(Game&, Entity&, const Message& msg)
193 { 218 {
194 dying = true; 219 dying = true;
195 isMoving = false; 220 isMoving = false;
221 } else if (msg.type == Message::Type::stopDying)
222 {
223 dying = false;
196 } 224 }
197} 225}
198 226
@@ -232,10 +260,7 @@ void PlayerPhysicsComponent::receive(Game&, Entity& entity, const Message& msg)
232 velocity.second = 0.0; 260 velocity.second = 0.0;
233 } else if (msg.type == Message::Type::jump) 261 } else if (msg.type == Message::Type::jump)
234 { 262 {
235 if (!frozen) 263 playSound("../res/Randomize87.wav", 0.25);
236 {
237 playSound("../res/Randomize87.wav", 0.25);
238 }
239 264
240 velocity.second = jump_velocity; 265 velocity.second = jump_velocity;
241 accel.second = jump_gravity; 266 accel.second = jump_gravity;
@@ -514,27 +539,19 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
514 if (dir == Direction::left) 539 if (dir == Direction::left)
515 { 540 {
516 collider.position.first = collision.axis; 541 collider.position.first = collision.axis;
517 542 collider.send(game, Message::Type::stopMovingHorizontally);
518 Message msg(Message::Type::stopMovingHorizontally);
519 collider.send(game, msg);
520 } else if (dir == Direction::right) 543 } else if (dir == Direction::right)
521 { 544 {
522 collider.position.first = collision.axis - collider.size.first; 545 collider.position.first = collision.axis - collider.size.first;
523 546 collider.send(game, Message::Type::stopMovingHorizontally);
524 Message msg(Message::Type::stopMovingHorizontally);
525 collider.send(game, msg);
526 } else if (dir == Direction::up) 547 } else if (dir == Direction::up)
527 { 548 {
528 collider.position.second = collision.axis; 549 collider.position.second = collision.axis;
529 550 collider.send(game, Message::Type::stopMovingVertically);
530 Message msg(Message::Type::stopMovingVertically);
531 collider.send(game, msg);
532 } else if (dir == Direction::down) 551 } else if (dir == Direction::down)
533 { 552 {
534 collider.position.second = collision.axis - collider.size.second; 553 collider.position.second = collision.axis - collider.size.second;
535 554 collider.send(game, Message::Type::stopMovingVertically);
536 Message msg(Message::Type::stopMovingVertically);
537 collider.send(game, msg);
538 } 555 }
539 } else if (collision.type == Collision::Type::wrap) 556 } else if (collision.type == Collision::Type::wrap)
540 { 557 {
@@ -569,9 +586,7 @@ bool MapCollisionComponent::processCollision(Game& game, Entity& collider, Colli
569 if (dir == Direction::right) 586 if (dir == Direction::right)
570 { 587 {
571 collider.position.first = collision.axis - collider.size.first; 588 collider.position.first = collision.axis - collider.size.first;
572 589 collider.send(game, Message::Type::walkLeft);
573 Message msg(Message::Type::walkLeft);
574 collider.send(game, msg);
575 } 590 }
576 } else if (collision.type == Collision::Type::platform) 591 } else if (collision.type == Collision::Type::platform)
577 { 592 {
diff --git a/src/components.h b/src/components.h index 2ec19ff..e0c4a24 100644 --- a/src/components.h +++ b/src/components.h
@@ -12,10 +12,12 @@ class Map;
12class UserMovementComponent : public Component { 12class UserMovementComponent : public Component {
13 public: 13 public:
14 void input(Game& game, Entity& entity, int key, int action); 14 void input(Game& game, Entity& entity, int key, int action);
15 void receive(Game&, Entity&, const Message& msg);
15 16
16 private: 17 private:
17 bool holdingLeft = false; 18 bool holdingLeft = false;
18 bool holdingRight = false; 19 bool holdingRight = false;
20 bool frozen = false;
19}; 21};
20 22
21class PhysicsBodyComponent : public Component { 23class PhysicsBodyComponent : public Component {
diff --git a/src/game.cpp b/src/game.cpp index edde71e..dd8f956 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -145,8 +145,7 @@ void Game::schedule(double time, std::function<void ()> callback)
145 145
146void Game::playerDie(Entity& player, const Map& curMap) 146void Game::playerDie(Entity& player, const Map& curMap)
147{ 147{
148 Message msg(Message::Type::die); 148 player.send(*this, Message::Type::die);
149 player.send(*this, msg);
150 149
151 playSound("../res/Hit_Hurt5.wav", 0.25); 150 playSound("../res/Hit_Hurt5.wav", 0.25);
152 151
@@ -157,8 +156,6 @@ void Game::playerDie(Entity& player, const Map& curMap)
157 } 156 }
158 157
159 player.position = save.position; 158 player.position = save.position;
160 159 player.send(*this, Message::Type::stopDying);
161 Message msg2(Message::Type::stopDying);
162 player.send(*this, msg2);
163 }); 160 });
164} 161}