Portal.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "Portal.hpp"
  2. #include "Echo.hpp"
  3. #include "Shared.hpp"
  4. Texture Portal::_blue_tex;
  5. Texture Portal::_orange_tex;
  6. void Portal::create(Shared* context, Vector2i src, Vector2i dest)
  7. {
  8. if(_blue_tex.getSize().x == 0) {
  9. _blue_tex.loadFromFile("data/blueportal.png");
  10. }
  11. _blue.setTexture(_blue_tex);
  12. _blue.setTextureRect(IntRect(0, 0, 16, 32));
  13. _blue.setPosition(src.x * 16, src.y * 16 - 16);
  14. context->tpa.push_back(src);
  15. if(_orange_tex.getSize().x == 0) {
  16. _orange_tex.loadFromFile("data/orangeportal.png");
  17. }
  18. _orange.setTexture(_orange_tex);
  19. _orange.setTextureRect(IntRect(0, 0, 16, 32));
  20. _orange.setPosition(dest.x * 16, dest.y * 16 - 16);
  21. context->tpb.push_back(dest);
  22. }
  23. void Portal::animate()
  24. {
  25. if(_clock.getElapsedTime().asSeconds() > 0.5f) {
  26. _blue.setTextureRect(IntRect((_blue.getTextureRect().left + 16) % 64, 0, 16, 32));
  27. _orange.setTextureRect(IntRect((_blue.getTextureRect().left + 16) % 64, 0, 16, 32));
  28. _clock.restart();
  29. }
  30. }
  31. void Portal::draw(RenderTarget& target, RenderStates states) const {
  32. target.draw(_blue, states);
  33. target.draw(_orange, states);
  34. }