]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Melee.cs
Player doesn't disappear
[chaz/carfire] / CarFire / CarFire / CarFire / Melee.cs
index 299f2e79a794b9b2e18b04081eb0239cb4b8a5a6..791999fcba25bf551fc2a0d17ce3c83b91848846 100644 (file)
@@ -15,15 +15,22 @@ namespace CarFire
         const int hitCoolDown = 18;\r
         const int baseHealth = 200;\r
         const int baseDamage = 30;\r
+        int coolDown;\r
         Texture2D charModel;\r
         Texture2D projectileModel;\r
+        bool isAttacking;\r
+        int velocityX;\r
+        int velocityY;\r
         #endregion \r
 \r
+        //zac variable\r
+        AnimateMelee animateMelee;\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
-            projectileSpeed = 8;\r
+            coolDown = hitCoolDown;\r
         }\r
         #endregion\r
 \r
@@ -33,6 +40,11 @@ namespace CarFire
             charModel = contentManager.Load<Texture2D>("cs"); //change to charModel when designed\r
             projectileModel = contentManager.Load<Texture2D>("projectile"); //change to a projectile model later\r
 \r
+            /*Zac\r
+             */\r
+            \r
+            animateMelee = new AnimateMelee(contentManager, this); \r
+\r
         }\r
         /// <summary>\r
         /// This method will draw a character to the screen.\r
@@ -41,22 +53,81 @@ namespace CarFire
         public override void Draw(SpriteBatch spriteBatch)\r
         {\r
             Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position);\r
-            spriteBatch.Draw(charModel, position, Color.White);\r
+            Point aPosition = Game.State.Map.GetPointFromCoordinates(Motion.Position);\r
+            Vector2 drawPosition = new Vector2(aPosition.X, aPosition.Y);\r
+            //spriteBatch.Draw(charModel, position, Color.White);\r
+            //if (isAttacking)\r
+            animateMelee.AttackLeft(spriteBatch, drawPosition);\r
+            \r
+        }\r
+        public override void UpdateFrame(TimeSpan timeSpan)\r
+        {\r
+            animateMelee.Update(timeSpan);\r
         }\r
-\r
         public override void Attack(List<Keys> keysPressed)\r
         {\r
-            if (hitCoolDown > 0)\r
-                hitCoolDown--;\r
-            else if (hitCoolDown == 0)\r
+            if (coolDown > 0)\r
+                coolDown--;\r
+            else if (coolDown == 0)\r
             {\r
+                isAttacking = false;\r
                 if (keysPressed.Contains<Keys>(Keys.Space))\r
                 {\r
-                    \r
+                    isAttacking = true;\r
+                    coolDown = hitCoolDown;\r
+                    int startX = Coordinates.X;\r
+                    int startY = Coordinates.Y;\r
+                    if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight)\r
+                    {\r
+                        startY = Coordinates.Y + 1;\r
+                    }\r
+                    else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)\r
+                    {\r
+                        startY = Coordinates.Y - 1;\r
+                    }\r
+                    if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight)\r
+                    {\r
+                        startX = Coordinates.X + 1;\r
+                    }\r
+                    else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)\r
+                    {\r
+                        startX = Coordinates.X - 1;\r
+                    }\r
+                    //Attack a monster\r
+                    if (!Game.IsCellOpen(new Point(startX, startY)))\r
+                    {\r
+                        IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY));\r
+                        //See if it is a monster\r
+                        if (toKill is IMonster)\r
+                        {\r
+                            IMonster hitMonster = (IMonster)toKill;\r
+                            hitMonster.causeDamageTo(this.Damage);\r
+                            if (hitMonster.Health > 0)\r
+                            {\r
+                                this.Score += Game.State.HitMonsterScore;\r
+                                Console.WriteLine(this.Score);\r
+                            }\r
+                            else\r
+                            {\r
+                                this.Score += Game.State.KillMonsterScore;\r
+                                Console.WriteLine(this.Score);\r
+                                //Remove dead monsters\r
+                                Game.State.Entities.Remove(toKill);\r
+                            }\r
+                        }\r
+                    }\r
                 }\r
             }\r
 \r
 \r
+        }\r
+        public override void PlayAttackSound()\r
+        {\r
+\r
+        }\r
+        public override void PlayDieSound()\r
+        {\r
+\r
         }\r
         #endregion\r
     }\r
This page took 0.02297 seconds and 4 git commands to generate.