❔ Making 2D map for simple worms style game

I am making basic worms game and I need map for it, I thought to just make map class with name and List<List<int>> mapMass variable but I am not sure if that will make sense. 0 would mean tile is empty and 1 that it is filled
36 Replies
Pobiega
Pobiega17mo ago
Lists are great for when you dont know the total count ahead of time. For a map, I imagine you do know the size. So I would recommend either a jagged array, or a multi dim array
Richard Evanson
Richard Evanson17mo ago
but do you think idea itself makes sense?
Pobiega
Pobiega17mo ago
int[][] or int[,] respectively its a very common way to make 2d maps
Richard Evanson
Richard Evanson17mo ago
I know one of these is limited to squire type cuz both height and length had to be the same which one is that
Pobiega
Pobiega17mo ago
neither. jagged allows different lengths per row, so to speak
Richard Evanson
Richard Evanson17mo ago
oh just each element can have different length
Pobiega
Pobiega17mo ago
yeah
Richard Evanson
Richard Evanson17mo ago
which one do you reccomend then
Pobiega
Pobiega17mo ago
while a 2d array enforces that all "rows" have the same length I'm used to jagged, so thats what I often end up using.
Anton
Anton17mo ago
multidimensional arrays in C# generally have incomplete API and are kind of terrible
Richard Evanson
Richard Evanson17mo ago
now that I found about Point class in C# maybe I should use that
TheRanger
TheRanger17mo ago
that can be slow
Anton
Anton17mo ago
what for? for indexing?
Richard Evanson
Richard Evanson17mo ago
for player movement and location
TheRanger
TheRanger17mo ago
yeah thats fine
Richard Evanson
Richard Evanson17mo ago
because half of things are written with Point class but it is good maybe Point class will just be indexes for map tile array
Anton
Anton17mo ago
use it if it's a struct
Richard Evanson
Richard Evanson17mo ago
1 for map tile being filled, 0 for empty and 2+ for players but then I will need to somehow track which player it is
TheRanger
TheRanger17mo ago
what do u mean?
Richard Evanson
Richard Evanson17mo ago
if I have map made out of tiles and certain tiles will be marked as player tiles I will also need to know which player is on those tiles
TheRanger
TheRanger17mo ago
ah well in strategy games they use something like Tile[,] not int[,]
Richard Evanson
Richard Evanson17mo ago
it will be Worms type of game is Tile another c# standart class?
TheRanger
TheRanger17mo ago
you have to define one
Richard Evanson
Richard Evanson17mo ago
but maybe I can just use int and assign each player a continues number from 2+
TheRanger
TheRanger17mo ago
you can put some data in the Tile instance like what player is on it
Richard Evanson
Richard Evanson17mo ago
since 1 and 0 is for map terrain
TheRanger
TheRanger17mo ago
or if its filled, or empty
Richard Evanson
Richard Evanson17mo ago
but making class would be better yeah
TheRanger
TheRanger17mo ago
Tile[0,0].IsEmpty = false; or like Tile[0,0].EnterPlayer(worm); you can define properties,fields, and methods for class Tile
Richard Evanson
Richard Evanson17mo ago
yeah it will be easier this way
TheRanger
TheRanger17mo ago
a tile is like a pixel in worms games right?
Richard Evanson
Richard Evanson17mo ago
well for my game it is it is like 2D but not from top but from side
Richard Evanson
Richard Evanson17mo ago
Richard Evanson
Richard Evanson17mo ago
I have made something like this 3 of those symbols is 1 tile but I still wonder how can I make it better should I even call it tile? tile sounds like something when you make it 2D from top so I should keep multidimensional array of tiles?
TheRanger
TheRanger17mo ago
why not, it IS a tile, right?
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.