TileRenderer.cpp 884 B

123456789101112131415161718192021222324252627282930313233
  1. #include "TileRenderer.h"
  2. #include "Graphics.h"
  3. #include "Rect.h"
  4. #define GRAPHICS WalrusRPG::Graphics
  5. #define TILERENDERER WalrusRPG::TileRenderer
  6. #define RECT WalrusRPG::Utils::Rect
  7. TILERENDERER::TileRenderer(unsigned short *_tilesheet, unsigned tile_width, 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) const
  12. {
  13. unsigned num_tiles_x = tilesheet[0] / tile_width;
  14. //unsigned num_tiles_y = sheet_height / tile_height;
  15. GRAPHICS::draw_sprite_sheet(tilesheet, rect.x, rect.y, RECT(tile_width * (id % num_tiles_x), tile_height * (id / num_tiles_x), tile_width, tile_height));
  16. }
  17. int TILERENDERER::get_tile_width() const
  18. {
  19. return tile_width;
  20. }
  21. int TILERENDERER::get_tile_height() const
  22. {
  23. return tile_height;
  24. }
  25. TILERENDERER::~TileRenderer()
  26. {
  27. }