Exemple #1
0
    public bool CheckCollision()
    {
        //Checks if there is a collision and enacts the collision process if there is one

        //gets position of active piece
        Vector3 activePosition = GameData.GetActivePiece().transform.position;

        //Position of the starting tile
        Vector3 startPosition = GetStartTile().transform.position;

        //collisions should not happen at the starting position
        if (activePosition == startPosition)
        {
            return(false);
        }


        //check each piece for a collision
        foreach (Player player in players)
        {
            if (!player.Equals(GameData.GetCurrPlayer()))
            {
                foreach (Character piece in player.GetPieces())
                {
                    if (piece.GetCurrTile() == GameData.GetActivePiece().GetCurrTile() && piece.GetCurrTile() != GetStartTile() && !piece.Equals(GetFinishTile()))
                    {
                        //determine smaller piece (active piece wins in case of tie)
                        Character smallerPiece = null;
                        if (piece.GetSize() > GameData.GetActivePiece().GetSize())
                        {
                            smallerPiece = GameData.GetActivePiece();
                        }
                        else
                        {
                            smallerPiece = piece;
                        }

                        //do the collision
                        GameGUI.ShowCollisionScreen(smallerPiece, player);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }