示例#1
0
    //checks if a grid space is not occupied. Ignores the gameObject it is called from
    //checks three things: enemy collision, player collision, and wall collision.
    //client of method can also prevent the method from automatically shifting hosts
    public bool IsValidMovement(int newX, int newY, bool isShiftHost)
    {
        //check enemy collisions
        GameObject enemyCollider = CheckArrayCollision(manager.GetEnemyList(), newX, newY);

        //if collides with Enemy, shift hosts
        if (enemyCollider != null)
        {
            if (manager.playerLivesLeft == 1 && isShiftHost)
            {
                bool hasMask = IsGermaphobe(enemyCollider);
                if ((!hasMask) || (hasMask && (!MaskFacingCorrectWay(enemyCollider))))
                {
                    enemyCollider.GetComponent <EntityTag>().GivePlayerControl();
                }
            }
            return(false);
        }

        //check dead people collision
        GameObject deadCollider = CheckArrayCollision(manager.GetDeadList(), newX, newY);

        if (deadCollider != null)
        {
            return(false);
        }

        //check player collisions

        if (CheckArrayCollision(manager.GetPlayer(), newX, newY) != null)
        {
            return(false);
        }

        //this is the point that the object is trying to move to
        Vector2 newWorldPoint = MidpointOfCell(gridLayout.CellToWorld(new Vector3Int(newX, newY, 0)));

        //check wall collisions
        if (CheckWallCollision(newWorldPoint, wallCollider))
        {
            return(false);
        }

        //check water collisions (if not a goose)
        if ((!entityTag.HasTag("Goose")) && CheckWallCollision(newWorldPoint, waterCollider))
        {
            return(false);
        }

        //nothing has collided, movement is vaild
        return(true);
    }
    public void Sneeze()
    {
        Debug.Log("Achoo!");
        int intensity = 2;

        if (entityTag.HasTag("Spitter"))
        {
            intensity = 4;
        }

        Vector2Int sneeze = new Vector2Int(gridMovement.x, gridMovement.y);

        for (int i = 0; i < intensity; i++)
        {
            sneeze += ConvertToVectorInt(gridMovement.direction);
            gridMovement.SneezeOnBlock(sneeze);
        }

        //
        if (manager.playerLivesLeft == 1)
        {
            manager.PlayerLose();
        }
    }