TileRenderer.cpp 1.1 KB

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