Exemplo n.º 1
0
 public Structure(CollisionBody collision, StructureData data) : base(collision)
 {
     this.Data = data;
     if (collision.Shape == CollisionBody.ShapeType.Rectangle)
     {
         RectangleBody rect = ((RectangleBody)this.Collision);
         rect.Size = new Vector2(collision.Region().Width *data.Width, collision.Region().Height *data.Height);
     }
 }
Exemplo n.º 2
0
        public Dictionary <uint, CollisionBody> GetPotentialCollisions(CollisionBody toCheck)
        {
            int xMin = 0;
            int xMax = 0;
            int yMin = 0;
            int yMax = 0;

            if (toCheck.Shape == CollisionBody.ShapeType.Circle)
            {
                CircleBody body = (CircleBody)toCheck;
                xMin = ((int)(Math.Max(body.Position.X - body.Radius / 2, 0)) / tileSize);
                xMax = (int)(Math.Min(body.Position.X + body.Radius / 2, maxWidth - 1)) / tileSize;
                yMin = ((int)(Math.Max(body.Position.Y - body.Radius / 2, 0)) / tileSize);
                yMax = (int)(Math.Min(body.Position.Y + body.Radius / 2, maxHeight - 1)) / tileSize;
            }
            else if (toCheck.Shape == CollisionBody.ShapeType.Rectangle)
            {
                RectangleBody body = (RectangleBody)toCheck;
                xMin = ((int)(Math.Max(body.Position.X, 0)) / tileSize);
                xMax = (int)(Math.Min(body.Position.X + body.Size.X, 49)) / tileSize;
                yMin = ((int)(Math.Max(body.Position.Y, 0)) / tileSize);
                yMax = (int)(Math.Min(body.Position.Y + body.Size.Y, 49)) / tileSize;
            }

            // Get every possible CollisionBody
            Dictionary <uint, CollisionBody> potentials = new Dictionary <uint, CollisionBody>();

            for (int y = yMin; y <= yMax; y++)
            {
                for (int x = xMin; x <= xMax; x++)
                {
                    foreach (CollisionBody c in Tiles[y * columns + x].Data.Values)
                    {
                        if (!potentials.ContainsKey(c.ID))
                        {
                            potentials.Add(c.ID, c);
                        }
                    }
                }
            }

            return(potentials);
        }
Exemplo n.º 3
0
        private List <PhysicsGridTile> GetCoveredTiles(CollisionBody body)
        {
            int xMin = 0;
            int xMax = 0;
            int yMin = 0;
            int yMax = 0;

            if (body.Shape == CollisionBody.ShapeType.Circle)
            {
                CircleBody circBody = (CircleBody)body;
                xMin = ((int)(Math.Max(circBody.Position.X - circBody.Radius / 2, 0)) / tileSize);
                xMax = (int)(Math.Min(circBody.Position.X + circBody.Radius / 2, maxWidth - 1)) / tileSize;
                yMin = ((int)(Math.Max(circBody.Position.Y - circBody.Radius / 2, 0)) / tileSize);
                yMax = (int)(Math.Min(circBody.Position.Y + circBody.Radius / 2, maxHeight - 1)) / tileSize;
            }
            else if (body.Shape == CollisionBody.ShapeType.Rectangle)
            {
                RectangleBody rectBody = (RectangleBody)body;
                xMin = ((int)(Math.Max(rectBody.Position.X, 0)) / tileSize);
                xMax = (int)(Math.Min(rectBody.Position.X + rectBody.Size.X, maxWidth - 1)) / tileSize;
                yMin = ((int)(Math.Max(rectBody.Position.Y, 0)) / tileSize);
                yMax = (int)(Math.Min(rectBody.Position.Y + rectBody.Size.Y, maxWidth - 1)) / tileSize;
            }

            List <PhysicsGridTile> toReturn = new List <PhysicsGridTile>();

            for (int y = yMin; y <= yMax; y++)
            {
                for (int x = xMin; x <= xMax; x++)
                {
                    toReturn.Add(Tiles[y * columns + x]);
                }
            }

            return(toReturn);
        }
Exemplo n.º 4
0
 public ElasticObject(CollisionBody collision) : base(collision)
 {
 }
Exemplo n.º 5
0
 public void Remove(CollisionBody body)
 {
     Data.Remove(body.ID);
 }
Exemplo n.º 6
0
 public void Add(CollisionBody body)
 {
     Data.Add(body.ID, body);
 }