X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/0cafec445af0a97d96feb1a1daefa1486142c73f..4fc09567c557a1110180940cca40fd7144921026:/SuperPolarityMac/LetterChooseWidget.cs diff --git a/SuperPolarityMac/LetterChooseWidget.cs b/SuperPolarityMac/LetterChooseWidget.cs new file mode 100644 index 0000000..e52733f --- /dev/null +++ b/SuperPolarityMac/LetterChooseWidget.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class LetterChooseWidget : Widget + { + int CurrentChar; + bool Locked; + int LockRate; + int CurrentTime; + + SpriteFont Font; + + public LetterChooseWidget(SuperPolarity game, Vector2 position) : base(game, position) + { + Active = false; + CurrentChar = 65; + Font = game.Content.Load("Fonts\\bigfont"); + LockRate = 300; + CurrentTime = 0; + + InputController.Bind("moveY", HandleMovement); + } + + public void HandleMovement(float value) + { + if (!Active) { return; } + + if (value > 0.8 && !Locked) { + CurrentChar = CurrentChar + 1; + + if (CurrentChar > 90) + { + CurrentChar = 32; + } + + Locked = true; + } + + if (value < -0.8 && !Locked) { + CurrentChar = CurrentChar - 1; + + if (CurrentChar < 32) + { + CurrentChar = 90; + } + + Locked = true; + } + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + if (CurrentTime > LockRate) + { + CurrentTime = 0; + Locked = false; + } + } + + public string Value() + { + return char.ConvertFromUtf32(CurrentChar); + } + + public override void Draw(SpriteBatch spriteBatch) + { + var color = new Color(0, 0, 0, 128); + if (Active) + { + color = new Color(201, 0, 68, 255); + } + spriteBatch.DrawString(Font, Value(), Position, color); + } + } +}