From 356c8e65fc38a3c44c9cee73c38f1bdccef2f30f Mon Sep 17 00:00:00 2001 From: brady Date: Wed, 17 Mar 2010 08:50:33 +0000 Subject: [PATCH] Added states for lobby gui. Welcome, CreateGame, FindGame, and Connected. Welcome screen about done. git-svn-id: https://bd85.net/svn/cs3505_group@6 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- .../lobbyTest/Content/Content.contentproj | 7 + .../lobbyTest/Content/menuFont.spritefont | 60 ++++++ Project06/lobbyTest/lobbyTest/Game1.cs | 61 +----- Project06/lobbyTest/lobbyTest/LobbyGUI.cs | 177 ++++++++++++++++++ .../lobbyTest/lobbyTest/lobbyTest.csproj | 2 + 5 files changed, 255 insertions(+), 52 deletions(-) create mode 100644 Project06/lobbyTest/lobbyTest/Content/menuFont.spritefont create mode 100644 Project06/lobbyTest/lobbyTest/LobbyGUI.cs diff --git a/Project06/lobbyTest/lobbyTest/Content/Content.contentproj b/Project06/lobbyTest/lobbyTest/Content/Content.contentproj index cd1be85..3c293d9 100644 --- a/Project06/lobbyTest/lobbyTest/Content/Content.contentproj +++ b/Project06/lobbyTest/lobbyTest/Content/Content.contentproj @@ -55,6 +55,13 @@ TextureProcessor + + + menuFont + FontDescriptionImporter + FontDescriptionProcessor + + + + + + + Times New Roman + + + 18 + + + 0 + + + true + + + + + + + + + + + + ~ + + + + diff --git a/Project06/lobbyTest/lobbyTest/Game1.cs b/Project06/lobbyTest/lobbyTest/Game1.cs index fbb8e73..cac6219 100644 --- a/Project06/lobbyTest/lobbyTest/Game1.cs +++ b/Project06/lobbyTest/lobbyTest/Game1.cs @@ -21,22 +21,7 @@ namespace lobbyTest GraphicsDeviceManager graphics; SpriteBatch spriteBatch; - 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; + lobbyGUI lbGui; public Game1() { @@ -55,6 +40,7 @@ namespace lobbyTest // TODO: Add your initialization logic here graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferWidth = 600; + lbGui = new lobbyGUI(); base.Initialize(); } @@ -66,22 +52,8 @@ namespace lobbyTest { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); - background = Content.Load("background"); - spotLight = Content.Load("spotlight"); - cs = Content.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; - // TODO: use this.Content to load your game content here + lbGui.LoadContent(Content, graphics); + } /// @@ -105,7 +77,8 @@ namespace lobbyTest this.Exit(); // TODO: Add your update logic here - UpdateSpotLight(gameTime); + lbGui.Update(gameTime); + base.Update(gameTime); } @@ -117,28 +90,12 @@ namespace lobbyTest { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteBlendMode.AlphaBlend); - // TODO: Add your drawing code here - 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); + lbGui.Draw(spriteBatch); + spriteBatch.End(); base.Draw(gameTime); } - - 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); - } - } + } } 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); + } + } + } +} diff --git a/Project06/lobbyTest/lobbyTest/lobbyTest.csproj b/Project06/lobbyTest/lobbyTest/lobbyTest.csproj index e438fc8..b1e59ec 100644 --- a/Project06/lobbyTest/lobbyTest/lobbyTest.csproj +++ b/Project06/lobbyTest/lobbyTest/lobbyTest.csproj @@ -70,6 +70,7 @@ False + False @@ -83,6 +84,7 @@ + -- 2.43.0