예제 #1
0
 protected bool RunCollisionScan()
 {
     // Starts Looping though the entities
     // Counter goes backwards just in case an entity is pulled out mid-loop
     for (int m_index = m_EntityCountainerCount; m_index >= 0; m_index--)
     {
         //Sets the Collision Test Object to be the current object in the list
         m_TestObjectEntity = EntityManager.Instance.DrawableGameObjects[m_index];
         //Exits the loop in the case that the Obtained object is the test object in the container
         if (m_BaseObjectEntity == m_TestObjectEntity)
             return false;
         //Updates the Values for the test Object that the Base Object will compare to
         UpdateTestInformation();
         //Runs Box Collision between Base and Test Object
         m_HasBoxCollided = RunBoxCollision();
         //If True: Runs Box Collision
         //If False: Test Object will go to the next object in the container
         if (m_HasBoxCollided)
         {
             m_HasPixelCollided = RunPixelCollision();
             if (m_HasPixelCollided)
                 return true;
         }
     }
     return false;
 }
예제 #2
0
 public Vector2 GetAILogicPosition(BaseDrawableGameEntity2D thisEntity, BaseDrawableGameEntity2D firstTargetEntity, BaseDrawableGameEntity2D secondTargetEntity)
 {
     //Updates the position of the targets
     m_TargetPositionFirst = firstTargetEntity.Sprite.Position;
     m_TargetPositionSecond = secondTargetEntity.Sprite.Position;
     //Quick way to update the current eneity moving
     m_ObjectPosition = thisEntity.Sprite.Position;
     m_Entity = thisEntity;
     //Checks to see if he is in range of the player
     m_Distance =  Math.Sqrt(((m_TargetPositionSecond.X - m_ObjectPosition.X)*(m_TargetPositionSecond.X - m_ObjectPosition.X)) + ((m_TargetPositionSecond.Y - m_ObjectPosition.Y)*(m_TargetPositionSecond.Y - m_ObjectPosition.Y)));
     //Changes states depending on the distance
     if (m_Distance < m_ObjectRangeRadius)
     {
         m_CurrentState = EntityState.SecondaryObjective;
     }
     else
     {
         m_CurrentState = EntityState.PrimaryObjective; ;
     }
     //logic for the state the entity is currently in
     switch (m_CurrentState)
     {
             //This code targets the house
         case EntityState.PrimaryObjective:
             //TODO
             m_FollowingHero = false;
             m_ObjectPosition.X -= m_ObjectSpeed * 0.5f;
             m_MeetsTarget = Kinetics.Instance.DoesCollideWithObject(m_Entity, firstTargetEntity);
             if (m_MeetsTarget)
             {
                 //put health attack whatever code here
             }
             break;
             //Targets the Player
         case EntityState.SecondaryObjective:
             m_FollowingHero = true;
             //Follow the seconday target which happens to be hero
              if (m_ObjectPosition.X > m_TargetPositionSecond.X)
                 m_ObjectPosition.X -= m_ObjectSpeed * 0.5f;
             else if (m_ObjectPosition.X < m_TargetPositionSecond.X)
                 m_ObjectPosition.X += m_ObjectSpeed * 0.5f;
             if (m_ObjectPosition.Y > m_TargetPositionSecond.Y)
                 m_ObjectPosition.Y -= m_ObjectSpeed * 0.5f;
             else if (m_ObjectPosition.Y < m_TargetPositionSecond.Y)
                 m_ObjectPosition.Y += m_ObjectSpeed * 0.5f;
             if (m_Distance < 1)
             {
                 m_ObjectPosition = m_TargetPositionSecond;
             }
             m_MeetsTarget = Kinetics.Instance.DoesCollideWithObject(m_Entity, secondTargetEntity);
             if (m_MeetsTarget)
             {
                 //put health attack whatever code here
             }
             break;
         default:
             break;
     }
     return m_ObjectPosition;
 }
예제 #3
0
 public bool RunPostitionCollision(BaseDrawableGameEntity2D objectEntity, Vector2 currentPosition, Vector2 futurePosition)
 {
     m_BaseObjectEntity = objectEntity;
     m_BaseObjectPosition = futurePosition;
     //UpdateInformation will set the values from the Obtained entity that is moving
     UpdateBaseInformation();
     //Starts the Collision Checking and returns if anythign has collided
     m_DoesCollide = RunCollisionScan();
     return m_DoesCollide;
 }
예제 #4
0
        public bool RunBoxCillision(BaseDrawableGameEntity2D baseObject, BaseDrawableGameEntity2D TestObject)
        {
            m_BaseSingleRectangle.X = (int)baseObject.Sprite.Position.X;
            m_BaseSingleRectangle.Y = (int)baseObject.Sprite.Position.Y;
            m_BaseSingleRectangle.Width = baseObject.Sprite.Texture.Bounds.Width;
            m_BaseSingleRectangle.Height = baseObject.Sprite.Texture.Bounds.Height;

            m_TestSingleRectangle.X = (int)TestObject.Sprite.Position.X;
            m_TestSingleRectangle.Y = (int)TestObject.Sprite.Position.Y;
            m_TestSingleRectangle.Width = TestObject.Sprite.Texture.Bounds.Width;
            m_TestSingleRectangle.Height = TestObject.Sprite.Texture.Bounds.Height;
            return m_BaseSingleRectangle.Intersects(m_TestSingleRectangle);
        }
예제 #5
0
 public Vector2 MoveObject(BaseDrawableGameEntity2D entityObject, Vector2 futurePosition)
 {
     m_CheckObjectEntity = entityObject;
     m_PreviousPosition = entityObject.Sprite.Position;
     m_NewPosition = futurePosition;
     //If ths position is still the same, skip collision logic
     if (m_PreviousPosition == m_NewPosition)
     {
         m_ValidPosition = m_NewPosition;
         return m_ValidPosition;
     }
     //Run Collision Checking and return if collision occured
     m_HasCollided = ObjectCollision.Instance.RunPostitionCollision(m_CheckObjectEntity, m_PreviousPosition, m_NewPosition);
     //Set the position accordingly if collision occured or not
     if (m_HasCollided)
         m_ValidPosition = m_PreviousPosition;
     else
         m_ValidPosition = m_NewPosition;
     return m_ValidPosition;
 }
예제 #6
0
 public bool DoesCollideWithObject(BaseDrawableGameEntity2D baseNetity, BaseDrawableGameEntity2D toTestEntity)
 {
     return ObjectCollision.Instance.RunBoxCillision(baseNetity, toTestEntity);
 }