SHARE
TWEET

Collision Code

a guest Feb 19th, 2016 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top