# Tile System with moving Platforms

I am using a tile based system where the level is stored in a char:

        char[,] Level2 = {{'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.','.','.','.','.','+','.'},
{'.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
{'.','.','.','.','.','.','.','-','-','-','.','.','#','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
{'.','.','.','-','-','-','.','.','.','.','.','.','#','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.'},
{'#','#','.','.','.','.','.','.','.','P','.','.','#','.','=','.'},
{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}};


I set a platform down and then have it move up and down or left and right. Useing a list that uses a class like so List<Block> Blocks;. This list holds the texture, position, and blockstate.

### How would I call upon the platform and then move it so that it will collide with the '+' or the wall ('#')?

        for (int x = 0; x < tileWidth; x++)
{
for (int y = 0; y < tileHeight; y++)
{
//Background
Blocks.Add(new Block(background, new Vector2(x * 50, y * 50), 0));

//Impassable Blocks
if (Levels[level][y, x] == '#')
{
Blocks.Add(new Block(blockSpriteA, new Vector2(x * 50, y * 50), 1));
}
//Blocks that are only passable if going up them
if (Levels[level][y, x] == '-')
{
Blocks.Add(new Block(blockSpriteB, new Vector2(x * 50, y * 50), 2));
}
//Platform Stoper
if (Levels[level][y, x] == '+')
{
Blocks.Add(new Block(movingArea, new Vector2(x * 50, y * 50), 3));
}
//Vertical Moving Platform
if (Levels[level][y, x] == '=')
{
Blocks.Add(new Block(platform, new Vector2((x * 50), (y * 50)), 4));
}
//Player Spawn
if (Levels[level][y, x] == 'P' && player.Position == Vector2.Zero)
{
player.Position = new Vector2(x * 50, (y + 1) * 50 - player.Texture.Height);
player.Velocity = new Vector2(0, 0);
player.initialVelocity = 0;
player.Time = 0;
player.isJumping = false;
}
else if (Levels[level][y, x] == 'P' && player.Position != Vector2.Zero)
{
throw new Exception("Only one 'P' is needed for each level");
}
}
}

• Wouldn't it be easier to handle this platform as an object instead of a tile of the map? Mar 26 '14 at 13:10
• The reasons for using this tile map is so that people creating the game will have an easier time. I want to make it easy for them to create anything they want as long as there is a tile for it. This in theory should be easy, if platform is going up and collides with wall or bounds then go down, then repeat. Mar 26 '14 at 13:12
• If you think designing a level this way is going to be easy, you should actually try making a bunch of levels this way. Sure, its better than making your level designers write XML or something, compared to a proper level editor its still going to be painful. What happens when you want to move a block of tiles? Even with a text editor with block editing support, everthing to the right of the moved block would be messed up. What happens when you run out of semantically meaningful characters? What happens when you run out of easily typed characters? These problems are just the beginning. Mar 26 '14 at 14:03
• @bcrist This is not supposed to be a big game, we are on a tight schedule I need to do this quick and we only need to have about around 15 tiles max. I would love to do something else but right now this is what is necessary. Mar 26 '14 at 14:06
• Well then do as @Christian said and treat the platform as an object. Make = correspond to the same tile as the background, but spawn a new movable object for the platform. Then each tick, after moving the platform according to its velocity, check the tile directly underneath it. If it's not a background tile, move the object back to where it was before its last movement, and invert it's velocity vector. Mar 26 '14 at 14:14

If your maps are small, which the one above seems so, using a list of blockCollidable = true items. Then when the character is moving have an

foreach(Block currentBlock in Collidables)
{
if (player.X + tileWidth > currentBlock.X && player.X < currentBlock.X + tileWidth)
{
if (player.Y...)
{
//Collision Code
}
}
}


Using that for your map editor you can easily add a check box on any block and make "invisible" blocks that are just collidable = 1 background blocks, or whatever you want to add.