Example #1
0
        private IEnumerator lerpToTarget()
        {
            float   currTime = 0;
            Vector3 startPos = this.transform.position;

            while (currTime < m_BulletLerpTime)
            {
                currTime += Time.deltaTime;
                float percentageCompleted = currTime / m_BulletLerpTime;
                this.transform.position = Vector3.Lerp(
                    startPos,
                    m_TargetZap.transform.position + new Vector3(m_TargetZap.Width / 2.0f, -m_TargetZap.Height / 2.0f, 0),
                    percentageCompleted
                    );
                yield return(null);
            }

            m_SpriteRenderer.enabled = false;
            m_ParticleSystem.Stop();
            // spawn green zap in place of previous zap
            GoodZap instance    = Instantiate(goodZap, m_TargetZap.transform.position, m_TargetZap.transform.rotation);
            ZapGrid currZapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();

            StartCoroutine(currZapGrid.DestroyAndReplaceZap(m_TargetZap.Row, m_TargetZap.Col, instance, m_ZapTransitionTime, this));
            // Destroy(this.gameObject);
        }
Example #2
0
        public void MoveRocketJump(int numRows)
        {
            ZapGrid currGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();

            if (currGrid)
            {
                m_CurrRow += numRows;
                m_CurrRow  = Mathf.Clamp(m_CurrRow, 0, currGrid.GetNumRows() - 1);

                bool underneathCurrZap = underneathCurrentZap();
                Zap  next = m_NextZap;
                Zap  curr = m_CurrZap;
                if (underneathCurrZap)
                {
                    m_NextZap = currGrid.GetZap(m_CurrRow, m_CurrCol);
                }
                else
                {
                    m_NextZap = currGrid.GetZap(m_CurrRow, m_NextCol);
                }
                m_CurrZap        = m_NextZap;
                m_TargetPosition = m_NextZap.GetOffsetPosition();
                m_StartPosition  = this.transform.position;
                m_LerpAmount     = 0.0f;

                // don't let player move while rocket jumpin
                m_CanMove = false;
            }
        }
Example #3
0
        private void startShootTimer()
        {
            Zap targetZap = null;

            // find target to shoot and shoot
            ZapGrid zapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();

            if (zapGrid != null)
            {
                List <Zap> dangerousZaps       = zapGrid.GetDangerousZaps();
                Vector3    worldSpaceTopScreen = Utility.ScreenUtilities.GetWSofSSPosition(0.0f, 1.0f);

                for (int i = 0; i < dangerousZaps.Count; i++)
                {
                    Zap currZap = dangerousZaps[i];
                    if (currZap.transform.position.y <= worldSpaceTopScreen.y &&
                        currZap.transform.position.y > this.transform.position.y &&
                        !zapsAlreadyShotAt.Contains(currZap))
                    {
                        targetZap = currZap;
                        break;
                    }
                }
            }

            if (targetZap != null)
            {
                StartCoroutine(rotateToTargetThenFire(targetZap));
            }
            else
            {
                Invoke("startShootTimer", m_ShootInterval);
            }
        }
Example #4
0
        // returns the zap we move through initially when moving up.
        public Zap MoveVertically()
        {
            ZapGrid currZapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();

            if (currZapGrid)
            {
                m_CurrRow++;
                // don't allow player to jump higher than number of rows in zap grid. Else argumentoutofrange exception
                m_CurrRow = Mathf.Clamp(m_CurrRow, 0, currZapGrid.GetNumRows());


                /* get correct zap on new line to go to
                 *  this will compare the distance between the curr and next zap
                 *  if next zap is closer then go to it and vice versa. */
                Zap  zapOnNewLine      = null;
                Zap  zapMovedThrough   = null;
                bool underneathCurrZap = underneathCurrentZap();
                if (underneathCurrZap)
                {
                    // handles to make sure that we can't repeatedly make up for increment issues when moving vertically.
                    if (m_PrevMovementState != MovementState.MovingVertical)
                    {
                        if (m_IsMovingRight)
                        {
                            m_NextCol--;
                        }
                        else
                        {
                            m_NextCol++;
                        }
                    }
                    zapOnNewLine    = currZapGrid.GetZap(m_CurrRow, m_NextCol);
                    zapMovedThrough = m_CurrZap;
                }
                else
                {
                    zapOnNewLine    = currZapGrid.GetZap(m_CurrRow, m_NextCol);
                    zapMovedThrough = m_NextZap;
                }


                if (zapOnNewLine != null)
                {
                    //m_P2 = m_CurrZap.GetOffsetPosition();
                    //m_P1 = m_StartPosition
                    //m_TargetPosition = GetPoint(m_LerpPercentage);
                    // figure out which zap we are closer too
                    m_CurrZap = zapOnNewLine;
                    m_NextZap = zapOnNewLine;
                    //m_CurrRow += numRows;
                    m_LerpAmount     = 0.0f;
                    m_StartPosition  = this.transform.position;
                    m_TargetPosition = zapOnNewLine.GetOffsetPosition();
                }

                return(zapMovedThrough);
            }

            return(null);
        }
Example #5
0
 void Update()
 {
     if (m_LucrativeZaps == null)
     {
         ZapGrid zapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();
         m_LucrativeZaps = zapGrid.GetLucrativeZaps();
     }
     else
     {
         for (int i = 0; i < m_LucrativeZaps.Count; i++)
         {
             Zap currZap = m_LucrativeZaps[i];
             if (currZap != null)
             {
                 if (currZap.transform.position.y < this.transform.position.y && !m_ZapsAlreadyBeingLerped.Contains(currZap))
                 {
                     // lerp to magnet
                     currZap.DisableCollision();
                     m_ZapsAlreadyBeingLerped.Add(currZap);
                     StartCoroutine(lerpZapToThisMagnet(currZap));
                 }
             }
         }
     }
 }
Example #6
0
 private void decideNextMovementType()
 {
     if (m_MovementState == MovementState.MovingHorizontal)
     {
         SetMovementState(MovementState.MovingHorizontal);
     }
     else if (m_MovementState == MovementState.MovingBounceBackFromZap)
     {
         SetSpeedMultiplier(1.0f, true);
         SetMovementState(MovementState.MovingHorizontal);
     }
     else if (m_MovementState == MovementState.MovingVertical)
     {
         ZapGrid currZapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();
         if (m_CurrRow == currZapGrid.GetNumRows())
         {
             MoveToWarpZone();
             return;
         }
         SetMovementState(MovementState.MovingHorizontal);
     }
     else if (m_MovementState == MovementState.MovingToWarpZone)
     {
         m_TargetPosition = this.transform.position;
         m_StartPosition  = this.transform.position;
         shouldRotateInTowardTargetPosition = false;
         if (!m_PlayerDecorations.GetWarpZonePS().isPlaying)
         {
             m_PlayerDecorations.ShowWarpZonePS();
         }
         GameMaster.Instance.m_UIManager.m_ShopCanvas.m_WarpStorePanel.Show();
     }
     else if (m_MovementState == MovementState.MovingToZapGrid)
     {
         SetMovementState(MovementState.MovingHorizontal);
         DeathStar deathStar = GameMaster.Instance.m_DeathStar;
         if (deathStar)
         {
             deathStar.ResetPosition();
             deathStar.SetIsMoving(true);
         }
     }
     else if (m_MovementState == MovementState.MovingRocketJump)
     {
         GameMaster.Instance.m_PlayerStats.SetInvicible(false);
         SetMovementState(MovementState.MovingHorizontal);
         m_CanMove = true;
         if (m_PlayerDecorations != null)
         {
             m_PlayerDecorations.DeactivateLockdown();
             m_PlayerDecorations.DeactivateAtmosphereFire();
         }
     }
 }
Example #7
0
 public void LerpToZapScale(float lerpPercentage)
 {
     // Lerp size of the player to be half the size of the zap width.
     if (!m_IsScaling)
     {
         ZapGrid zapGrid    = GameMaster.Instance.m_ZapManager.GetZapGrid();
         float   zapWidth   = zapGrid.GetZap(0, 0).Width;
         Sprite  s          = m_SpriteRenderer.sprite;
         float   unitWidth  = s.textureRect.width / s.pixelsPerUnit;
         float   unitHeight = s.textureRect.height / s.pixelsPerUnit;
         m_CurrScale   = this.transform.localScale;
         m_TargetScale = zapWidth / unitWidth * m_SizePercentage;
         m_TargetScale = Mathf.Clamp(m_TargetScale, 0.0f, m_MaxScale);
         m_IsScaling   = true;
     }
     LerpScale(m_TargetScale, lerpPercentage);
 }
Example #8
0
        public void MoveHorizontally()
        {
            // switch next and curr zap if we have a next zap
            if (m_NextZap != null)
            {
                m_StartPosition = m_NextZap.GetOffsetPosition();
                m_CurrZap       = m_NextZap;
                m_CurrCol       = m_NextCol;
            }

            // check to make sure we don't go out of bounds
            ZapGrid currZapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();

            if (currZapGrid != null)
            {
                if (m_IsMovingRight)
                {
                    if (m_NextCol + 1 < currZapGrid.GetNumCols(m_CurrRow))
                    {
                        m_NextCol++;
                    }
                    else
                    {
                        m_IsMovingRight = false;
                        m_NextCol--;
                    }
                }
                else
                {
                    if (m_NextCol - 1 >= 0)
                    {
                        m_NextCol--;
                    }
                    else
                    {
                        m_IsMovingRight = true;
                        m_NextCol++;
                    }
                }

                m_NextZap        = currZapGrid.GetZap(m_CurrRow, m_NextCol);
                m_TargetPosition = m_NextZap.GetOffsetPosition();
                m_StartPosition  = this.transform.position;
            }
        }
Example #9
0
        private IEnumerator spawnLaser()
        {
            ZapManager zapManager = GameMaster.Instance.m_ZapManager;

            if (zapManager)
            {
                ZapGrid zapGrid = zapManager.GetZapGrid();
                int     numRows = zapGrid.GetNumRows();
                int     numCols = zapGrid.GetNumCols(0);

                // get random row to spawn lasers on
                int randomRow = Random.Range(0, numRows);
                Zap zapInRow  = zapGrid.GetZap(randomRow, 0);

                // spawn on left or right side of the screen
                int     randomSide    = Random.Range(0, 2);
                bool    isOnRightSide = (randomSide == 1) ? true : false;
                Vector3 spawnPos      = Vector3.zero;

                // spawn the laser
                Laser laserInstance = Instantiate(m_LaserPrefab, this.transform);

                // make changes to lasers position based on if it is on left or right side of the screen.
                if (randomSide == 0) // spawn on left side of screen
                {
                    spawnPos = Utility.ScreenUtilities.GetWSofSSPosition(0.0f, 0.0f);
                }
                else // spawn on right side of screen
                {
                    spawnPos = Utility.ScreenUtilities.GetWSofSSPosition(1.0f, 0.0f);
                }

                // make sure the laser is spawned at the same y position as the zap row.
                spawnPos.y = zapInRow.GetOffsetPosition().y;
                spawnPos.z = 80.0f;
                laserInstance.SetPositionLaserPost(spawnPos, isOnRightSide);
            }

            yield return(new WaitForSeconds(m_SpawnTime));

            StartCoroutine(spawnLaser());
        }
Example #10
0
 // gets called when we reach a zap (one time per zap)
 private void fillMovementData()
 {
     if (m_MovementState == MovementState.MovingHorizontal)
     {
         MoveHorizontally();
     }
     else if (m_MovementState == MovementState.MovingVertical)
     {
         Zap  zapMovedThrough = getZapCurrentlyUnderneath();
         bool isRocketZap     = zapMovedThrough is RocketZap;
         if (!isRocketZap)
         {
             MoveVertically();
         }
         zapMovedThrough.ApplyImmediateEffect();
     }
     else if (m_MovementState == MovementState.MovingToZapGrid)
     {
         ZapGrid currZapGrid = GameMaster.Instance.m_ZapManager.GetZapGrid();
         m_TargetPosition = currZapGrid.GetZap(0, 0).GetOffsetPosition();
     }
 }