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:
123 case lobbyState.FindGame:
124 if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
125 currentState = lobbyState.Welcome;
128 case lobbyState.Connected:
133 previousKeyboardState = Keyboard.GetState();
139 /// Draws the lobby GUI. Has different states for difference menu configurations
141 public long Draw(SpriteBatch spriteBatch)
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)
148 case lobbyState.Welcome:
149 if (selected == createGameText)
150 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
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);
156 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
159 case lobbyState.CreateGame:
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);
166 //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);
168 case lobbyState.Connected:
176 private void UpdateSpotLight(GameTime gameTime)
178 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
179 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
181 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
183 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
185 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
187 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);