//======================================== // Self-Define //------------------------------ //---------------------- // Public Functions //---------------------- // Protected Functions //---------------------- // Private Functions /// <summary> /// /// </summary> private void DoAbsorbEffect() { if (mAbsorbEffect) { mAbsorbEffectTimer += Time.deltaTime; if (mTimeToAbsorb < mAbsorbEffectTimer) { // start the effect mGoStraightAction.MoveSpeed += (0.1f - mGoStraightAction.MoveSpeed) / mTimeToAbsorb * Time.deltaTime; if (JCS_Utility.WithInRange(-mAcceptTimeRange, mAcceptTimeRange, mGoStraightAction.MoveSpeed)) { //mGoStraightAction.MoveSpeed = mRecordMoveSpeed; // end the effect. mAbsorbEffect = false; } } } else { mGoStraightAction.MoveSpeed += (mRecordMoveSpeed - mGoStraightAction.MoveSpeed) / mAbsorbBackFriction * Time.deltaTime; } }
/// <summary> /// Decide what item to drop base on /// the array list we have! /// </summary> /// <returns> item to drop. </returns> private JCS_Item ItemDropped() { JCS_Item item = null; float totalChance = 0; // add all possiblity chance together. for (int index = 0; index < mItemSet.Length; ++index) { totalChance += mItemSet[index].dropRate; } float dropIndex = JCS_Random.Range(0, totalChance + 1); float accumMaxDropRate = 0; float accumMinDropRate = 0; for (int index = 0; index < mItemSet.Length; ++index) { accumMaxDropRate += mItemSet[index].dropRate; if (index == 0) { if (JCS_Utility.WithInRange(0, mItemSet[0].dropRate, dropIndex)) { item = mItemSet[0].item; break; } continue; } // 比如: 10, 20, 30, 40 // Loop 1: 0 ~ 10 // Loop 2: 20(30-10) ~ 30 // Loop 3: 30(60-30) ~ 60 // Loop 4: 40(100-60) ~ 100 每個都減掉上一個的Drop Rate! if (JCS_Utility.WithInRange(accumMinDropRate, accumMaxDropRate, dropIndex)) { item = mItemSet[index].item; break; } accumMinDropRate += mItemSet[index].dropRate; } // meaning the last one. if (item == null && mItemSet.Length != 0 && mItemSet[mItemSet.Length - 1].dropRate != 0) { item = mItemSet[mItemSet.Length - 1].item; } return(item); }
/// <summary> /// Do the sprite action. /// </summary> /// <param name="sr"></param> /// <param name="currentPos"></param> private void DoSpriteAction(SpriteRenderer sr, Vector3 currentPos) { if (sr == null) { return; } if (!mFreezeX) { // object going left if (currentPos.x < mLastPosition.x) { if (mIsFacingRight) { sr.flipX = false; } else { sr.flipX = true; } } // object going right else if (currentPos.x > mLastPosition.x) { if (mIsFacingRight) { sr.flipX = true; } else { sr.flipX = false; } } if (JCS_Utility.WithInRange(90, 270, this.transform.localEulerAngles.z)) { sr.flipX = !sr.flipX; } } if (!mFreezeY) { // object going down if (currentPos.y < mLastPosition.y) { if (mIsFacingUp) { sr.flipY = false; } else { sr.flipY = true; } } // object going up else if (currentPos.y > mLastPosition.y) { if (mIsFacingUp) { sr.flipY = true; } else { sr.flipY = false; } } // TODO(JenChieh): this have not test yet!!! if (JCS_Utility.WithInRange(90, 270, this.transform.localEulerAngles.z)) { sr.flipY = !sr.flipY; } } }
/* Functions */ private void LateUpdate() { Vector3 currentPos = this.transform.position; // if the position are the same, meaning the object // is idle. (have not been move) if (currentPos == mLastPosition) { return; } Vector3 newScale = this.transform.localScale; if (!mFreezeX) { // object going left if (currentPos.x < mLastPosition.x) { if (mIsFacingRight) { newScale.x = JCS_Mathf.ToNegative(newScale.x); } else { newScale.x = JCS_Mathf.ToPositive(newScale.x); } } // object going right else if (currentPos.x > mLastPosition.x) { if (mIsFacingRight) { newScale.x = JCS_Mathf.ToPositive(newScale.x); } else { newScale.x = JCS_Mathf.ToNegative(newScale.x); } } if (JCS_Utility.WithInRange(90, 270, this.transform.localEulerAngles.z)) { newScale.x = JCS_Mathf.ToReverse(newScale.x); } } if (!mFreezeY) { // object going down if (currentPos.y < mLastPosition.y) { if (mIsFacingUp) { newScale.y = JCS_Mathf.ToNegative(newScale.y); } else { newScale.y = JCS_Mathf.ToPositive(newScale.y); } } // object going up else if (currentPos.y > mLastPosition.y) { if (mIsFacingUp) { newScale.y = JCS_Mathf.ToPositive(newScale.y); } else { newScale.y = JCS_Mathf.ToNegative(newScale.y); } } // TODO(JenChieh): this have not test yet!!! if (JCS_Utility.WithInRange(90, 270, this.transform.localEulerAngles.z)) { newScale.y = JCS_Mathf.ToReverse(newScale.y); } } // update last position mLastPosition = currentPos; // apply new scale this.transform.localScale = newScale; }