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;
18 Vector2 backgroundPos;
20 Vector2 spotLightCenter;
24 Vector2 spotLightVelocity;
33 Vector2 createGamePos;
34 string createGameText;
38 KeyboardState previousKeyboardState;
39 KeyboardState currentKeyboardState;
41 private enum lobbyState
49 lobbyState currentState;
53 currentState = lobbyState.Welcome;
56 public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)
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);
67 zero = new Vector2(0, 0);
69 MaxX = graphics.GraphicsDevice.Viewport.Width;
71 MaxY = graphics.GraphicsDevice.Viewport.Height;
75 menuFont = contentManager.Load<SpriteFont>("menuFont");
76 createGamePos = new Vector2(100f, MaxY / 3);
77 createGameText = "Create Game";
78 selected = createGameText;
80 findGamePos = new Vector2(100f, (MaxY / 3) + 60);
81 findGameText = "Find Game";
84 public void UnloadContent()
89 public long Update(GameTime gameTime)
91 UpdateSpotLight(gameTime);
92 currentKeyboardState = Keyboard.GetState();
96 case lobbyState.Welcome:
97 if (selected == createGameText)
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;
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;
112 case lobbyState.CreateGame:
115 case lobbyState.FindGame:
118 case lobbyState.Connected:
123 previousKeyboardState = Keyboard.GetState();
129 /// Draws the lobby GUI. Has different states for difference menu configurations
131 public long Draw(SpriteBatch spriteBatch)
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)
138 case lobbyState.Welcome:
139 if (selected == createGameText)
140 spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);
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);
146 spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);
148 case lobbyState.CreateGame:
151 case lobbyState.FindGame:
154 case lobbyState.Connected:
162 private void UpdateSpotLight(GameTime gameTime)
164 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
165 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
167 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
169 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
171 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
173 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);