Ejemplo n.º 1
0
        /* Player is moving, bomb is moving */
        private bool HandlePlayerMovingBombMovingCollision(Bomb bomb)
        {
            Debug.Assert(IsMoving());
            Debug.Assert(bomb.IsMoving());

            bool hasKick = HasKick();

            if (direction == Util.Opposite(bomb.direction)) // moving in opposite directions
            {
                if (IsMovingTowards(bomb))
                {
                    if (CheckCell2BoundsCollision(bomb) || CheckBounds2CellCollision(bomb))
                    {
                        if (hasKick)
                        {
                            // move bomb out of player`s cell
                            bomb.MoveOutOfCell(this);

                            // kick in the moving direction
                            TryKick(bomb);

                            return true;
                        }

                        // treat player as an obstacle
                        bomb.HandleObstacleCollistion(this);

                        // make sure player is out of bomb`s cell
                        MoveOutOfCell(bomb);

                        return true;
                    }
                }
            }
            else if (direction == bomb.direction) // moving in the same direction
            {
                if (bomb.IsMovingTowards(this)) // bomb`s following player?
                {
                    if (bomb.CheckBounds2CellCollision(this)) // bomb bounds should collide player`s cell
                    {
                        // treat player as an obstacle
                        bomb.HandleObstacleCollistion(this);

                        return true;
                    }
                }
                else if (IsMovingTowards(bomb)) // player`s following bomb
                {
                    if (CheckCell2BoundsCollision(bomb) || CheckBounds2CellCollision(bomb))
                    {
                        if (hasKick)
                        {
                            // kick in the moving direction
                            TryKick(bomb);

                            return true;
                        }

                        // make sure player is out of bomb`s cell
                        MoveOutOfCell(bomb);

                        return true;
                    }
                }
            }
            else // player and bomb move in perpendicular directions
            {
                if (CheckCell2CellCollision(bomb))
                {
                    return false;
                }

                if (CheckBounds2CellCollision(bomb) && CheckBounds2BoundsCollision(bomb))
                {
                    if (IsMovingTowards(bomb))
                    {
                        if (hasKick)
                        {
                            TryKick(bomb);
                        }

                        MoveOutOfCell(bomb);

                        return true;
                    }
                }

                if (bomb.CheckBounds2BoundsCollision(this))
                {
                    if (bomb.IsMovingTowards(this))
                    {
                        bomb.HandleObstacleCollistion(this);
                        return true;
                    }
                }
            }

            return false;
        }