]> Dogcows Code - chaz/carfire/commitdiff
git-svn-id: https://bd85.net/svn/cs3505_group@93 92bb83a3-7c8f-8a45-bc97-515c4e399668
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 19:07:03 +0000 (19:07 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Thu, 15 Apr 2010 19:07:03 +0000 (19:07 +0000)
CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/Projectile.cs

index ed6ab458cabdb91c1e2df54570d533e040846f03..eda371168b541b105400ed6fe1698e7af81b6fd8 100644 (file)
@@ -1,4 +1,6 @@
-using System;\r
+#define SINGLE_TEST\r
+\r
+using System;\r
 using System.Collections.Generic;\r
 using System.Linq;\r
 using System.Text;\r
@@ -16,9 +18,13 @@ namespace CarFire
     {\r
         List<Projectile> mProjectiles = new List<Projectile>();\r
         List<IPlayer> mCharacters = new List<IPlayer>();\r
+        Texture2D everything;\r
         Map mMap;\r
         int currentCenterX = 5;\r
         int currentCenterY = 5;\r
+#if SINGLE_TEST\r
+        List<Keys> mLastPressedKeys = new List<Keys>();\r
+#endif\r
         public Display()\r
         {\r
             /*\r
@@ -33,12 +39,13 @@ namespace CarFire
         /// </summary>\r
         public void LoadContent(ContentManager contentManager)\r
         {\r
-            Texture2D everything = contentManager.Load<Texture2D>("cs");\r
+            everything = contentManager.Load<Texture2D>("cs");\r
             mMap = contentManager.Load<Map>("Maps/stable");\r
             Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
             mMap.CenterCell = new Vector2(currentCenterX,currentCenterY);\r
             //Debugging... Spawn eight projectiles.\r
             //Diagonals\r
+            \r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300));\r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300));\r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300));\r
@@ -48,6 +55,7 @@ namespace CarFire
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300));\r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));\r
             mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));\r
+             \r
 \r
             \r
             // TODO: use this.Content to load your game content here\r
@@ -69,6 +77,30 @@ namespace CarFire
         /// <param name="gameTime">Provides a snapshot of timing values.</param>\r
         public void Update(TimeSpan timespan)\r
         {\r
+            //INPUT - testing input... has to be through network later\r
+#if SINGLE_TEST\r
+            KeyboardState keyState = Keyboard.GetState();\r
+\r
+            List<Keys> pressedKeys = new List<Keys>();\r
+            List<Keys> releasedKeys = new List<Keys>();\r
+\r
+            Keys[] pressedKeysArray = keyState.GetPressedKeys();\r
+            foreach (Keys k in pressedKeysArray)\r
+            {\r
+                if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);\r
+                else mLastPressedKeys.Remove(k);\r
+            }\r
+\r
+            releasedKeys = mLastPressedKeys;\r
+            mLastPressedKeys = new List<Keys>(pressedKeysArray);\r
+            //Just apply input for the first player\r
+            mCharacters[0].MovePlayer(pressedKeys);\r
+            if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))\r
+            {\r
+                mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5,0), mCharacters[0].GridX +1, mCharacters[0].GridY+1, (int)mCharacters[0].GridX*(int)Map.PixelsToUnitSquares,(int)mCharacters[0].GridY*(int)Map.PixelsToUnitSquares));\r
+            }\r
+            mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
+#endif\r
 \r
             for (int i = 0; i < mProjectiles.Count; i++ )\r
             {\r
@@ -83,14 +115,16 @@ namespace CarFire
             //Check for collisons\r
             for (int j = 0; j < mCharacters.Count; j++) \r
             {\r
+               \r
+                \r
                 for (int i = 0; i < mProjectiles.Count; i++)\r
                 {\r
                     if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY)\r
                     {\r
-                        //Debug - not sure if you can remove while doing for each\r
-                        //Alternative - while loop, and decrement projectile counter if projectile is removed.\r
-                        mProjectiles.Remove(mProjectiles[i]);\r
                         mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
+                        Console.WriteLine(mCharacters[j].Health);\r
+                        mProjectiles.RemoveAt(i);\r
+                        i--;\r
                     }\r
                 }\r
             }\r
index a294a7851bbbb15a9d8f5ba15e0da84446da383c..cabb38d5ba410b2fb700c79d965f43557c458a41 100644 (file)
@@ -51,6 +51,7 @@ namespace CarFire
             gridY = _gridY;\r
             pixelX = _pixelX;\r
             pixelY = _pixelY;\r
+            damage = 20;\r
         }\r
         public void Update(TimeSpan timespan)\r
         {\r
@@ -70,7 +71,7 @@ namespace CarFire
                 // to move into the path of projectiles.\r
                 //if (open)\r
                 {\r
-                Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);\r
+                //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);\r
                     pixelX += (int)velocity.X;\r
                     pixelY += (int)velocity.Y;\r
                     gridX = (int)(pixelX /Map.PixelsToUnitSquares);\r
This page took 0.025386 seconds and 4 git commands to generate.