X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FDisplay.cs;h=ed848fa31d07596d970b868cf8c55336765e1102;hp=ed6ab458cabdb91c1e2df54570d533e040846f03;hb=236bc590ff21370c1139a8c01ff35f7b30af743d;hpb=d0bdd76b2cfd38fe985a7493f42b5d6e0f79ac91 diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index ed6ab45..ed848fa 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,10 @@ -using System; +#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; using System.Linq; using System.Text; @@ -14,13 +20,19 @@ namespace CarFire /// public class Display { - List mProjectiles = new List(); - List mCharacters = new List(); - Map mMap; - int currentCenterX = 5; - int currentCenterY = 5; - public Display() + Texture2D everything; + Texture2D projectile1; + Game mGame; + GameLogic mGameLogic; + HUD theHUD; +#if SINGLE_TEST + List mLastPressedKeys = new List(); +#endif + public Display(Game game) { + mGame = game; + mGameLogic = new GameLogic(game); + theHUD = new HUD(game); /* mMap = aMap; mCharacters = characters; @@ -33,24 +45,9 @@ namespace CarFire /// public void LoadContent(ContentManager contentManager) { - Texture2D 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 + everything = contentManager.Load("cs"); + projectile1 = contentManager.Load("projectile"); + theHUD.LoadContent(contentManager); } /// @@ -67,33 +64,14 @@ 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,int thisPlayer) { + mGameLogic.Update(timeSpan, thisPlayer); - for (int i = 0; i < mProjectiles.Count; i++ ) - { - mProjectiles[i].Update(timespan); - if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) - { - - mProjectiles.RemoveAt(i); - i--; - } - } - //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); - } - } - } +#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 } /// @@ -102,25 +80,27 @@ namespace CarFire /// Used to draw with public void Draw(SpriteBatch spriteBatch) { - mMap.Draw(spriteBatch); - foreach(Projectile projectile in mProjectiles) + mGame.State.Map.Draw(spriteBatch); + mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); }); + + foreach(Projectile projectile in mGame.State.mProjectiles) { - //Debug - follow a projectile to make sure following is working. - if (mProjectiles.IndexOf(projectile) == 6) - mMap.CenterCell = new Vector2(projectile.GridX, projectile.GridY); 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) - { - mCharacters.Add(player); + if (mGame.State.mCharacters[i] != null) + { + mGame.State.mCharacters[i].Draw(spriteBatch); + + } + } + theHUD.Draw(spriteBatch); + + } + } }