Esempio n. 1
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        // Gets Rigidbody2D compnent
        rb2d = gameObject.GetComponent <Rigidbody2D>();

        // Gets BoxCollider2D component
        bc2d = GetComponent <BoxCollider2D>();

        // Get half bc2d height
        colliderHalfHeight = bc2d.size.y / 2;
        colliderHalfWidth  = bc2d.size.x / 2;

        // Freeze Support
        freezeTimer          = gameObject.AddComponent <Timer>();
        freezeDuration       = ConfigurationUtils.FreezerEffectDuration;
        freezeTimer.Duration = freezeDuration * Time.deltaTime;
        p1IsFrozen           = false;
        p2IsFrozen           = false;

        // Support for event manager system
        hitsAddedEvent = new HitsAddedEvent();
        EventManager.AddHitsInvoker(this);

        ballDiedEvent = new BallDiedEvent();
        EventManager.FreezerEffectListener(FreezePaddle);
    }
Esempio n. 2
0
    // Used for intitalizing the parent Start method
    public override void Start()
    {
        base.Start();
        // Applies the freeze duration to freezer effect
        if (ballType == PickUpEffectsEnum.FreezerEffect)
        {
            freezeDuration = ConfigurationUtils.FreezerEffectDuration;
        }
        if (ballType == PickUpEffectsEnum.SpeedUpEffect)
        {
            speedUpEffectSpeed = ConfigurationUtils.SpeedUpEffectForce;
        }

        // Event manager support
        freezerEffectActivated   = new FreezerEffectsActivatedEvent();
        speedUpEffectActiveEvent = new SpeedUpEffectActiveEvent();
        ballDiedEvent            = new BallDiedEvent();

        // makes this class an invoker of following event
        EventManager.FreezerEffectInvoker(this);
        //EventManager.BallDiedInvoker(this);
    }
Esempio n. 3
0
    // Start is called before the first frame update
    void Start()
    {
        multiplier = 1;

        lifeTimer          = gameObject.AddComponent <Timer>();
        lifeTimer.Duration = ConfigurationUtils.BallDeathTimer;
        lifeTimer.AddTimerFinishedEventListener(TimerEventFinished);

        stopTimer          = gameObject.AddComponent <Timer>();
        stopTimer.Duration = stopTimerTime;
        stopTimer.AddTimerFinishedEventListener(StopTimerEventFinished);
        stopTimer.Run();

        speedUpTimer = gameObject.AddComponent <Timer>();
        speedUpTimer.AddTimerFinishedEventListener(SpeedUpTimerEventFinished);

        EventManager.AddSpeedUpEffectListener(HandleSpeedUpEvent);

        reduceBallsEvent = new ReduceBallsEvent();
        EventManager.AddReduceBallsEventInvoker(this);

        ballDiedEvent = new BallDiedEvent();
        EventManager.AddBallDiedEventInvoker(this);
    }
Esempio n. 4
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));
    }