]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Projectile.cs
Improved projectiles
[chaz/carfire] / CarFire / CarFire / CarFire / Projectile.cs
index e9fd47b2cc95b06eb8b5cbc379a1728e48b1cda3..308e313d39dbbfae5fa5467d84f30f34b3d7bf54 100644 (file)
@@ -40,48 +40,51 @@ namespace CarFire
                             Texture2D _projectileModel,\r
                             Vector2 _velocity,\r
                             int _gridX,\r
-                            int _gridY,\r
+                            int _gridY)\r
+                            /*,\r
                             int _pixelX,\r
-                            int _pixelY)\r
+                            int _pixelY)*/\r
         {\r
             theMap = _currentMap;\r
             projectileModel = _projectileModel;\r
             velocity = _velocity;\r
             gridX = _gridX;\r
             gridY = _gridY;\r
-            pixelX = _pixelX;\r
-            pixelY = _pixelY;\r
+            pixelX = _gridX * (int)Map.PixelsToUnitSquares;\r
+            pixelY = _gridY * (int)Map.PixelsToUnitSquares;\r
+            damage = 20;\r
         }\r
-        public void Update()\r
+        public void Update(TimeSpan timespan)\r
         {\r
+            /*\r
             //See if something moved onto this projectile.\r
-            if(theMap.IsCellOpen(gridX, gridY))\r
+            if(theMap.isOpenSquare(gridX, gridY))\r
             {\r
-                //theMap.damageSquare(gridX, gridY, damage);\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
-            /*\r
-            if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)\r
+            if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)\r
             {\r
-                bool open = theMap.IsCellOpen((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);\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
+                //if (open)\r
                 {\r
+                //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);\r
                     pixelX += (int)velocity.X;\r
                     pixelY += (int)velocity.Y;\r
-                    gridX = pixelX / theMap.gridToPixelRatio;\r
-                    gridY = pixelY / theMap.gridToPixelRatio;\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
+                //else\r
                 {\r
                     //theMap.damageSquare(gridX, gridY, damage);\r
                 }\r
             }\r
-            */\r
             //If it is not moving grid positions just increment pixelX and pixelY\r
             else\r
             {\r
@@ -96,9 +99,15 @@ namespace CarFire
         /// <param name="spriteBatch"></param>\r
         /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>\r
         /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>\r
-        public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)\r
+        public void Draw(SpriteBatch spriteBatch)\r
         {\r
-            spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);\r
+            //Console.WriteLine(gridX + " " + gridY);\r
+            //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));\r
+            Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));\r
+            //spriteBatch.Draw(projectileModel, position, Color.White);\r
+            Rectangle position2 = new Rectangle((int)(pixelX), (int)(pixelY), (int)Map.PixelsToUnitSquares, (int)Map.PixelsToUnitSquares);\r
+            Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));\r
+            spriteBatch.Draw(projectileModel, position3, Color.White);\r
         }\r
 \r
         /// <summary>\r
This page took 0.029731 seconds and 4 git commands to generate.