コード例 #1
0
        public List <Side>[] OpenSides(int layer)
        {
            var sides = new[]
            {
                new List <Side>(), new List <Side>()
            };

            var required = WorldHelpers.GetOpenSides(_bottomTileNumber, layer);

            if (required.Contains(Side.Top))
            {
                if (TileAbove == null)
                {
                    sides[0].Add(Side.Top);
                }
                else if (
                    !(BottomTilesAbove.Contains(TileAbove.BottomTileNumber) ||
                      BottomTilesAbove.Contains(TileAbove.TopTileNumber)))
                {
                    sides[0].Add(Side.Top);
                }
            }
            if (required.Contains(Side.Bottom))
            {
                if (TileBelow == null)
                {
                    sides[0].Add(Side.Bottom);
                }
                else if (
                    !(BottomTilesBelow.Contains(TileBelow.BottomTileNumber) ||
                      BottomTilesBelow.Contains(TileBelow.TopTileNumber)))
                {
                    sides[0].Add(Side.Bottom);
                }
            }
            if (required.Contains(Side.Left))
            {
                if (TileToLeft == null)
                {
                    sides[0].Add(Side.Left);
                }
                else if (
                    !(BottomTilesToLeft.Contains(TileToLeft.BottomTileNumber) ||
                      BottomTilesToLeft.Contains(TileToLeft.TopTileNumber)))
                {
                    sides[0].Add(Side.Left);
                }
            }
            if (required.Contains(Side.Right))
            {
                if (TileToRight == null)
                {
                    sides[0].Add(Side.Right);
                }
                else if (
                    !(BottomTilesToRight.Contains(TileToRight.BottomTileNumber) ||
                      BottomTilesToRight.Contains(TileToRight.TopTileNumber)))
                {
                    sides[0].Add(Side.Right);
                }
            }


            required = WorldHelpers.GetOpenSides(_topTileNumber, layer);
            if (required.Contains(Side.Top))
            {
                if (TileAbove == null)
                {
                    sides[1].Add(Side.Top);
                }
                else if (!(TopTilesAbove.Contains(TileAbove.TopTileNumber) || TopTilesAbove.Contains(TileAbove.BottomTileNumber)))
                {
                    sides[1].Add(Side.Top);
                }
            }
            if (required.Contains(Side.Bottom))
            {
                if (TileBelow == null)
                {
                    sides[1].Add(Side.Bottom);
                }
                else if (!(TopTilesBelow.Contains(TileBelow.TopTileNumber) || TopTilesBelow.Contains(TileBelow.BottomTileNumber)))
                {
                    sides[1].Add(Side.Bottom);
                }
            }
            if (required.Contains(Side.Left))
            {
                if (TileToLeft == null)
                {
                    sides[1].Add(Side.Left);
                }
                else if (!(TopTilesToLeft.Contains(TileToLeft.TopTileNumber) || TopTilesToLeft.Contains(TileToLeft.BottomTileNumber)))
                {
                    sides[1].Add(Side.Left);
                }
            }
            if (required.Contains(Side.Right))
            {
                if (TileToRight == null)
                {
                    sides[1].Add(Side.Right);
                }
                else if (!(TopTilesToRight.Contains(TileToRight.TopTileNumber) || TopTilesToRight.Contains(TileToRight.BottomTileNumber)))
                {
                    sides[1].Add(Side.Right);
                }
            }
            return(sides);
        }
コード例 #2
0
        public override void Draw(SpriteBatch batch)
        {
            var offset = Game.Center - new Vector2(Game.TileSet.TileWidth / 2f, Game.TileSet.TileHeight / 2f);

            foreach (var s in WorldHelpers.GetOpenSides(CurrentTile, 1))
            {
                var vec = offset - new Vector2(100, 0);
                if (s == Side.Bottom)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Top)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White, MathHelper.ToRadians(180), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Left)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White, MathHelper.ToRadians(90), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Right)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White, MathHelper.ToRadians(270), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
            }
            foreach (var s in WorldHelpers.GetOpenSides(CurrentTile, 2))
            {
                var vec = offset - new Vector2(100, 0);
                if (s == Side.Bottom)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White * 0.5f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Top)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White * 0.5f, MathHelper.ToRadians(180), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Left)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White * 0.5f, MathHelper.ToRadians(90), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
                if (s == Side.Right)
                {
                    batch.Draw(Textures.Starter, vec, null, Color.White * 0.5f, MathHelper.ToRadians(270), Vector2.Zero, 1f, SpriteEffects.None, 1f);
                }
            }
            Game.TileSet.DrawTile(batch, CurrentTile, offset, Vector2.Zero, null, 0.5f);
            Game.TileSet.DrawTileBridges(batch, CurrentTile, offset, Vector2.Zero, null, 0.6f);

            foreach (var l in Rails)
            {
                batch.DrawLine(l.Start + offset, l.End + offset, Color.Red, 1);
            }
            foreach (var l in SpecialRails)
            {
                batch.DrawLine(l.Start + offset, l.End + offset, Color.Blue, 1);
            }
            foreach (var w in Water)
            {
                batch.FillRectangle(new Rectangle((int)offset.X + w.X, (int)offset.Y + w.Y, w.Width, w.Height),
                                    Color.Red * .5f);
            }
            foreach (var w in Teleporters)
            {
                batch.FillRectangle(new Rectangle((int)offset.X + w.X, (int)offset.Y + w.Y, w.Width, w.Height),
                                    Color.Green * .5f);
            }
            foreach (var b in Bouncers)
            {
                batch.DrawNode(b, offset);
            }
            if (Elevation == Elevation.Horizontal)
            {
                batch.Draw(Textures.HorizontalElevation, new Vector2(offset.X + Game.TileSet.TileWidth, offset.Y),
                           Color.White);
            }
            else if (Elevation == Elevation.Vertical)
            {
                batch.Draw(Textures.VerticalElevation, new Vector2(offset.X + Game.TileSet.TileWidth, offset.Y),
                           Color.White);
            }
            offset += new Vector2(0, Game.TileSet.TileHeight);
            batch.DrawString(Fonts.GameFont, "Tile (" + CurrentTile + ")", offset, Color.White);
            DrawTileList(batch, Connections.First(p => p.Key == Side.Top).Value, "T", Vector2.Zero);
            DrawTileList(batch, Connections.First(p => p.Key == Side.Bottom).Value, "B", new Vector2(0, (Game.TileSet.TileWidth * 0.5f) * 1));
            DrawTileList(batch, Connections.First(p => p.Key == Side.Left).Value, "L", new Vector2(0, (Game.TileSet.TileWidth * 0.5f) * 2));
            DrawTileList(batch, Connections.First(p => p.Key == Side.Right).Value, "R", new Vector2(0, (Game.TileSet.TileWidth * 0.5f) * 3));
            base.Draw(batch);
        }