X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Project06%2FlobbyTest%2FlobbyTest%2FLobbyGUI.cs;fp=Project06%2FlobbyTest%2FlobbyTest%2FLobbyGUI.cs;h=b1205672cb48b962663afdfee0e15e05b2a85b2e;hb=356c8e65fc38a3c44c9cee73c38f1bdccef2f30f;hp=0000000000000000000000000000000000000000;hpb=53c3423a7dc02531e793531bf7aee257786ee208;p=chaz%2Fcarfire diff --git a/Project06/lobbyTest/lobbyTest/LobbyGUI.cs b/Project06/lobbyTest/lobbyTest/LobbyGUI.cs new file mode 100644 index 0000000..b120567 --- /dev/null +++ b/Project06/lobbyTest/lobbyTest/LobbyGUI.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace lobbyTest +{ + public class lobbyGUI + { + Texture2D background; + Texture2D spotLight; + Texture2D cs; + + Vector2 backgroundPos; + Vector2 spotLightPos; + Vector2 spotLightCenter; + Vector2 csPos; + + Vector2 zero; + Vector2 spotLightVelocity; + + int MaxX; + int MinX; + int MaxY; + int MinY; + + SpriteFont menuFont; + string selected; + Vector2 createGamePos; + string createGameText; + Vector2 findGamePos; + string findGameText; + + KeyboardState previousKeyboardState; + KeyboardState currentKeyboardState; + + private enum lobbyState + { + Welcome, + CreateGame, + FindGame, + Connected + } + + lobbyState currentState; + + public lobbyGUI() + { + currentState = lobbyState.Welcome; + } + + public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) + { + background = contentManager.Load("background"); + spotLight = contentManager.Load("spotlight"); + cs = contentManager.Load("cs"); + backgroundPos = new Vector2(0f, 0f); + spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98); + spotLightCenter = new Vector2(800f, 800f); + spotLightVelocity = new Vector2(-100, 33); + csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98); + + zero = new Vector2(0, 0); + + MaxX = graphics.GraphicsDevice.Viewport.Width; + MinX = 0; + MaxY = graphics.GraphicsDevice.Viewport.Height; + MinY = 100; + + //menu fonts + menuFont = contentManager.Load("menuFont"); + createGamePos = new Vector2(100f, MaxY / 3); + createGameText = "Create Game"; + selected = createGameText; + + findGamePos = new Vector2(100f, (MaxY / 3) + 60); + findGameText = "Find Game"; + } + + public void UnloadContent() + { + + } + + public long Update(GameTime gameTime) + { + UpdateSpotLight(gameTime); + currentKeyboardState = Keyboard.GetState(); + //check inputs + switch (currentState) + { + case lobbyState.Welcome: + if (selected == createGameText) + { + if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) + currentState = lobbyState.CreateGame; + if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up)) + selected = findGameText; + } + else + { + if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) + currentState = lobbyState.FindGame; + if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up)) + selected = createGameText; + } + break; + case lobbyState.CreateGame: + + break; + case lobbyState.FindGame: + + break; + case lobbyState.Connected: + + break; + + } + previousKeyboardState = Keyboard.GetState(); + + return 1; + } + + /// + /// Draws the lobby GUI. Has different states for difference menu configurations + /// + public long Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); + spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); + spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0); + switch (currentState) + { + case lobbyState.Welcome: + if (selected == createGameText) + spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f); + else + spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f); + if (selected == findGameText) + spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f); + else + spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f); + break; + case lobbyState.CreateGame: + + break; + case lobbyState.FindGame: + + break; + case lobbyState.Connected: + + break; + } + + return 1; + } + + private void UpdateSpotLight(GameTime gameTime) + { + spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds, + spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds); + + if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall + { + spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y); + } + else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall + { + spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1); + } + } + } +}