Advertisement
Guest User

Collision Code

a guest
Feb 19th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. CollisionComponent::CollisionComponent(luabridge::LuaRef& componentTable)
  2. {
  3.     if (componentTable["boundingBox"].isTable())
  4.     {
  5.         luabridge::LuaRef boundingBoxTable = componentTable["boundingBox"];
  6.         boundingBox = sf::FloatRect(boundingBoxTable[1], boundingBoxTable[2], boundingBoxTable[3], boundingBoxTable[4]);
  7.     }
  8.  
  9.     if (componentTable["collide"].isFunction())
  10.         didCollide = std::make_shared<luabridge::LuaRef>(componentTable["collide"]);
  11.     else
  12.         didCollide.reset();
  13. }
  14.  
  15. void CollisionComponent::collide(LuaEntity* ent1, LuaEntity* ent2)
  16. {
  17.     if (didCollide)
  18.     {
  19.         try
  20.         {
  21.             (*didCollide)(ent1, ent2);
  22.         }
  23.         catch (luabridge::LuaException const& e)
  24.         {
  25.             std::cout << "LuaException: " << e.what() << std::endl;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement