コード例 #1
0
ファイル: BuildMap.cs プロジェクト: aaronmell/DotNetFish
        /// <summary>
        /// Processes all of the Tiles and determines if they are an edge or not. Edgetiles get added to the list, and the 
        /// other tiles get water / land added to them. 
        /// </summary>
        /// <param name="bmpData">The bmp data we arew processing</param>
        /// <param name="gameWorldX">The game's x coordinate</param>
        /// <param name="gameWorldY">The game's y coordinate</param>		
        private void ProcessTile(BmpData bmpData, int gameWorldX, int gameWorldY)
        {
            bool hasWater = false;
            bool hasLand = false;

            CheckEdges(bmpData, _graphicsTileSize, out hasWater, out hasLand);

            if (hasLand && hasWater)
            {
                //We generate the edge connections for each tile just like they are by themselves.
                //After all of the tiles are processed we will do a second pass to ensure everything is connected.
                MapGraphicsTile mapGraphicsTile = new MapGraphicsTile();
                _gameWorld.GameMap[gameWorldX, gameWorldY] = new MapTile(_mapGraphicsTileSet.EdgePlaceHolder);
                mapGraphicsTile.TileType = TileType.EdgePlaceHolder;
                _edgeTiles.Add(new Point(gameWorldX, gameWorldY), mapGraphicsTile);
            }

            else if (hasLand)
                _gameWorld.GameMap[gameWorldX, gameWorldY] = new MapTile(_mapGraphicsTileSet.LandTile);
            else
                _gameWorld.GameMap[gameWorldX, gameWorldY] = new MapTile(_mapGraphicsTileSet.WaterTile);

            //Need to release the locked bits here
            bmpData.Dispose();
        }
コード例 #2
0
ファイル: BuildMap.cs プロジェクト: aaronmell/DotNetFish
        /// <summary>
        /// Detemines if a GmapTile contains a transition in it. 
        /// </summary>
        /// <param name="gmapX">The google maps X coordinates</param>
        /// <param name="gmapY">The google maps Y coordinates</param>
        /// <param name="gmapBitmap">The bitmap we are processing</param>
        /// <returns>a value indicating if a tile has a transition in it. </returns>
        private bool CheckGmapTilesForTransitions(int gmapX, int gmapY, Bitmap gmapBitmap, int zoomLevel, Point currentAbsolutePosition)
        {
            int offset = getOffSet(zoomLevel);
            bool hasWater = false;
            bool hasLand = false;
            using (BmpData largeBmpData = new BmpData(gmapBitmap, 256))
                CheckEdges(largeBmpData, 256, out hasWater, out hasLand);

            //if we have land and water on the tile, then we need to Process it normally, otherwise we can skip all of that.
            if (hasLand && hasWater)
                return true;

            MapGraphicsTile mapGraphicsTile = new MapGraphicsTile();

            if (hasLand)
                 mapGraphicsTile= _mapGraphicsTileSet.LandTile;
            else
                mapGraphicsTile= _mapGraphicsTileSet.WaterTile;

                MapTile mapTile = new MapTile(mapGraphicsTile);

            for (int x = currentAbsolutePosition.X * _graphicsTileSize; x < (currentAbsolutePosition.X * _graphicsTileSize) + (_graphicsTileSize * offset); x++)
            {
                for (int y = currentAbsolutePosition.Y * _graphicsTileSize; y < (currentAbsolutePosition.Y * _graphicsTileSize) + (_graphicsTileSize * offset); y++)
                {
                    _gameWorld.GameMap[x,y] = mapTile;
                }
            }

            return false;
        }
コード例 #3
0
ファイル: BuildMap.cs プロジェクト: aaronmell/DotNetFish
        /// <summary>
        /// Processes the gmap tile. splits the gmap tile up into smaller tiles and then checks each tile for the transitions.
        /// </summary>
        /// <param name="gmapX">The google maps X coordinates</param>
        /// <param name="gmapY">The google maps Y coordinates</param>
        /// <param name="gmapBitmap">The bitmap we are processing</param>
        private void ProcessGmapTiles(int gmapX, int gmapY, Bitmap gmapBitmap)
        {
            //The bitmap coming in as 256x256 This needs to be broken down further into 16x16 sized
            //tiles in order to get the proper size of the map
            for (int tileX = 0; tileX < _graphicsTileSize; tileX++)
            {
                for (int tileY = 0; tileY < _graphicsTileSize; tileY++)
                {
                    using (Bitmap smallBmp = new Bitmap(_graphicsTileSize, _graphicsTileSize))
                    {
                        using (Graphics gfx = Graphics.FromImage(smallBmp))
                            gfx.DrawImage(gmapBitmap,new Rectangle(0,0,16,16),tileX * _graphicsTileSize,tileY * _graphicsTileSize,16,16,GraphicsUnit.Pixel);
            //#if DEBUG
                        smallBmp.Save("C:\\tiles\\smalltile" + ((gmapX * _graphicsTileSize) + tileX) + "-" + ((gmapY * _graphicsTileSize) + tileY) + ".jpg");
            //#endif
                        BmpData bmpData = new BmpData(smallBmp, _graphicsTileSize);

                        ProcessTile(bmpData, (gmapX * _graphicsTileSize) + tileX, (gmapY * _graphicsTileSize) + tileY);
                        bmpData.Dispose();
                    }
                }
            }
        }
コード例 #4
0
ファイル: BuildMap.cs プロジェクト: aaronmell/DotNetFish
        /// <summary>
        /// Checks the Edges of a Tile to determine if the tile contains land,water or both
        /// </summary>
        /// <param name="bmpData"></param>
        /// <param name="tileSize"></param>
        /// <param name="hasWater"></param>
        /// <param name="hasLand"></param>
        private void CheckEdges(BmpData bmpData, int tileSize, out bool hasWater, out bool hasLand)
        {
            hasWater = false;
            hasLand = false;
            bool retval;
            //Loop though all of the pixels on the Y edge
            for (int y = 0; y < tileSize; y++)
            {
                for (int x = 0; x < tileSize; x++)
                {
                    int position = (y * bmpData.BitmapData.Stride) + (x * 4);

                    Color color = SetColor(bmpData.RgbValues[position], bmpData.RgbValues[position + 1], bmpData.RgbValues[position + 2]);
                    retval = IsWater(color);

                    if (retval == true)
                        hasWater = true;
                    else
                        hasLand = true;

                    if (hasLand && hasWater)
                        break;

                    //only check the left and right edges.
                    if (y != 0 && y != tileSize - 1)
                        x+= tileSize - 2;
                }
                if (hasLand && hasWater)
                    return;
            }
        }