Thread: A multidimentional array to a class.

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    A multidimentional array to a class.

    This is a tiledata, each number represents a sprite:
    Code:
    int my_house_area[10][10] =
        {
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            },
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            },
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            }
            ,
            {
                1,2,3,4,5,6,7,8,9,10
            }
        };
    The initilization code:
    Code:
    void LoadStage::SetStage( int area[10][10]){
        this->area[10][10]=area[10][10];
        for(int y = 0; y<10; y++) {
            for(int x = 0; x<10; x++) {
                draw_sprite(buffer,sprites[area[x][y]],x*32,y*32);
            }
        }
    }
    The code does work if I make "sprites[1]" (1-10), and the "sprites" considers more than 10 bitmaps.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Are you sure this works:
    Code:
    this->area[10][10]=area[10][10];
    Isn't it saying to take the [10][10] element from the array called area (which is out of bounds) and assign it to the corresponding element in this->area.

    You might need to copy data in a loop.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    Ok, it works, thanks ;-)

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Do yourself a a favor and wrap the array into a class that can both save to disk and load from disk. The draw function will draw tiles in place of the numbers - or simply will draw the graphic tile represented by the number in the array.


    Code:
    ...
    DWORD dwTileID=m_pMapMgr->GetMap(dwCurLayer,dwOffset);
    
    ...Draw the tile - dwTileID
    This means you need a class to handle a collection of tiles, a class to wrap access to a simple 2D array, and a class that encapsulates a tile object.

    Think objects, objects, objects. It will help.
    Last edited by VirtualAce; 07-12-2006 at 04:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  3. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  4. Replies: 4
    Last Post: 09-12-2001, 02:05 PM