diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-17 15:55:37 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-17 15:55:37 -0400 |
| commit | 90aadf3844386824140a20d7fbb847bc16009a94 (patch) | |
| tree | 6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /src/components/physics_body.cpp | |
| parent | bc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff) | |
| parent | 86f0106d0523825549f1e74b835688c78a10cf6c (diff) | |
| download | therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2 therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip | |
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
Diffstat (limited to 'src/components/physics_body.cpp')
| -rw-r--r-- | src/components/physics_body.cpp | 66 |
1 files changed, 0 insertions, 66 deletions
| diff --git a/src/components/physics_body.cpp b/src/components/physics_body.cpp deleted file mode 100644 index 97394d1..0000000 --- a/src/components/physics_body.cpp +++ /dev/null | |||
| @@ -1,66 +0,0 @@ | |||
| 1 | #include "physics_body.h" | ||
| 2 | #include "game.h" | ||
| 3 | #include "consts.h" | ||
| 4 | |||
| 5 | void PhysicsBodyComponent::receive(Game&, Entity&, const Message& msg) | ||
| 6 | { | ||
| 7 | if (msg.type == Message::Type::walkLeft) | ||
| 8 | { | ||
| 9 | velocity.first = -90; | ||
| 10 | } else if (msg.type == Message::Type::walkRight) | ||
| 11 | { | ||
| 12 | velocity.first = 90; | ||
| 13 | } else if (msg.type == Message::Type::stopWalking) | ||
| 14 | { | ||
| 15 | velocity.first = 0.0; | ||
| 16 | } else if (msg.type == Message::Type::setHorizontalVelocity) | ||
| 17 | { | ||
| 18 | velocity.first = msg.velocity; | ||
| 19 | } else if (msg.type == Message::Type::setVerticalVelocity) | ||
| 20 | { | ||
| 21 | velocity.second = msg.velocity; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | void PhysicsBodyComponent::tick(Game&, Entity& entity, double dt) | ||
| 26 | { | ||
| 27 | // Accelerate | ||
| 28 | velocity.first += accel.first * dt; | ||
| 29 | velocity.second += accel.second * dt; | ||
| 30 | |||
| 31 | // Terminal velocity | ||
| 32 | #define TERMINAL_VELOCITY_X (2 * TILE_WIDTH * FRAMES_PER_SECOND) | ||
| 33 | #define TERMINAL_VELOCITY_Y (2 * TILE_HEIGHT * FRAMES_PER_SECOND) | ||
| 34 | if (velocity.first < -TERMINAL_VELOCITY_X) velocity.first = -TERMINAL_VELOCITY_X; | ||
| 35 | if (velocity.first > TERMINAL_VELOCITY_X) velocity.first = TERMINAL_VELOCITY_X; | ||
| 36 | if (velocity.second < -TERMINAL_VELOCITY_Y) velocity.second = -TERMINAL_VELOCITY_Y; | ||
| 37 | if (velocity.second > TERMINAL_VELOCITY_Y) velocity.second = TERMINAL_VELOCITY_Y; | ||
| 38 | |||
| 39 | // Do the movement | ||
| 40 | entity.position.first += velocity.first * dt; | ||
| 41 | entity.position.second += velocity.second * dt; | ||
| 42 | } | ||
| 43 | |||
| 44 | void PhysicsBodyComponent::detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position) | ||
| 45 | { | ||
| 46 | // If already colliding, do nothing! | ||
| 47 | if ((old_position.first + collider.size.first > entity.position.first) | ||
| 48 | && (old_position.first < entity.position.first + entity.size.first) | ||
| 49 | && (old_position.second + collider.size.second > entity.position.second) | ||
| 50 | && (old_position.second < entity.position.second + entity.size.second)) | ||
| 51 | { | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | |||
| 55 | // If newly colliding, SHOCK AND HORROR! | ||
| 56 | if ((collider.position.first + collider.size.first > entity.position.first) | ||
| 57 | && (collider.position.first < entity.position.first + entity.size.first) | ||
| 58 | && (collider.position.second + collider.size.second > entity.position.second) | ||
| 59 | && (collider.position.second < entity.position.second + entity.size.second)) | ||
| 60 | { | ||
| 61 | Message msg(Message::Type::collision); | ||
| 62 | msg.collisionEntity = &collider; | ||
| 63 | |||
| 64 | entity.send(game, msg); | ||
| 65 | } | ||
| 66 | } | ||
