my map is showing up 90 degrees turned!

This is a discussion on my map is showing up 90 degrees turned! within the C++ Programming forums, part of the General Programming Boards category; I know there is probably something simple causing this not to work right, but for some reason my map engine ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    my map is showing up 90 degrees turned!

    I know there is probably something simple causing this not to work right, but for some reason my map engine draws all the maps 90 degrees counterclockwise! I don't feel like turning my head evertime I change the map around! I adjusted for temporary purposes, the height and width of the map, so it's not that, I rotated the array 90 degrees on purpose. Here is some source. (I am using Allegro)
    Code:
      short int cell[26][26]=
      {
       {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       };
    Code:
    void draw_map()
    // Map drawing
    {
     int right=0;      // Position in the X axis in the map file
     int down=0;       // Position in the Y axis in the map file
     int drawpointx=0; // Position in the X axis on the screen
     int drawpointy=0; // Position in the Y axis on the screen
     while (right!=25 && down!=18)
       // print cells to the back buffer until you reach the end of the file
       {
       blit(CURRENT_TILE,buffer,0,0,drawpointx,drawpointy,Tiles[0]->w,Tiles[0]->h);
       drawpointx+=TILE_SIZE; // Move drawing point forward
       right++; // Go to the next tile
       if (right==25) // If you get to the end of a row, go down a column
       {
       right=0; // Reset the X position
       drawpointy+=TILE_SIZE; // Move drawing point down a tile
       drawpointx=0; // Reset the X screen position
       down++; // Go down one column
       }
       }
    }

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    Maybe you swaped down and right? Anyway, having a while loop with a if statement wouldn't be considered fast. You should only have if-statements in a time critical loop if you encapsulate it with #if _DEBUG, and use it for debug reason: "If this var is that there is an error we should fix before a release"-kind of thing.

    Do like this instead:

    Code:
    drawpointy = 0;
    down = 0;
    while(down < iMapHeight)
    {
        drawpointx = 0;
        right = 0;
        while(right < iMapWidth)
        {
            drawpointx += TILE_SIZE; 
            blit(CURRENT_TILE, buffer, 0, 0, drawpointx, drawpointy, Tiles[0]->w, Tiles[0]->h);
            ++right;
        }
        drawpointy+=TILE_SIZE;
        ++down;
    }
    Could be a for-loop also.

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I got a new function to do it, but it still is 90 degrees turned counterclockwise!

    Code:
    #define CURRENT_TILE Tiles[cell[right][down]]
    void draw_map()
    // Map drawing
    {
     short int down=0;
     short int right=0;
     while (right < 25)
        {
         while (down < 18)
           {
         blit(CURRENT_TILE,buffer,0,0,right*32,down*32,CURRENT_TILE->w,CURRENT_TILE->h);
         down++;
           }
         down=0;
         right++;
        }
    }

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    and yes, I have tried switching them around.

    BTW, this is the real array I will use once I get the darn thing to work right.

    Code:
      short int cell[26][26]=
      {
       {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1},
       };

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You have mixed up your RIGHT and DOWN loopers. See the sample code below.
    The numbers I add to the Number-array are meant to be like this:

    1 2 3
    4 5 6
    7 8 9

    But when I loop through the X, the output will be 1 4 7, not 1 2 3 as you would think.
    Code:
    int main()
    {
       int Number[3][3]={{1,2,3},{4,5,6},{7,8,9}};
       for(int x=0; x<3; x++)
       {
          printf("%d",Number[x][0]);
       }
       getch();
       return 0;
    }
    To correct your program, try this instead:

    #define CURRENT_TILE Tiles[cell[down][right]]


    PS:
    Your cell-array is 26*26, but when you render the map you loop 25*18 .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    because when I try to use 25 by 18, it says I am putting two many numbers in the array.

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    the output from your program is 147

    is that right, or is it supposed to be 123?

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by frenchfry164
    the output from your program is 147

    is that right, or is it supposed to be 123?
    That piece of code was meant to be a smaller simulation of your code. The output is correct: 147. You see that when you increase your X you actually increase your Y. Swap the both.
    Code:
      1 2 3 <--- 1 2 3
      4 5 6
      7 8 9 
    
      ^
      |
    1 4 7
    Did you try to change this:

    #define CURRENT_TILE Tiles[cell[right][down]]

    into this:

    #define CURRENT_TILE Tiles[cell[down][right]]
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Oh, im sorry, I didn't tell you before that your idea fixed my problem. Yes I had those swapped. I swapped everything else BUT that, when I changed it around and it worked, I slapped myself for making such a stupid mistake.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 09:32 AM
  2. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 02:15 PM
  3. Creating a map engine.
    By suzakugaiden in forum Game Programming
    Replies: 11
    Last Post: 06-21-2005, 06:06 AM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  5. Is this right
    By Granger9 in forum C Programming
    Replies: 6
    Last Post: 08-14-2002, 03:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21