Exemplo n.º 1
0
        public GameWorldArea(TiledMapObject obj)
        {
            this.details = obj;

            this.ID     = obj.Identifier;
            this.bounds = null;

            if (obj is TiledMapPolygonObject)
            {
                var polyObj = (TiledMapPolygonObject)obj;
                var polygon = new PolygonF(polyObj.Points.Select(x => new Vector2(x.X, x.Y)));
                polygon.Offset(new Vector2(polyObj.Position.X, polyObj.Position.Y));

                this.bounds = polygon;
            }
            else if (obj is TiledMapRectangleObject)
            {
                var rectObj = (TiledMapRectangleObject)obj;
                this.bounds = new RectangleF((int)rectObj.Position.X, (int)rectObj.Position.Y, (int)rectObj.Size.Width, (int)rectObj.Size.Height);
            }
            else
            {
                throw new ArgumentException("Invalid GameMapArea");
            }


            if (obj.Properties != null)
            {
                String lifeDegen, speedModifier, slippery;

                if (obj.Properties.TryGetValue("life_degeneration", out lifeDegen))
                {
                    this.degenerationRatio = float.Parse(lifeDegen, CultureInfo.InvariantCulture);
                }

                if (obj.Properties.TryGetValue("speed_modifier", out speedModifier))
                {
                    this.speedModifier = float.Parse(speedModifier, CultureInfo.InvariantCulture);
                }
                else
                {
                    this.speedModifier = 1.0f;
                }

                if (obj.Properties.TryGetValue("slippery", out slippery))
                {
                    this.slippery = Boolean.Parse(slippery);
                }
            }
        }
Exemplo n.º 2
0
        public void Polygon_Transform_Translation_Test()
        {
            var vertices = new[] 
            {
                new Vector2(0, 0),
                new Vector2(10, 0),
                new Vector2(10, 10),
                new Vector2(0, 10)
            };

            var polygon = new PolygonF(vertices);
            polygon.Offset(new Vector2(2, 3));

            Assert.AreEqual(new Vector2(2, 3), polygon.Vertices[0]);
            Assert.AreEqual(new Vector2(12, 3), polygon.Vertices[1]);
            Assert.AreEqual(new Vector2(12, 13), polygon.Vertices[2]);
            Assert.AreEqual(new Vector2(2, 13), polygon.Vertices[3]);
        }
Exemplo n.º 3
0
        public void Polygon_Transform_Translation_Test()
        {
            var vertices = new[]
            {
                new Vector2(0, 0),
                new Vector2(10, 0),
                new Vector2(10, 10),
                new Vector2(0, 10)
            };

            var polygon = new PolygonF(vertices);

            polygon.Offset(new Vector2(2, 3));

            Assert.AreEqual(new Vector2(2, 3), polygon.Vertices[0]);
            Assert.AreEqual(new Vector2(12, 3), polygon.Vertices[1]);
            Assert.AreEqual(new Vector2(12, 13), polygon.Vertices[2]);
            Assert.AreEqual(new Vector2(2, 13), polygon.Vertices[3]);
        }