]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Human.cs
Player can now stop and 'aim' by pressing left control.
[chaz/carfire] / CarFire / CarFire / CarFire / Human.cs
index d1746e388b4a15f68ed8128327e5cd7ef2a9525a..519d9d02f14908767e150112472c01d7638d6bd1 100644 (file)
@@ -18,8 +18,6 @@ namespace CarFire
             up,\r
             down\r
         };\r
-        //The number of frames between each square movements\r
-        const int moveCoolDown = 15;\r
         //The number of frames between each projectile is spawned.\r
         const int shootCoolDown = 10;\r
         State state;\r
@@ -124,13 +122,20 @@ namespace CarFire
                 state = State.down;\r
 \r
             Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
-            if (theMap.IsCellOpen(destination))\r
+            if (!keysPressed.Contains(Keys.LeftControl))\r
             {\r
-                mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+                if (theMap.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.Update(timeSpan);\r
+                mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
             }\r
 \r
 \r
@@ -140,31 +145,63 @@ namespace CarFire
             {\r
                 if (keysPressed.Contains<Keys>(Keys.Space))\r
                 {\r
-                    //TODO spawn projectile... needs to be added to display though\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
+                    {\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
+                    {\r
+                        velocityY = -1;\r
+                        startY = Coordinates.Y - 1;\r
+                    }\r
+                    if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.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
+                    {\r
+                        velocityX = -1;\r
+                        startX = Coordinates.X - 1;\r
+                    }\r
+                    Vector2 toShoot = new Vector2(velocityX, velocityY);\r
+                    toShoot.Normalize();\r
+                    toShoot *= projectileSpeed;\r
+                    projectileCoolDown = shootCoolDown;\r
+                    theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+                        toShoot, new Point(startX, startY)));\r
+\r
+                    /*\r
                     if (state == State.up)\r
                     {\r
                         projectileCoolDown = shootCoolDown;\r
                         theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
-                            new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1));\r
+                            new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));\r
                     }\r
                     if (state == State.down)\r
                     {\r
                         projectileCoolDown = shootCoolDown;\r
                         theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
-                            new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1));\r
+                            new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));\r
                     }\r
                     if (state == State.right)\r
                     {\r
                         projectileCoolDown = shootCoolDown;\r
                         theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
-                            new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y));\r
+                            new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));\r
                     }\r
                     if (state == State.left)\r
                     {\r
                         projectileCoolDown = shootCoolDown;\r
                         theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
-                            new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y));\r
+                            new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));\r
                     }\r
+                     */\r
                 }\r
             }\r
         }\r
This page took 0.024613 seconds and 4 git commands to generate.