Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        mat    = new Material[2];
        mat[0] = Resources.Load <Material>("BallStandard");
        mat[1] = Resources.Load <Material>("PaddleMaterialRed");
        // Sprite renderer
        spriteRenderer         = gameObject.GetComponent <SpriteRenderer>();
        spriteRenderer.enabled = false;

        // Timer to make the ball wait before dropping
        waitTimer          = gameObject.AddComponent <Timer>();
        waitTimer.Duration = WaitDuration;
        waitTimer.Run();

        // Timer to make the ball dissappear
        timer          = gameObject.AddComponent <Timer>();
        timer.Duration = ConfigurationUtils.BallLifeTime + WaitDuration;
        timer.Run();

        // Effect timer
        effectTimer = gameObject.AddComponent <Timer>();
        EventManager.addSpeedListener(speedEffect);

        // Event
        ballLostEvent = new BallLostEvent();
        EventManager.addBallLostInvoker(this);

        ballDieEvent = new BallDieEvent();
        EventManager.addBallDieInvoker(this);

        // Set initial color
        if (EffectUtils.isSpeedupInEffect && EffectUtils.timeRemaining > 1)
        {
            isSpedUp = true;
            effect[1].GetComponent <Renderer>().material = mat[1];
            spriteRenderer.material = mat[1];
        }
        else
        {
            effect[1].GetComponent <Renderer>().material = mat[0];
        }
        Instantiate(effect[1], transform.position, Quaternion.identity);
    }
Exemple #2
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    public virtual void Start()
    {
        speedUpActive = false;

        // gets Rigidbody2D Componenet
        rb2d = GetComponent <Rigidbody2D>();

        // Ball Collider Support
        ballCollider  = gameObject.GetComponent <BoxCollider2D>();
        ballHalfWidth = ballCollider.size.x / 2;

        // Initializes Events
        pointsAddedEvent = new PointsAddedEvent();
        ballLostEvent    = new BallLostEvent();
        ballDiedEvent    = new BallDiedEvent();

        // Adds appropriate invokers to the ball
        EventManager.AddPointsAddedInvoker(this);
        EventManager.BallLostInvoker(this);
        EventManager.BallDiedInvoker(this);
        EventManager.SpeedUpEffectListener(SpeedUpActive);

        // Angle selection support
        float angleSelect = Random.value;

        // Death Timer (with invoker)
        deathTimer = gameObject.AddComponent <Timer>();
        deathTimer.AddTimerFinishedListener(BallDeathTimer);
        deathTimer.Duration = ConfigurationUtils.BallLifetime;
        deathTimer.Run();

        // Start Timer (with invoker)
        startTimer = gameObject.AddComponent <Timer>();
        startTimer.AddTimerFinishedListener(BallStartTimer);
        startTimer.Duration = 1;
        startTimer.Run();

        speedUpTimer = gameObject.AddComponent <Timer>();
        speedUpTimer.AddTimerFinishedListener(SpeedUpDisabled);

        // Gets ball spawner component
        ballSpawner = Camera.main.GetComponent <BallSpawner>();

        // Sets min and max angle off of Random.Range
        if (angleSelect < 0.5f)
        {
            // sets left side angle to radians
            minAngle = 135 * Mathf.Deg2Rad;
            maxAngle = 225 * Mathf.Deg2Rad;
        }
        else
        {
            // sets right side angle to radians
            minAngle = -45f * Mathf.Deg2Rad;
            maxAngle = 45f * Mathf.Deg2Rad;
        }

        // Applies points and hits for Bonus Balls
        if (ballType == PickUpEffectsEnum.BonusBall)
        {
            score = ConfigurationUtils.BonusBallPoints;
            hits  = ConfigurationUtils.BonusBallHit;
        }

        // If not a Bonus Ball, Standard points are issued
        if (ballType == PickUpEffectsEnum.StandardBall)
        {
            score = ConfigurationUtils.StandardBallHit;
            hits  = ConfigurationUtils.StandardBallHit;
        }
        // randomly selects from the min and max angles
        float angle = Random.Range(minAngle, maxAngle);

        // sets new direction
        direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
    }