Home > Software design >  How to make a 2d grid with c#
How to make a 2d grid with c#

Time:07-15

I want to start making 2d simulations like conway's game of life, pathfinding and sand simulations and so.. I understand the concept and that I have to make a grid... The thing is that i can't find how to make a grid.. I have tried searching and I don't seem to find a proper tutorial or something helpful... I am using monogame framework and have some knowledge with c#. I just want to understand how to make one so i can use it to make simulations if someone can break it down for me or give me an existing tutorial I'll be thankful.

CodePudding user response:

For this type of "game" I would rather use .NET MAUI and its Grid. The grid in Monogame can be draw either as a whole image of grid or as an array of lines, for which a 1x1px (but better is the middle pixel of 3x3px) source white image is sufficient (the color can be changed during rendering). This can then be stretched to any width or height to render the entire grid to the screen. You then need to have a 2D array (bool[,]) with a state map in the background for faster processing and redraw the result on the screen. I have a YouTube tutorial and GitHub source code for a tower defense game in Monogame, where I also use grid layout, but it's only in Czech language.

CodePudding user response:

you are looking for a multidimensional array ?

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays

  • Related