Exemplo n.º 1
0
        int WPM = 600; //default WPM for text

        #endregion Fields

        #region Constructors

        public MessageEvent(int column, int row, RenderContext renderContext)
            : base(column, row)
        {
            base.isCollidable = true;
            base.IsPassable = true;
            this.typingState = GameConstants.TYPING_STATE.NotTyped;
            Scale(48f, 48f, 48f);
            //Position = new Vector3(Position.X, Position.Y - 2, Position.Z - 27); //not sure about this position
            //HitboxHeightOffset = 2;
            HitboxHeight = GameConstants.SINGLE_CELL_SIZE;
            HitboxWidth = GameConstants.SINGLE_CELL_SIZE;
            //Translate(new Vector3(0, 0, 0));

            typedMessageLines = new List<String>(4);
            typedMessage = "";
        }
Exemplo n.º 2
0
 /*
  * make length of text shown (as a substring) proportional to the (elapsed time) / (total timelength of text).
  * Can make eg. as default, each char amounting to maybe ~50ms more time, or something => 20 chars per second.
  * Maybe 33 chars per second - for 400 WPM.
  */
 /// <summary>
 /// Start typing the message.
 /// </summary>
 public void StartTyping()
 {
     typingState = GameConstants.TYPING_STATE.Typing;
     //resets elapsedTypingTime to 0 if necessary.
     elapsedTypingTime = 0;
     //could also reset totalTimeToType to what would correspond to the WPM
 }
Exemplo n.º 3
0
        /// <summary>
        /// Update code for the MessageEvent. Handles typing internally; it's just a matter of incrementing the state in order to start it.
        /// </summary>
        /// <param name="renderContext"></param>
        public override void Update(RenderContext renderContext)
        {
            if (this.typingState == GameConstants.TYPING_STATE.Disabled || this.typingState == GameConstants.TYPING_STATE.NotTyped) //Completely cease update upon being disabled.
            {
                return;
            }

            //Action button leads to closing the screen, if typing is all displayed.
            if (this.typingState == GameConstants.TYPING_STATE.DoneTyping
                && ((Keyboard.GetState().IsKeyDown(Keys.F) && lastKey.IsKeyUp(Keys.F)) ||
                    (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B) && lastButton.IsButtonUp(Buttons.B))))
            {
                this.typingState = GameConstants.TYPING_STATE.Disabled;
                GameplayScreen.messageActive = false;
            }

            //Action button leads to finishing typing, if currently typing.
            else if(this.typingState == GameConstants.TYPING_STATE.Typing
                 && ((Keyboard.GetState().IsKeyDown(Keys.F) && lastKey.IsKeyUp(Keys.F)) ||
                    (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B) && lastButton.IsButtonUp(Buttons.B))))
            {
                FinishTyping();
            }

            //When typing, have the typed text update, as if it were a typewriter.
            if (typingState == GameConstants.TYPING_STATE.Typing)
            {
                if (soundFX == null)
                {
                    soundFX = new SoundEffectPlayer(renderContext.Player);
                    soundFX.LoadSound("Type", renderContext.Sounds["Type"]);
                    soundFX.PlayAndLoopSound("Type");
                }
                //Update the typed text until it's done.
                if (elapsedTypingTime < totalTimeToType)
                {
                    elapsedTypingTime += renderContext.GameTime.ElapsedGameTime.Milliseconds;
                    typedMessage = Message.Substring(0, (int)(Message.Length * elapsedTypingTime / totalTimeToType)); //Get current message to be typed for the current point

                }
                else //done
                {
                    FinishTyping();
                }
            }
            else if (typingState == GameConstants.TYPING_STATE.DoneTyping) //Use the complete message.
            {
                typedMessage = Message;
            }
            typedMessageLines = GetLines(typedMessage, renderContext, renderContext.Textures["MessageBackground"].Width - 30); //Wrap text according to the width of the message box.

            //Update the previous button and key state.
            lastKey = Keyboard.GetState();
            lastButton = GamePad.GetState(PlayerIndex.One);

            base.Update(renderContext);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Used to eg. just finish displaying the text immediately.
 /// For example, if the player presses a button to finish displaying the text (before it were done typing).
 /// If such were the case, note that elapsedTypingTime would still be < totalTypingTime.
 /// </summary>
 public void FinishTyping()
 {
     typingState = GameConstants.TYPING_STATE.DoneTyping;
     soundFX.SoundInstances["Type"].Stop();
     soundFX.SoundInstances["Type"].Dispose();
 }