Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:12:15+00:00 2026-06-17T22:12:15+00:00

How do I load Levels in my game, as in Layer 1 would be

  • 0

How do I load Levels in my game, as in Layer 1 would be Objects, Layer 2 would be Characters and so on. I only need 3 layers, and they will all be put on top of each other. i.e having a flower with a transparent background to be put on grass or dirt on the layer below.I would like to Read From the same file too. How would i go about doing this? Any help would be appreciated.

I load the map from a level file which are just numbers corresponding to a tile in the tilesheet.

And here is the code that interprets it

void LoadMap(const char *filename, std::vector< std::vector <int> > &map)
{
    std::ifstream openfile(filename); 
    if(openfile.is_open())
    {
        std::string line, value;
        int space;

        while(!openfile.eof())
        {
            std::getline(openfile, line);

            if(line.find("[TileSet]") != std::string::npos)
            {
                state = TileSet;
                continue;
            }
            else if (line.find("[Layer1]") != std::string::npos)
            {
                state = Map;
                continue;
            }

            switch(state)
            {
            case TileSet:
                if(line.length() > 0)
                    tileSet = al_load_bitmap(line.c_str());
                break;
            case Map: 

                std::stringstream str(line);
                std::vector<int> tempVector;

                while(!str.eof())
                {
                    std::getline(str, value, ' ');
                    if(value.length() > 0)
                                 tempVector.push_back(atoi(value.c_str()));
                }
                map.push_back(tempVector);
                break;
            }
        }
    }
    else
    {
  }
  }

and this is how it draws the map. Also the tile sheet is 1280 by 1280 and the tilesizeX and tilesizeY is 64

void DrawMap(std::vector <std::vector <int> > map)
{    
    int mapRowCount = map.size();

    for(int i, j = 0; i < mapRowCount; i ++)
    {
        int mapColCount = map[i].size();

        for (int j = 0; j < mapColCount; ++j)
        {
              int tilesetIndex = map[i][j];
              int tilesetRow = floor(tilesetIndex / TILESET_COLCOUNT);
              int tilesetCol = tilesetIndex % TILESET_COLCOUNT;    
              al_draw_bitmap_region(tileSet, tilesetCol * TileSizeX, tilesetRow * TileSizeY, TileSizeX, TileSizeY, j * TileSizeX, i * TileSizeX, NULL);
        }
    }
}

EDIT: https://i.stack.imgur.com/VDUqv.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:12:16+00:00Added an answer on June 17, 2026 at 10:12 pm

    Looks like you need more than one two-dimensional array.

    Try something like this:

    unsigned int map[3][8][8];
    #define OBJECTS_LAYER 0
    #define CHARACTER_LAYER 1
    #define FLOWER_ID 2
    
    //...
    
    map[OBJECTS_LAYER][3][4] = FLOWER_ID;
    

    Edit 1

    Per the OP’s description, a layer is a 2 dimensional array, 8 x 8, which would be represented as:

    unsigned int layer[8][8];
    

    Th OP’s map has multiple layers. This translates into a container of layers.
    One method is to use another dimension of the array. Much like a layered cake, or floors in a building.

    unsigned int map[/* maximum layers */][8 /* from layer above */][8 /* from layer above */];
    

    To access the position [3,4] of layer 1 the expression would be:

    map[0][3][4]
    

    Since indices are zero-based in C++, the first layer has index of zero.

    To access floor 3, row 2, column 7 of a building one would use the nomenclature:

    empire_state_building[2][1][6]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making my first game in iOS and I need to load some levels
init.el (setq make-backup-files nil) (add-to-list 'load-path ~/.emacs.d/) ; Add all top-level subdirectories of .emacs.d
I'm working on a game with cocos2D game engine and make load all the
I am making a game which has to load all bitmaps at start because
So I've created a game, runs perfectly in eclipse--all of the images load and
Here's my function to load my content: $(#site-nav .nav1).on('click', function () { $(this).addClass(nav-active); $('ul.top-level').load('assets/includes/recent.php',
I load a webpage from my assets in a webview. Now i need to
I have 10 Levels. Just like a normal game, you can't play the next
I'm working on a windows phone 7 game and I have saved the levels
I need to create a game for one of my projects. The game is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.