Portal.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "Portal.h"
  2. #include "Model.h"
  3. #include <iostream>
  4. #include "Player.h"
  5. #include "WorldHandler.h"
  6. Portal::Portal(const std::string &fileName,
  7. const Vec3f &position,
  8. Vec3f &rotation,
  9. const float &scale)
  10. {
  11. model = Model::load(fileName);
  12. this->position = position;
  13. this->rotation = rotation;
  14. this->scale = scale;
  15. this->canCollide = true;
  16. started = false;
  17. delay = 0;
  18. sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/portal.wav", false);
  19. music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
  20. music->SetPos(position, Vec3f());
  21. mayEnter = false;
  22. maxCrystals = 0;
  23. }
  24. Portal::~Portal()
  25. {
  26. // Model::unload(model);
  27. CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
  28. }
  29. void Portal::collide()
  30. {
  31. if (maxCrystals == (Player::getInstance()->crystals) && !mayEnter)
  32. {
  33. canCollide = false;
  34. mayEnter = true;
  35. }
  36. }
  37. bool Portal::enter(float deltaTime)
  38. {
  39. if (delay > 3 && started)
  40. {
  41. delay = 0;
  42. return true;
  43. }
  44. if (delay == 0 && !started)
  45. {
  46. music->Play();
  47. started = true;
  48. }
  49. delay += deltaTime;
  50. return false;
  51. }