Crystal.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Crystal.wav", false);
  15. music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
  16. music->SetPos(position, Vec3f());
  17. crystalRot = 0;
  18. }
  19. Crystal::~Crystal()
  20. {
  21. CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
  22. if (model)
  23. Model::unload(model);
  24. //if isfilled, means model is model filled, so model empty has to been deleted.
  25. //if is not filled, means model is model empty, so model filled has to been deleted.
  26. if (isFilled)
  27. if(empty)
  28. Model::unload(empty);
  29. else
  30. if(filled)
  31. Model::unload(filled);
  32. }
  33. void Crystal::draw()
  34. {
  35. crystalRot -= 0.5f;
  36. rotation = Vec3f(0, crystalRot, 0);
  37. Entity::draw();
  38. }
  39. void Crystal::collide()
  40. {
  41. if (isFilled)
  42. {
  43. music->Play();
  44. Player::getInstance()->crystals++;
  45. isFilled = false;
  46. model = empty;
  47. }
  48. }