2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework.Content;
6 using Microsoft.Xna.Framework.Input;
7 using Microsoft.Xna.Framework;
8 using Microsoft.Xna.Framework.Graphics;
17 Texture2D selectGameScreen;
19 Vector2 backgroundPos;
21 Vector2 spotLightCenter;
25 Vector2 spotLightVelocity;
34 Vector2 createGamePos;
35 string createGameText;
39 Vector2 returnToMainPos;
40 string returnToMainText;
42 KeyboardState previousKeyboardState;
43 KeyboardState currentKeyboardState;
45 private enum lobbyState
53 lobbyState currentState;
57 currentState = lobbyState.Welcome;
60 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
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);
72 zero = new Vector2(0, 0);
74 MaxX = graphics.GraphicsDevice.Viewport.Width;
76 MaxY = graphics.GraphicsDevice.Viewport.Height;
80 menuFont = contentManager.Load<SpriteFont>("menuFont");
81 createGamePos = new Vector2(100f, MaxY / 3);
82 createGameText = "Create Game";
83 selected = createGameText;
85 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
86 findGameText = "Find Game";
88 returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);
89 returnToMainText = "press [ X ] to return to main menu";
92 public void UnloadContent()
97 public long Update(GameTime gameTime)
99 UpdateSpotLight(gameTime);
100 currentKeyboardState = Keyboard.GetState();
102 switch (currentState)
104 case lobbyState.Welcome:
105 if (selected == createGameText)
107 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
108 currentState = lobbyState.CreateGame;
109 if (currentKeyboardState.IsKeyDown(Keys.Down))
110 selected = findGameText;
114 if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))
115 currentState = lobbyState.FindGame;
116 if (currentKeyboardState.IsKeyDown(Keys.Up))
117 selected = createGameText;
120 case lobbyState.CreateGame:
121 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
122 currentState = lobbyState.Welcome;
125 case lobbyState.FindGame:
126 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
127 currentState = lobbyState.Welcome;
130 case lobbyState.Connected:
131 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
132 currentState = lobbyState.Welcome;
137 previousKeyboardState = Keyboard.GetState();
143 /// Draws the lobby GUI. Has different states for difference menu configurations
145 public long Draw(SpriteBatch spriteBatch)
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)
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);
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);
161 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
164 case lobbyState.CreateGame:
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);
171 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
173 case lobbyState.Connected:
181 private void UpdateSpotLight(GameTime gameTime)
183 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
184 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
186 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
188 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
190 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
192 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);