Since we store a reference to which tile should be drawn in the centre of the screen the first thing we do in WorldToScreen() is adjust the world co-ordinate given so it is relative to the centre of the screen (subtract centre). Then we need to scale the distance in the world space to match screen space. Since world space uses units of whole tiles and screen space is in pixels we multiply by the size in pixels of the tiles (32 in this example) and also the scale of the map (currently fixed to 1). This gives us a screen co-ordinate relative to the centre of the screen. To finish off, we find the absolute screen position relative to the top-left of the screen by adding the co-ordinates of the centre of the screen in pixels.
We render all the visible tiles of the map in the Draw() method. This uses the DrawOnMap() method for each tile that appears on screen. To calculate which tiles appear on screen we use the ScreenToworld() method to find the world co-ordinates at the top-left and bottom- right of the screen. Once we have this information we can simply loop through all the tiles inbetween and call DrawOnMap() to render them.
The Move() method within GameObject is called to move the object once the derived class has set up the 'vector' variable appropriately. In this method we calculate what area of the map the object needs to move through for both the horizontal and vertical movement. Fig 2 shows the player about to move horizontally with the blue area indicating the area we will try and move the player though. We can calculate the bounds of the blue rectangle using simple maths as everything either lines up with the player position or is given by the amount we're trying to move. This area is passed to the map's Collide() method along with the direction we're trying to move.
In the Collide() method within the Map class we deal with whole tiles so we need to convert the bounding area passed in to whole tiles as shown in fig 2. We then check each of the tiles highlighted to see if it's solid. The order we check each of the tiles depends on the movement direction passed in. For moving to the right we need to check the tiles on the left before the tiles on the right, if we were moving upwards through this area then we'd need to check the two tiles at the bottom before the two at the top. The reason for this is that as soon as we encounter a solid tile we calculate the position an object would get stopped at, in this case it would be the left edge of the brick as we're trying to move right.
The x-coordinate of the left edge of the brick gets returned to the GameObject so that we can then adjust the position of the object so it is flush against the surface of the brick as shown in fig 3. We'd then do the same for the y direction. If we were falling then we'd only need to check the tile directly below us since we now fit exactly in one tile horizontally.