Game/Source/ModuleMap.cpp
UpdateStatus ModuleMap::PostUpdate()
{
	if (mapLoaded == false) return UpdateStatus::UPDATE_CONTINUE;

	// L04: DONE 5: Prepare the loop to draw all tilesets + DrawTexture()
	ListItem<MapLayer*>* mapLayerItem;
	mapLayerItem = mapData.layers.start;

	// L06: TODO 4: Make sure we draw all the layers and not just the first one
	while (mapLayerItem != NULL) {

		if (mapLayerItem->data->properties.GetProperty("Draw") == 1)
		{
			for (int x = 0; x < mapLayerItem->data->width; x++)
			{
				for (int y = 0; y < mapLayerItem->data->height; y++)
				{
					// L04: DONE 9: Complete the draw function
					int gid = mapLayerItem->data->Get(x, y);

					if (gid > 0) {

						//L06: TODO 4: Obtain the tile set using GetTilesetFromTileId
						//now we always use the firt tileset in the list
						//TileSet* tileset = mapData.tilesets.start->data;
						TileSet* tileset = GetTilesetFromTileId(gid);

						SDL_Rect r = tileset->GetTileRect(gid);
						iPoint pos = MapToWorld(x, y);

						App->renderer->AddTextureRenderQueue(tileset->texture, iPoint(pos.x, pos.y), r, 1, 1, 0.5f);
					}

				}
			}
		}

		mapLayerItem = mapLayerItem->next;
	}

	return UpdateStatus::UPDATE_CONTINUE;
}
// Draw the map (all requried layers)
Draw the map (all requried layers)
Draw the map ( all requried layers )
UpdateStatus ModuleMap::PostUpdate()
{
	if (mapLoaded == false) return UpdateStatus::UPDATE_CONTINUE;
	ListItem<MapLayer*>* mapLayerItem;
	mapLayerItem = mapData.layers.start;
	while (mapLayerItem != NULL) {
		if (mapLayerItem->data->properties.GetProperty("Draw") == 1)
		{
			for (int x = 0; x < mapLayerItem->data->width; x++)
			{
				for (int y = 0; y < mapLayerItem->data->height; y++)
				{
					int gid = mapLayerItem->data->Get(x, y);
					if (gid > 0) {
						TileSet* tileset = GetTilesetFromTileId(gid);
						SDL_Rect r = tileset->GetTileRect(gid);
						iPoint pos = MapToWorld(x, y);
						App->renderer->AddTextureRenderQueue(tileset->texture, iPoint(pos.x, pos.y), r, 1, 1, 0.5f);
					}
				}
			}
		}
		mapLayerItem = mapLayerItem->next;
	}
	return UpdateStatus::UPDATE_CONTINUE;
}
UpdateStatus ModuleMap :: PostUpdate ( ) { if ( mapLoaded == false ) return UpdateStatus :: UPDATE_CONTINUE ; ListItem < MapLayer * > * mapLayerItem ; mapLayerItem = mapData . layers . start ; while ( mapLayerItem != NULL ) { if ( mapLayerItem -> data -> properties . GetProperty ( " " ) == 1 ) { for ( int x = 0 ; x < mapLayerItem -> data -> width ; x ++ ) { for ( int y = 0 ; y < mapLayerItem -> data -> height ; y ++ ) { int gid = mapLayerItem -> data -> Get ( x , y ) ; if ( gid > 0 ) { TileSet * tileset = GetTilesetFromTileId ( gid ) ; SDL_Rect r = tileset -> GetTileRect ( gid ) ; iPoint pos = MapToWorld ( x , y ) ; App -> renderer -> AddTextureRenderQueue ( tileset -> texture , iPoint ( pos . x , pos . y ) , r , 1 , 1 , 0.5f ) ; } } } } mapLayerItem = mapLayerItem -> next ; } return UpdateStatus :: UPDATE_CONTINUE ; }
Draw the map (all requried layers)
Draw the map ( all requried layers )
// L04: DONE 5: Prepare the loop to draw all tilesets + DrawTexture() // L06: TODO 4: Make sure we draw all the layers and not just the first one // L04: DONE 9: Complete the draw function //L06: TODO 4: Obtain the tile set using GetTilesetFromTileId //now we always use the firt tileset in the list //TileSet* tileset = mapData.tilesets.start->data;