Ejemplo n.º 1
0
        ////////////////

        public WormholePortal(Vector2 worldPos, Color color)
        {
            (int minX, int maxX, int minY, int maxY)bounds = WormholesWorld.GetTileBoundsForWormholes();

            this.IsMisplaced = (worldPos.X / 16f) < 64f || (worldPos.X / 16f) > bounds.maxX ||
                               (worldPos.Y / 16f) < Main.worldSurface || (worldPos.Y / 16f) > bounds.maxY;

            if (Main.maxTilesX > 160)
            {
                worldPos.X = MathHelper.Clamp(worldPos.X, 160, (Main.maxTilesX - 10) * 16);
            }
            else
            {
                worldPos.X = MathHelper.Clamp(worldPos.X, 0, Main.maxTilesX * 16);
            }
            if (Main.maxTilesY > 160)
            {
                worldPos.Y = MathHelper.Clamp(worldPos.Y, 160, (Main.maxTilesY - 10) * 16);
            }
            else
            {
                worldPos.Y = MathHelper.Clamp(worldPos.Y, 0, Main.maxTilesY * 16);
            }
//DebugHelpers.Log( "wall of "+color.ToString()+": "+Main.tile[(int)(pos.X/16f)+2, (int)(pos.Y/16f)+4].wall );

            this.Pos       = worldPos;
            this.BaseColor = color;

            // Clients and single only
            if (Main.netMode != 2)
            {
                this.Rect     = new Rectangle((int)worldPos.X, (int)worldPos.Y, WormholePortal.Width, WormholePortal.Height);
                this.Animator = new SpriteAnimator(1, WormholePortal.FrameCount, WormholePortal.Tex, color);
            }
        }
Ejemplo n.º 2
0
        /////////////////

        private Vector2 GetRandomClearMapPos()
        {
            Vector2 randPos;
            int     worldX, worldY;
            bool    found = false, isEmpty = false;
            int     minWldDistSqr = WormholesConfig.Instance.MinimumTileDistanceBetweenWormholes * 16;

            minWldDistSqr *= minWldDistSqr;

            (int minX, int maxX, int minY, int maxY)bounds = WormholesWorld.GetTileBoundsForWormholes();

            do
            {
                found = true;

                do
                {
                    worldX = Main.rand.Next(bounds.minX, bounds.maxX);
                    worldY = Main.rand.Next(bounds.minY, bounds.maxY);

                    isEmpty = true;
                    for (int i = worldX; i < worldX + 6; i++)
                    {
                        for (int j = worldY; j < worldY + 8; j++)
                        {
                            Tile tile = Framing.GetTileSafely(i, j);

                            bool _;
                            isEmpty = !TileHelpers.IsSolid(tile, true, true) && !tile.lava() && !TileWallGroupIdentityHelpers.IsDungeon(tile, out _);
                            if (!isEmpty)
                            {
                                break;
                            }
                        }
                        if (!isEmpty)
                        {
                            break;
                        }
                    }
                } while(!isEmpty);
                //} while( Collision.SolidCollision( new Vector2(world_x*16f, world_y*16f), WormholePortal.Width, WormholePortal.Height ) );

                randPos = new Vector2(worldX * 16f, worldY * 16f);

                // Not too close to other portals?
                for (int i = 0; i < this.Links.Count; i++)
                {
                    var link = this.Links[i];

                    float distSqr = Vector2.DistanceSquared(link.LeftPortal.Pos, randPos);
                    if (distSqr < minWldDistSqr)
                    {
                        found = false;
                        break;
                    }

                    distSqr = Vector2.DistanceSquared(link.RightPortal.Pos, randPos);
                    if (distSqr < minWldDistSqr)
                    {
                        found = false;
                        break;
                    }
                }
            } while(!found);

            return(randPos);
        }