]> Dogcows Code - chaz/carfire/blob - Project06/lobbyTest/lobbyTest/LobbyGUI.cs
edited join game screen
[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
122 break;
123 case lobbyState.FindGame:
124 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
125 currentState = lobbyState.Welcome;
126
127 break;
128 case lobbyState.Connected:
129
130 break;
131
132 }
133 previousKeyboardState = Keyboard.GetState();
134
135 return 1;
136 }
137
138 /// <summary>
139 /// Draws the lobby GUI. Has different states for difference menu configurations
140 /// </summary>
141 public long Draw(SpriteBatch spriteBatch)
142 {
143 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
144 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
145 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
146 switch (currentState)
147 {
148 case lobbyState.Welcome:
149 if (selected == createGameText)
150 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
151 else
152 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);
153 if (selected == findGameText)
154 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
155 else
156 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
157 break;
158
159 case lobbyState.CreateGame:
160
161 break;
162 case lobbyState.FindGame:
163 spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
164 //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
165
166 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
167 break;
168 case lobbyState.Connected:
169
170 break;
171 }
172
173 return 1;
174 }
175
176 private void UpdateSpotLight(GameTime gameTime)
177 {
178 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
179 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
180
181 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
182 {
183 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
184 }
185 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
186 {
187 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
188 }
189 }
190 }
191 }
This page took 0.042074 seconds and 4 git commands to generate.