Example #1
0
        public SideOfObstacle WhereCollide(GameObjects go)
        {
            if (this.CheckCollision(go))
            {
                //if (prev == SideOfObstacle.Top)
                //{

                /*for (int i = go.HitBox.X; i < go.HitBox.X + go.HitBox.Width; i++)
                 * {
                 *  if (this.hitBox.Contains(i, go.HitBox.Y + go.HitBox.Height))
                 *  {
                 *      state = SideOfObstacle.Top;
                 *      Console.WriteLine("Hit Top");
                 *      return state;
                 *  }
                 * }
                 * for (int i = go.HitBox.X + 2; i < go.HitBox.X + (go.HitBox.Width - 2); i++)
                 * {
                 *  if (this.hitBox.Contains(i, go.HitBox.Y))
                 *  {
                 *      state = SideOfObstacle.Bottom;
                 *      return state;
                 *  }
                 *
                 * }*/
                for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                {
                    if (this.hitBox.Contains(go.HitBox.X, i))
                    {
                        state = SideOfObstacle.Right;
                        return(state);
                    }
                }
                for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                {
                    if (this.hitBox.Contains(go.HitBox.X + go.HitBox.Width, i))
                    {
                        state = SideOfObstacle.Left;
                        return(state);
                    }
                }
                //}


                /*else
                 * {
                 *  for (int i = go.HitBox.X + 2; i < go.HitBox.X + (go.HitBox.Width - 2); i++)
                 *  {
                 *      if (this.hitBox.Contains(i, go.HitBox.Y + go.HitBox.Height))
                 *      {
                 *          state = SideOfObstacle.Top;
                 *          Console.WriteLine("Hit Top");
                 *          return state;
                 *      }
                 *  }
                 *  for (int i = go.HitBox.X + 2; i < go.HitBox.X + (go.HitBox.Width - 2); i++)
                 *  {
                 *      if (this.hitBox.Contains(i, go.HitBox.Y))
                 *      {
                 *          state = SideOfObstacle.Bottom;
                 *          return state;
                 *      }
                 *
                 *  }
                 *  for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                 *  {
                 *      if (this.hitBox.Contains(go.HitBox.X, i))
                 *      {
                 *          state = SideOfObstacle.Right;
                 *          return state;
                 *      }
                 *
                 *  }
                 *  for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                 *  {
                 *      if (this.hitBox.Contains(go.HitBox.X + go.HitBox.Width, i))
                 *      {
                 *          state = SideOfObstacle.Left;
                 *          return state;
                 *      }
                 *
                 *  }
                 * }*/

                state = SideOfObstacle.NoCollide;
                return(state);
            }
            else
            {
                state = SideOfObstacle.NoCollide;
                return(state);
            }
        }
Example #2
0
        public SideOfObstacle WhereCollide(GameObjects go)
        {
            if (this.CheckCollision(go))
            {
                if (prev == SideOfObstacle.Top)
                {
                    for (int i = go.HitBox.X; i < go.HitBox.X + go.HitBox.Width; i++)
                    {
                        if (this.hitBox.Contains(i, go.HitBox.Y + go.HitBox.Height))
                        {
                            state = SideOfObstacle.Top;
                            Console.WriteLine("Hit Top");
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.X + 20; i < go.HitBox.X + (go.HitBox.Width - 20); i++)
                    {
                        if (this.hitBox.Contains(i, go.HitBox.Y))
                        {
                            state = SideOfObstacle.Bottom;
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                    {
                        if (this.hitBox.Contains(go.HitBox.X, i))
                        {
                            state = SideOfObstacle.Right;
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                    {
                        if (this.hitBox.Contains(go.HitBox.X + go.HitBox.Width, i))
                        {
                            state = SideOfObstacle.Left;
                            return(state);
                        }
                    }
                }


                else
                {
                    for (int i = go.HitBox.X + 20; i < go.HitBox.X + (go.HitBox.Width - 20); i++)
                    {
                        if (this.hitBox.Contains(i, go.HitBox.Y + go.HitBox.Height))
                        {
                            state = SideOfObstacle.Top;
                            Console.WriteLine("Hit Top");
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.X + 20; i < go.HitBox.X + (go.HitBox.Width - 20); i++)
                    {
                        if (this.hitBox.Contains(i, go.HitBox.Y))
                        {
                            state = SideOfObstacle.Bottom;
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                    {
                        if (this.hitBox.Contains(go.HitBox.X, i))
                        {
                            state = SideOfObstacle.Right;
                            return(state);
                        }
                    }
                    for (int i = go.HitBox.Y; i < go.HitBox.Y + go.HitBox.Height; i++)
                    {
                        if (this.hitBox.Contains(go.HitBox.X + go.HitBox.Width, i))
                        {
                            state = SideOfObstacle.Left;
                            return(state);
                        }
                    }
                }

                state = SideOfObstacle.NoCollide;
                return(state);
            }
            else
            {
                state = SideOfObstacle.NoCollide;
                return(state);
            }
        }