From: Kyle Date: Thu, 15 Apr 2010 19:07:03 +0000 (+0000) Subject: git-svn-id: https://bd85.net/svn/cs3505_group@93 92bb83a3-7c8f-8a45-bc97-515c4e399668 X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=f1390d70a75797ad27bde6471ab9581e8a2a5f87;p=chaz%2Fcarfire git-svn-id: https://bd85.net/svn/cs3505_group@93 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index ed6ab45..eda3711 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,6 @@ -using System; +#define SINGLE_TEST + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -16,9 +18,13 @@ namespace CarFire { List mProjectiles = new List(); List mCharacters = new List(); + Texture2D everything; Map mMap; int currentCenterX = 5; int currentCenterY = 5; +#if SINGLE_TEST + List mLastPressedKeys = new List(); +#endif public Display() { /* @@ -33,12 +39,13 @@ namespace CarFire /// public void LoadContent(ContentManager contentManager) { - Texture2D everything = contentManager.Load("cs"); + everything = contentManager.Load("cs"); mMap = contentManager.Load("Maps/stable"); Map.DefaultTile = contentManager.Load("default"); mMap.CenterCell = new Vector2(currentCenterX,currentCenterY); //Debugging... Spawn eight projectiles. //Diagonals + mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5,5), 10, 10, 300, 300)); mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 5), 10, 10, 300, 300)); mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, -5), 10, 10, 300, 300)); @@ -48,6 +55,7 @@ namespace CarFire mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, 0), 10, 10, 300, 300)); mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300)); mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300)); + // TODO: use this.Content to load your game content here @@ -69,6 +77,30 @@ namespace CarFire /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { + //INPUT - testing input... has to be through network later +#if SINGLE_TEST + KeyboardState keyState = Keyboard.GetState(); + + List pressedKeys = new List(); + List releasedKeys = new List(); + + Keys[] pressedKeysArray = keyState.GetPressedKeys(); + foreach (Keys k in pressedKeysArray) + { + if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k); + else mLastPressedKeys.Remove(k); + } + + releasedKeys = mLastPressedKeys; + mLastPressedKeys = new List(pressedKeysArray); + //Just apply input for the first player + mCharacters[0].MovePlayer(pressedKeys); + if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter)) + { + 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)); + } + mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); +#endif for (int i = 0; i < mProjectiles.Count; i++ ) { @@ -83,14 +115,16 @@ namespace CarFire //Check for collisons for (int j = 0; j < mCharacters.Count; j++) { + + for (int i = 0; i < mProjectiles.Count; i++) { if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY) { - //Debug - not sure if you can remove while doing for each - //Alternative - while loop, and decrement projectile counter if projectile is removed. - mProjectiles.Remove(mProjectiles[i]); mCharacters[j].causeDamageTo(mProjectiles[i].Damage); + Console.WriteLine(mCharacters[j].Health); + mProjectiles.RemoveAt(i); + i--; } } } diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index a294a78..cabb38d 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -51,6 +51,7 @@ namespace CarFire gridY = _gridY; pixelX = _pixelX; pixelY = _pixelY; + damage = 20; } public void Update(TimeSpan timespan) { @@ -70,7 +71,7 @@ namespace CarFire // to move into the path of projectiles. //if (open) { - Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY); + //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY); pixelX += (int)velocity.X; pixelY += (int)velocity.Y; gridX = (int)(pixelX /Map.PixelsToUnitSquares);