Exemplo n.º 1
0
        public void GetComponentValuesInDrawState()
        {
            var entity = new Entity2D(Rectangle.One)
            {
                Color          = Color.Red,
                Rotation       = 1.0f,
                RotationCenter = Vector2D.One
            };

            EntitiesRunner.Current.State = UpdateDrawState.Draw;
            Assert.AreEqual(entity.DrawArea, entity.Get <Rectangle>());
            Assert.AreEqual(entity.Color, entity.Get <Color>());
            Assert.AreEqual(entity.Rotation, entity.Get <float>());
            Assert.AreEqual(entity.RotationCenter, entity.Get <Vector2D>());
        }
        private void SetDrawAreaPosition(Entity2D entity, int row, int column)
        {
            Size size = entity.Get <Material>().DiffuseMap != null
                                ? entity.Get <Material>().DiffuseMap.PixelSize
                                : entity.Get <Material>().Animation.Frames[0].PixelSize;

            float widthScale  = size.Width > size.Height ? 1.0f : size.Width / size.Height;
            float heightScale = size.Width > size.Height ? size.Height / size.Width : 1.0f;

            entity.DrawArea =
                Rectangle.FromCenter(new Vector2D(0.175f + 0.2f * column, 0.3f + 0.2f * row),
                                     new Size(0.15f * widthScale, 0.15f * heightScale));
            CreateOutline(row, column);
            StartPreviewList.Add(entity);
        }
Exemplo n.º 3
0
        public void SetAndGetEntity2DComponentsDirectly()
        {
            var entity = new Entity2D(DoubleSizedRectangle)
            {
                Color = Color.Red
            };

            entity.Set(Color.Green);
            Assert.AreEqual(Color.Green, entity.Get <Color>());
            entity.Set(Rectangle.One);
            Assert.AreEqual(Rectangle.One, entity.Get <Rectangle>());
            entity.Set(5.0f);
            Assert.AreEqual(5.0f, entity.Get <float>());
            entity.Set(Vector2D.One);
            Assert.AreEqual(Vector2D.One, entity.Get <Vector2D>());
            entity.RenderLayer = -10;
            Assert.AreEqual(-10, entity.RenderLayer);
        }
Exemplo n.º 4
0
		private void AddToBatch(Entity2D entity)
		{
			var color = entity.Get<OutlineColor>().Value;
			List<Vector2D> points = null;
			if (entity.Contains<List<Vector2D>>())
				points = entity.Get<List<Vector2D>>();
			if (points == null || points.Count <= 1)
			{
				points = new List<Vector2D>();
				points.Add(entity.DrawArea.TopLeft);
				points.Add(entity.DrawArea.BottomLeft);
				points.Add(entity.DrawArea.BottomRight);
				points.Add(entity.DrawArea.TopRight);
			}
			lastPoint = points[points.Count - 1];
			foreach (Vector2D point in points)
				AddLine(point, color);
		}
Exemplo n.º 5
0
            private void AddVertices(Entity2D entity)
            {
                var area = entity.DrawArea;

                foreach (Vector2D pos in entity.Get <Data>().LinePoints)
                {
                    vertices.Add(new VertexPosition2DColor(
                                     ScreenSpace.Current.ToPixelSpaceRounded(pos * area.Height + area.Center), entity.Color));
                }
            }
Exemplo n.º 6
0
		public void ApplyUpdateWithVelocity()
		{
			var entity2D = new Entity2D(new Rectangle(0, 0, 1, 1));
			entity2D.Add(velocity);
			entity2D.Start<Velocity2D.PositionUpdate>();
			var originalPosition = entity2D.Center;
			entity2D.Get<Velocity2D.Data>().Accelerate(2.0f, 90.0f);
			AdvanceTimeAndUpdateEntities();
			Assert.AreNotEqual(originalPosition, entity2D.Center);
		}
Exemplo n.º 7
0
        public void ApplyUpdateWithVelocity()
        {
            var entity2D = new Entity2D(new Rectangle(0, 0, 1, 1));

            entity2D.Add(velocity);
            entity2D.Start <Velocity2D.PositionUpdate>();
            var originalPosition = entity2D.Center;

            entity2D.Get <Velocity2D.Data>().Accelerate(2.0f, 90.0f);
            AdvanceTimeAndUpdateEntities();
            Assert.AreNotEqual(originalPosition, entity2D.Center);
        }
        private void AddToBatch(Entity2D entity)
        {
            var             color  = entity.Get <OutlineColor>().Value;
            List <Vector2D> points = null;

            if (entity.Contains <List <Vector2D> >())
            {
                points = entity.Get <List <Vector2D> >();
            }
            if (points == null || points.Count <= 1)
            {
                points = new List <Vector2D>();
                points.Add(entity.DrawArea.TopLeft);
                points.Add(entity.DrawArea.BottomLeft);
                points.Add(entity.DrawArea.BottomRight);
                points.Add(entity.DrawArea.TopRight);
            }
            lastPoint = points[points.Count - 1];
            foreach (Vector2D point in points)
            {
                AddLine(point, color);
            }
        }
Exemplo n.º 9
0
 private void AddToBatch(Entity2D entity)
 {
     var points = entity.Get<List<Vector2D>>();
     if (points.Count < 3)
         return;
     if (points.Count > CircularBuffer.TotalMaximumVerticesLimit)
         throw new TooManyVerticesForPolygon(points.Count); //ncrunch: no coverage
     var color = entity.Color;
     if (offset + points.Count > vertices.Length)
         ResizeVertices(); //ncrunch: no coverage
     for (int num = 0; num < points.Count; num++)
         vertices[offset + num] =
             new VertexPosition2DColor(ScreenSpace.Current.ToPixelSpace(points[num]), color);
     BuildIndices(points.Count);
     offset += points.Count;
 }
Exemplo n.º 10
0
 private void AddVertices(Entity2D entity)
 {
     var area = entity.DrawArea;
     foreach (Vector2D pos in entity.Get<Data>().LinePoints)
         vertices.Add(new VertexPosition2DColor(
             ScreenSpace.Current.ToPixelSpaceRounded(pos * area.Height + area.Center), entity.Color));
 }
Exemplo n.º 11
0
		private void SetDrawAreaPosition(Entity2D entity, int row, int column)
		{
			Size size = entity.Get<Material>().DiffuseMap != null
				? entity.Get<Material>().DiffuseMap.PixelSize
				: entity.Get<Material>().Animation.Frames[0].PixelSize;
			float widthScale = size.Width > size.Height ? 1.0f : size.Width / size.Height;
			float heightScale = size.Width > size.Height ? size.Height / size.Width : 1.0f;
			entity.DrawArea =
				Rectangle.FromCenter(new Vector2D(0.175f + 0.2f * column, 0.3f + 0.2f * row),
					new Size(0.15f * widthScale, 0.15f * heightScale));
			CreateOutline(row, column);
			StartPreviewList.Add(entity);
		}
Exemplo n.º 12
0
 private void SetDrawAreaPosition(Entity2D entity, int row, int column)
 {
     Size size;
     if (entity.Get<Material>().DiffuseMap != null)
         size = entity.Get<Material>().DiffuseMap.PixelSize;
     else
         size = entity.Get<Material>().Animation.Frames[0].PixelSize; //ncrunch: no coverage
     if (size.Width > size.Height)
     {
         var aspect = size.Height / size.Width;
         entity.DrawArea =
             Rectangle.FromCenter(new Vector2D(0.175f + 0.2f * column, 0.3f + 0.2f * row),
                 new Size(0.15f, 0.15f * aspect));
     }
     else
     {
         var aspect = size.Width / size.Height;
         entity.DrawArea =
             Rectangle.FromCenter(new Vector2D(0.175f + 0.2f * column, 0.3f + 0.2f * row),
                 new Size(0.15f * aspect, 0.15f));
     }
     new Line2D(new Vector2D(0.09f + 0.2f * column, 0.215f + 0.2f * row),
         new Vector2D(0.15f + 0.11f + 0.2f * column, 0.215f + 0.2f * row),
         new Datatypes.Color(67, 78, 200));
     new Line2D(new Vector2D(0.09f + 0.2f * column, 0.215f + 0.2f * row),
         new Vector2D(0.09f + 0.2f * column, 0.125f + 0.26f + 0.2f * row),
         new Datatypes.Color(67, 78, 200));
     new Line2D(new Vector2D(0.15f + 0.11f + 0.2f * column, 0.125f + 0.26f + 0.2f * row),
         new Vector2D(0.15f + 0.11f + 0.2f * column, 0.215f + 0.2f * row),
         new Datatypes.Color(67, 78, 200));
     new Line2D(new Vector2D(0.15f + 0.11f + 0.2f * column, 0.125f + 0.26f + 0.2f * row),
         new Vector2D(0.09f + 0.2f * column, 0.125f + 0.26f + 0.2f * row),
         new Datatypes.Color(67, 78, 200));
     StartPreviewList.Add(entity);
 }