]>
Commit | Line | Data |
---|---|---|
9ad526c0 | 1 | using System; |
bca44639 BB |
2 | using System.Collections.Generic; |
3 | using System.Linq; | |
4 | using System.Text; | |
5 | using Microsoft.Xna.Framework; | |
6 | using Microsoft.Xna.Framework.Graphics; | |
7 | ||
8 | namespace SuperPolarity | |
9 | { | |
10 | class LetterChooseWidget : Widget | |
11 | { | |
12 | int CurrentChar; | |
13 | bool Locked; | |
14 | int LockRate; | |
15 | int CurrentTime; | |
16 | ||
17 | SpriteFont Font; | |
18 | ||
19 | public LetterChooseWidget(SuperPolarity game, Vector2 position) : base(game, position) | |
20 | { | |
21 | Active = false; | |
22 | CurrentChar = 65; | |
23 | Font = game.Content.Load<SpriteFont>("Fonts\\bigfont"); | |
24 | LockRate = 300; | |
25 | CurrentTime = 0; | |
26 | ||
27 | InputController.Bind("moveY", HandleMovement); | |
28 | } | |
29 | ||
30 | public void HandleMovement(float value) | |
31 | { | |
32 | if (!Active) { return; } | |
33 | ||
34 | if (value > 0.8 && !Locked) { | |
35 | CurrentChar = CurrentChar + 1; | |
36 | ||
37 | if (CurrentChar > 90) | |
38 | { | |
39 | CurrentChar = 32; | |
40 | } | |
41 | ||
42 | Locked = true; | |
43 | } | |
44 | ||
45 | if (value < -0.8 && !Locked) { | |
46 | CurrentChar = CurrentChar - 1; | |
47 | ||
48 | if (CurrentChar < 32) | |
49 | { | |
50 | CurrentChar = 90; | |
51 | } | |
52 | ||
53 | Locked = true; | |
54 | } | |
55 | } | |
56 | ||
57 | public override void Update(GameTime gameTime) | |
58 | { | |
59 | base.Update(gameTime); | |
60 | ||
61 | CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; | |
62 | if (CurrentTime > LockRate) | |
63 | { | |
64 | CurrentTime = 0; | |
65 | Locked = false; | |
66 | } | |
67 | } | |
68 | ||
69 | public string Value() | |
70 | { | |
71 | return char.ConvertFromUtf32(CurrentChar); | |
72 | } | |
73 | ||
74 | public override void Draw(SpriteBatch spriteBatch) | |
75 | { | |
76 | var color = new Color(0, 0, 0, 128); | |
77 | if (Active) | |
78 | { | |
79 | color = new Color(201, 0, 68, 255); | |
80 | } | |
81 | spriteBatch.DrawString(Font, Value(), Position, color); | |
82 | } | |
83 | } | |
84 | } |