]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Game.cs
Basic Changes to Character, Small Changes to Display as well to make it so a Player...
[chaz/carfire] / CarFire / CarFire / CarFire / Game.cs
index d213f2e279a6e0400015eb7b4d518884b94e7298..a2b6cafb7e0f26f1a4121fc53b5ab97a41c3126d 100644 (file)
@@ -9,27 +9,76 @@ using Microsoft.Xna.Framework.Input;
 \r
 namespace CarFire\r
 {\r
+    //code from Prof Jensen's TestHarness\r
+    // This class encapsulates inputs from the players.\r
+    public class NextInputs\r
+    {\r
+        public List<Keys>[] keysPressed;\r
+        public List<Keys>[] keysReleased;\r
+        public int[] mouseLocationX;\r
+        public int[] mouseLocationY;\r
+        public bool[] mouseLocationChanged;\r
+        public bool[] mousePressed;\r
+        public bool[] mousePressedChanged;\r
+\r
+        public NextInputs()\r
+        {\r
+            keysPressed = new List<Keys>[4];\r
+            keysReleased = new List<Keys>[4];\r
+            mouseLocationX = new int[4];\r
+            mouseLocationY = new int[4];\r
+            mouseLocationChanged = new bool[4];\r
+            mousePressed = new bool[4];\r
+            mousePressedChanged = new bool[4];\r
+            for (int i = 0; i < 4; i++)\r
+                keysPressed[i] = new List<Keys>();\r
+            for (int i = 0; i < 4; i++)\r
+                keysReleased[i] = new List<Keys>();\r
+        }\r
+    }\r
+\r
     public class Game : IDeterministicGame\r
     {\r
         #region IDeterministicGame Members\r
         List<IPlayer> mPlayers;\r
+        NextInputs inputs;\r
+        Object[] playerIdentifiers;\r
         Display mDisplay;\r
         Map mMap;\r
 \r
         public Game()\r
         {\r
             mDisplay = new Display();\r
+            mPlayers = new List<IPlayer>();\r
         }\r
         public void LoadContent(ContentManager contentManager)\r
         {\r
             //Texture2D everything = contentManager.Load<Texture2D>("default");\r
             mDisplay.LoadContent(contentManager);\r
+            int currentCenterX = 5; //Creates a map like the one in Display\r
+            int currentCenterY = 5;\r
+            mMap = contentManager.Load<Map>("Maps/stable");\r
+            Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
+            mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);\r
+\r
+            Human player = new Human(mMap, "");\r
+            player.LoadContent(contentManager);\r
+            mPlayers.Add(player);\r
+            mDisplay.AddCharacters(player);\r
         }\r
 \r
         public void UnloadContent()\r
         {\r
         }\r
 \r
+        private int idPlayer(Object playerIdentifier)\r
+        {\r
+            for (int i = 0; i < playerIdentifiers.Length; i++)\r
+                if (playerIdentifiers[i] == playerIdentifier)\r
+                    return i;\r
+            throw new Exception("Illegal player identifier" + playerIdentifier);\r
+        }\r
+\r
         public Vector2 PreferredScreenSize\r
         {\r
             get { return new Vector2(800, 600); }\r
@@ -47,6 +96,10 @@ namespace CarFire
 \r
         public void ResetGame(object[] playerIdentifiers, object thisPlayer)\r
         {\r
+            foreach (IPlayer player in mPlayers)\r
+            {\r
+                player.Spawn(mMap.CenterCell);\r
+            }\r
         }\r
 \r
         public long CurrentFrameNumber\r
@@ -61,6 +114,14 @@ namespace CarFire
 \r
         public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed)\r
         {\r
+            //code from Prof Jensen's TestHarness\r
+            int player = idPlayer(playerIdentifier);\r
+\r
+            if (isKeyPressed && !inputs.keysPressed[player].Contains(key))\r
+                inputs.keysPressed[player].Add(key);\r
+\r
+            if (!isKeyPressed && !inputs.keysReleased[player].Contains(key))\r
+                inputs.keysReleased[player].Add(key);\r
         }\r
 \r
         public void ApplyMouseLocationInput(object playerIdentifier, int x, int y)\r
This page took 0.026705 seconds and 4 git commands to generate.