• Advertisement

AtomicWinter

Member
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

2 Neutral

About AtomicWinter

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. Method 2, but you want to avoid looping through all of the tiles every frame. Here is an example of how to do that: https://gamedev.stackexchange.com/questions/32140/effecient-tilemap-rendering Also, you may want to look up quadtrees to help with spatial queries as well.
  2. C++ Initializer list woes

    Arbiter32u test1(stuff, {1U,2U,3U}); What is {1U,2U,3U}? Is that just an array of unsigned ints, a std::initializer_list, or? The compiler most likely doesn't know you are wanting to pass a std::initializer_list since your passing it to args. When you use auto the compiler is able to deduce it to a std::initializer_list before passing it to the args. This would work fine since you are actually passing the list to the args, which represents one object/arg: Arbiter32u test1(0, std::initializer_list<int32u>({ 1U,2U,3U })); As a matter of fact, you should be able to do this as well since you are allowing multiple args to be passed: Arbiter32u test1(0, std::initializer_list<int32u>({ 1U,2U,3U }), 0, 1, 2, 3.0, 4); //OR Arbiter32u test1(0, std::initializer_list<unsigned int>({ 1U,2U,3U }), 0, std::initializer_list<unsigned int>({ 1U,2U,3U }), 2, 3.0, 4); If you add this, just as an example. then it would work fine for just your std::initializer_list so you can use Arbiter32u test1(stuff, {1U,2U,3U}): template<typename ...Args> Arbiter(int stuff, std::initializer_list<int32u> args) : subject(args) { } Perhaps someone with more knowledge on this would have better information for you.
  3. The best thing you can do is to learn how to debug your code. If you step through the logic of your program you will be able to see what is actually happening and what values are being assigned where. I believe that is going to be the best thing here. It's hard for me to understand some of the logic without seeing more. For instance, in your CheckBorders method I am not sure what those magic numbers are or represent. If I remember from your previous questions those are the edges of the grid (and hence the name), but others looking at the code would not know this. You need to make constants to represent what those actually mean (GRID_MIN_X, GRID_MAX_X, GRID_MIN_Y, GRID_MAX_Y, etc.). Anyway, start a debug and step through your code. You will instantly be able to spot the issue.
  4. C# creating and manipulating a grid

    Sorry. Didn't see the C#, Unity tag. This can easily be converted should you desire. Best of luck. OK; this was a quick few minute mock-up and just an idea... I did not test this, add validation, const correctness, etc. Strictly just a mock-up. With that being said, I don't see the problem with a 1D array. It can easily be done for the entire grid as well as only the visible portion of the grid. Here are a few simple structures that could define the game tile as well as the grid cell. The idea with the grid cell is to have an occupied flag. When you go to place a tile, query a cell, etc. then you can easily see if there is a tile placed there already. Another nice thing is if you want to remove a tile. When you remove a tile you can simply set the occupied flag to false to allow a new tile to be placed there. struct GameTile { //--Tile POD implementation }; struct GridCell { bool Occupied; GameTile Tile; }; Here is an example class showing the basic concept of working with the grid. Of course you can set your access modifiers however you want: class Grid { private: const static int GRID_ROWS = 30; const static int GRID_COLUMNS = 20; const static int SCREEN_GRID_ROWS = 15; //--The number of visible rows on the screen. This should, of course, be //--less than the number of GRID_ROWS GridCell cells[GRID_COLUMNS * GRID_ROWS] = { 0 }; public: GameTile GetCellTile(int x, int y) { return cells[GetCellIndex(x, y)].Tile; } void SetCellTile(int x, int y, GameTile tile) { cells[GetCellIndex(x, y)].Tile = tile; SetOccupied(x, y, true); } void RemoveCellTile(int x, int y) { //--No need to actually remove anything... just set the cell as unoccupied. SetOccupied(x, y, false); } bool CellIsOccupied(int x, int y) { return cells[GetCellIndex(x, y)].Occupied; } void SetOccupied(int x, int y, bool occupied) { cells[GetCellIndex(x, y)].Occupied = occupied; } public: void AutoPlaceTile(int x, int y, GameTile tile) { if (!CellIsOccupied(x, y)) { SetCellTile(x, y, tile); return; } //--Add logic to check neighbor tiles and place new tiles } private: //--This will give you the index for the entire array int GetCellIndex(int x, int y) { if (x < 0 || x > GRID_COLUMNS) { //--Handle this } if (y < 0 || y > GRID_ROWS) { //--Handle this } return y * GRID_COLUMNS + x; } //--This will only give you the index to tiles visible on the screen. //--I'm guessing that the non-visible cells are all above the visible cells. int GetScreenCellIndex(int x, int y) { auto screenY = SCREEN_GRID_ROWS + y; //This needs tested... if (x < 0 || x > GRID_COLUMNS) { //--Handle this } if (screenY < 0 || screenY > GRID_ROWS) { //--Handle this } return screenY * GRID_COLUMNS + x; } }; I hope this will help give you an idea or two so you can finish your implementation. I don't know exactly how you want your blocks to flow, but with this it should be relatively easy to perform the auto tile placement logic.
  • Advertisement