]> Dogcows Code - chaz/carfire/commitdiff
Character selection is now done in the Game Class instead of the display class.
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 22 Apr 2010 21:55:39 +0000 (21:55 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 22 Apr 2010 21:55:39 +0000 (21:55 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@130 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/Game.cs
CarFire/CarFire/CarFire/Human.cs

index dd0721215e3a2d5dc69b693af1e051afd105086c..5b22c8c541f50817942cb15c4a00d14e6227fe80 100644 (file)
@@ -23,7 +23,7 @@ namespace CarFire
         bool playerChosen = false;\r
         List<Projectile> mProjectiles = new List<Projectile>();\r
         //List<IPlayer> mCharacters = new List<IPlayer>();\r
-        IPlayer[] mCharacters = new IPlayer[4];\r
+        //IPlayer[] mCharacters = new IPlayer[4];\r
         Texture2D everything;\r
         Texture2D projectile1;\r
         Game mGame;\r
@@ -107,16 +107,16 @@ namespace CarFire
                 \r
             }\r
             //Check for collisons\r
-            for (int j = 0; j < mCharacters.Length; j++) \r
+            for (int j = 0; j < mGame.State.mCharacters.Length; j++) \r
             {\r
                \r
-                if(mCharacters[j] != null)\r
+                if(mGame.State.mCharacters[j] != null)\r
                 for (int i = 0; i < mProjectiles.Count; i++)\r
                 {\r
-                    if (mProjectiles[i].Coordinates.X == mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mCharacters[j].Coordinates.Y)\r
+                    if (mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)\r
                     {\r
-                        mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
-                        Console.WriteLine(mCharacters[j].Health);\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
@@ -126,24 +126,24 @@ namespace CarFire
             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 (mCharacters[i] == null)\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
+                        //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
-                    mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i));\r
+                    mGame.State.mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i));\r
                    \r
                 }\r
             }\r
-            if (mCharacters[thisPlayer] != null)\r
+            if (mGame.State.mCharacters[thisPlayer] != null)\r
             {\r
-                mGame.State.Map.CenterCell = mCharacters[thisPlayer].Position;\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
@@ -178,9 +178,9 @@ namespace CarFire
             for(int i = 0; i < mGame.State.NumberOfPlayers; i++)//IPlayer character in mCharacters)\r
             {\r
 \r
-                if (mCharacters[i] != null)\r
+                if (mGame.State.mCharacters[i] != null)\r
                 {\r
-                    mCharacters[i].Draw(spriteBatch);\r
+                    mGame.State.mCharacters[i].Draw(spriteBatch);\r
                     \r
                 }\r
             }\r
index 38ec627d1456dcff5531f055f9e4a3f45808872d..c867b3c749e072a65d4fbe30a50913427e2b7191 100644 (file)
@@ -24,6 +24,8 @@ namespace CarFire
 \r
         public Map Map;\r
         public List<IEntity> Entities = new List<IEntity>();\r
+        public IPlayer[] mCharacters = new IPlayer[4];\r
+        public Display mDisplay;\r
 \r
         #endregion\r
 \r
@@ -243,12 +245,12 @@ namespace CarFire
 \r
         public Game()\r
         {\r
-            mDisplay = new Display(this);\r
+           \r
         }\r
         public void LoadContent(ContentManager contentManager)\r
         {\r
             mContentManager = contentManager;\r
-            mDisplay.LoadContent(contentManager);\r
+            \r
         }\r
 \r
         public void UnloadContent()\r
@@ -290,6 +292,8 @@ namespace CarFire
 \r
             State = new GameState(numPlayers);\r
             mInputs = new NextInputs(numPlayers);\r
+            State.mDisplay = new Display(this);\r
+            State.mDisplay.LoadContent(mContentManager);\r
 \r
             State.Map = mContentManager.Load<Map>("Maps/stable");\r
             State.Map.Game = this;\r
@@ -361,7 +365,7 @@ namespace CarFire
         public long Update(TimeSpan elapsedTime)\r
         {\r
             State.AdvanceFrame(mInputs, elapsedTime.Milliseconds);  // Apply the inputs, advance game state.\r
-            mDisplay.Update(elapsedTime, State, mThisPlayerID);\r
+            State.mDisplay.Update(elapsedTime, State, 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
@@ -371,7 +375,24 @@ namespace CarFire
 \r
         public long Draw(SpriteBatch spriteBatch)\r
         {\r
-            mDisplay.Draw(spriteBatch);\r
+            bool allCharactersSelected = true;\r
+            for (int i = 0; i < State.NumberOfPlayers; i++)\r
+            {\r
+                //If player has not selected a player yet let them select one.\r
+                if (State.mCharacters[i] == null)\r
+                {\r
+                    allCharactersSelected = false;\r
+                    if (State.GetKeysDown(i).Contains(Keys.Enter))\r
+                    {\r
+                        State.mCharacters[i] = new Human(this, "", State.Map.GetStartingPositionForPlayer(i + 1));\r
+                        State.mCharacters[i].LoadContent(mContentManager);\r
+                    }\r
+                }\r
+            }\r
+            if (allCharactersSelected)\r
+            {\r
+                State.mDisplay.Draw(spriteBatch);\r
+            }\r
             return CurrentFrameNumber;\r
         }\r
 \r
index 6c037947d9f50f6744b255039c338cb961073150..5b4c6a01777597625c460f10f6d7aa629c2d447a 100644 (file)
@@ -24,23 +24,19 @@ namespace CarFire
 \r
         MovementManager mMotion;\r
         bool visible;\r
-        Display theDisplay;\r
 \r
         //Used to draw projectiles\r
         int projectileSpeed;\r
         int projectileCoolDown;\r
         \r
 \r
-        public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position)\r
+        public Human(Game theGame, String Name, Point position)\r
         {\r
             game = theGame;\r
             CharName = Name;\r
-            theDisplay = mDisplay;\r
             health = 100;\r
             score = 0;\r
             visible = false;\r
-            charModel = model;\r
-            projectileModel = projectile;\r
             projectileSpeed = 8;\r
 \r
             // Speed is the number of grid cells you can move through per second.\r
@@ -145,7 +141,7 @@ namespace CarFire
                     toShoot.Normalize();\r
                     toShoot *= projectileSpeed;\r
                     projectileCoolDown = shootCoolDown;\r
-                    theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,\r
+                    game.State.mDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel,\r
                         toShoot, new Point(startX, startY)));\r
 \r
              \r
This page took 0.030153 seconds and 4 git commands to generate.