public void enqueueNewCol(ColorType newCol, float duration) { bool done = false; if (newCol == ColorType.NoColor) { return; } if (currentQueue.Count > 0) { // this seems to duplicate it TimedColor lastCol = currentQueue[currentQueue.Count - 1]; if (lastCol.colorName == newCol) { // without taking the last one float currQueueLen = getQueueDuration(false); if (lastCol.remainingTime <= duration) { if (currQueueLen + duration < MAXHOURGLASSDURATION) { lastCol.remainingTime = duration; } else { lastCol.remainingTime = MAXHOURGLASSDURATION - currQueueLen; } currentQueue[currentQueue.Count - 1] = lastCol; //is this necessary? } done = true; } } if (!done) { float currQueueLen = getQueueDuration(); bool changeit = isStack || (currentQueue.Count == 0); if (MAXHOURGLASSDURATION - currQueueLen >= duration) { currentQueue.Add(new TimedColor(newCol, duration)); } else { currentQueue.Add(new TimedColor(newCol, MAXHOURGLASSDURATION - currQueueLen)); } if (changeit) { changeCols(newCol); } } }
// Update is called once per frame void Update() { if (isPaused) { return; } // only if it's not paused gameTimer += Time.deltaTime; float timeToReduce = Time.deltaTime; bool done = false; bool changed = false; if (GameInputManager.getKeyDown(GameInputManager.InputType.AccelerateTime)) { isAccelerated = true; } if (GameInputManager.getKeyUp(GameInputManager.InputType.AccelerateTime)) { isAccelerated = false; } if (isAccelerated) { timeToReduce *= timeAcceleration; } while (!done && currentQueue.Count != 0) { TimedColor topCol = currentQueue[ActiveColorIndex]; if (topCol.remainingTime - timeToReduce > Mathf.Epsilon) { topCol.remainingTime -= timeToReduce; currentQueue[ActiveColorIndex] = topCol; done = true; } else { float removedTime = topCol.remainingTime; currentQueue.RemoveAt(ActiveColorIndex); changed = true; timeToReduce -= removedTime; } } if (changed) { updatecol(); } }