Search code examples
c#.netxnamonogame

Monogame - Loading between levels


I'm currently building a 2D platformer using Monogame and I'm having a bit of an issue. The way I have designed my game is that I use an array to draw out the map of tiles, which all have collision, like this:

protected override void LoadContent()
{
    map.Generate(new int[,] {

    // 0 = no tile drawn
    // 3 = tile is drawn

    {0,0,0,0,0,0,0,0,0,0,},
    {0,0,0,0,0,0,0,0,0,0,},
    {0,0,0,0,0,0,0,0,0,0,},
    {0,0,0,0,0,0,0,0,0,0,},
    {3,3,3,3,3,3,3,3,3,3,},
    {3,3,3,3,3,3,3,3,3,3,},

    }, 57); // size 
}

However I'm trying to think of a way that allows me to load another array that of course would have tiles placed differently once the player reaches a certain point, for example, using the array in my question, if the player spawns on the left and reaches the last tile on the right.

What would be the simplest way of trying to accomplish this?


Solution

  • Here's a good reference, supplied by Microsoft. This will allow you to examine and breakdown a working version of a 2D platformer.

    https://msdn.microsoft.com/en-us/library/dd254916%28v=xnagamestudio.31%29.aspx

    In brief, this is what I would expect to implement, regarding a 2D platformer and several levels (not scrolling).

    1. Define the total screens, block size, total blocks to draw on the screen.
    2. Create an array of screen block data.
    3. Set the game screen number to your start screen.
    4. Use that number to reference into the screen block data array and draw the blocks on screen.

    The above data could be generated as a binary file and loaded in at start-up, or for ease created as an array of screne block data within your game class.

    I'm sure the tutorial I've linked will guide you in the development of your game.