TileRenderer.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "TileRenderer.h"
  2. #include "Graphics.h"
  3. #define TILERENDERER WalrusRPG::TileRenderer
  4. using namespace WalrusRPG;
  5. using namespace WalrusRPG::Utils;
  6. TILERENDERER::TileRenderer(WalrusRPG::Graphics::Texture &_tilesheet, unsigned tile_width,
  7. unsigned tile_height)
  8. : tilesheet(_tilesheet), tile_width(tile_width), tile_height(tile_height)
  9. {
  10. }
  11. void TILERENDERER::render(const unsigned id, const Rect &rect)
  12. {
  13. unsigned num_tiles_x = tilesheet.get_dimensions().width / tile_width;
  14. // unsigned num_tiles_y = sheet_height / tile_height;
  15. Graphics::put_sprite(tilesheet, rect.x, rect.y,
  16. Rect(tile_width * (id % num_tiles_x),
  17. tile_height * (id / num_tiles_x), tile_width, tile_height));
  18. }
  19. int TILERENDERER::get_tile_width() const
  20. {
  21. return tile_width;
  22. }
  23. int TILERENDERER::get_tile_height() const
  24. {
  25. return tile_height;
  26. }
  27. TILERENDERER::~TileRenderer()
  28. {
  29. // Nothing else than the current object is dynamically allocated, nothing should be
  30. // done here atm.
  31. }