XNA 2D Array help

Pillow Pants

New member
Joined
Jan 26, 2013
Messages
1
Programming Experience
Beginner
I'm trying to figure out how to add each "block" to a 2D array which I can then access and change the corresponding bool value to true or false as needed. Basically what this is meant to do is create an initial grid of white squares using one sprite and then as I click on each tile/square it changes from white to black. The following code is from one class which uses another class called "Seed".

Can anyone help me here please, I've been struggling with this for quite some time. I'm using XNA.



C#:
public override void Update(GameTime gameTime)
{
           for (int j = 0; j < 50; j++)
            {
                for (int i = 0; i < 50; i++)
                {
                 if ((mousePosX >= SpaceX) && (mousePosX < SpaceX + 10) && (mousePosY > SpaceY) && (mousePosY < SpaceY + 10))
                    {
                        if (mouseState.LeftButton == ButtonState.Pressed)
                        {

                             change bool value stored at array[i,j] to true;
                        }
                    }
                 }
              } 
}
            public override void Draw(GameTime gameTime)
        {
            MouseState mouseState, Pos;


            mouseState = Mouse.GetState();
            Pos = Mouse.GetState();
            int mousePosX, mousePosY;
            mousePosX = Pos.X;
            mousePosY = Pos.Y;
            int SpaceX = 0;
            int SpaceY = 0;
            for (int j = 0; j < 50; j++)
            {
                for (int i = 0; i < 50; i++)
                {


                    
                            isAlive = false;
                            Seed block = new Seed(true);
                            block.LoadContent();
                            block.position = position;
                            position = new Rectangle(SpaceX, SpaceY, 10, 10);
                            Game1.Instance.children.Add(block);


                    SpaceX += 11;
                }
                SpaceX = 0;
                SpaceY += 11;


            }
            SpaceY = 0;






        }
 

Latest posts

Back
Top Bottom