Пример #1
0
        //closest colliding wall to a bomb within a bounding box
        private float ClosestCollidingWallOrBlock(Bomb b, BoundingBox bB)
        {
            float max = (float)b.ExplosionLength;
            float temp;

            for (int i = 0; i < m_Walls.Count; i++)
            {
                if (bB.Intersects(m_Walls[i].BoundingBox))
                {

                    temp = Vector3.Distance(b.Position, m_Walls[i].Position);
                    if (temp < max)
                    {
                        max = temp;
                    }
                }
            }

            for (int i = 0; i < m_Blocks.Count; i++)
            {
                if (bB.Intersects(m_Blocks[i].BoundingBox))
                {

                    temp = Vector3.Distance(b.Position, m_Blocks[i].Position);
                    if (temp < max)
                    {
                        max = temp;
                    }
                }
            }

            return max;
        }
Пример #2
0
        /*Checks for objects within explosion range
         *(dictated by the closest colliding wall to the bombs original explosion range)
         */
        private List<GameEntity> ExplosionCollision(Bomb b, BoundingBox bB, float explosionLength)
        {
            List<GameEntity> affectedByExplosion = new List<GameEntity>();

            float temp;

            //does bomb hit player?
            if (bB.Intersects(m_Player.BoundingSphere))
            {
                affectedByExplosion.Add(m_Player);
            }

            #region Blocks in explosion range
            for (int i = 0; i < m_Blocks.Count; i++)
            {
                if (bB.Intersects(m_Blocks[i].BoundingBox))
                {
                    temp = Vector3.Distance(b.Position, m_Blocks[i].Position);
                    if (temp <= explosionLength)
                    {
                        affectedByExplosion.Add(m_Blocks[i]);
                    }
                }
            }
            #endregion

            #region Agents in explosion range
            for (int i = 0; i < m_Agents.Count; i++)
            {
                if (bB.Intersects(m_Agents[i].BoundingSphere))
                {
                    temp = Vector3.Distance(b.Position, m_Agents[i].Position);
                    if (temp <= explosionLength)
                    {
                        affectedByExplosion.Add(m_Agents[i]);
                    }
                }
            }
            #endregion

            #region Bombs in explosion range
            for (int i = 0; i < m_Bombs.Count; i++)
            {
                if (bB.Intersects(m_Bombs[i].BoundingSphere))
                {
                    temp = Vector3.Distance(b.Position, m_Bombs[i].Position);
                    if (temp <= explosionLength)
                    {
                        affectedByExplosion.Add(m_Bombs[i]);
                    }
                }
            }
            #endregion

            return affectedByExplosion;
        }
Пример #3
0
        public List<GameEntity> explosion(Bomb b)
        {
            List<GameEntity> affectedByExplosion = new List<GameEntity>();

            float x = b.Position.X;
            float y = b.Position.Y;
            float z = b.Position.Z;
            float halfR = (float)(b.Radius*.5);
            float explosionLength = (float)(b.ExplosionLength);
            float tempLength = 0;

            //add an explosion at bomb center, explosion cube ☼
            m_Explosions.Add(b.Position);

            BoundingBox up = BoundingBox.CreateFromPoints(new Vector3[8]
            {
                new Vector3(x+halfR,y,z),
                new Vector3(x+halfR,y,z),
                new Vector3(x-halfR,y,z),
                new Vector3(x-halfR,y,z),
                new Vector3(x+halfR,y,z+explosionLength),
                new Vector3(x+halfR,y,z+explosionLength),
                new Vector3(x-halfR,y,z+explosionLength),
                new Vector3(x-halfR,y,z+explosionLength),
            });

            //this block and others like it do the following
            //1. determine the farthest the explosion can go
            //2. add that distance in referrence to the bombs to a list of positions to have an explosion model on
            //3. calls a function that returns a list of objects affected by explosion to bigger list of those affected
            tempLength = ClosestCollidingWallOrBlock(b, up);
            m_Explosions.Add(b.Position + new Vector3(0,0,-tempLength));
            affectedByExplosion.AddRange(ExplosionCollision(b, up, tempLength));

            BoundingBox down = BoundingBox.CreateFromPoints(new Vector3[8]
            {
                new Vector3(x+halfR,y,z),
                new Vector3(x+halfR,y,z),
                new Vector3(x-halfR,y,z),
                new Vector3(x-halfR,y,z),
                new Vector3(x+halfR,y,z-explosionLength),
                new Vector3(x+halfR,y,z-explosionLength),
                new Vector3(x-halfR,y,z-explosionLength),
                new Vector3(x-halfR,y,z-explosionLength),
            });

            tempLength = ClosestCollidingWallOrBlock(b, down);
            m_Explosions.Add(b.Position + new Vector3(0,0,tempLength));
            affectedByExplosion.AddRange(ExplosionCollision(b, down, tempLength));

            BoundingBox left = BoundingBox.CreateFromPoints(new Vector3[8]
            {
                new Vector3(x,y,z+halfR),
                new Vector3(x,y,z+halfR),
                new Vector3(x,y,z-halfR),
                new Vector3(x,y,z-halfR),
                new Vector3(x-explosionLength,y,z+halfR),
                new Vector3(x-explosionLength,y,z+halfR),
                new Vector3(x-explosionLength,y,z-halfR),
                new Vector3(x-explosionLength,y,z-halfR),
            });

            tempLength = ClosestCollidingWallOrBlock(b, left);
            m_Explosions.Add(b.Position + new Vector3(-tempLength,0,0));
            affectedByExplosion.AddRange(ExplosionCollision(b, left, tempLength));

            BoundingBox right = BoundingBox.CreateFromPoints(new Vector3[8]
            {
                new Vector3(x,y,z+halfR),
                new Vector3(x,y,z+halfR),
                new Vector3(x,y,z-halfR),
                new Vector3(x,y,z-halfR),
                new Vector3(x+explosionLength,y,z+halfR),
                new Vector3(x+explosionLength,y,z+halfR),
                new Vector3(x+explosionLength,y,z-halfR),
                new Vector3(x+explosionLength,y,z-halfR),
            });

            tempLength = ClosestCollidingWallOrBlock(b, right);
            m_Explosions.Add(b.Position + new Vector3(tempLength,0,0));
            affectedByExplosion.AddRange(ExplosionCollision(b, right, tempLength));

            return affectedByExplosion;

            //BoundingBox.CreateFromPoints();
        }