]> Dogcows Code - chaz/carfire/commitdiff
Improved projectiles
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 19 Apr 2010 03:49:40 +0000 (03:49 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 19 Apr 2010 03:49:40 +0000 (03:49 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@102 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/Human.cs
CarFire/CarFire/CarFire/Projectile.cs

index 774833b67b7bb875422f7b32d58df4b4000f583a..d40c7e80c87d928b29394791d8b46c1bcacd5ffe 100644 (file)
@@ -21,6 +21,7 @@ namespace CarFire
         //List<IPlayer> mCharacters = new List<IPlayer>();\r
         IPlayer[] mCharacters = new IPlayer[4];\r
         Texture2D everything;\r
+        Texture2D projectile1;\r
         Map mMap;\r
         int currentCenterX = 5;\r
         int currentCenterY = 5;\r
@@ -42,6 +43,7 @@ namespace CarFire
         public void LoadContent(ContentManager contentManager)\r
         {\r
             everything = contentManager.Load<Texture2D>("cs");\r
+            projectile1 = contentManager.Load<Texture2D>("projectile");\r
             mMap = contentManager.Load<Map>("Maps/stable");\r
             Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
             mMap.CenterCell = new Vector2(currentCenterX,currentCenterY);\r
@@ -105,23 +107,7 @@ namespace CarFire
             mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
 #endif\r
             \r
-            for (int i = 0; i < 4; i++)\r
-            {\r
-                if (mCharacters[i] == null)\r
-                {\r
-                    if(state.keysDown[i].Contains(Keys.Enter))\r
-                    {\r
-                        mCharacters[i] = (new Human(mMap, "", everything, everything, this));\r
-                        mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i+1).X;\r
-                        mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i+1).Y;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
-                    mCharacters[i].MovePlayer(state.keysDown[i]);\r
-                }\r
-            }\r
+            \r
             for (int i = 0; i < mProjectiles.Count; i++ )\r
             {\r
                 mProjectiles[i].Update(timespan);\r
@@ -148,6 +134,25 @@ namespace CarFire
                     }\r
                 }\r
             }\r
+            for (int i = 0; i < 4; i++)\r
+            {\r
+                //If player has not selected a player yet let them select one.\r
+                if (mCharacters[i] == null)\r
+                {\r
+                    if (state.keysDown[i].Contains(Keys.Enter))\r
+                    {\r
+                        mCharacters[i] = (new Human(mMap, "", everything, projectile1, this));\r
+                        mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i + 1).X;\r
+                        mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i + 1).Y;\r
+                    }\r
+                }\r
+                else\r
+                {\r
+\r
+                    mCharacters[i].MovePlayer(state.keysDown[i]);\r
+                    mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
+                }\r
+            }\r
         }\r
 \r
         /// <summary>\r
index 30546f3827db7e1a8c20f4b2af4720d33181516f..9350d8605e099e92c6c4afecf1e4e7cd27292468 100644 (file)
@@ -18,6 +18,8 @@ namespace CarFire
             up,\r
             down\r
         };\r
+        const int moveCoolDown = 12;\r
+        const int shootCoolDown = 10;\r
         //Member Variables\r
         State state;\r
         String CharName;\r
@@ -38,6 +40,7 @@ namespace CarFire
         int movementCoolDown;\r
         Display theDisplay;\r
         int projectileSpeed;\r
+        int projectileCoolDown;\r
 \r
         public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay)\r
         {\r
@@ -53,8 +56,8 @@ namespace CarFire
             state = State.up;\r
             charModel = model;\r
             projectileModel = projectile;\r
-            movementCoolDown = movementSpeed;\r
             projectileSpeed = 30;\r
+            \r
         }\r
 \r
         public void LoadContent(ContentManager contentManager)\r
@@ -111,76 +114,85 @@ namespace CarFire
                 {\r
                     gridX -= 1;\r
                     gridY -= 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move upright\r
                 else if (keysPressed.Contains<Keys>(Keys.Up) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1))\r
                 {\r
                     gridX += 1;\r
                     gridY -= 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move downleft\r
                 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1))\r
                 {\r
                     gridX -= 1;\r
                     gridY += 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move downright\r
                 else if (keysPressed.Contains<Keys>(Keys.Down) && keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1))\r
                 {\r
                     gridX += 1;\r
                     gridY += 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move up\r
                 else if (keysPressed.Contains<Keys>(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1))\r
                 {\r
                     state = State.up;\r
                     gridY -= 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move down\r
                 else if (keysPressed.Contains<Keys>(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1))\r
                 {\r
                     state = State.down;\r
                     gridY += 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move left\r
                 else if (keysPressed.Contains<Keys>(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY))\r
                 {\r
                     state = State.left;\r
                     gridX -= 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
                 // move right\r
                 else if (keysPressed.Contains<Keys>(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY))\r
                 {\r
                     state = State.right;\r
                     gridX += 1;\r
-                    movementCoolDown = movementSpeed;\r
+                    movementCoolDown = moveCoolDown;\r
                 }\r
             }\r
-            if (keysPressed.Contains<Keys>(Keys.Space))\r
+            if (projectileCoolDown > 0)\r
+                projectileCoolDown--;\r
+            else if (projectileCoolDown == 0)\r
             {\r
-                //TODO spawn projectile... needs to be added to display though\r
-                if (state == State.up)\r
+                if (keysPressed.Contains<Keys>(Keys.Space))\r
                 {\r
-                    theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY));\r
-                }\r
-                if (state == State.down)\r
-                {\r
-                    theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));\r
-                }\r
-                if (state == State.right)\r
-                {\r
-                    theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX +1, GridY));\r
-                }\r
-                if (state == State.left)\r
-                {\r
-                    theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX, GridY));\r
+                    //TODO spawn projectile... needs to be added to display though\r
+                    if (state == State.up)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1));\r
+                    }\r
+                    if (state == State.down)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1));\r
+                    }\r
+                    if (state == State.right)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY));\r
+                    }\r
+                    if (state == State.left)\r
+                    {\r
+                        projectileCoolDown = shootCoolDown;\r
+                        theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY));\r
+                    }\r
                 }\r
             }\r
         }\r
index 23e103a2a2127e3536b93993f63ca49e507b3ec9..308e313d39dbbfae5fa5467d84f30f34b3d7bf54 100644 (file)
@@ -104,9 +104,10 @@ namespace CarFire
             //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(pixelX-30, pixelY-30, 60, 60);\r
-            //spriteBatch.Draw(projectileModel, position2, Color.White);\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.031503 seconds and 4 git commands to generate.