]> Dogcows Code - chaz/carfire/commitdiff
Added states for lobby gui. Welcome, CreateGame, FindGame, and Connected. Welcome...
authorbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Wed, 17 Mar 2010 08:50:33 +0000 (08:50 +0000)
committerbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Wed, 17 Mar 2010 08:50:33 +0000 (08:50 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@6 92bb83a3-7c8f-8a45-bc97-515c4e399668

Project06/lobbyTest/lobbyTest/Content/Content.contentproj
Project06/lobbyTest/lobbyTest/Content/menuFont.spritefont [new file with mode: 0644]
Project06/lobbyTest/lobbyTest/Game1.cs
Project06/lobbyTest/lobbyTest/LobbyGUI.cs [new file with mode: 0644]
Project06/lobbyTest/lobbyTest/lobbyTest.csproj

index cd1be85cf0f86b3b60e6390b3ebb0b99801b245e..3c293d9aafed838923b0bf03b0f3c51dce154584 100644 (file)
       <Processor>TextureProcessor</Processor>\r
     </Compile>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="menuFont.spritefont">\r
+      <Name>menuFont</Name>\r
+      <Importer>FontDescriptionImporter</Importer>\r
+      <Processor>FontDescriptionProcessor</Processor>\r
+    </Compile>\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\v3.0\Microsoft.Xna.GameStudio.ContentPipeline.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r
diff --git a/Project06/lobbyTest/lobbyTest/Content/menuFont.spritefont b/Project06/lobbyTest/lobbyTest/Content/menuFont.spritefont
new file mode 100644 (file)
index 0000000..72495a3
--- /dev/null
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<!--\r
+This file contains an xml description of a font, and will be read by the XNA\r
+Framework Content Pipeline. Follow the comments to customize the appearance\r
+of the font in your game, and to change the characters which are available to draw\r
+with.\r
+-->\r
+<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">\r
+  <Asset Type="Graphics:FontDescription">\r
+\r
+    <!--\r
+    Modify this string to change the font that will be imported.\r
+    -->\r
+    <FontName>Times New Roman</FontName>\r
+\r
+    <!--\r
+    Size is a float value, measured in points. Modify this value to change\r
+    the size of the font.\r
+    -->\r
+    <Size>18</Size>\r
+\r
+    <!--\r
+    Spacing is a float value, measured in pixels. Modify this value to change\r
+    the amount of spacing in between characters.\r
+    -->\r
+    <Spacing>0</Spacing>\r
+\r
+    <!--\r
+    UseKerning controls the layout of the font. If this value is true, kerning information\r
+    will be used when placing characters.\r
+    -->\r
+    <UseKerning>true</UseKerning>\r
+\r
+    <!--\r
+    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",\r
+    and "Bold, Italic", and are case sensitive.\r
+    -->\r
+    <Style>Bold</Style>\r
+\r
+    <!--\r
+    If you uncomment this line, the default character will be substituted if you draw\r
+    or measure text that contains characters which were not included in the font.\r
+    -->\r
+    <!-- <DefaultCharacter>*</DefaultCharacter> -->\r
+\r
+    <!--\r
+    CharacterRegions control what letters are available in the font. Every\r
+    character from Start to End will be built and made available for drawing. The\r
+    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin\r
+    character set. The characters are ordered according to the Unicode standard.\r
+    See the documentation for more information.\r
+    -->\r
+    <CharacterRegions>\r
+      <CharacterRegion>\r
+        <Start>&#32;</Start>\r
+        <End>&#126;</End>\r
+      </CharacterRegion>\r
+    </CharacterRegions>\r
+  </Asset>\r
+</XnaContent>\r
index fbb8e733c7fe77fe03cf911bf51b052f7421f7db..cac6219b2a6fbb54311f352832002a15ed366e42 100644 (file)
@@ -21,22 +21,7 @@ namespace lobbyTest
         GraphicsDeviceManager graphics;\r
         SpriteBatch spriteBatch;\r
 \r
-        Texture2D background;\r
-        Texture2D spotLight;\r
-        Texture2D cs;\r
-\r
-        Vector2 backgroundPos;\r
-        Vector2 spotLightPos;\r
-        Vector2 spotLightCenter;\r
-        Vector2 csPos;\r
-\r
-        Vector2 zero;\r
-        Vector2 spotLightVelocity;\r
-\r
-        int MaxX;\r
-        int MinX;\r
-        int MaxY;\r
-        int MinY;\r
+        lobbyGUI lbGui;\r
 \r
         public Game1()\r
         {\r
@@ -55,6 +40,7 @@ namespace lobbyTest
             // TODO: Add your initialization logic here\r
             graphics.PreferredBackBufferWidth = 800;\r
             graphics.PreferredBackBufferWidth = 600;\r
+            lbGui = new lobbyGUI();\r
             base.Initialize();\r
         }\r
 \r
@@ -66,22 +52,8 @@ namespace lobbyTest
         {\r
             // Create a new SpriteBatch, which can be used to draw textures.\r
             spriteBatch = new SpriteBatch(GraphicsDevice);\r
-            background = Content.Load<Texture2D>("background");\r
-            spotLight = Content.Load<Texture2D>("spotlight");\r
-            cs = Content.Load<Texture2D>("cs");\r
-            backgroundPos = new Vector2(0f, 0f);\r
-            spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);\r
-            spotLightCenter = new Vector2(800f, 800f);\r
-            spotLightVelocity = new Vector2(-100, 33);\r
-            csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);\r
-  \r
-            zero = new Vector2(0, 0);\r
-\r
-            MaxX = graphics.GraphicsDevice.Viewport.Width;\r
-            MinX = 0;\r
-            MaxY = graphics.GraphicsDevice.Viewport.Height;\r
-            MinY = 100;\r
-            // TODO: use this.Content to load your game content here\r
+            lbGui.LoadContent(Content, graphics);\r
+            \r
         }\r
 \r
         /// <summary>\r
@@ -105,7 +77,8 @@ namespace lobbyTest
                 this.Exit();\r
 \r
             // TODO: Add your update logic here\r
-            UpdateSpotLight(gameTime);\r
+            lbGui.Update(gameTime);\r
+            \r
             base.Update(gameTime);\r
         }\r
 \r
@@ -117,28 +90,12 @@ namespace lobbyTest
         {\r
             GraphicsDevice.Clear(Color.CornflowerBlue);\r
             spriteBatch.Begin(SpriteBlendMode.AlphaBlend);\r
-            // TODO: Add your drawing code here\r
-            spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);\r
-            spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);\r
-            spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);\r
 \r
+            lbGui.Draw(spriteBatch);\r
+            \r
             spriteBatch.End();\r
             base.Draw(gameTime);\r
         }\r
-\r
-        private void UpdateSpotLight(GameTime gameTime)\r
-        {\r
-            spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,\r
-                                        spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);\r
-\r
-            if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall\r
-            {\r
-                spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);\r
-            }\r
-            else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall\r
-            {\r
-                spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);\r
-            }\r
-        }\r
+        \r
     }\r
 }\r
diff --git a/Project06/lobbyTest/lobbyTest/LobbyGUI.cs b/Project06/lobbyTest/lobbyTest/LobbyGUI.cs
new file mode 100644 (file)
index 0000000..b120567
--- /dev/null
@@ -0,0 +1,177 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Input;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+\r
+namespace lobbyTest\r
+{\r
+    public class lobbyGUI\r
+    {\r
+        Texture2D background;\r
+        Texture2D spotLight;\r
+        Texture2D cs;\r
+\r
+        Vector2 backgroundPos;\r
+        Vector2 spotLightPos;\r
+        Vector2 spotLightCenter;\r
+        Vector2 csPos;\r
+\r
+        Vector2 zero;\r
+        Vector2 spotLightVelocity;\r
+\r
+        int MaxX;\r
+        int MinX;\r
+        int MaxY;\r
+        int MinY;\r
+\r
+        SpriteFont menuFont;\r
+        string selected;\r
+        Vector2 createGamePos;\r
+        string createGameText;\r
+        Vector2 findGamePos;\r
+        string findGameText;\r
+\r
+        KeyboardState previousKeyboardState;\r
+        KeyboardState currentKeyboardState;\r
+\r
+        private enum lobbyState\r
+        {\r
+            Welcome,\r
+            CreateGame,\r
+            FindGame,\r
+            Connected\r
+        }\r
+\r
+        lobbyState currentState;\r
+\r
+        public lobbyGUI()\r
+        {\r
+            currentState = lobbyState.Welcome;\r
+        }\r
+\r
+        public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
+        {\r
+            background = contentManager.Load<Texture2D>("background");\r
+            spotLight = contentManager.Load<Texture2D>("spotlight");\r
+            cs = contentManager.Load<Texture2D>("cs");\r
+            backgroundPos = new Vector2(0f, 0f);\r
+            spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);\r
+            spotLightCenter = new Vector2(800f, 800f);\r
+            spotLightVelocity = new Vector2(-100, 33);\r
+            csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);\r
+\r
+            zero = new Vector2(0, 0);\r
+\r
+            MaxX = graphics.GraphicsDevice.Viewport.Width;\r
+            MinX = 0;\r
+            MaxY = graphics.GraphicsDevice.Viewport.Height;\r
+            MinY = 100;\r
+\r
+            //menu fonts\r
+            menuFont = contentManager.Load<SpriteFont>("menuFont");\r
+            createGamePos = new Vector2(100f, MaxY / 3);\r
+            createGameText = "Create Game";\r
+            selected = createGameText;\r
+\r
+            findGamePos = new Vector2(100f, (MaxY / 3) + 60);\r
+            findGameText = "Find Game";\r
+        }\r
+\r
+        public void UnloadContent()\r
+        {\r
+            \r
+        }\r
+\r
+        public long Update(GameTime gameTime)\r
+        {\r
+            UpdateSpotLight(gameTime);\r
+            currentKeyboardState = Keyboard.GetState();\r
+            //check inputs\r
+            switch (currentState)\r
+            {\r
+                case lobbyState.Welcome:\r
+                    if (selected == createGameText)\r
+                    {\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
+                            currentState = lobbyState.CreateGame;\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up))\r
+                            selected = findGameText;\r
+                    }\r
+                    else\r
+                    {\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
+                            currentState = lobbyState.FindGame;\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Down) || currentKeyboardState.IsKeyDown(Keys.Up))\r
+                            selected = createGameText;\r
+                    }\r
+                    break;\r
+                case lobbyState.CreateGame:\r
+\r
+                    break;\r
+                case lobbyState.FindGame:\r
+\r
+                    break;\r
+                case lobbyState.Connected:\r
+\r
+                    break;\r
+\r
+            }\r
+            previousKeyboardState = Keyboard.GetState();\r
+\r
+            return 1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Draws the lobby GUI. Has different states for difference menu configurations\r
+        /// </summary>\r
+        public long Draw(SpriteBatch spriteBatch)\r
+        {\r
+            spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);\r
+            spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);\r
+            spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);\r
+            switch (currentState)\r
+            {\r
+                case lobbyState.Welcome:\r
+                    if (selected == createGameText)\r
+                        spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    else\r
+                        spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);\r
+                    if (selected == findGameText)\r
+                        spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    else\r
+                        spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    break;\r
+                case lobbyState.CreateGame:\r
+                    \r
+                    break;\r
+                case lobbyState.FindGame:\r
+                    \r
+                    break;\r
+                case lobbyState.Connected:\r
+                    \r
+                    break;\r
+            }\r
+\r
+            return 1;\r
+        }\r
+\r
+        private void UpdateSpotLight(GameTime gameTime)\r
+        {\r
+            spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,\r
+                                        spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);\r
+\r
+            if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall\r
+            {\r
+                spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);\r
+            }\r
+            else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall\r
+            {\r
+                spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);\r
+            }\r
+        }\r
+    }\r
+}\r
index e438fc8e06ae4f8e1a045e041a74c1a2e5bb527d..b1e59ecf2e08af84f8a52699ceffa2389e351b06 100644 (file)
@@ -70,6 +70,7 @@
     <Reference Include="System">\r
       <Private>False</Private>\r
     </Reference>\r
+    <Reference Include="System.Data" />\r
     <Reference Include="System.Xml">\r
       <Private>False</Private>\r
     </Reference>\r
@@ -83,6 +84,7 @@
     </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <Compile Include="LobbyGUI.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
     <Compile Include="Program.cs" />\r
     <Compile Include="Game1.cs" />\r
This page took 0.028928 seconds and 4 git commands to generate.