Guest User

Untitled

a guest
Jan 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // ...
  2.  
  3. bool canJump = false;
  4. bool canLeft = true;
  5. bool canRight = true;
  6.  
  7. for (b2ContactEdge* ce = _playerBody->GetContactList(); ce; ce = ce->next) {
  8. b2Contact* c = ce->contact;
  9.  
  10. if (c->IsTouching()) {
  11. b2WorldManifold worldManifold;
  12. c->GetWorldManifold(&worldManifold);
  13.  
  14. // Math::dot...
  15. // Returns 0 when two vectors are perpendicular, > 0 when two vectors are in the same general direction,
  16. // 1 when two normalized vectors are parallel, < 0 when two vectors are in opposite general direction and
  17. // -1 when two normalized* vectors are antiparallel.
  18.  
  19. if(Math::dot(Vector2(worldManifold.normal.x, worldManifold.normal.y), Vector2::yAxis(-1)) == 1) {
  20. canJump = true;
  21. }
  22.  
  23. if(Math::dot(Vector2(worldManifold.normal.x, worldManifold.normal.y), Vector2::xAxis(-1)) == 1) {
  24. canLeft = false;
  25. }
  26.  
  27. if(Math::dot(Vector2(worldManifold.normal.x, worldManifold.normal.y), Vector2::xAxis(1)) == 1) {
  28. canRight = false;
  29. }
  30. }
  31. }
  32.  
  33. b2Vec2 vel = _playerBody->GetLinearVelocity();
  34.  
  35. if (pressedKeys[KeyEvent::Key::Comma] && canJump) {
  36. vel.y = 8.f;
  37. }
  38.  
  39. if (pressedKeys[KeyEvent::Key::A] && canLeft) {
  40. vel.x = -3.f;
  41. }
  42.  
  43. if (pressedKeys[KeyEvent::Key::E] && canRight) {
  44. vel.x = 3.f;
  45. }
  46.  
  47. _playerBody->SetLinearVelocity(vel);
Add Comment
Please, Sign In to add comment