Foreground.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <vector>
  19. #include <SFML/Graphics.hpp>
  20. /**
  21. * @class Foreground
  22. * @author POSITIVE MENTAL ATTITUDE
  23. * @date 06/09/16
  24. * @file Foreground.hpp
  25. * @brief The destructible foreground.
  26. */
  27. class Foreground: public sf::Drawable
  28. {
  29. public:
  30. Foreground() = default;
  31. ~Foreground();
  32. void create(sf::Image& foreground, sf::Image& normal, sf::Image& map);
  33. void create(std::string foreground, std::string normal, std::string map);
  34. void setResolution(sf::Vector2u resolution);
  35. void setPosition(sf::Vector2f position);
  36. void reloadFromTile(int x, int y, bool neighbouring = false);
  37. void reloadFromPixel(int x, int y, bool neighbouring = false);
  38. bool destroy(unsigned x, unsigned y);
  39. const sf::Vector2u getSize() const;
  40. const unsigned getTileSize() const;
  41. unsigned const tileAlpha(unsigned x, unsigned y, unsigned pixelX, unsigned pixelY);
  42. void renderNormals(bool render);
  43. void move(sf::Vector2f movement);
  44. void rotate(float rotation);
  45. private:
  46. void draw(sf::RenderTarget& target, sf::RenderStates states) const;
  47. std::vector<std::pair<sf::Image, sf::Texture>> _tiles;
  48. std::vector<std::vector<sf::Sprite>> _sprites;
  49. std::vector<std::pair<sf::Image, sf::Texture>> _normalTiles;
  50. std::vector<std::vector<sf::Sprite>> _normalSprites;
  51. sf::Vector2u _renderCount;
  52. sf::Vector2u _tileCount;
  53. unsigned _tileSize;
  54. sf::Vector2u _position;
  55. bool _renderNormals;
  56. };