Beispiel #1
0
        /// <summary>
        /// Deserializes the first Frame of this State.
        /// </summary>
        /// <param name="stream">Input Stream</param>
        /// <param name="version">Protocol Version</param>
        public void DeserializeFirst(BinaryReader stream, byte version)
        {
            BlockBorder = stream.ReadBoolean();
            int width = stream.ReadInt32();
            int height = stream.ReadInt32();
            Tiles = new MapTile[width, height];

            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                {
                    Tiles[x, y] = new MapTile()
                    {
                        Shape = (TileShape)stream.ReadByte(),
                        Speed = (TileSpeed)stream.ReadByte(),
                        Height = (TileHeight)stream.ReadByte()
                    };
                }
        }
Beispiel #2
0
        private SolidBrush GetCellcolor(MapTile tile)
        {
            if (tile.Shape != TileShape.Flat &&
                tile.Shape != TileShape.RampBottom &&
                tile.Shape != TileShape.RampTop &&
                tile.Shape != TileShape.RampLeft &&
                tile.Shape != TileShape.RampRight)
                return new SolidBrush(Color.Black);

            Color baseColor = Color.SandyBrown;
            switch (tile.Speed)
            {
                case TileSpeed.Stop: baseColor = Color.FromArgb(64, 64, 64); break;
                case TileSpeed.Slowest: baseColor = Color.FromArgb(99, 49, 0); break;
                case TileSpeed.Slower: baseColor = Color.FromArgb(204, 143, 83); break;
                case TileSpeed.Normal: baseColor = Color.FromArgb(26, 175, 43); break;
                case TileSpeed.Faster: baseColor = Color.FromArgb(192, 192, 192); break;
            }

            switch (tile.Height)
            {
                case TileHeight.High:
                    baseColor = Color.FromArgb(baseColor.R + 30, baseColor.G + 30, baseColor.B + 30);
                    break;
                case TileHeight.Medium:
                    break;
                case TileHeight.Low:
                    baseColor = Color.FromArgb(baseColor.R - 20, baseColor.G - 20, baseColor.B - 20);
                    break;
            }

            return new SolidBrush(baseColor);
        }
Beispiel #3
0
        /// <summary>
        ///     Ermittelt die Höhe der Position auf Basis der Zellen- und Positionsangaben.
        ///     TODO: Test!
        /// </summary>
        /// <param name="tile">Aktuelle Zelle</param>
        /// <param name="relativePosition">Position relativ zur Zelle</param>
        /// <returns>Höhe in Spieleinheiten</returns>
        public static float GetHeight(MapTile tile, Vector2 relativePosition)
        {
            var cropped = new Vector2(
                Math.Max(0, Math.Min(CELLSIZE, relativePosition.X)),
                Math.Max(0, Math.Min(CELLSIZE, relativePosition.Y)));

            // Basic Height
            float basic = 0;

            switch (tile.Height)
            {
            case TileHeight.Low:
                basic = MapTile.HEIGHT_LOW;
                break;

            case TileHeight.Medium:
                basic = MapTile.HEIGHT_MEDIUM;
                break;

            case TileHeight.High:
                basic = MapTile.HEIGHT_HIGH;
                break;

            default:
                throw new ArgumentException("Height of tile is undefined");
            }

            // Im Falle eines flachen Tile einfach basiswert zurück geben
            if (tile.Shape == TileShape.Flat)
            {
                return(basic);
            }

            // In allen anderen Fällen darf der Height-Wert nicht auf max sein.
            if (tile.Height == TileHeight.High)
            {
                throw new ArgumentException("Height=High is not valid for ramps and canyon Tiles");
            }

            // Diff ermitteln
            float diff = 0;

            switch (tile.Height + 1)
            {
            case TileHeight.Low:
                diff = MapTile.HEIGHT_LOW - basic;
                break;

            case TileHeight.Medium:
                diff = MapTile.HEIGHT_MEDIUM - basic;
                break;

            case TileHeight.High:
                diff = MapTile.HEIGHT_HIGH - basic;
                break;

            default:
                throw new ArgumentException("Height has an invalid value");
            }

            var projected = new Vector2(relativePosition.X / CELLSIZE, relativePosition.Y / CELLSIZE);

            Func <float, float> ramp = v => ((v * diff) + basic);

            // Shape berücksichtigen
            switch (tile.Shape)
            {
            case TileShape.CanyonBottom:
            case TileShape.RampBottom:
                // Curve from bottom to top
                return(ramp(1 - projected.Y));

            case TileShape.CanyonTop:
            case TileShape.RampTop:
                // Curve from top to bottom
                return(ramp(projected.Y));

            case TileShape.CanyonLeft:
            case TileShape.RampLeft:
                // Curve from left to right
                return(ramp(projected.X));

            case TileShape.CanyonRight:
            case TileShape.RampRight:
                // Curve from right to left
                return(ramp(1 - projected.X));

            case TileShape.CanyonUpperLeftConvex:
                return((projected.Y > projected.X) ? ramp(projected.X) : ramp(projected.Y));

            case TileShape.CanyonUpperRightConvex:
                return(((1 - projected.Y) > projected.X) ? ramp(projected.Y) : ramp(1 - projected.X));

            case TileShape.CanyonLowerLeftConvex:
                return(((1 - projected.Y) > projected.X) ? ramp(projected.X) : ramp(1 - projected.Y));

            case TileShape.CanyonLowerRightConvex:
                return((projected.Y > projected.X) ? ramp(1 - projected.Y) : ramp(1 - projected.X));

            case TileShape.CanyonUpperLeftConcave:
                return((projected.Y > projected.X) ? ramp(1 - projected.X) : ramp(1 - projected.Y));

            case TileShape.CanyonUpperRightConcave:
                return(((1 - projected.Y) > projected.X) ? ramp(1 - projected.Y) : ramp(projected.X));

            case TileShape.CanyonLowerLeftConcave:
                return(((1 - projected.Y) > projected.X) ? ramp(1 - projected.X) : ramp(projected.Y));

            case TileShape.CanyonLowerRightConcave:
                return((projected.Y > projected.X) ? ramp(projected.Y) : ramp(projected.X));

            default:
                throw new ArgumentException("Unexpected Tile Shape");
            }
        }