A multidimentional array to a class.

This is a discussion on A multidimentional array to a class. within the C++ Programming forums, part of the General Programming Boards category; 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. #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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    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, 10:03 PM
  2. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 05:48 AM
  3. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. Replies: 4
    Last Post: 09-12-2001, 02:05 PM

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