Sign in to follow this  

Creating new blocks

Recommended Posts

Rather than creating a new question I decided to just edit this one:


I have an int rotate that holds the rotation for each block. 0 is normal, 1 is clockwise, 2 upside down... I'm able to change the variable by pressing Up on the keyboard, but the block won't change its rotation

private Vector2[] RotateBlock()
            if (Rotate == 1)
                if (Position == LeftLPosition)
                    LeftLPosition[0] = new Vector2(LeftLPosition[0].X + 20, LeftLPosition[0].Y + 20);
                    LeftLPosition[1] = new Vector2(LeftLPosition[1].X + 0, LeftLPosition[1].Y + 0);
                    LeftLPosition[2] = new Vector2(LeftLPosition[2].X - 20, LeftLPosition[2].Y - 20);
                    LeftLPosition[3] = new Vector2(LeftLPosition[3].X - 0, LeftLPosition[3].Y - 40);

                    return LeftLPosition;

This is just the first part of the method but it shows the main picture. 

            if (CheckKey(Keys.Up))
                block.Rotate += 1;

This is in the block update method.


I've tried adding a block parameter to the method and using block.LeftLPosition = new Vector2() but that didn't work. I've also moved the line to call the method to different places in the update method and that didn't work either

Edited by burnt_casadilla

Share this post

Link to post
Share on other sites
DiegoSLTS    2113

Maybe you should share more code, there's too little info to give a proper answer.


I'm just guessing now, but I think you're problem is that you're blocks are new, but the "sub-blocks" (the Vector2[] that you pass as the first parameter) are being reused.


If you're just storing them as an attribute and then changing them to make the block fall try making a copy instead of just assigning, so when the next piece receives the same Vector2[] it won't affect the Vector2[] of the previous block.


To get a better answer you should probably explain what do you do with those Vector2[] after you created the Block.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this