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