]> Dogcows Code - chaz/carfire/blob - Project06/lobbyTest/lobbyTest/LobbyGUI.cs
Added states for lobby gui. Welcome, CreateGame, FindGame, and Connected. Welcome...
[chaz/carfire] / Project06 / lobbyTest / lobbyTest / LobbyGUI.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework.Content;
6 using Microsoft.Xna.Framework.Input;
7 using Microsoft.Xna.Framework;
8 using Microsoft.Xna.Framework.Graphics;
9
10 namespace lobbyTest
11 {
12 public class lobbyGUI
13 {
14 Texture2D background;
15 Texture2D spotLight;
16 Texture2D cs;
17
18 Vector2 backgroundPos;
19 Vector2 spotLightPos;
20 Vector2 spotLightCenter;
21 Vector2 csPos;
22
23 Vector2 zero;
24 Vector2 spotLightVelocity;
25
26 int MaxX;
27 int MinX;
28 int MaxY;
29 int MinY;
30
31 SpriteFont menuFont;
32 string selected;
33 Vector2 createGamePos;
34 string createGameText;
35 Vector2 findGamePos;
36 string findGameText;
37
38 KeyboardState previousKeyboardState;
39 KeyboardState currentKeyboardState;
40
41 private enum lobbyState
42 {
43 Welcome,
44 CreateGame,
45 FindGame,
46 Connected
47 }
48
49 lobbyState currentState;
50
51 public lobbyGUI()
52 {
53 currentState = lobbyState.Welcome;
54 }
55
56 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
57 {
58 background = contentManager.Load<Texture2D>("background");
59 spotLight = contentManager.Load<Texture2D>("spotlight");
60 cs = contentManager.Load<Texture2D>("cs");
61 backgroundPos = new Vector2(0f, 0f);
62 spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);
63 spotLightCenter = new Vector2(800f, 800f);
64 spotLightVelocity = new Vector2(-100, 33);
65 csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);
66
67 zero = new Vector2(0, 0);
68
69 MaxX = graphics.GraphicsDevice.Viewport.Width;
70 MinX = 0;
71 MaxY = graphics.GraphicsDevice.Viewport.Height;
72 MinY = 100;
73
74 //menu fonts
75 menuFont = contentManager.Load<SpriteFont>("menuFont");
76 createGamePos = new Vector2(100f, MaxY / 3);
77 createGameText = "Create Game";
78 selected = createGameText;
79
80 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
81 findGameText = "Find Game";
82 }
83
84 public void UnloadContent()
85 {
86
87 }
88
89 public long Update(GameTime gameTime)
90 {
91 UpdateSpotLight(gameTime);
92 currentKeyboardState = Keyboard.GetState();
93 //check inputs
94 switch (currentState)
95 {
96 case lobbyState.Welcome:
97 if (selected == createGameText)
98 {
99 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
100 currentState = lobbyState.CreateGame;
101 if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up))
102 selected = findGameText;
103 }
104 else
105 {
106 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
107 currentState = lobbyState.FindGame;
108 if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up))
109 selected = createGameText;
110 }
111 break;
112 case lobbyState.CreateGame:
113
114 break;
115 case lobbyState.FindGame:
116
117 break;
118 case lobbyState.Connected:
119
120 break;
121
122 }
123 previousKeyboardState = Keyboard.GetState();
124
125 return 1;
126 }
127
128 /// <summary>
129 /// Draws the lobby GUI. Has different states for difference menu configurations
130 /// </summary>
131 public long Draw(SpriteBatch spriteBatch)
132 {
133 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
134 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
135 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
136 switch (currentState)
137 {
138 case lobbyState.Welcome:
139 if (selected == createGameText)
140 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
141 else
142 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
143 if (selected == findGameText)
144 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
145 else
146 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
147 break;
148 case lobbyState.CreateGame:
149
150 break;
151 case lobbyState.FindGame:
152
153 break;
154 case lobbyState.Connected:
155
156 break;
157 }
158
159 return 1;
160 }
161
162 private void UpdateSpotLight(GameTime gameTime)
163 {
164 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
165 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
166
167 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
168 {
169 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
170 }
171 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
172 {
173 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
174 }
175 }
176 }
177 }
This page took 0.037683 seconds and 4 git commands to generate.