]> Dogcows Code - chaz/carfire/commitdiff
Scoring implemented, melee attack implemented.
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 01:15:50 +0000 (01:15 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 01:15:50 +0000 (01:15 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@145 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Game.cs
CarFire/CarFire/CarFire/GameLogic.cs
CarFire/CarFire/CarFire/Melee.cs
CarFire/CarFire/CarFire/Player.cs
CarFire/CarFire/CarFire/Projectile.cs
CarFire/CarFire/CarFire/SaberMonster.cs

index f91882e047c08f85e578ec0e3716d3cce5986d9d..e42a827b8d93f920bf613415e917037c88ad48a4 100644 (file)
@@ -15,6 +15,10 @@ namespace CarFire
     public class GameState\r
     {\r
         #region Public Properties\r
+        private const int hitMonsterScore = 20;\r
+        private const int killMonsterScore = 100;\r
+        public int HitMonsterScore { get { return hitMonsterScore; } }\r
+        public int KillMonsterScore { get { return killMonsterScore; } }\r
 \r
         public long FrameNumber { get { return mFrameNumber; } }\r
 \r
@@ -27,7 +31,7 @@ namespace CarFire
         public List<Projectile> mProjectiles = new List<Projectile>();\r
         public Player[] mCharacters;\r
         public Display mDisplay;\r
-        public AI AIData;\r
+        //public AI AIData;\r
         #endregion\r
 \r
 \r
@@ -369,7 +373,7 @@ namespace CarFire
             State.Map.Tilemap = tilemap;\r
             State.Entities = State.Map.GetAllEntities(this);\r
 \r
-            State.AIData = new AI(this);\r
+            //State.AIData = new AI(this);\r
 \r
             /*\r
             mPlayers.Clear();\r
index 6f859d0b72b9349c29cc9796ad69ebc75c87aabc..dce9fe33d206bb77111b40c56aeee8cafa121a34 100644 (file)
@@ -11,20 +11,46 @@ namespace CarFire
 {\r
     class GameLogic\r
     {\r
+        \r
         Game mGame;\r
         public GameLogic(Game game)\r
         {\r
             mGame = game;\r
         }\r
+        /// <summary>\r
+        /// Update the game logic.\r
+        /// </summary>\r
+        /// <param name="timespan">timeslice</param>\r
+        /// <param name="thisPlayer">index of the player to center the screen around</param>\r
         public void Update(TimeSpan timespan, int thisPlayer)\r
         {\r
             //Handle projectiles - update and check for wall collisions\r
             for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
             {\r
                 bool removed = false;\r
-                if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+                //Check to see if there are any entities in the square with the projectile\r
+                if (!mGame.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
                 {\r
-\r
+                    //The projectile has hit something.\r
+                    IEntity hitEntity = mGame.GetEntityAtCoordinates(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y));\r
+                    //If it is a monster than decrement monster health and increment the score of the player who shot it.\r
+                    if (hitEntity is IMonster)\r
+                    {\r
+                        IMonster hitMonster = (IMonster)hitEntity;\r
+                        hitMonster.causeDamageTo(mGame.State.mProjectiles[i].Damage);\r
+                        if (hitMonster.Health > 0)\r
+                        {\r
+                            mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.HitMonsterScore;\r
+                            Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);\r
+                        }\r
+                        else\r
+                        {\r
+                            mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score += mGame.State.KillMonsterScore;\r
+                            Console.WriteLine(mGame.State.mCharacters[mGame.State.mProjectiles[i].CharacterIndex].Score);\r
+                            //Remove dead monsters\r
+                            mGame.State.Entities.Remove(hitEntity);\r
+                        }\r
+                    }\r
                     mGame.State.mProjectiles.RemoveAt(i);\r
                     removed = true;\r
                     i--;\r
@@ -52,21 +78,8 @@ namespace CarFire
             //Update input for each player\r
             for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
             {\r
-                //If player has not selected a player yet let them select one.\r
-                if (mGame.State.mCharacters[i] == null)\r
-                {\r
-                    if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
-                    {\r
-                        //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
-                    }\r
-                }\r
-                //Regular player input updates\r
-                else\r
-                {\r
-\r
+                if(mGame.State.mCharacters[i] != null)\r
                     mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
-\r
-                }\r
             }\r
             if (mGame.State.mCharacters[thisPlayer] != null)\r
             {\r
index f52301219c667184ef107a0d4f1e3cc366329288..38be3038a5ae2e231affcf3ac3b9a29890173a65 100644 (file)
@@ -59,33 +59,41 @@ namespace CarFire
                     int startY = Coordinates.Y;\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 (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight)\r
                     {\r
-                        velocityY = -1;\r
                         startY = Coordinates.Y - 1;\r
                     }\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 (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft)\r
                     {\r
-                        velocityX = -1;\r
                         startX = Coordinates.X - 1;\r
                     }\r
                     //Attack a monster\r
                     if (!Game.IsCellOpen(new Point(startX, startY)))\r
                     {\r
-                        foreach (IEntity entity in Game.State.Entities)\r
+                        IEntity toKill = Game.GetEntityAtCoordinates(new Point(startX, startY));\r
+                        //See if it is a monster\r
+                        if (toKill is IMonster)\r
                         {\r
-                            //See if it is a monster\r
-\r
-                            //Damage the monster\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
index da1af4ecc02a385cef816c1d5a2ca97d1326337b..02d6eec92a8838ffc9cdc365dfcd5a06e404270a 100644 (file)
@@ -28,7 +28,7 @@ namespace CarFire
 \r
         #region Public Properties\r
         public int Health { get { return playerHealth; } set{playerHealth = value;} }\r
-        public int Score { get { return score; } }\r
+        public int Score { get { return score; } set { score = value; } }\r
         public bool alive { get { return playerHealth > 0; } }\r
         public Game Game { get { return game; } }\r
         public MovementManager Motion { get { return mMotion; } }\r
index 95d0d6e83525c8405d922953f7ad5ac50a7e6a82..611cc380ed18e6b5593a2a847ed96a55b2d0e56e 100644 (file)
@@ -96,6 +96,7 @@ namespace CarFire
         public int PixelX { get { return pixelX; } set { pixelX = value; } }\r
         public int PixelY { get { return pixelY; } set { pixelY = value; } }\r
         public int Damage { get { return damage; } set { damage = value; } }\r
+        public int CharacterIndex { get { return mCharacterIndex; } }\r
         public Vector2 Position { get { return mMotion.Position; } }\r
         public Point Coordinates { get { return mMotion.Coordinates; } }\r
     }\r
index ce5916987a472986505a8c5f2c6284c2f89f14b5..91d82a093f495a666c07f9aa65c71f8dc3154fcc 100644 (file)
@@ -196,7 +196,9 @@ namespace CarFire
         /// </summary>\r
         public int Health\r
         {\r
-            get { throw new NotImplementedException(); }\r
+            //TODO do this right\r
+            get { return 0; }\r
+            //get { throw new NotImplementedException(); }\r
         }\r
 \r
         /// <summary>\r
@@ -205,7 +207,8 @@ namespace CarFire
         /// <param name="amount"></param>\r
         public void causeDamageTo(int amount)\r
         {\r
-            throw new NotImplementedException();\r
+            //TODO do this right\r
+            //throw new NotImplementedException();\r
         }\r
 \r
         /// <summary>\r
This page took 0.0324 seconds and 4 git commands to generate.