Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Level.h"
- Level::Level(int w, int h) {
- this->w = w;
- this->h = h;
- this->Resize(w, h);
- }
- Level::~Level() {
- // Delete the tiles in memory.
- for(int r = 0; r < h; r++) {
- for(int c = 0; c < w; c++) {
- this->tiles[r][c].~Tile();
- }
- }
- }
- void Level::Resize(int w, int h) {
- // Set the number of rows according to the height of the map.
- this->tiles.resize(h);
- for(int i = 0; i < h; i++) {
- // Set the number of columns according to the width of the map.
- this->tiles.at(i).resize(w);
- }
- }
- int Level::GetWidth() {
- return this->w;
- }
- int Level::GetHeight() {
- return this->h;
- }
- void Level::AddTile(int x, int y, Tile* tile) {
- this->tiles[y][x] = *tile;
- }
- Tile* Level::GetTile(int x, int y) {
- return &(this->tiles[y][x]);
- }
- void Level::DrawTiles(sf::RenderWindow* window) {
- for(int r = 0; r < h; r++) {
- for(int c = 0; c < w; c++) {
- this->tiles[r][c].Draw(window);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement