Crystal.cpp 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Crystal.h"
  2. #include "Model.h"
  3. #include "Player.h"
  4. Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale)
  5. {
  6. this->filled = Model::load(filled);
  7. this->empty = Model::load(empty);
  8. model = this->filled;
  9. this->position = position;
  10. this->rotation = rotation;
  11. this->scale = scale;
  12. this->canCollide = true;
  13. isFilled = true;
  14. }
  15. Crystal::~Crystal()
  16. {
  17. if (model)
  18. Model::unload(model);
  19. //if isfilled, means model is model filled, so model empty has to been deleted.
  20. //if is not filled, means model is model empty, so model filled has to been deleted.
  21. if (isFilled)
  22. if(empty)
  23. Model::unload(empty);
  24. else
  25. if(filled)
  26. Model::unload(filled);
  27. }
  28. void Crystal::draw()
  29. {
  30. Entity::draw();
  31. }
  32. void Crystal::collide()
  33. {
  34. if (isFilled)
  35. {
  36. Player::getInstance()->crystals++;
  37. isFilled = false;
  38. model = empty;
  39. }
  40. }