Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Reverend-Speed · Sep 23, 2018 at 09:00 PM · rotation2d game2d array

How can I accomplish Tetris rotations with 2D arrays?

Good god, who knew Tetris was so complicated? I'm a self-taught intermediate/advanced Unity developer (going by the classifications on Unity's tutorials) so I usually know my way around developing a lot of games, but this...!

Can anybody help me rotate a Tetramino as represented by a 2D array? Examples of the arrays follow:

            int[][] tetraminoT = 
             {
             new int[] {0,0,0,},
             new int[] {1,1,1,},
             new int[] {0,1,0,}
             };
 
         int[][] tetraminoJ =
         {
             new int[] {0,1,0,},
             new int[] {0,1,0,},
             new int[] {1,1,0,}
         };
 
         int[][] tetraminoI =
         {
             new int[] {0,1,0,0 },
             new int[] {0,1,0,0 },
             new int[] {0,1,0,0 },
             new int[] {0,1,0,0 }
         };

Using a gameObject as a pivot and calling Transform.Rotate or Rigidbody.MoveRotation are insufficient to answer this question. I'd rather solve this in game space and get some more practice with array nonsense.

Setting up the board, the tetraminos, moving them, checking for completed rows - none of this is a problem, and I expect to be able to implement SRS & wall kick stuff when I get over this roadblock.

A lot of people seem to think that this page holds the answer, but I'm having serious trouble parsing it.

Can anybody help a fellow traveller out? Thanks in advance. =) --Rev

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Sep 24, 2018 at 06:01 AM

just loop through your x and y as if you where making a duplicate. but instead switch the x and y when assigning to the new output:)

 public static int[][] Rotated(int[][] t){
         
         int[][] ret = new int[t[0].Length][];
         int x = ret.Length;
         while(x>0){x--;ret[x] = new int[t.Length];}
 
 
         x = t.Length;
         while (x>0) {x--;
             int y = t[x].Length;
             while(y>0){y--;
 
         //simply switch the x and y when assinging to the new array;
                 ret[y][x]=t[x][y];
             
             }}
     
         return ret;
         
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

136 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I create a 2d shooting mechanic (Left and Right)? 1 Answer

Error while spawning multiple objects 1 Answer

Can you have an Objects Sprite ignore the objects rotation 1 Answer

Top Down Shooter Player Controller 1 Answer

Sword rotation not working? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges