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; } }
// 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); }
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); }
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; } }
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()); }
// 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(); } }