X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FDisplay.cs;h=01fbbba44d946e7988c29b5cb79a339581d24fd6;hb=0470a7b148c79aaacf0d8107b5bd40fa1e81ac0a;hp=8f4fbdccf803fc361bbfcec5f9213106e1b1db89;hpb=e55c1fd13b13e01468b622f0c5b3f6a4846aed0b;p=chaz%2Fcarfire diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 8f4fbdc..01fbbba 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,8 @@ -#define SINGLE_TEST +#undef SINGLE_TEST + +// Define INGAME_ZOOM to allow zooming in and out with +// the PageUp and PageDown keys. +#define INGAME_ZOOM using System; using System.Collections.Generic; @@ -17,16 +21,17 @@ namespace CarFire public class Display { List mProjectiles = new List(); - List mCharacters = new List(); + //List mCharacters = new List(); + //IPlayer[] mCharacters = new IPlayer[4]; Texture2D everything; - Map mMap; - int currentCenterX = 5; - int currentCenterY = 5; + Texture2D projectile1; + Game mGame; #if SINGLE_TEST List mLastPressedKeys = new List(); #endif - public Display() + public Display(Game game) { + mGame = game; /* mMap = aMap; mCharacters = characters; @@ -40,25 +45,7 @@ namespace CarFire public void LoadContent(ContentManager contentManager) { 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)); - mProjectiles.Add(new Projectile(mMap, everything, new Vector2(-5, -5), 10, 10, 300, 300)); - //Vertical and horizontal - mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, 5), 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(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 + projectile1 = contentManager.Load("projectile"); } /// @@ -75,8 +62,9 @@ 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, int thisPlayer) { + //INPUT - testing input... has to be through network later #if SINGLE_TEST KeyboardState keyState = Keyboard.GetState(); @@ -101,33 +89,76 @@ namespace CarFire } mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); #endif - + + //Handle projectiles - update and check for wall collisions for (int i = 0; i < mProjectiles.Count; i++ ) { - mProjectiles[i].Update(timespan); - if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) + bool removed = false; + if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y))) { mProjectiles.RemoveAt(i); + removed = true; i--; } + if(!removed) + mProjectiles[i].Update(timespan); + } //Check for collisons - for (int j = 0; j < mCharacters.Count; j++) + for (int j = 0; j < mGame.State.mCharacters.Length; j++) { - + if(mGame.State.mCharacters[j] != null) for (int i = 0; i < mProjectiles.Count; i++) { - if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY) + if (mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y) { - mCharacters[j].causeDamageTo(mProjectiles[i].Damage); - Console.WriteLine(mCharacters[j].Health); + mGame.State.mCharacters[j].causeDamageTo(mProjectiles[i].Damage); + Console.WriteLine(mGame.State.mCharacters[j].Health); mProjectiles.RemoveAt(i); i--; } } } + //Update input for each player + for (int i = 0; i < mGame.State.NumberOfPlayers; i++) + { + //If player has not selected a player yet let them select one. + if (mGame.State.mCharacters[i] == null) + { + if (mGame.State.GetKeysDown(i).Contains(Keys.Enter)) + { + //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1)); + } + } + //Regular player input updates + else + { + + mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i)); + + } + } + if (mGame.State.mCharacters[thisPlayer] != null) + { + mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position; + } + //Handle wall collisions of projectiles again... + for (int i = 0; i < mProjectiles.Count; i++) + { + if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y))) + { + mProjectiles.RemoveAt(i); + i--; + } + + } + +#if INGAME_ZOOM + if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mGame.State.Map.Zoom = mGame.State.Map.Zoom + 0.5f; + if (Keyboard.GetState().IsKeyDown(Keys.PageDown)) mGame.State.Map.Zoom = mGame.State.Map.Zoom - 0.5f; +#endif } /// @@ -136,21 +167,31 @@ namespace CarFire /// Used to draw with public void Draw(SpriteBatch spriteBatch) { - mMap.Draw(spriteBatch); + mGame.State.Map.Draw(spriteBatch); + mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); }); + foreach(Projectile projectile in mProjectiles) { projectile.Draw(spriteBatch); - } - foreach(IPlayer character in mCharacters) + for(int i = 0; i < mGame.State.NumberOfPlayers; i++)//IPlayer character in mCharacters) { - character.Draw(spriteBatch); - } - } - public void AddCharacters(IPlayer player) + if (mGame.State.mCharacters[i] != null) + { + mGame.State.mCharacters[i].Draw(spriteBatch); + + } + } + + } + /// + /// Add a projectile to the Display. + /// + /// + public void AddProjectiles(Projectile projectile) { - mCharacters.Add(player); + mProjectiles.Add(projectile); } } }