]> Dogcows Code - chaz/carfire/commitdiff
Basic Changes to Character, Small Changes to Display as well to make it so a Player...
authorbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 07:29:46 +0000 (07:29 +0000)
committerbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 07:29:46 +0000 (07:29 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@91 92bb83a3-7c8f-8a45-bc97-515c4e399668

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

index 9bfefef94ff26059a94d4b5a98c75f3a8210a865..ed6ab458cabdb91c1e2df54570d533e040846f03 100644 (file)
@@ -15,7 +15,7 @@ namespace CarFire
     public class Display\r
     {\r
         List<Projectile> mProjectiles = new List<Projectile>();\r
-        List<Character> mCharacters = new List<Character>();\r
+        List<IPlayer> mCharacters = new List<IPlayer>();\r
         Map mMap;\r
         int currentCenterX = 5;\r
         int currentCenterY = 5;\r
@@ -49,6 +49,7 @@ namespace CarFire
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));\r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));\r
 \r
+            \r
             // TODO: use this.Content to load your game content here\r
         }\r
 \r
@@ -89,7 +90,7 @@ namespace CarFire
                         //Debug - not sure if you can remove while doing for each\r
                         //Alternative - while loop, and decrement projectile counter if projectile is removed.\r
                         mProjectiles.Remove(mProjectiles[i]);\r
-                        mCharacters[j].Health -= mProjectiles[i].Damage;\r
+                        mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
                     }\r
                 }\r
             }\r
@@ -110,11 +111,16 @@ namespace CarFire
                 projectile.Draw(spriteBatch);\r
                 \r
             }\r
-            foreach(Character character in mCharacters)\r
+            foreach(IPlayer character in mCharacters)\r
             {\r
                 character.Draw(spriteBatch);\r
             } \r
         }\r
+\r
+        public void AddCharacters(IPlayer player)\r
+        {\r
+            mCharacters.Add(player);\r
+        }\r
     }\r
 }\r
 \r
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
index e0f6cc59cb0f1d600d3172e564bd6d40f05ea648..acb0d3b8cd92cca04d68ca30fe11027aecbc3e44 100644 (file)
@@ -38,7 +38,7 @@ namespace CarFire
             visible = false;\r
         }\r
 \r
-        public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
+        public void LoadContent(ContentManager contentManager)\r
         {\r
             charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed\r
         }\r
@@ -56,9 +56,12 @@ namespace CarFire
 \r
         public long Draw(SpriteBatch spriteBatch)\r
         {\r
+            spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);\r
             return 0;\r
         }\r
 \r
+        public int GridX { get { return gridX; } set { gridX = value; } }\r
+        public int GridY { get { return gridY; } set { gridY = value; } }\r
         public int Health { get { return health; } }\r
         public int Score { get { return score; } }\r
         public bool alive { get { return health > 0; } }\r
@@ -130,10 +133,10 @@ namespace CarFire
             health += amount;\r
         }\r
 \r
-        public void Spawn(Point mapPoint)\r
+        public void Spawn(Vector2 spawn)\r
         {\r
-            gridX = mapPoint.X;\r
-            gridY = mapPoint.Y;\r
+            gridX = (int)spawn.X;\r
+            gridY = (int)spawn.Y;\r
             visible = true;\r
         }\r
 \r
index 7eb761146d66547e563ca3e0b810ccf1ff4f7ef8..3b9830148e0f4ec13d7de0e81909194120b68233 100644 (file)
@@ -11,12 +11,14 @@ namespace CarFire
 {\r
     public interface ICharacter\r
     {\r
-        void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics);\r
+        void LoadContent(ContentManager contentManager);\r
         void UnloadContent();\r
         long Update(GameTime gameTime, NetworkManager networkGame);\r
         long Draw(SpriteBatch spriteBatch);\r
         int Health { get; }\r
         void causeDamageTo(int amount);\r
+        int GridX { get; set; }\r
+        int GridY { get; set; }\r
     }\r
 \r
     public interface IPlayer : ICharacter\r
@@ -24,7 +26,7 @@ namespace CarFire
         void MovePlayer(List<Keys> keysPressed);\r
         int Score { get; }\r
         void powerUp(int amount);\r
-        void Spawn(Point mapPoint);\r
+        void Spawn(Vector2 spawn);\r
         bool alive { get; }\r
     }\r
 \r
This page took 0.033952 seconds and 4 git commands to generate.