Beispiel #1
0
        public void SpawnRequirement()
        {
            if (_requirements.Count == 0 && _factories.Count != 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    var index   = UnityEngine.Random.Range(0, _factories.Count);
                    var factory = _factories[index];
                    var spawn   = factory.Pop();
                    spawn.GetComponent <Collider>().enabled = false;
                    spawn.transform.position = _level.RunesPositions[i].position;
                    spawn.transform.SetParent(_level.RuneTransform);
                    var def = Lifetime.Define(_level.Lifetime);

                    var activeReq = new ActiveRune();
                    activeReq.Spawn    = spawn;
                    activeReq.Lifetime = def;

                    _requirements.Add(activeReq);

                    def.Lifetime.AddAction(() =>
                    {
                        factory.Push(spawn);
                        _level.ToPool(spawn.transform);
                        _requirements.Remove(activeReq);
                    });
                }
            }
        }
Beispiel #2
0
        private void Awake()
        {
            // Setting up references.
            m_GroundCheck  = transform.Find("GroundCheck");
            m_CeilingCheck = transform.Find("CeilingCheck");
            m_Anim         = GetComponent <Animator>();
            playerLives    = GetComponent <Lives>();
            m_Rigidbody2D  = GetComponent <Rigidbody2D>();
            selectedRune   = ActiveRune.none;
            ActivateRunes();
            fireImmunity       = false;
            invincibilityTimer = 0;

            //Setup the values for gravity
            normalGravity = 3.0f;
            waterGravity  = 0.0f;

            // Initialize ball
        }
Beispiel #3
0
        private void FixedUpdate()
        {
            m_Grounded   = false;
            fireImmunity = false;

            // Increment the water cool down timer
            waterSpawnCounter += Time.deltaTime;

            //find 2d mouse position
            Vector3 mousePos = Input.mousePosition;

            mousePos.z = 10.0f;
            mousePos   = activeCam.ScreenToWorldPoint(mousePos);
            Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);

            //set gravity depending if you're in water or not
            if (!inWater)
            {
                //gameObject.GetComponent<m_Rigidbody2D>().;
                m_Grounded = true;
            }
            else
            {
                //Not be able to jump infinitely
            }



            //count down invincibility time
            if (invincibilityTimer > 0)
            {
                invincibilityTimer -= Time.deltaTime;
            }

            // The player is grounded if a circlecast to the groundcheck position hits anything designated as ground
            // This can be done using layers instead but Sample Assets will not overwrite your project settings.
            Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);
            for (int i = 0; i < colliders.Length; i++)
            {
                if (colliders[i].gameObject != gameObject)
                {
                    m_Grounded = true;
                }
            }
            m_Anim.SetBool("Ground", m_Grounded);

            // Set the vertical animation
            m_Anim.SetFloat("vSpeed", m_Rigidbody2D.velocity.y);

            if (m_Selection)
            {
                //draw all runes
                DrawAll();



                //find the distances between each rune and the mouse
                foreach (GameObject thisRune in runes)
                {
                    if (thisRune.activeSelf)
                    {
                        Vector2 runePos = thisRune.transform.position;
                        runeDistances.Add(Vector2.Distance(mousePos, runePos));
                    }
                }

                float currentDistance = float.MaxValue;
                //set the active rune to the current closest
                for (int i = 0; i < runeDistances.Count; i++)
                {
                    if (runeDistances[i] < currentDistance)
                    {
                        selectedRune    = (ActiveRune)i;
                        currentDistance = runeDistances[i];
                    }
                }

                //sets to no runes active if there is no distances
                if (currentDistance == float.MaxValue)
                {
                    selectedRune = (ActiveRune)3;
                }

                //clear list for next update
                runeDistances.Clear();
            }

            //when no longer selecting rune make all but that rune invisible
            if (Input.GetMouseButtonUp(1))
            {
                DrawSelected();
            }

            //Set Colors
            if (selectedRune == ActiveRune.fire)
            {
                gameObject.GetComponent <SpriteRenderer>().color = Color.red;
            }
            else if (selectedRune == ActiveRune.water)
            {
                gameObject.GetComponent <SpriteRenderer>().color = Color.blue;
            }

            //activate rune primary based on selected rune
            if (runePrimaryActive)
            {
                switch (selectedRune)
                {
                case (ActiveRune.fire):
                    SpawnFire(mousePos2D);
                    break;

                case (ActiveRune.water):
                    if (waterSpawnCounter >= waterSpawnTimer)
                    {
                        SpawnWater(mousePos2D);
                        waterSpawnCounter = 0f;
                    }
                    break;
                }
            }

            //activate rune primary based on selected rune
            if (runeSecondaryActive)
            {
                switch (selectedRune)
                {
                case (ActiveRune.fire):
                    fireImmunity = true;
                    break;

                case (ActiveRune.water):

                    break;
                }
            }
        }