Advertisement
Guest User

Level.cpp

a guest
Nov 25th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "Level.h"
  2.  
  3. Level::Level(int w, int h) {
  4.     this->w = w;
  5.     this->h = h;
  6.     this->Resize(w, h);
  7. }
  8.  
  9. Level::~Level() {
  10.     // Delete the tiles in memory.
  11.     for(int r = 0; r < h; r++) {
  12.         for(int c = 0; c < w; c++) {
  13.             this->tiles[r][c].~Tile();
  14.         }
  15.     }
  16. }
  17.  
  18. void Level::Resize(int w, int h) {
  19.     // Set the number of rows according to the height of the map.
  20.     this->tiles.resize(h);
  21.     for(int i = 0; i < h; i++) {
  22.         // Set the number of columns according to the width of the map.
  23.         this->tiles.at(i).resize(w);
  24.     }
  25. }
  26.  
  27. int Level::GetWidth() {
  28.     return this->w;
  29. }
  30.  
  31. int Level::GetHeight() {
  32.     return this->h;
  33. }
  34.  
  35. void Level::AddTile(int x, int y, Tile* tile) {
  36.     this->tiles[y][x] = *tile;
  37. }
  38.  
  39. Tile* Level::GetTile(int x, int y) {
  40.     return &(this->tiles[y][x]);
  41. }
  42.  
  43. void Level::DrawTiles(sf::RenderWindow* window) {
  44.     for(int r = 0; r < h; r++) {
  45.         for(int c = 0; c < w; c++) {
  46.             this->tiles[r][c].Draw(window);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement