Example #1
0
        public void SpawnObstacle(int x, int y, int radius)
        {
            int tileX = x >> 9;
            int tileY = y >> 9;

            if (!this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(tileX, tileY)))
            {
                int minSquare = 0;
                int minTileX  = -1;
                int minTileY  = -1;

                for (int i = -radius; i <= radius; i++)
                {
                    int posX = tileX + i;
                    int midX = (posX << 9) | 256;
                    int midY = (radius << 9) - 256 - ((y >> 9) << 9);

                    for (int j = -radius; j <= radius; j++)
                    {
                        int posY = tileY + j;

                        if (this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(posX, posY)))
                        {
                            int goX = this.GetX();
                            int goY = this.GetY();

                            int square = (goX - midX) * (goX - midX) + (goY + midY) * (goY + midY);

                            if (minSquare == 0 || square < minSquare)
                            {
                                minSquare = square;
                                minTileX  = posX;
                                minTileY  = posY;
                            }
                        }

                        midY -= 512;
                    }
                }

                if (minSquare == 0)
                {
                    return;
                }

                tileX = minTileX;
                tileY = minTileY;
            }

            LogicObstacleData data = this.GetSpellData().GetSpawnObstacle();

            if (data != null)
            {
                LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.GetVillageType());
                gameObject.SetInitialPosition(tileX << 9, tileY << 9);
                this.GetGameObjectManager().AddGameObject(gameObject, -1);
            }
        }