aboutsummaryrefslogtreecommitdiff
path: root/SuperPolarity/LetterChooseWidget.cs
blob: 44ca84449e112669729dc4b5c3cdf304cc4a33b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<SpriteFont>("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);
        }
    }
}