2 Replies - 791 Views - Last Post: 26 March 2018 - 05:45 AM

#1 Shaddoll Beast   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 17

Rotation of a 2D Array?

Posted 19 March 2018 - 03:00 PM

Hi guys,

I would like to have that nice feauture in my game to rotate the whole current level.
The level itself is represented by an [,] array of objects.

Is there any solution to turn an 2D array about 90/180/270 degree during runtime? Maybe by using a Matrix?
All attributes of the turned objects should also follow them to their new location.

I give you some parts of my code below if it helps my explanation (maybe it's not important at all).

    class Element            // Boulders, Gems, Bombs, Items, etc.
    {
        public ushort ID;
        public AnimatedSprite Sprite, CurrentSprite;
        public Texture2D Texture;

        public int PosX;
        public int PosY;
        public int SpritePosX;     // PosX * 48
        public int SpritePosY;     // PosY * 48

        public bool Falling;
        public byte RollDirection = 0;    // 0 = idle, 1 = left, 2 = right
        public bool Reserved;
        public bool InExplosion;
    }

    static class Field        // the level itself where elements and player are moving
    {
        public static Element[,] Square = new Element[50, 30];

        public static void TurnLevel_90Degree()
        {
            /* unknown code
               how to turn
               the Square-array */
        }
    }




I read and tried to find out a bit about matrices, but I really don't get the logic of that whole matrix thing on my own :huh2:/>

Any help there outside?

Thanks! :smile2:/>

Is This A Good Question/Topic? 0
  • +

Replies To: Rotation of a 2D Array?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,148
  • Joined: 12-June 08

Re: Rotation of a 2D Array?

Posted 20 March 2018 - 05:44 AM

Perhaps just keep track of the rotation degree and handle that in the 'draw' portion.
Was This Post Helpful? 0
  • +
  • -

#3 Shaddoll Beast   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 17

Re: Rotation of a 2D Array?

Posted 26 March 2018 - 05:45 AM

Only to draw the stuff in the turned angle isn't enough. The game physics would also be rotated that way (things falling sideways then).

Doing more research, I luckily found a capable solution now.
Thanks anyways!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1