Exemple #1
0
    public void Initialize(GameObject ballPrefab, GameObject gameOverGroup,
                           GameObject winScreenGroup, LineRenderer lineRenderer, float ballSize)
    {
        name = "Ingame";

        _ballPrefab     = ballPrefab;
        _gameOverGroup  = gameOverGroup;
        _winScreenGroup = winScreenGroup;
        _lineRenderer   = lineRenderer;

        gameOverGroup.SetActive(false);
        winScreenGroup.SetActive(false);

        InitializeBallSpawner(ballPrefab, ballSize);
        InitializeBallShooter(_ballSpawner);
        SetupCamera();

        _grid = new Ball[MAX_GRID_WIDTH, MAX_GRID_HEIGHT];

        int gridHeight = 6;

        for (int y = 0; y < gridHeight; ++y)
        {
            for (int x = 0; x < MAX_GRID_WIDTH; ++x)
            {
                SpawnBallOnGrid(x, y, Ball.GenerateCappedRandomValue());
            }
        }

        _boundsPlanes    = new Plane[3];
        _boundsPlanes[0] = new Plane(Vector3.right, 0.0f);                            // left
        _boundsPlanes[1] = new Plane(Vector3.left, _ballSpawner.GeneratePosition(MAX_GRID_WIDTH, 0).magnitude
                                     - _ballSpawner.GetBallRadius());                 // right
        _boundsPlanes[2] = new Plane(Vector3.down, _ballSpawner.GetBallRadius() * 2); // up

        _canShoot   = true;
        _canMoveRow = false;
    }