Beispiel #1
0
        public static bool CheckCollision(Player p, Enemy e, DimensionalManager dm)
        {
            int activeDimensions = dm.GetNumberOfActiveDimensions();

            Position playerPostion = p.getPosition();
            Position enemyPosition = e.GetPosition();

            float playerWidth = p.getRadius();
            float enemyRadius = e.GetWidth();

            float totalDistance = 0.0f;

            for (int i = 0; i < activeDimensions; ++i)
            {
                float distance = Math.Abs(playerPostion.GetPosition(i) - enemyPosition.GetPosition(i));
                totalDistance += (distance * distance);

            }

            return totalDistance < ((playerWidth + enemyRadius) * (playerWidth + enemyRadius));
        }
Beispiel #2
0
        private float GetSize(Enemy enemy)
        {
            float totalDistance = 0;
            for (int i = 0; i <= dimensionalManager.GetNumberOfActiveDimensions(); ++i)
            {
                //We don't look in our plane, but if this plane is currently 1D, then the y axis also contributes to size like any other perp dim
                if (i == xDimension || (i == yDimension && render2d))
                {
                    continue; //we don't look at this plane as we are this plane!
                }

                //Does the sphere intersect with this plane eg in axis i (perpendicular to this plane) is the
                //position of the enemy in i, +- its width, still intersecting with this plane
                //if it is not then the size is 0 (eg don't draw)
                float dimOffset = Math.Abs(planePosition.GetPosition(i) - enemy.GetPosition().GetPosition(i));
                if (dimOffset >= enemy.GetWidth())
                {
                    return 0.0f;
                }
                else
                {
                    totalDistance += dimOffset * dimOffset;
                }
            }

            //Otherwise will be some deg 2 polynomial based on how far away it is in each dimension

            float radius =  (float)Math.Sqrt(enemy.GetWidth() * enemy.GetWidth() - totalDistance);
            return radius;
        }