コード例 #1
0
        //Searchs for id of the object in collidingObjects
        /// <summary>
        ///  Дава обектите с който GameObject се докосва
        /// </summary>
        /// <param name="gameObject">Обекта който искате да проверите</param>
        /// <returns>Лист от GameObjects с който е докоснат</returns>
        public List<GameObject> GetCollidingObjects(GameObject gameObject)
        {
            var result = new List<GameObject>();

            if(collidingObjects.ContainsKey(gameObject.id))
            {
                result = collidingObjects[gameObject.id];
            }

            return result;
        }
コード例 #2
0
 public GameObject(GameObject obj)
 {
     rectangle = obj.rectangle;
     id = obj.id;
     isStatic = obj.isStatic;
     isDestroyable = obj.isDestroyable;
     isDestroyed = obj.isDestroyed;
     x = obj.x;
     y = obj.y;
     spriteWidth = obj.spriteWidth;
     spriteHeight = obj.spriteHeight;
 }
コード例 #3
0
        /// <summary>
        /// Проверява всеки 1 обект дали граничи с objectToCollideTo
        /// </summary>
        /// <param name="allGameObjects">Всички обекти в сцената/играта</param>
        /// <param name="objectToCollideTo">Обекта на който да се направи проверката</param>
        /// <returns>Лист от обектите който граничат с него. Ако не гранични нито 1 обект листа ще е празен!</returns>
        private List<GameObject> GetCollidingObjects(List<GameObject> allGameObjects, GameObject objectToCollideTo)
        {
            var collidingObjects = new List<GameObject>();

            foreach(GameObject gameObject in allGameObjects)
            {
                if (IsColliding(gameObject.rectangle, objectToCollideTo.rectangle) && gameObject.id != objectToCollideTo.id)
                {
                    collidingObjects.Add(gameObject);
                }
            }

            return collidingObjects;
        }
コード例 #4
0
        //TODO SleepingCollision objects / if object doesnt move n frame dont calculate again
        //TODO GroupedCollision checks if 2 or more objects are static and they are colliding and they form rectangle then make new rectangle containing both
        /// <summary>
        /// Лъч който проверява дали има обекти в дадената посока
        /// </summary>
        /// <param name="x">х от къде да започне</param>
        /// <param name="y">у от къде да започен</param>
        /// <param name="direction">Посока в която да търси</param>
        /// <param name="length">Дължина</param>
        /// <param name="widthOfTheRay">Дебелина на лъча</param>
        /// <returns>Лист от gameObject</returns>
        public List<GameObject> RayCast(int x, int y, Directions direction, int length, int widthOfTheRay)
        {
            List<GameObject> result = new List<GameObject>();

            int width = 0;
            int height = 0;

            switch (direction)
            {
                case Directions.Down:

                    width = widthOfTheRay;
                    height = length;

                    x -= width / 2;

                    break;

                case Directions.Up:

                    width = widthOfTheRay;
                    height = length;

                    y -= length;
                    x -= widthOfTheRay / 2;

                    break;

                case Directions.Left:

                    width = length;
                    x -= length;
                    height = widthOfTheRay;

                    y -= height / 2;

                    break;

                case Directions.Right:

                    width = length;
                    height = widthOfTheRay;

                    y -= height / 2;

                    break;
            }

            Rectangle rayCastLineRect = new Rectangle(x, y, width, height);
            GameObject rayCastObj = new GameObject();

            rayCastObj.rectangle = rayCastLineRect;

            result = GetCollidingObjects(allGameObjects, rayCastObj);

            somethingToDebug.Add(rayCastObj.rectangle);

            return result;
        }