]> Dogcows Code - chaz/carfire/commitdiff
Melee and Ranged now inheret from Player
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 02:27:53 +0000 (02:27 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Fri, 23 Apr 2010 02:27:53 +0000 (02:27 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@134 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
CarFire/CarFire/CarFire/Player.cs [new file with mode: 0644]
CarFire/CarFire/CarFire/Ranged.cs

index d7f666f2a8b21e206647447f0f23dda6fb881cc2..b067b277ce40ac4564755b08e7c2956fb2aefb98 100644 (file)
@@ -86,6 +86,7 @@
   <ItemGroup>\r
     <Compile Include="IEntity.cs" />\r
     <Compile Include="Melee.cs" />\r
+    <Compile Include="Player.cs" />\r
     <Compile Include="SaberMonster.cs" />\r
     <Compile Include="MovementManager.cs" />\r
     <Compile Include="PathFinder.cs" />\r
index c6a1e440b7f25231ffaed486b05599e8f68d0700..01fbbba44d946e7988c29b5cb79a339581d24fd6 100644 (file)
@@ -20,7 +20,6 @@ namespace CarFire
     /// </summary>\r
     public class Display\r
     {\r
-        bool playerChosen = false;\r
         List<Projectile> mProjectiles = new List<Projectile>();\r
         //List<IPlayer> mCharacters = new List<IPlayer>();\r
         //IPlayer[] mCharacters = new IPlayer[4];\r
index 3fd5ef0511e11af41721d50d0ffbdb031715bae8..dce6ba45cadb5309632d4ff847cc132a7a4126a9 100644 (file)
@@ -24,7 +24,7 @@ namespace CarFire
 \r
         public Map Map;\r
         public List<IEntity> Entities = new List<IEntity>();\r
-        public IPlayer[] mCharacters = new IPlayer[4];\r
+        public Player[] mCharacters = new Player[4];\r
         public Display mDisplay;\r
 \r
         #endregion\r
index a22a9decd2b1d66237572eab6908b2bb0b2ab54c..3e20f837b301aa5a2323cd8c1add51318f6a1d7e 100644 (file)
@@ -24,6 +24,11 @@ namespace CarFire
         bool alive { get; }\r
         void Attack();\r
         void UpdatePosition(TimeSpan timeSpan, List<Keys> keysPressed);\r
+        /*\r
+        void AddHealth(int healthBoost);\r
+        void IncreaseDamage(int damageBoost);\r
+        void PlayAttackSound();\r
+        void PlayDieSound();*/\r
     }\r
 \r
     public interface IMonster : ICharacter\r
index 0d69287846486f5ceaeaaab875b79a3de1c41fa8..299f2e79a794b9b2e18b04081eb0239cb4b8a5a6 100644 (file)
@@ -9,137 +9,55 @@ using Microsoft.Xna.Framework.Input;
 \r
 namespace CarFire\r
 {\r
-    public class Melee : IPlayer\r
+    public class Melee : Player\r
     {\r
-        //The number of frames between each projectile is spawned.\r
-        const int shootCoolDown = 18;\r
-        String CharName;\r
-        Game game;\r
+        #region Member Variables\r
+        const int hitCoolDown = 18;\r
+        const int baseHealth = 200;\r
+        const int baseDamage = 30;\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
+        #endregion \r
 \r
+        #region Public Methods\r
         public Melee(Game theGame, String Name, Point position, int playerIndex)\r
+            : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)\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
+        #endregion\r
 \r
-        public void LoadContent(ContentManager contentManager)\r
+        #region Overridden Methods From Player\r
+        public override 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
+        public override void Draw(SpriteBatch spriteBatch)\r
         {\r
-            Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
+            Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.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
+        public override void Attack(List<Keys> keysPressed)\r
         {\r
-\r
-            UpdatePosition(timeSpan, keysPressed);\r
-\r
-            if (projectileCoolDown > 0)\r
-                projectileCoolDown--;\r
-            else if (projectileCoolDown == 0)\r
+            if (hitCoolDown > 0)\r
+                hitCoolDown--;\r
+            else if (hitCoolDown == 0)\r
             {\r
                 if (keysPressed.Contains<Keys>(Keys.Space))\r
                 {\r
-                    Attack();\r
+                    \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
+        #endregion\r
     }\r
 }
\ No newline at end of file
diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs
new file mode 100644 (file)
index 0000000..f1d121c
--- /dev/null
@@ -0,0 +1,126 @@
+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
+\r
+namespace CarFire\r
+{\r
+    public class Player : ICharacter\r
+    {\r
+        #region Member variables\r
+        //The number of frames between each projectile is spawned.\r
+        const int shootCoolDown = 18;\r
+        String CharName;\r
+        Game game;\r
+        int playerHealth;\r
+        int playerDamage;\r
+        int score;\r
+        MovementManager mMotion;\r
+        int mPlayerIndex;\r
+        #endregion\r
+\r
+\r
+        public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage)\r
+        {\r
+            game = theGame;\r
+            CharName = Name;\r
+            score = 0;\r
+            playerHealth = health;\r
+            playerDamage = damage;\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 virtual void LoadContent(ContentManager contentManager)\r
+        {\r
+\r
+        }\r
+        /// <summary>\r
+        /// This method will draw a character to the screen.\r
+        /// </summary>\r
+        /// <param name="spriteBatch"></param>\r
+        public virtual void Draw(SpriteBatch spriteBatch)\r
+        {\r
+        }\r
+\r
+        public int Health { get { return playerHealth; } }\r
+        public int Score { get { return score; } }\r
+        public bool alive { get { return playerHealth > 0; } }\r
+        public Game Game { get { return game; } }\r
+        public MovementManager Motion { get { return mMotion; } }\r
+        public int PlayerIndex { get { return mPlayerIndex; } }\r
+        public Vector2 Position { get { return mMotion.Position; } }\r
+        public Point Coordinates { get { return mMotion.Coordinates; } }\r
+        public int Damage { get { return playerDamage; } }\r
+\r
+        public void causeDamageTo(int amount)\r
+        {\r
+            playerHealth -= amount;\r
+        }\r
+\r
+        public void Update(TimeSpan timeSpan)\r
+        {\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
+            Attack(keysPressed);\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 virtual void Attack(List<Keys> keysPressed)\r
+        {\r
+                \r
+        }\r
+        public void powerUp(int amount)\r
+        {\r
+            playerHealth += amount;\r
+        }\r
+\r
+        public void Spawn(Vector2 spawn)\r
+        {\r
+            \r
+        }\r
+\r
+\r
+    }\r
+    \r
+}\r
index b859cd6246fc79a1b1632b5d156e6b3dedd55b74..874aa2f9ce936fab44f6aab28ada43e7e0f32b8c 100644 (file)
@@ -9,142 +9,70 @@ using Microsoft.Xna.Framework.Input;
 \r
 namespace CarFire\r
 {\r
-    public class Ranged : IPlayer\r
+    public class Ranged : Player\r
     {\r
         //The number of frames between each projectile is spawned.\r
         const int shootCoolDown = 18;\r
-        String CharName;\r
-        Game game;\r
+        const int baseHealth = 100;\r
+        const int baseDamage = 20;\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
 \r
         public Ranged(Game theGame, String Name, Point position, int playerIndex)\r
+            : base(theGame, Name, position, playerIndex, baseHealth, baseDamage)\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
+        public override 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
+        public override void Draw(SpriteBatch spriteBatch)\r
         {\r
-            Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
+            Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.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
+        public override void Attack(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
-             float velocityX = 0;\r
+                    float velocityX = 0;\r
                     float velocityY = 0;\r
                     int startX = Coordinates.X;\r
                     int startY = Coordinates.Y;\r
-                    if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)\r
+                    if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)\r
                     {\r
                         velocityY = 1;\r
                         startY = Coordinates.Y + 1;\r
                     }\r
-                    else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)\r
+                    else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)\r
                     {\r
                         velocityY = -1;\r
                         startY = Coordinates.Y - 1;\r
                     }\r
-                    if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)\r
+                    if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)\r
                     {\r
                         velocityX = 1;\r
                         startX = Coordinates.X + 1;\r
                     }\r
-                    else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)\r
+                    else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)\r
                     {\r
                         velocityX = -1;\r
                         startX = Coordinates.X - 1;\r
@@ -153,21 +81,14 @@ namespace CarFire
                     toShoot.Normalize();\r
                     toShoot *= projectileSpeed;\r
                     projectileCoolDown = shootCoolDown;\r
-                    game.State.mDisplay.AddProjectiles(new Projectile(game, projectileModel,\r
-                        toShoot, new Point(startX, startY), mPlayerIndex, damage));\r
+                    Game.State.mDisplay.AddProjectiles(new Projectile(Game, projectileModel,\r
+                        toShoot, new Point(startX, startY), PlayerIndex, Damage));\r
+                }\r
+            }\r
+             \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
     }\r
This page took 0.039579 seconds and 4 git commands to generate.