]> Dogcows Code - chaz/carfire/commitdiff
Split human class into Melee and ranged... probably should do some sort
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 00:57:48 +0000 (00:57 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 00:57:48 +0000 (00:57 +0000)
of inheritance... later.

git-svn-id: https://bd85.net/svn/cs3505_group@133 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/CarFire.csproj
CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/Game.cs
CarFire/CarFire/CarFire/IPlayer.cs
CarFire/CarFire/CarFire/Melee.cs [new file with mode: 0644]
CarFire/CarFire/CarFire/Projectile.cs
CarFire/CarFire/CarFire/Ranged.cs [moved from CarFire/CarFire/CarFire/Human.cs with 89% similarity]

index 0b85b765923542f4c63ba75fe7c748fa84fcc05b..d7f666f2a8b21e206647447f0f23dda6fb881cc2 100644 (file)
   </ItemGroup>\r
   <ItemGroup>\r
     <Compile Include="IEntity.cs" />\r
+    <Compile Include="Melee.cs" />\r
     <Compile Include="SaberMonster.cs" />\r
     <Compile Include="MovementManager.cs" />\r
     <Compile Include="PathFinder.cs" />\r
     <Compile Include="ChatInfo.cs" />\r
     <Compile Include="Display.cs" />\r
     <Compile Include="Game.cs" />\r
-    <Compile Include="Human.cs" />\r
+    <Compile Include="Ranged.cs" />\r
     <Compile Include="IDeterministicGame.cs" />\r
     <Compile Include="IPlayer.cs" />\r
     <Compile Include="IScreenManager.cs" />\r
index 5b22c8c541f50817942cb15c4a00d14e6227fe80..c6a1e440b7f25231ffaed486b05599e8f68d0700 100644 (file)
@@ -137,7 +137,7 @@ namespace CarFire
                 else\r
                 {\r
 \r
-                    mGame.State.mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i));\r
+                    mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
                    \r
                 }\r
             }\r
index 4aa1cfe83aff7eea3d60f74d2289042d66cd34b7..3fd5ef0511e11af41721d50d0ffbdb031715bae8 100644 (file)
@@ -384,7 +384,7 @@ namespace CarFire
                     allCharactersSelected = false;\r
                     if (State.GetKeysDown(i).Contains(Keys.Enter))\r
                     {\r
-                        State.mCharacters[i] = new Human(this, "", State.Map.GetStartingPositionForPlayer(i + 1), i);\r
+                        State.mCharacters[i] = new Ranged(this, "", State.Map.GetStartingPositionForPlayer(i + 1), i);\r
                         State.mCharacters[i].LoadContent(mContentManager);\r
                     }\r
                 }\r
index f90fc151afc8d2f5557c21a15938a3e4089ec13a..a22a9decd2b1d66237572eab6908b2bb0b2ab54c 100644 (file)
@@ -17,11 +17,13 @@ namespace CarFire
 \r
     public interface IPlayer : ICharacter\r
     {\r
-        void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed);\r
+        void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed);\r
         int Score { get; }\r
         void powerUp(int amount);\r
         void Spawn(Vector2 spawn);\r
         bool alive { get; }\r
+        void Attack();\r
+        void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed);\r
     }\r
 \r
     public interface IMonster : ICharacter\r
diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs
new file mode 100644 (file)
index 0000000..0d69287
--- /dev/null
@@ -0,0 +1,145 @@
+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
+    public class Melee : IPlayer\r
+    {\r
+        //The number of frames between each projectile is spawned.\r
+        const int shootCoolDown = 18;\r
+        String CharName;\r
+        Game game;\r
+        Texture2D charModel;\r
+        Texture2D projectileModel;\r
+        int health;\r
+        int damage;\r
+        int range;\r
+        int score;\r
+\r
+        MovementManager mMotion;\r
+        bool visible;\r
+\r
+        //Used to draw projectiles\r
+        int projectileSpeed;\r
+        int projectileCoolDown;\r
+        int mPlayerIndex;\r
+\r
+\r
+        public Melee(Game theGame, String Name, Point position, int playerIndex)\r
+        {\r
+            game = theGame;\r
+            CharName = Name;\r
+            health = 100;\r
+            score = 0;\r
+            visible = false;\r
+            projectileSpeed = 8;\r
+            mPlayerIndex = playerIndex;\r
+\r
+            // Speed is the number of grid cells you can move through per second.\r
+            mMotion = new MovementManager(position, 4.0f);\r
+        }\r
+\r
+        public void LoadContent(ContentManager contentManager)\r
+        {\r
+            charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed\r
+            projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later\r
+\r
+        }\r
+\r
+\r
+        public void Update(TimeSpan timeSpan)\r
+        {\r
+        }\r
+        /// <summary>\r
+        /// This method will draw a character to the screen.\r
+        /// </summary>\r
+        /// <param name="spriteBatch"></param>\r
+        public void Draw(SpriteBatch spriteBatch)\r
+        {\r
+            Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
+            spriteBatch.Draw(charModel, position, Color.White);\r
+        }\r
+\r
+        public int Health { get { return health; } }\r
+        public int Score { get { return score; } }\r
+        public bool alive { get { return health > 0; } }\r
+\r
+        public Vector2 Position { get { return mMotion.Position; } }\r
+        public Point Coordinates { get { return mMotion.Coordinates; } }\r
+\r
+        public void causeDamageTo(int amount)\r
+        {\r
+            health -= amount;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Moves the current player being controlled based on a given set of key presses.\r
+        /// The player can only move one grid space per movePlayer call. Thus this method\r
+        /// is made to be called ever update. The player will only move if the grid space\r
+        /// that is being moved to is an open space.\r
+        /// </summary>\r
+        /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>\r
+        public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)\r
+        {\r
+\r
+            UpdatePosition(timeSpan, keysPressed);\r
+\r
+            if (projectileCoolDown > 0)\r
+                projectileCoolDown--;\r
+            else if (projectileCoolDown == 0)\r
+            {\r
+                if (keysPressed.Contains<Keys>(Keys.Space))\r
+                {\r
+                    Attack();\r
+                }\r
+            }\r
+        }\r
+        public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)\r
+        {\r
+            bool moveLeft = keysPressed.Contains(Keys.Left);\r
+            bool moveRight = keysPressed.Contains(Keys.Right);\r
+            bool moveUp = keysPressed.Contains(Keys.Up);\r
+            bool moveDown = keysPressed.Contains(Keys.Down);\r
+            Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
+            if (!keysPressed.Contains(Keys.LeftControl))\r
+            {\r
+                if (game.IsCellOpen(destination))\r
+                {\r
+                    mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+                }\r
+                else\r
+                {\r
+                    mMotion.Update(timeSpan);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+            }\r
+        }\r
+        public void Attack()\r
+        {\r
+            //melee attack\r
+\r
+        }\r
+        public void powerUp(int amount)\r
+        {\r
+            health += amount;\r
+        }\r
+\r
+        public void Spawn(Vector2 spawn)\r
+        {\r
+            //gridX = (int)spawn.X;\r
+            //gridY = (int)spawn.Y;\r
+            visible = true;\r
+        }\r
+\r
+\r
+    }\r
+}
\ No newline at end of file
index 6603272c2f84ea9655d965c35ff8e5be1437cee3..95d0d6e83525c8405d922953f7ad5ac50a7e6a82 100644 (file)
@@ -43,7 +43,8 @@ namespace CarFire
                             Texture2D _projectileModel,\r
                             Vector2 _velocity,\r
                             Point _position,\r
-                            int characterNumber)\r
+                            int characterNumber,\r
+                            int _damage)\r
                 \r
         {\r
             mGame = theGame;\r
@@ -51,7 +52,7 @@ namespace CarFire
             projectileModel = _projectileModel;\r
             velocity = _velocity;\r
             mPosition = _position;\r
-            damage = 20;\r
+            damage = _damage;\r
             // Speed is the number of grid cells you can move through per second.\r
             mMotion = new MovementManager(mPosition, velocity.Length());\r
         }\r
similarity index 89%
rename from CarFire/CarFire/CarFire/Human.cs
rename to CarFire/CarFire/CarFire/Ranged.cs
index 0d65d494a744cdfaf4b5a7e609af887431139200..b859cd6246fc79a1b1632b5d156e6b3dedd55b74 100644 (file)
@@ -9,7 +9,7 @@ using Microsoft.Xna.Framework.Input;
 \r
 namespace CarFire\r
 {\r
-    public class Human : IPlayer\r
+    public class Ranged : IPlayer\r
     {\r
         //The number of frames between each projectile is spawned.\r
         const int shootCoolDown = 18;\r
@@ -31,7 +31,7 @@ namespace CarFire
         int mPlayerIndex;\r
         \r
 \r
-        public Human(Game theGame, String Name, Point position, int playerIndex)\r
+        public Ranged(Game theGame, String Name, Point position, int playerIndex)\r
         {\r
             game = theGame;\r
             CharName = Name;\r
@@ -85,7 +85,22 @@ namespace CarFire
         /// that is being moved to is an open space.\r
         /// </summary>\r
         /// <param name="keysPressed">A general list of keys that are pressed. Other keys can be included but only direction keys will be used</param>\r
-        public void MovePlayer(TimeSpan timeSpan, List<Keys> keysPressed)\r
+        public void UpdateInput(TimeSpan timeSpan, List<Keys> keysPressed)\r
+        {\r
+\r
+            UpdatePosition(timeSpan, keysPressed);\r
+\r
+            if (projectileCoolDown > 0)\r
+                projectileCoolDown--;\r
+            else if (projectileCoolDown == 0)\r
+            {\r
+                if (keysPressed.Contains<Keys>(Keys.Space))\r
+                {\r
+                    Attack();\r
+                }\r
+            }\r
+        }\r
+        public void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed)\r
         {\r
             bool moveLeft = keysPressed.Contains(Keys.Left);\r
             bool moveRight = keysPressed.Contains(Keys.Right);\r
@@ -107,15 +122,10 @@ namespace CarFire
             {\r
                 mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
             }\r
-\r
-\r
-            if (projectileCoolDown > 0)\r
-                projectileCoolDown--;\r
-            else if (projectileCoolDown == 0)\r
-            {\r
-                if (keysPressed.Contains<Keys>(Keys.Space))\r
-                {\r
-                    float velocityX = 0;\r
+        }\r
+        public void Attack()\r
+        {\r
+             float velocityX = 0;\r
                     float velocityY = 0;\r
                     int startX = Coordinates.X;\r
                     int startY = Coordinates.Y;\r
@@ -144,14 +154,9 @@ namespace CarFire
                     toShoot *= projectileSpeed;\r
                     projectileCoolDown = shootCoolDown;\r
                     game.State.mDisplay.AddProjectiles(new Projectile(game, projectileModel,\r
-                        toShoot, new Point(startX, startY), mPlayerIndex));\r
-\r
-             \r
-                }\r
-            }\r
+                        toShoot, new Point(startX, startY), mPlayerIndex, damage));\r
+                \r
         }\r
-\r
-\r
         public void powerUp(int amount)\r
         {\r
             health += amount;\r
This page took 0.033596 seconds and 4 git commands to generate.