Ejemplo n.º 1
0
		/// <summary>
		/// Adds shapes of entity to collision collection.
		/// </summary>
		/// <param name="shapedEntity"></param>
		public void Add(IShapedEntity shapedEntity)
		{
			if (shapedEntity.Shapes == null || shapedEntity.Shapes.Count == 0 || !shapedEntity.IsCollision)
				return;

			foreach (var points in shapedEntity.Shapes)
			{
				var line1 = new LinePath(points[0], points[1]);
				var line2 = new LinePath(points[1], points[2]);
				var line3 = new LinePath(points[2], points[3]);
				var line4 = new LinePath(points[3], points[0]);

				lock (_tree)
				{
					_tree.Insert(line1);
					_tree.Insert(line2);
					_tree.Insert(line3);
					_tree.Insert(line4);
				}

				lock (_reference)
				{
					if (!_reference.ContainsKey(shapedEntity.EntityId))
						_reference[shapedEntity.EntityId] = new List<LinePath>();

					_reference[shapedEntity.EntityId].Add(line1);
					_reference[shapedEntity.EntityId].Add(line2);
					_reference[shapedEntity.EntityId].Add(line3);
					_reference[shapedEntity.EntityId].Add(line4);
				}
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Adds shapes of entity to collision collection.
        /// </summary>
        /// <param name="shapedEntity"></param>
        public void Add(IShapedEntity shapedEntity)
        {
            if (shapedEntity.Shapes == null || shapedEntity.Shapes.Count == 0 || !shapedEntity.IsCollision)
            {
                return;
            }

            foreach (var points in shapedEntity.Shapes)
            {
                var line1 = new LinePath(points[0], points[1]);
                var line2 = new LinePath(points[1], points[2]);
                var line3 = new LinePath(points[2], points[3]);
                var line4 = new LinePath(points[3], points[0]);

                lock (_tree)
                {
                    _tree.Insert(line1);
                    _tree.Insert(line2);
                    _tree.Insert(line3);
                    _tree.Insert(line4);
                }

                lock (_reference)
                {
                    if (!_reference.ContainsKey(shapedEntity.EntityId))
                    {
                        _reference[shapedEntity.EntityId] = new List <LinePath>();
                    }

                    _reference[shapedEntity.EntityId].Add(line1);
                    _reference[shapedEntity.EntityId].Add(line2);
                    _reference[shapedEntity.EntityId].Add(line3);
                    _reference[shapedEntity.EntityId].Add(line4);
                }
            }
        }