コード例 #1
0
        public BoxCollider(float _x, float _y, float _width, float _height)
        {
            //
            // Special BoxCollider that is stationary and will not move
            // likke a building or card pile
            //
            Rectangle _boxToCollide = new Rectangle(_x, _y, _width, _height);

            OriginLocal  = new Vector2(_x / 2, _y / 2);
            boxContainer = new Rectangle(_boxToCollide.x,
                                         _boxToCollide.y,
                                         _boxToCollide.width,
                                         _boxToCollide.height);


            CollisionBox   = new BoxAABB();
            boxContainer.x = (_boxToCollide.x - OriginLocal.X) + 10;
            boxContainer.y = (_boxToCollide.y - OriginLocal.Y / 2) + 10;
            BoxPoints      = new List <Vector2>();
            Vector2 topL = new Vector2(boxContainer.x, boxContainer.y);
            Vector2 topR = new Vector2(topL.X + boxContainer.width, topL.Y);
            Vector2 botL = new Vector2(topL.X, topL.Y + boxContainer.height);
            Vector2 botR = new Vector2(topR.X, topR.Y + boxContainer.height);

            BoxPoints.Add(topL);
            BoxPoints.Add(botL);
            BoxPoints.Add(botR);
            BoxPoints.Add(topR);
            //
            // Find the min & max vectors for collision
            //
            CollisionBox.Fit(BoxPoints);                            //updates the position of this collider
            RenderLayer   = Global.BOXCOLLIDER_LAYER;               //make sure this is drawn first
            fixedCollider = true;
        }
コード例 #2
0
 public CollisionResult(bool _collided = false)
 {
     Collided      = false;
     CompEntity    = null;
     BoxContainer  = new BoxAABB();
     CollisionArea = new Rectangle(0, 0, 0, 0);
 }
コード例 #3
0
        public static bool CollidedWithBox(Entity entity, out CollisionResult _collisionResult)
        {
            //
            // currently not used
            //
            _collisionResult = new CollisionResult();
            //
            // Find the Entity in question, if not in database then no collision
            //
            if (!ColliderCollection.ContainsKey(entity))
            {
                return(false);
            }
            //
            // Find out what kind of collider entity has?
            //
            BoxCollider bx = entity.Get <BoxCollider>();
            //CircleCollider cx = entity.Get<CircleCollider>();

            BoxAABB boxA = bx.CollisionBox;

            //Vector2 boxA = new Vector2(bx.CollisionBox.x, bx.CollisionBox.y);
            //
            // Find entity and ask

            //
            // Test collision with other "registered" BoxColliders
            //
            foreach (KeyValuePair <Entity, int> entry in ColliderCollection)
            {
                if (entry.Key == entity)
                {
                    continue;
                }
                if (entry.Value != (int)CollidreShape.Box)
                {
                    continue;
                }

                Entity ent = entry.Key;
                bx = ent.Get <BoxCollider>();
                if (bx == null)                     //incase collider was removed
                {
                    return(false);
                }

                if (boxA.Overlaps(bx.CollisionBox))
                {
                    _collisionResult.CompEntity = entry.Key;
                    _collisionResult.Collided   = true;

                    //_collisionResult.BoxContainer = entry.Value;
                    //_collisionResult.CollisionArea = Raylib.GetCollisionRec(boxA, entry.Value);
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Box to check for collisions. Box goes around the image (using scales)
        /// </summary>
        /// <param name="boxToCollide"></param>
        //public BoxCollider(Rectangle _boxToCollide)
        //      {
        //	theCenter = new Vector2(_boxToCollide.width * 0.5f, _boxToCollide.height * 0.5f);
        //	boxContainer = new Rectangle(_boxToCollide.x - theCenter.X,
        //								 _boxToCollide.y - theCenter.Y,
        //								 _boxToCollide.width,
        //								 _boxToCollide.height);


        //	CollisionBox = new BoxAABB();
        //	setSceneColliders = false;
        //	RenderLayer = Global.BOXCOLLIDER_LAYER;				//make sure this is drawn first
        //}
        public BoxCollider(float _width, float _height)
        {
            Rectangle _boxToCollide = new Rectangle(0, 0, _width, _height);

            OriginLocal = new Vector2(_boxToCollide.width * 0.5f, _boxToCollide.height * 0.5f);

            boxContainer = new Rectangle(_boxToCollide.x - OriginLocal.X,
                                         _boxToCollide.y - OriginLocal.Y,
                                         _boxToCollide.width,
                                         _boxToCollide.height);


            CollisionBox  = new BoxAABB();
            RenderLayer   = Global.BOXCOLLIDER_LAYER;                       //make sure this is drawn first
            fixedCollider = false;
        }
コード例 #5
0
 //
 // Collision box check
 //
 public bool Overlaps(BoxAABB otherCollider)
 {
     return(!(max.X < otherCollider.min.X || max.Y < otherCollider.min.Y || min.X > otherCollider.max.X || min.Y > otherCollider.max.Y));
 }
コード例 #6
0
        //
        // Circle check with collision box
        //
        public bool Overlaps(BoxAABB aabb)
        {
            Vector2 diff = aabb.ClosestPoint(Center) - Center;

            return(DotProduct(diff, diff) <= (Radius * Radius));
        }