]> Dogcows Code - chaz/carfire/commitdiff
Seperated GameLogic from the Display
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 03:33:30 +0000 (03:33 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 03:33:30 +0000 (03:33 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@137 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/CarFire.csproj
CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/Game.cs
CarFire/CarFire/CarFire/GameLogic.cs [new file with mode: 0644]
CarFire/CarFire/CarFire/Ranged.cs

index b067b277ce40ac4564755b08e7c2956fb2aefb98..43537127e39235a477ae7613b5f3b1627d2869ce 100644 (file)
@@ -84,6 +84,7 @@
     </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <Compile Include="GameLogic.cs" />\r
     <Compile Include="IEntity.cs" />\r
     <Compile Include="Melee.cs" />\r
     <Compile Include="Player.cs" />\r
index 01fbbba44d946e7988c29b5cb79a339581d24fd6..c6ae062c2ad93fa57cbedcb031d0647c7e2952d0 100644 (file)
@@ -20,18 +20,17 @@ namespace CarFire
     /// </summary>\r
     public class Display\r
     {\r
-        List<Projectile> mProjectiles = new List<Projectile>();\r
-        //List<IPlayer> mCharacters = new List<IPlayer>();\r
-        //IPlayer[] mCharacters = new IPlayer[4];\r
         Texture2D everything;\r
         Texture2D projectile1;\r
         Game mGame;\r
+        GameLogic mGameLogic;\r
 #if SINGLE_TEST\r
         List<Keys> mLastPressedKeys = new List<Keys>();\r
 #endif\r
         public Display(Game game)\r
         {\r
             mGame = game;\r
+            mGameLogic = new GameLogic(game);\r
             /*\r
             mMap = aMap;\r
             mCharacters = characters;\r
@@ -62,98 +61,9 @@ namespace CarFire
         /// checking for collisions, gathering input, and playing audio.\r
         /// </summary>\r
         /// <param name="gameTime">Provides a snapshot of timing values.</param>\r
-        public void Update(TimeSpan timespan, GameState state, int thisPlayer)\r
+        public void Update(TimeSpan timeSpan,int thisPlayer)\r
         {\r
-            \r
-            //INPUT - testing input... has to be through network later\r
-#if SINGLE_TEST\r
-            KeyboardState keyState = Keyboard.GetState();\r
-\r
-            List<Keys> pressedKeys = new List<Keys>();\r
-            List<Keys> releasedKeys = new List<Keys>();\r
-\r
-            Keys[] pressedKeysArray = keyState.GetPressedKeys();\r
-            foreach (Keys k in pressedKeysArray)\r
-            {\r
-                if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);\r
-                else mLastPressedKeys.Remove(k);\r
-            }\r
-\r
-            releasedKeys = mLastPressedKeys;\r
-            mLastPressedKeys = new List<Keys>(pressedKeysArray);\r
-            //Just apply input for the first player\r
-            mCharacters[0].MovePlayer(pressedKeys);\r
-            if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))\r
-            {\r
-                mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5,0), mCharacters[0].GridX +1, mCharacters[0].GridY+1, (int)mCharacters[0].GridX*(int)Map.PixelsToUnitSquares,(int)mCharacters[0].GridY*(int)Map.PixelsToUnitSquares));\r
-            }\r
-            mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
-#endif\r
-            \r
-            //Handle projectiles - update and check for wall collisions\r
-            for (int i = 0; i < mProjectiles.Count; i++ )\r
-            {\r
-                bool removed = false;\r
-                if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
-                {\r
-               \r
-                    mProjectiles.RemoveAt(i);\r
-                    removed = true;\r
-                    i--;\r
-                }\r
-                if(!removed)\r
-                mProjectiles[i].Update(timespan);\r
-                \r
-            }\r
-            //Check for collisons\r
-            for (int j = 0; j < mGame.State.mCharacters.Length; j++) \r
-            {\r
-               \r
-                if(mGame.State.mCharacters[j] != null)\r
-                for (int i = 0; i < mProjectiles.Count; i++)\r
-                {\r
-                    if (mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)\r
-                    {\r
-                        mGame.State.mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
-                        Console.WriteLine(mGame.State.mCharacters[j].Health);\r
-                        mProjectiles.RemoveAt(i);\r
-                        i--;\r
-                    }\r
-                }\r
-            }\r
-            //Update input for each player\r
-            for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
-            {\r
-                //If player has not selected a player yet let them select one.\r
-                if (mGame.State.mCharacters[i] == null)\r
-                {\r
-                    if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
-                    {\r
-                        //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
-                    }\r
-                }\r
-                //Regular player input updates\r
-                else\r
-                {\r
-\r
-                    mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
-                   \r
-                }\r
-            }\r
-            if (mGame.State.mCharacters[thisPlayer] != null)\r
-            {\r
-                mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;\r
-            }\r
-                //Handle wall collisions of projectiles again...\r
-            for (int i = 0; i < mProjectiles.Count; i++)\r
-            {\r
-                if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
-                {\r
-                    mProjectiles.RemoveAt(i);\r
-                    i--;\r
-                }          \r
-\r
-            }\r
+            mGameLogic.Update(timeSpan, thisPlayer);\r
 \r
 #if INGAME_ZOOM\r
             if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mGame.State.Map.Zoom = mGame.State.Map.Zoom + 0.5f;\r
@@ -170,7 +80,7 @@ namespace CarFire
             mGame.State.Map.Draw(spriteBatch);\r
             mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); });\r
 \r
-            foreach(Projectile projectile in mProjectiles)\r
+            foreach(Projectile projectile in mGame.State.mProjectiles)\r
             {\r
                 projectile.Draw(spriteBatch);\r
             }\r
@@ -185,14 +95,7 @@ namespace CarFire
             }\r
             \r
         }\r
-        /// <summary>\r
-        /// Add a projectile to the Display.\r
-        /// </summary>\r
-        /// <param name="projectile"></param>\r
-        public void AddProjectiles(Projectile projectile)\r
-        {\r
-            mProjectiles.Add(projectile);\r
-        }\r
+        \r
     }\r
 }\r
 \r
index be18be785b8d8a35c7f02dfbcbced0d8c414be74..937cd4d87a243d20a1cf6978eacc465b103a49cf 100644 (file)
@@ -24,6 +24,7 @@ namespace CarFire
 \r
         public Map Map;\r
         public List<IEntity> Entities = new List<IEntity>();\r
+        public List<Projectile> mProjectiles = new List<Projectile>();\r
         public Player[] mCharacters = new Player[4];\r
         public Display mDisplay;\r
 \r
@@ -380,7 +381,7 @@ namespace CarFire
         public long Update(TimeSpan elapsedTime)\r
         {\r
             State.AdvanceFrame(mInputs, elapsedTime.Milliseconds);  // Apply the inputs, advance game state.\r
-            State.mDisplay.Update(elapsedTime, State, mThisPlayerID);\r
+            State.mDisplay.Update(elapsedTime, mThisPlayerID);\r
             State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); });\r
             mInputs = new NextInputs(State.NumberOfPlayers);  // Start with inputs cleared on the next frame.\r
             //mDisplay.Update(elapsedTime);\r
diff --git a/CarFire/CarFire/CarFire/GameLogic.cs b/CarFire/CarFire/CarFire/GameLogic.cs
new file mode 100644 (file)
index 0000000..6f859d0
--- /dev/null
@@ -0,0 +1,87 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Input;\r
+\r
+namespace CarFire\r
+{\r
+    class GameLogic\r
+    {\r
+        Game mGame;\r
+        public GameLogic(Game game)\r
+        {\r
+            mGame = game;\r
+        }\r
+        public void Update(TimeSpan timespan, int thisPlayer)\r
+        {\r
+            //Handle projectiles - update and check for wall collisions\r
+            for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+            {\r
+                bool removed = false;\r
+                if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+                {\r
+\r
+                    mGame.State.mProjectiles.RemoveAt(i);\r
+                    removed = true;\r
+                    i--;\r
+                }\r
+                if (!removed)\r
+                    mGame.State.mProjectiles[i].Update(timespan);\r
+\r
+            }\r
+            //Check for collisons\r
+            for (int j = 0; j < mGame.State.mCharacters.Length; j++)\r
+            {\r
+\r
+                if (mGame.State.mCharacters[j] != null)\r
+                    for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+                    {\r
+                        if (mGame.State.mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mGame.State.mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)\r
+                        {\r
+                            mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage);\r
+                            Console.WriteLine(mGame.State.mCharacters[j].Health);\r
+                            mGame.State.mProjectiles.RemoveAt(i);\r
+                            i--;\r
+                        }\r
+                    }\r
+            }\r
+            //Update input for each player\r
+            for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
+            {\r
+                //If player has not selected a player yet let them select one.\r
+                if (mGame.State.mCharacters[i] == null)\r
+                {\r
+                    if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
+                    {\r
+                        //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
+                    }\r
+                }\r
+                //Regular player input updates\r
+                else\r
+                {\r
+\r
+                    mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
+\r
+                }\r
+            }\r
+            if (mGame.State.mCharacters[thisPlayer] != null)\r
+            {\r
+                mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;\r
+            }\r
+            //Handle wall collisions of projectiles again...\r
+            for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+            {\r
+                if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+                {\r
+                    mGame.State.mProjectiles.RemoveAt(i);\r
+                    i--;\r
+                }\r
+\r
+            }\r
+        }\r
+    }\r
+}\r
index 02593ab706ceb3f2d1731532e4e2e367a6a2d14f..b1203dda96619505ed3e9757d0d8e46bcebe48ff 100644 (file)
@@ -85,7 +85,7 @@ namespace CarFire
                     toShoot.Normalize();\r
                     toShoot *= projectileSpeed;\r
                     projectileCoolDown = shootCoolDown;\r
-                    Game.State.mDisplay.AddProjectiles(new Projectile(Game, projectileModel,\r
+                    Game.State.mProjectiles.Add(new Projectile(Game, projectileModel,\r
                         toShoot, new Point(startX, startY), PlayerIndex, Damage));\r
                 }\r
             }\r
This page took 0.03014 seconds and 4 git commands to generate.