Esempio n. 1
0
 public static void CopyMethod(EntitySquares dst, EntitySquares src)
 {
     dst.squares.Clear();
     //Won't ever use this, because CopyMethod will only be used for AddEnt, and it will never start with any squares.
     //for (int i = 0, max = src.squares.Count; i < max; ++i)
     //{
     //    dst.squares.Add(src.squares[i]);
     //}
     dst.entity = src.entity;
 }
Esempio n. 2
0
        public CollisionManager()
        {
            sqrMan = new SquareManager();
            entsqrs = new RecycleArray<EntitySquares>(EntitySquares.CopyMethod, EntitySquares.CreateCopyMethod);
            entsqrs.SetDataMode(false);
            addedEntSqrTemp = new EntitySquares();
            addedECITemp = new EntityCollisionInfo();

            collideAgainstEnts = new List<Entity>();
            collideAgainstBlocks = new List<Block>();

            collideEntsInfo = new RecycleArray<EntityCollisionInfo>(EntityCollisionInfo.CopyMethod, EntityCollisionInfo.CreateCopyMethod);
            collideEntsInfo.SetDataMode(false);
            collideBlocksInfo = new RecycleArray<EntityCollisionInfo>(EntityCollisionInfo.CopyMethod, EntityCollisionInfo.CreateCopyMethod);
            collideBlocksInfo.SetDataMode(false);

            colliderList = new List<Collider>();
        }
Esempio n. 3
0
 public static EntitySquares CreateCopyMethod(EntitySquares src)
 {
     EntitySquares created = new EntitySquares();
     CopyMethod(created, src);
     return created;
 }
Esempio n. 4
0
 private void DoCollisions(EntitySquares e)
 {
     Collider entityCollider = e.entity.GetCollider();
     foreach (Entity e2 in collideAgainstEnts)
     {
         float collideTime = e2.GetCollider().DoCollide(entityCollider);
         if (EntityEntityCollision(e2.GetCollider(), entityCollider))
         {
             addedECITemp.collideTime = collideTime;
             addedECITemp.pushOut = e2.GetCollider().GetPushOut();
             addedECITemp.collideEnt = e2;
             collideEntsInfo.Add(addedECITemp);
             addedECITemp.collideBlock = null;
             addedECITemp.collideEnt = null;
             addedECITemp.collideTime = 1;
             addedECITemp.pushOut = Vector2.Zero;
         }
     }
     entityCollider = e.entity.GetCollider(); //unknown why this fixes weird bug
     foreach (Block b in collideAgainstBlocks)
     {
         float collideTime = b.GetCollider().DoCollide(entityCollider);
         if (collideTime < 1)
         {
             addedECITemp.collideTime = collideTime;
             addedECITemp.pushOut = b.GetCollider().GetPushOut();
             addedECITemp.collideBlock = b;
             collideBlocksInfo.Add(addedECITemp);
             addedECITemp.collideBlock = null;
             addedECITemp.collideEnt = null;
             addedECITemp.collideTime = 1;
             addedECITemp.pushOut = Vector2.Zero;
         }
     }
 }
Esempio n. 5
0
        //////////////////////////////////////////////////////
        //  Add other entities and block occupying the same square
        //////////////////////////////////////////////////////
        private void AddToCollideAgainst(EntitySquares e)
        {
            //
            //  for each square touching to the entity...
            //
            for (int j = 0, maxSqrs = e.squares.Count; j < maxSqrs; ++j)
            {
                Square sqr = e.squares.ElementAt(j);

                //first square doesnt need to check for duplicates
                //any more squares than 1, it needs to check for duplicates

                //          First square
                if (j == 0)
                {
                    foreach (Block b in sqr.blocks)
                    {
                        collideAgainstBlocks.Add(b);
                    }
                    foreach (Entity collideEntity in sqr.ents)
                    {
                        collideAgainstEnts.Add(collideEntity);
                    }
                }
                else
                //      All squares after the first
                {
                    foreach (Block b in sqr.blocks)
                    {
                        //add if not duplicate
                        if (!collideAgainstBlocks.Contains(b))
                            collideAgainstBlocks.Add(b);
                    }
                    foreach (Entity collideEntity in sqr.ents)
                    {
                        //add if not duplicate
                        if (!collideAgainstEnts.Contains(collideEntity))
                            collideAgainstEnts.Add(collideEntity);
                    }
                }

                //remove references to itself from the squares it references.
                //this prevents collisions from being performed twice, once when a->b, another when b->a
                sqr.ents.Remove(e.entity);
            }
        }