• Advertisement
Sign in to follow this  

Trying to make 2D tile based game in Dart...2D array index confusion nightmare please help :(

This topic is 1145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok so as the title says I am making a 2D tile-based game in Dart (using port of Phaser.js as the engine). Unfortunately at some point in developing the code up to what I have now I seem to have screwed up and "confused x and y" and such, realising despairingly how if a 2D array is supposed to represent an x-y grid then by default grid[1][0] is the x-y point (0,1), etc I was trying to debug it more yesterday with a helpful friend of mine and I believe we did make some progress but the problem is not totally fixed. Even though it's not a really really huge codebase as it stands (it's only like 4 or 5 files it's running through as far as my problem is concerned) I'm at my wits end here from trying, often a bit blindly, to fix the issues by swapping x and y values and the like in some function calls but to no avail.

 

To better explain I should mention I am using an A* implementation to do pathfinding about the grid, and I guess some of the x-y confusion may have arisen from the fact that as I said the grid[1][0] notation for a 2D array would translate to a grid[y][x] format if you were to think of it as x and y rather than row-col but at the same time everything in the A* code seems have initially been accessing array cells as grid[x][y]

 

I know perhaps it's a bit of a stretch but I would like if someone could help me solve this problem of coordinate confusion so that I can progress with real development. I don't really expect someone to volunteer to trawl through all my code alone and (hopefully) fix the problem since that might be pretty tough but rather if someone is willing I would like to look through the code with them, perhaps using a more live chat system to cooperate so that they could look for issues and I could be there to make sure they understand what's going on in the code. Naturally having Dart experience would help but this is really more of a logical error. At the same time though I can imagine trying to look through an unfamiliar language and editor (Dart Editor) might be daunting for some, and indeed I think if someone is going to help me it would be helpful for them if they could have the DartEditor to run my code locally; that sounds better than trying to spend a lot of time explaining in chat like "Oh when I click tile (1,0) it moves to that one instead, or when I click that tile I get an error pointing to line 100, called from foo, called from bar...." But I suppose I'm open to trying whatever a would-be volunteer sees as potentially useful.

 

If someone is going to take up my request, please reply as soon as you can. Even if right now is not a good time we can try to arrange something. If people want to look at (or clone) my code it is here: https://github.com/TheIceMageX50/TextFuelledCombat

 

Quick Edit: I suppose I should point out where best to look if you're just taking a first look at some of the code: All source code files are in web directory. game_map is my map class. textfueledcombat.dart is my "main" where I have my main function to start it all off. astar_pathfinder is as the name suggests. character.dart has moveTo function which uses astar to find the path and then actually moves the character sprite on the screen. Although right now "moveToFix" is what's being used because the original which I've meant to delete had some overcomplicated, unnecessary logic to it because I went about some things the wrong way..

Edited by MagusOfIce

Share this post


Link to post
Share on other sites
Advertisement

Update: Thankfully I eventually managed to solve my problem yesterday. I suppose leaving it for a while and coming back with a somewhat clear head helped.

Share this post


Link to post
Share on other sites

If you are having troubles with ordering of indices, you can make yourself a function that accepts indices in whatever order you want.

 

item = array.atXY(x, y)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement