コード例 #1
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // spawn and destroy ball to calculate
        // spawn location min and max
        GameObject    tempBall = Instantiate <GameObject>(prefabBall);
        BoxCollider2D collider = tempBall.GetComponent <BoxCollider2D>();
        float         ballColliderHalfWidth  = collider.size.x / 2;
        float         ballColliderHalfHeight = collider.size.y / 2;

        spawnLocationMin = new Vector2(
            tempBall.transform.position.x - ballColliderHalfWidth,
            tempBall.transform.position.y - ballColliderHalfHeight);

        spawnLocationMax = new Vector2(
            tempBall.transform.position.x + ballColliderHalfWidth,
            tempBall.transform.position.y + ballColliderHalfHeight);

        Destroy(tempBall);

        // initialize and start spawn timer
        spawnRange = ConfigurationUtils.MaxSpawnSeconds - ConfigurationUtils.MinSpawnSeconds;

        spawnTimer = gameObject.AddComponent <Timer>();
        spawnTimer.AddTimerFinishedListener(HandleSpawnTimerFinished);
        spawnTimer.Duration = GetSpawnDelay();
        spawnTimer.Run();

        EventManager.AddBallDiedListener(SpawnBall);
        EventManager.AddBallLostListener(SpawnBall);


        // spawn first Ball
        SpawnBall();
    }
コード例 #2
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // spawn and destroy ball to calculate
        // spawn location min and max
        GameObject    tempBall = Instantiate <GameObject>(prefabStandardBall);
        BoxCollider2D collider = tempBall.GetComponent <BoxCollider2D>();
        float         ballColliderHalfWidth  = collider.size.x / 2;
        float         ballColliderHalfHeight = collider.size.y / 2;
        Vector2       spawnLocation          = Vector2.zero;

        spawnLocationMin = new Vector2(
            spawnLocation.x - ballColliderHalfWidth,
            spawnLocation.y - ballColliderHalfHeight);
        spawnLocationMax = new Vector2(
            spawnLocation.x + ballColliderHalfWidth,
            spawnLocation.y + ballColliderHalfHeight);
        Destroy(tempBall);

        // initialize and start spawn timer
        spawnRange = ConfigurationUtils.MaxSpawnDelay -
                     ConfigurationUtils.MinSpawnDelay;
        spawnTimer          = gameObject.AddComponent <Timer>();
        spawnTimer.Duration = GetSpawnDelay();
        spawnTimer.Run();
        spawnTimer.AddTimerFinishedListener(HandleSpawnTimerFinished);

        // add as listener for events
        EventManager.AddBallLostListener(HandleBallLostEvent);
        EventManager.AddBallDiedListener(HandleBallDiedEvent);
    }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        scoreText     = scoreTextGameObject.GetComponent <Text>();
        leftHitsText  = leftHitsTextGameObject.GetComponent <Text>();
        rightHitsText = rightHitsTextGameObject.GetComponent <Text>();

        // add as listener for various events
        EventManager.AddBallLostListener(AddPoints);
        EventManager.AddHitsAddedListener(AddHits);
    }
コード例 #4
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        leftScore  = 0;
        rightScore = 0;
        leftHits   = 0;
        rightHits  = 0;

        scoreText     = scoreTextGameObject.GetComponent <Text>();
        leftHitsText  = leftHitsTextGameObject.GetComponent <Text>();
        rightHitsText = rightHitsTextGameObject.GetComponent <Text>();

        // add as listener for various events
        EventManager.AddBallLostListener(AddPoints);
        EventManager.AddHitsAddedListener(AddHits);
        EventManager.AddPlayerWonInvoker(this);
    }
コード例 #5
0
    protected override void Initialize()
    {
        gameEndedEvent = new GameEnded();

        var ballsLeftGameObject = GameObject.FindGameObjectWithTag(BallsTag);

        ballsLeftText = ballsLeftGameObject.GetComponent <Text>();

        var scoreGameObject = GameObject.FindGameObjectWithTag(ScoreTag);

        scoreText = scoreGameObject.GetComponent <Text>();

        EventManager.AddGameEndedInvoker(this);
        EventManager.AddBallLostListener(OnBallLost);
        EventManager.AddBlockDestroyedListener(OnBlockDestroyed);

        GetComponent <HUD>().enabled = false;
    }
コード例 #6
0
ファイル: HUD.cs プロジェクト: kartikdhar44/Wacky-Breakout
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // initialize score text
        scoreText      = GameObject.FindGameObjectWithTag("ScoreText").GetComponent <Text>();
        scoreText.text = ScorePrefix + score;

        // initialize balls left value and text
        ballsLeft          = ConfigurationUtils.BallsPerGame;
        ballsLeftText      = GameObject.FindGameObjectWithTag("BallsLeftText").GetComponent <Text>();
        ballsLeftText.text = BallsLeftPrefix + ballsLeft;

        // add listeners to the event manager
        EventManager.AddPointsAddedListener(AddPoints);
        EventManager.AddBallLostListener(ReduceBallsLeft);

        // last ball lost support
        lastBallLost = new LastBallLost();
        EventManager.AddLastBallLostInvoker(this);
    }
コード例 #7
0
ファイル: HUD.cs プロジェクト: Police-Cat/WackyBreackout
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // initialize score text
        score          = 0;
        scoreText      = GameObject.FindGameObjectWithTag("ScoreText").GetComponent <Text>();
        scoreText.text = ScorePrefix + score;

        // initialize balls left value and text
        ballsLeft          = ConfigurationUtils.BallsPerGame;
        ballsLeftText      = GameObject.FindGameObjectWithTag("BallsLeftText").GetComponent <Text>();
        ballsLeftText.text = BallsLeftPrefix + ballsLeft;

        EventManager.AddPointsAddedListener(AddPoints);
        EventManager.AddBallLostListener(ReduceBallsLeft);

        lastBallLost = new LastBallLost();
        EventManager.AddLastBallLostInvoker(this);

        // Take high score
        highScore = PlayerPrefs.GetInt("HighScore");
    }
コード例 #8
0
ファイル: BallSpawner.cs プロジェクト: zixu6769/Wacky-Pong
    bool retrySpawn = true;        // Pending spawn
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // Create a temp ball for measureing its size
        GameObject tempBall = Instantiate(StandardBall) as GameObject;

        // Connect the boxCollider component
        bc2D = tempBall.GetComponent <BoxCollider2D>();
        // Get the length and height of the collider
        collider_length = bc2D.size.x;
        collider_height = bc2D.size.y;
        // Assgin value to the diagonal corners
        // divide 2 to get half length/width, divide 10 because the ball is scaled
        upperleft  = new Vector2(-collider_length / 20, collider_height / 20);
        lowerright = new Vector2(collider_length / 20, -collider_height / 20);
        // Create and run the random timer
        randomTimer          = gameObject.AddComponent <Timer>();
        randomTimer.Duration = RandomTimerDecider();
        randomTimer.Run();
        // Destroy the temp ball
        Destroy(tempBall);
        // Add listeners for events
        EventManager.AddBallLostListener(DrawBall);
        EventManager.AddBallDeadListener(DrawBall);
    }