XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Level array problems

Last post 9/18/2008 6:25 PM by Gate2501. 3 replies.
  • 9/18/2008 4:53 AM

    Level array problems

    Hi, this is my first post. What I'm attempting is a tile-based game, where a level is stored in a variable array. It looks something like this:

     

    int[,] map1 =

    {

    {1,1,0,0,},

    {0,0,0,0,},

    {0,0,0,0,}

    }

     

    In map1, each number corresponds to a different tile / object. The MapBuilder static class would build the map (create the objects to populate the level) and it would also draw the map objects.

    Now I'm trying to figure out how to make it so that...

     

    currentLevel = 1;

    MapBuilder.DrawMap("MapBuilder.map" + currentLevel.ToString() );

     

    Basically, I want it to be where currentLevel stores the currently-played level, and you can draw the map depending on the currentLevel variable. This way, I could do the line above where the MapBuilder static class just draws the map of the currently-played level. Is there a function that converts "MapBuilder.map" + currentLevel.ToString() to reference the map variable in the MapBuilder class (where map1 is stored).

  • 9/18/2008 6:26 AM In reply to

    Re: Level array problems

    I think the easiest way to accomplish what you want is to make an array of levels. Storing all the maps in an array.

    That way you could access it like this:          MapBuilder.DrawMap(MapBuilder.map[currentLevel]);

    I hope that helps. If I misunderstood your question then by all means shout angrily at me and I'll try and right my wrongs.
    Sigurd



    My Blog - Updates on my game project Era Astral and mixed articles about C# and XNA
  • 9/18/2008 11:35 AM In reply to

    Re: Level array problems

    That works fine for small maps, but if the map is HUGE you're wasting a lot of memory by keeping all maps in memory. In that case you just keep the desired map in memory (in the map[ array) and swap them in and out from disc when needed.
  • 9/18/2008 6:25 PM In reply to

    Re: Level array problems

    I just finished designing my tile arrays yesterday for my game.

    The best way that I have found to do it, is to store all levels in a METHOD of your mapbuilder class.  My mapbuilder class is called Cake, and I can Cake.bake(parameters); on initialization to build the current level.

    I set up different bake(); parameters to represent the different levels, so it will only build your current level.

Page 1 of 1 (4 items) Previous Next