My main problem is I don't understand how to get the position of the generated tiles or how to tell where the mouse is. Should I use collision to detect mouse or something else? Is there something I can do to optimize my code and make it easier to get things like the position
I took some things out of my code like loading of the textures just to make it shorter for you guys since that isn't part of the problem.
My Tile Generation Code
public Block[] tiles = new Block[3];
public int width, height;
public int[,] index;
public Rectangle tileRect;
public void Load(ContentManager content)
{
tiles[0] = new Block { Type = BlockType.Grass, Position = Vector2.Zero, texture = grass};
tiles[1] = new Block { Type = BlockType.Dirt, Position = Vector2.Zero, texture = dirt};
width = 50;
height = 50;
index = new int[width, height];
Random rand = new Random();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
index[x,y] = rand.Next(0,2);
}
}
}
public void Draw(SpriteBatch spriteBatch)
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
spriteBatch.Draw(tiles[index[x,y]].texture, tileRect = new Rectangle(x * 64, y * 64, 64, 64),
Color.White);
}
}
}
Block Properties Code
public enum BlockType
{
Dirt,
Grass,
Selection
}
public class Block
{
public BlockType Type { get; set; }
public Vector2 Position { get; set; }
public Texture2D texture { get; set; }
}