TileRenderer.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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(unsigned short *_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[0] / 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,
  18. tile_height));
  19. }
  20. int TILERENDERER::get_tile_width() const
  21. {
  22. return tile_width;
  23. }
  24. int TILERENDERER::get_tile_height() const
  25. {
  26. return tile_height;
  27. }
  28. TILERENDERER::~TileRenderer()
  29. {
  30. // Nothing else than the current object is dynamically allocated, nothing should be
  31. // done here atm.
  32. }