diff --git a/common/graphics/tile_sheet.hpp b/common/graphics/tile_sheet.hpp index c0ee836..ce60989 100644 --- a/common/graphics/tile_sheet.hpp +++ b/common/graphics/tile_sheet.hpp @@ -49,4 +49,3 @@ private: }; #endif - \ No newline at end of file diff --git a/common/map/region.cpp b/common/map/region.cpp index b4314cf..e1d614d 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -30,17 +30,32 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): x(argX), y(argY) { - tiles = static_cast(calloc(width * height * depth, sizeof(int))); + tiles = new int**[width]; + for (int i = 0; i < width; ++i) { + tiles[i] = new int*[height]; + for (int j = 0; j < height; ++j) { + tiles[i][j] = new int[depth]; + for (int k = 0; k < depth; ++k) { + tiles[i][j][k] = 0; + } + } + } } Region::~Region() { - free(tiles); + for (int i = 0; i < width; ++i) { + for (int j = 0; j < height; j++) { + delete tiles[i][j]; + } + delete tiles[i]; + } + delete tiles; } int Region::SetTile(int x, int y, int z, int v) { - return *(tiles + x*width + y*height + z*depth) = v; + return tiles[x][y][z] = v; } int Region::GetTile(int x, int y, int z) { - return *(tiles + x*width + y*height + z*depth); + return tiles[x][y][z]; } diff --git a/common/map/region.hpp b/common/map/region.hpp index 7193fed..4d083ad 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -44,7 +44,7 @@ private: const int x; const int y; - int* tiles = nullptr; + int*** tiles = nullptr; }; #endif diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index 4a4c9b4..4865b2a 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -35,7 +35,7 @@ using namespace std; EditorScene::EditorScene(ConfigUtility* const arg1): config(*arg1), - region(20, 20, 1, 0, 0) + region(20, 20, 3, 0, 0) { //create the debugging "window" debugInfo.CreateSurface(256, 256); @@ -51,8 +51,8 @@ EditorScene::EditorScene(ConfigUtility* const arg1): menuBar.SetImage(&buttonImage); menuBar.SetEntries({ - {"File", "-New", "-Open", "-Save", "-Save As...", "-Close", "Exit"}, - {"Edit", "-Set Tile", "-Load Sheet", "-Delete Sheet", "-Metadata", "-Run Script"}, + {"File", "New", "Open", "Save", "Save As...", "Close", "Exit"}, + {"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"}, {"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"} }); @@ -87,10 +87,14 @@ void EditorScene::Render(SDL_Surface* const screen) { //debug for (int i = 0; i < region.GetWidth(); i++) { for (int j = 0; j < region.GetHeight(); j++) { -// for (int k = 0; k < region.GetDepth(); k++) { - cout << region.GetTile(i,j,0) << endl; - tsheet.DrawTo(screen, i*tsheet.GetTileW(), j*tsheet.GetTileH(), region.GetTile(i,j,0)); -// } + for (int k = 0; k < region.GetDepth(); k++) { + tsheet.DrawTo( + screen, + i*tsheet.GetTileW()+region.GetX()-camera.x, + j*tsheet.GetTileH()+region.GetY()-camera.y, + region.GetTile(i,j,k) + ); + } } } @@ -168,7 +172,7 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) { break; case 5: { - //Quit + //EXIT SDL_Event e; e.type = SDL_QUIT; SDL_PushEvent(&e);