private void Init(int nLives, int nBombs) { int W = Game.GraphicsDeviceManager.PreferredBackBufferWidth; int H = Game.GraphicsDeviceManager.PreferredBackBufferHeight; livesString = new StringToDraw(Game, "Lives: " + nLives, new Vector2((float)5.0f / W, (float)(H - 25.0f) / H), Game.Content.Load <SpriteFont>("GeomCloneFont")); scoreString = new StringToDraw(Game, "Score: 0", new Vector2((float)5.0f / W, (float)5.0f / H), Game.Content.Load <SpriteFont>("GeomCloneFont")); bombsString = new StringToDraw(Game, "Bombs: " + nBombs, new Vector2((float)5.0f / W, (float)(H - 50.0f) / H), Game.Content.Load <SpriteFont>("GeomCloneFont")); numberOfLives = nLives; numberOfBombs = nBombs; Color c = Color.White; //Color c = new Color(Color.White, 127); rotation = 45.0f; moveFactorPerSecond = 0.0f; shootDirection = new Vector2(1, 0); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2((float)7 / referenceWidth, (float)5 / referenceHeight), -40.0f, 0.4f, 0.5f, c)); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2(-(float)7 / referenceWidth, (float)5 / referenceHeight), 40.0f, 0.4f, 0.5f, c)); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2((float)5 / referenceWidth, -(float)4 / referenceHeight), -25.0f, 0.25f, 0.5f, c)); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2(-(float)5 / referenceWidth, -(float)4 / referenceHeight), 25.0f, 0.25f, 0.5f, c)); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2((float)12 / referenceWidth, -(float)8 / referenceHeight), 65.0f, 0.325f, 0.5f, c)); parts.Add(new ActorPart(Game, texture, position, rotation, new Vector2(-(float)12 / referenceWidth, -(float)8 / referenceHeight), -65.0f, 0.325f, 0.5f, c)); ChangeState(new PlayerBorn(CurrentLevel, this)); }
protected override IEnumerator AnimateText(StringToDraw stringToDrawStruct) { string stringToDraw = stringToDrawStruct.str; float delay = stringToDrawStruct.delay; bool drawAtOnce = stringToDrawStruct.atOnce; // wait the specified delay yield return new WaitForSeconds(delay); // We store the "finished" drawn text in case the user skips the current drawing sequence. textAfterDrawing = text.text + stringToDraw; if (drawAtOnce) { text.text = textAfterDrawing + '\n'; } else { // Draw each character in the string. Don't do a draw delay for whitespace characters for (int i = 0; i < stringToDraw.Length; i++) { char c = stringToDraw[i]; text.text += c; if (c != ' ') { yield return new WaitForSeconds(charDrawDelay); } // if we reached the end of the string, if (i == stringToDraw.Length - 1) { text.text += System.Environment.NewLine; UnlockDrawing(); DrawingEnded(); charDrawDelay = setCharDrawDelay; yield break; } } } }
protected abstract IEnumerator AnimateText(StringToDraw std);
protected override IEnumerator AnimateText(StringToDraw stringToDrawStruct) { LockDrawing(); ClearTerminal(); string stringToDraw = stringToDrawStruct.str; float delay = stringToDrawStruct.delay; bool drawAtOnce = stringToDrawStruct.atOnce; bool clearAfterDraw = false; bool receivedInterrupt = false; // wait the specified delay yield return new WaitForSeconds(delay); // We store the "finished" drawn text in case the user skips the current drawing sequence. textAfterDrawing = text.text + stringToDraw; if (drawAtOnce) { text.text = textAfterDrawing + '\n'; UnlockDrawing(); DrawingEnded(); } else { // Draw each character in the string. Don't do a draw delay for whitespace characters for (int i = 0; i < stringToDraw.Length; i++) { char c = stringToDraw[i]; text.text += c; if (c != ' ') { if (interruptDrawingQueue.Count > 0 && !receivedInterrupt) { DrawSettings settings = interruptDrawingQueue.Dequeue(); charDrawDelay = settings.charDrawDelay; if (settings.invisible) { Color col = text.color; col.a = 0; text.color = col; } if (settings.clearAfterDrawing) { clearAfterDraw = true; } receivedInterrupt = true; } yield return new WaitForSeconds(charDrawDelay); } // if we reached the end of the string, if (i == stringToDraw.Length - 1) { if (clearAfterDraw) { ClearTerminal(); } if (receivedInterrupt) { ResetDrawSettings(); } RepositionBlinkingChar(); text.text += System.Environment.NewLine; DrawingEnded(); UnlockDrawing(); yield break; } } } }