Beispiel #1
0
        public List <T> GetEntitiesAtPos(Vector2f pos)
        {
            if (level == MAX_LEVEL)
            {
                return(entities);
            }

            List <T> returnEntities      = new List <T>();
            List <T> childReturnEntities = new List <T>();

            FloatRect boundsRect = bounds.AsFloatRect();

            if (entities.Count > 0)
            {
                returnEntities = entities;
            }

            if (pos.X > boundsRect.Left + boundsRect.Width / 2.0f && pos.X < boundsRect.Left + boundsRect.Width)
            {
                if (pos.Y > boundsRect.Top + boundsRect.Height / 2.0f && pos.Y < boundsRect.Top + boundsRect.Height)
                {
                    childReturnEntities = pSE.GetEntitiesAtPos(pos);

                    returnEntities.AddRange(childReturnEntities);

                    return(returnEntities);
                }
                else
                if (pos.Y > boundsRect.Top && pos.Y <= boundsRect.Top + boundsRect.Height / 2.0f)
                {
                    childReturnEntities = pNE.GetEntitiesAtPos(pos);
                    returnEntities.AddRange(childReturnEntities);
                    return(returnEntities);
                }
            }
            else
            if (pos.X > boundsRect.Left && pos.X <= boundsRect.Left + boundsRect.Width / 2.0f)
            {
                if (pos.Y > boundsRect.Top + boundsRect.Height / 2.0f && pos.Y < boundsRect.Top + boundsRect.Height)
                {
                    childReturnEntities = pSW.GetEntitiesAtPos(pos);
                    returnEntities.AddRange(childReturnEntities);
                    return(returnEntities);
                }
                else
                if (pos.Y > boundsRect.Top && pos.Y <= boundsRect.Top + boundsRect.Height / 2.0f)
                {
                    childReturnEntities = pNW.GetEntitiesAtPos(pos);
                    returnEntities.AddRange(childReturnEntities);
                    return(returnEntities);
                }
            }

            return(returnEntities);
        }
Beispiel #2
0
        public void checkBulletVsEntityCollisions(float step_time)
        {
            List <cMonster> collisionMonsters = new List <cMonster>();

            for (int b = 0; b < bullets.Count; b++)
            {
                Vector2f intersection = new Vector2f(0.0f, 0.0f);

                collisionMonsters = treeMonsters.GetEntitiesAtPos(bullets[b].Position);


                int monster = getIndexOfClosestMonsterColliding(collisionMonsters, bullets[b], bullets[b].Position, step_time);

                if (monster > -1)
                {
                    cCollision.resolveMonsterVsBullet(collisionMonsters[monster], bullets[b], intersection);
                }


                /*
                 * int m = 0;
                 * while (m < collisionMonsters.Count
                 *      // && !cSatCollision.checkAndResolve(bullets[b], collisionMonsters[m], step_time, false)
                 *      //!cCollision.testBulletVsEntity(bullets[b].Position, bullets[b].LastPosition, collisionMonsters[m].Bounds, ref intersection)
                 *      )
                 * {
                 *  if (bullets[b].Alive == false) break;
                 *
                 *  if (!collisionMonsters[m].Disabled && cSatCollision.checkAndResolve(bullets[b], collisionMonsters[m], step_time, false))
                 *  {
                 *      cCollision.resolveMonsterVsBullet(collisionMonsters[m], bullets[b], intersection);
                 *  }
                 *  m++;
                 * }
                 */

                /*
                 * if (m < collisionMonsters.Count)
                 * {
                 *  cCollision.resolveMonsterVsBullet(collisionMonsters[m], bullets[b], intersection);
                 * }
                 */
            }
        }