❔ 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
Pobiega2y 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
Jack Badassson
Jack BadasssonOP2y ago
but do you think idea itself makes sense?
Pobiega
Pobiega2y ago
int[][] or int[,] respectively its a very common way to make 2d maps
Jack Badassson
Jack BadasssonOP2y 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
Pobiega2y ago
neither. jagged allows different lengths per row, so to speak
Jack Badassson
Jack BadasssonOP2y ago
oh just each element can have different length
Pobiega
Pobiega2y ago
yeah
Jack Badassson
Jack BadasssonOP2y ago
which one do you reccomend then
Pobiega
Pobiega2y 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
Anton2y ago
multidimensional arrays in C# generally have incomplete API and are kind of terrible
Jack Badassson
Jack BadasssonOP2y ago
now that I found about Point class in C# maybe I should use that
TheRanger
TheRanger2y ago
that can be slow
Anton
Anton2y ago
what for? for indexing?
Jack Badassson
Jack BadasssonOP2y ago
for player movement and location
TheRanger
TheRanger2y ago
yeah thats fine
Jack Badassson
Jack BadasssonOP2y 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
Anton2y ago
use it if it's a struct
Jack Badassson
Jack BadasssonOP2y 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
TheRanger2y ago
what do u mean?
Jack Badassson
Jack BadasssonOP2y 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
TheRanger2y ago
ah well in strategy games they use something like Tile[,] not int[,]
Jack Badassson
Jack BadasssonOP2y ago
it will be Worms type of game is Tile another c# standart class?
TheRanger
TheRanger2y ago
you have to define one
Jack Badassson
Jack BadasssonOP2y ago
but maybe I can just use int and assign each player a continues number from 2+
TheRanger
TheRanger2y ago
you can put some data in the Tile instance like what player is on it
Jack Badassson
Jack BadasssonOP2y ago
since 1 and 0 is for map terrain
TheRanger
TheRanger2y ago
or if its filled, or empty
Jack Badassson
Jack BadasssonOP2y ago
but making class would be better yeah
TheRanger
TheRanger2y ago
Tile[0,0].IsEmpty = false; or like Tile[0,0].EnterPlayer(worm); you can define properties,fields, and methods for class Tile
Jack Badassson
Jack BadasssonOP2y ago
yeah it will be easier this way
TheRanger
TheRanger2y ago
a tile is like a pixel in worms games right?
Jack Badassson
Jack BadasssonOP2y ago
well for my game it is it is like 2D but not from top but from side
Jack Badassson
Jack BadasssonOP2y ago
Jack Badassson
Jack BadasssonOP2y 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
TheRanger2y ago
why not, it IS a tile, right?
Accord
Accord2y 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.
Want results from more Discord servers?
Add your server