]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Projectile.cs
better player movement (walls are no longer sticky)
[chaz/carfire] / CarFire / CarFire / CarFire / Projectile.cs
index cabb38d5ba410b2fb700c79d965f43557c458a41..a1d7f2779ccb7d8de22f23885d44817f4b2fdab8 100644 (file)
@@ -15,7 +15,6 @@ namespace CarFire
     public class Projectile\r
     {\r
         //Member Variables\r
-        Map theMap;\r
         Vector2 velocity;\r
         Texture2D projectileModel;\r
         int damage;\r
@@ -25,7 +24,11 @@ namespace CarFire
         //these will have to be transformed to the coordinate system that the drawable screen is using.\r
         int pixelX;\r
         int pixelY;\r
-   \r
+        MovementManager mMotion;\r
+        Point mPosition;\r
+        int mCharacterIndex;\r
+        Game mGame;\r
+\r
         /// <summary>\r
         /// The Constructor for a projectile object.\r
         /// </summary>\r
@@ -36,60 +39,40 @@ namespace CarFire
         /// <param name="_gridY">The starting Y position in the map grid</param>\r
         /// <param name="_pixelX">The absolute X pixel position on the map</param>\r
         /// <param name="_pixelY"> The absolute Y pixel position on the map</param>\r
-        public Projectile(Map _currentMap,\r
+        public Projectile(Game theGame,\r
                             Texture2D _projectileModel,\r
                             Vector2 _velocity,\r
-                            int _gridX,\r
-                            int _gridY,\r
-                            int _pixelX,\r
-                            int _pixelY)\r
+                            Point _position,\r
+                            int characterNumber,\r
+                            int _damage)\r
+                \r
         {\r
-            theMap = _currentMap;\r
+            mGame = theGame;\r
+            mCharacterIndex = characterNumber;\r
             projectileModel = _projectileModel;\r
             velocity = _velocity;\r
-            gridX = _gridX;\r
-            gridY = _gridY;\r
-            pixelX = _pixelX;\r
-            pixelY = _pixelY;\r
-            damage = 20;\r
+            mPosition = _position;\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
-        public void Update(TimeSpan timespan)\r
+        public void Update(TimeSpan timeSpan)\r
         {\r
-            /*\r
-            //See if something moved onto this projectile.\r
-            if(theMap.isOpenSquare(gridX, gridY))\r
-            {\r
-                theMap.damageSquare(gridX, gridY, damage);\r
-            }\r
-             */\r
-            //If the projectile will be moving to a new grid position we need to check to see if it is occupied.\r
-            if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)\r
-            {\r
-                //bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));\r
-                //If open just move this projectile there\r
-                //***Map doesn't need to know that this projectile is there because players/monsters are allowed\r
-                // to move into the path of projectiles.\r
-                //if (open)\r
-                {\r
-                //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);\r
-                    pixelX += (int)velocity.X;\r
-                    pixelY += (int)velocity.Y;\r
-                    gridX = (int)(pixelX /Map.PixelsToUnitSquares);\r
-                    gridY = (int)(pixelY / Map.PixelsToUnitSquares);\r
-                }\r
-                //If the square isn't open then just damage whatever is there\r
-                //TODO: A projectile must be deleted after this happens\r
-                //else\r
-                {\r
-                    //theMap.damageSquare(gridX, gridY, damage);\r
-                }\r
-            }\r
-            //If it is not moving grid positions just increment pixelX and pixelY\r
-            else\r
-            {\r
-                pixelX += (int)velocity.X;\r
-                pixelY += (int)velocity.Y;\r
-            }\r
+            bool moveRight = false;\r
+            bool moveLeft = false;\r
+            bool moveUp = false;\r
+            bool moveDown = false;\r
+            if (velocity.X > 0)\r
+                moveRight = true;\r
+            else if (velocity.X < 0)\r
+                moveLeft = true;\r
+            if (velocity.Y > 0)\r
+                moveDown = true;\r
+            else if (velocity.Y < 0)\r
+                moveUp = true;\r
+            Point destination = MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
+            mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+            \r
             \r
         }\r
         /// <summary>\r
@@ -100,12 +83,9 @@ namespace CarFire
         /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>\r
         public void Draw(SpriteBatch spriteBatch)\r
         {\r
-            //Console.WriteLine(gridX + " " + gridY);\r
-            //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));\r
-            Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));\r
+            Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position);\r
             spriteBatch.Draw(projectileModel, position, Color.White);\r
-            //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60);\r
-            //spriteBatch.Draw(projectileModel, position2, Color.White);\r
+         \r
         }\r
 \r
         /// <summary>\r
@@ -115,7 +95,9 @@ namespace CarFire
         public int GridY { get { return gridY; } set { gridY = value; } }\r
         public int PixelX { get { return pixelX; } set { pixelX = value; } }\r
         public int PixelY { get { return pixelY; } set { pixelY = value; } }\r
-        public Map TheMap { get { return theMap; } set { theMap = 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
 }\r
This page took 0.024539 seconds and 4 git commands to generate.