Beispiel #1
0
        private void RigidCollide()
        {
            //RIGIDCOLLIDE

            if (_rigidColliders.Count > 0)
            {
                for (int i = 0; i <= (_rigidColliders.Count - 1); i++)
                {
                    //sets a new IRigidCollider to the current RCollider being itterated on
                    IRigidCollide tempRCol = _rigidColliders[i];

                    //create variables for the min and max value of x and y of the tempRCol
                    Vector2 min1 = tempRCol.ColPos;

                    Vector2 max1 = new Vector2(min1.X + tempRCol.Width, min1.Y + tempRCol.Height);

                    //this creates an int that will be used to chheck against other RColliders. 1 is added so that it will never check against itself or other R colliders that have already
                    //run through the loop to revent multiple collisions being called by the same 2 objects

                    int checkInt = i + 1;

                    for (int ii = checkInt; ii <= (_rigidColliders.Count - 1); ii++)
                    {
                        //creates a new IRigid for the collidabel being checked against
                        IRigidCollide checkRCol = _rigidColliders[ii];

                        //create variables for the min and max value of x and y of the checkRCol
                        Vector2 min2 = checkRCol.ColPos;

                        Vector2 max2 = new Vector2(min2.X + checkRCol.Width, min2.Y + checkRCol.Height);

                        //call the Axis alinged bounding box test
                        if (AABBCollision(min1, max1, min2, max2))
                        {
                            //The collision mgr, needs to identify by how much the objects have collided
                            //declare a vector to send the two objects once their collision magnitude has been calculated
                            Vector2 collMag = new Vector2();

                            //first determine the magnituted if the object overlap on the x axis

                            collMag.X = (Math.Min(Math.Abs(min1.X - max2.X), Math.Abs(max1.X - min2.X)));

                            collMag.Y = (Math.Min(Math.Abs(min1.Y - max2.Y), Math.Abs(max1.Y - min2.Y)));

                            collMag.X = collMag.X * -1;

                            collMag.Y = collMag.Y * -1;
                            //CollMag is then sent to both objects along with the posiiton of the oposite object

                            //the first collider
                            tempRCol.Collide(collMag, min2);
                            //the second collider
                            checkRCol.Collide(collMag, min1);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        //AddCollider - This method will add a collidable object to the CollisionMgr's list of Collidables
        //It will take in an IEntity and check itself if the IEntity is a collidable and then store it in its list


        public void AddCollider(IEntity pEntity)
        {
            //create a temporary IEntity to store pEntity
            IEntity tempEnt = pEntity;

            //Check if tempEnt is an ICollidable

            if (tempEnt is ICollidable)
            {
                //this will retrive the ID of the tempEnt, so that it can be stored in the ICollideable
                int tempID = tempEnt.eID;

                //this casts the tempEnt as a ICollidable
                ICollidable newCollidable = (ICollidable)tempEnt;

                //this initializes the ICollidable
                newCollidable.Initialize(tempID);

                //the new Collidable is stored in the '_mCollidersArray'
                _mColliders.Add(newCollidable);


                //this checks if the newCollidable is a Rigid Collider
                if (newCollidable is IRigidCollide)
                {
                    IRigidCollide newRigid = (IRigidCollide)newCollidable;
                    //this adds it to the _rigidCollide list
                    _rigidColliders.Add(newRigid);
                }

                //thi checks if the new Collidable is a IPlayCollider
                if (newCollidable is IPlayCollide)
                {
                    //this casts new collideable as a Player collider
                    IPlayCollide newPlayCollide = (IPlayCollide)newCollidable;

                    //this adds it to the _playCollide list
                    _playCollide.Add(newPlayCollide);
                }

                //this checks if the new Collider is an instanc eof IPlayer
                if (newCollidable is IPlayer)
                {
                    //this cast the new collider as a IPlayer
                    IPlayer newPlayer = (IPlayer)newCollidable;

                    //this adds it to the player list
                    _mPlayers.Add(newPlayer);
                }
            }
        }