X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FDisplay.cs;h=d40c7e80c87d928b29394791d8b46c1bcacd5ffe;hp=98f91ed45eeeb9243301e05d35478b7a32545cf5;hb=6f4eff30ee197a57bbedb2067f94b12ab0d69d48;hpb=89e5ee7d83cfb353b6c98dcbf6ed6b87833b9866 diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 98f91ed..d40c7e8 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,6 @@ -using System; +#undef SINGLE_TEST + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -14,11 +16,18 @@ namespace CarFire /// public class Display { + bool playerChosen = false; List mProjectiles = new List(); - List mCharacters = new List(); + //List mCharacters = new List(); + IPlayer[] mCharacters = new IPlayer[4]; + Texture2D everything; + Texture2D projectile1; Map mMap; int currentCenterX = 5; int currentCenterY = 5; +#if SINGLE_TEST + List mLastPressedKeys = new List(); +#endif public Display() { /* @@ -33,12 +42,14 @@ namespace CarFire /// public void LoadContent(ContentManager contentManager) { - Texture2D everything = contentManager.Load("cs"); + everything = contentManager.Load("cs"); + projectile1 = contentManager.Load("projectile"); 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,7 +59,9 @@ 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 } @@ -66,27 +79,80 @@ namespace CarFire /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. - public void Update(TimeSpan timespan) + public void Update(TimeSpan timespan, GameState state) { - mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); - foreach (Projectile projectile in mProjectiles) + + //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++ ) { - projectile.Update(timespan); + mProjectiles[i].Update(timespan); + if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) + { + + mProjectiles.RemoveAt(i); + i--; + } } //Check for collisons - foreach (Character character in mCharacters) + for (int j = 0; j < mCharacters.Length; j++) { - foreach (Projectile projectile in mProjectiles) + + if(mCharacters[j] != null) + for (int i = 0; i < mProjectiles.Count; i++) { - if (projectile.GridX == character.GridX && projectile.GridY == character.GridY) + 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(projectile); - character.Health -= projectile.Damage; + mCharacters[j].causeDamageTo(mProjectiles[i].Damage); + Console.WriteLine(mCharacters[j].Health); + mProjectiles.RemoveAt(i); + i--; } } } + for (int i = 0; i < 4; i++) + { + //If player has not selected a player yet let them select one. + if (mCharacters[i] == null) + { + if (state.keysDown[i].Contains(Keys.Enter)) + { + mCharacters[i] = (new Human(mMap, "", everything, projectile1, this)); + mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i + 1).X; + mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i + 1).Y; + } + } + else + { + + mCharacters[i].MovePlayer(state.keysDown[i]); + mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); + } + } } /// @@ -101,12 +167,22 @@ namespace CarFire projectile.Draw(spriteBatch); } - foreach(Character character in mCharacters) + for(int i = 0; i < 4; i++)//IPlayer character in mCharacters) { - character.Draw(spriteBatch); - } - - + if(mCharacters[i] != null) + mCharacters[i].Draw(spriteBatch); + } + } + /* + public void AddCharacters(IPlayer player) + { + mCharacters[mCharacters.Length] = player; + //mCharacters.Add(player); + } + */ + public void AddProjectiles(Projectile projectile) + { + mProjectiles.Add(projectile); } } }