From: Kyle Date: Thu, 22 Apr 2010 21:55:39 +0000 (+0000) Subject: Character selection is now done in the Game Class instead of the display class. X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=25534219ab3703f063d98867f928e47e6cecc0f1;p=chaz%2Fcarfire Character selection is now done in the Game Class instead of the display class. git-svn-id: https://bd85.net/svn/cs3505_group@130 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index dd07212..5b22c8c 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -23,7 +23,7 @@ namespace CarFire bool playerChosen = false; List mProjectiles = new List(); //List mCharacters = new List(); - IPlayer[] mCharacters = new IPlayer[4]; + //IPlayer[] mCharacters = new IPlayer[4]; Texture2D everything; Texture2D projectile1; Game mGame; @@ -107,16 +107,16 @@ namespace CarFire } //Check for collisons - for (int j = 0; j < mCharacters.Length; j++) + for (int j = 0; j < mGame.State.mCharacters.Length; j++) { - if(mCharacters[j] != null) + if(mGame.State.mCharacters[j] != null) for (int i = 0; i < mProjectiles.Count; i++) { - if (mProjectiles[i].Coordinates.X == mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mCharacters[j].Coordinates.Y) + 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--; } @@ -126,24 +126,24 @@ namespace CarFire for (int i = 0; i < mGame.State.NumberOfPlayers; i++) { //If player has not selected a player yet let them select one. - if (mCharacters[i] == null) + 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)); + //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1)); } } //Regular player input updates else { - mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i)); + mGame.State.mCharacters[i].MovePlayer(timespan, mGame.State.GetKeysDown(i)); } } - if (mCharacters[thisPlayer] != null) + if (mGame.State.mCharacters[thisPlayer] != null) { - mGame.State.Map.CenterCell = mCharacters[thisPlayer].Position; + mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position; } //Handle wall collisions of projectiles again... for (int i = 0; i < mProjectiles.Count; i++) @@ -178,9 +178,9 @@ namespace CarFire for(int i = 0; i < mGame.State.NumberOfPlayers; i++)//IPlayer character in mCharacters) { - if (mCharacters[i] != null) + if (mGame.State.mCharacters[i] != null) { - mCharacters[i].Draw(spriteBatch); + mGame.State.mCharacters[i].Draw(spriteBatch); } } diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 38ec627..c867b3c 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -24,6 +24,8 @@ namespace CarFire public Map Map; public List Entities = new List(); + public IPlayer[] mCharacters = new IPlayer[4]; + public Display mDisplay; #endregion @@ -243,12 +245,12 @@ namespace CarFire public Game() { - mDisplay = new Display(this); + } public void LoadContent(ContentManager contentManager) { mContentManager = contentManager; - mDisplay.LoadContent(contentManager); + } public void UnloadContent() @@ -290,6 +292,8 @@ namespace CarFire State = new GameState(numPlayers); mInputs = new NextInputs(numPlayers); + State.mDisplay = new Display(this); + State.mDisplay.LoadContent(mContentManager); State.Map = mContentManager.Load("Maps/stable"); State.Map.Game = this; @@ -361,7 +365,7 @@ namespace CarFire public long Update(TimeSpan elapsedTime) { State.AdvanceFrame(mInputs, elapsedTime.Milliseconds); // Apply the inputs, advance game state. - mDisplay.Update(elapsedTime, State, mThisPlayerID); + State.mDisplay.Update(elapsedTime, State, mThisPlayerID); State.Entities.ForEach(delegate(IEntity e) { e.Update(elapsedTime); }); mInputs = new NextInputs(State.NumberOfPlayers); // Start with inputs cleared on the next frame. //mDisplay.Update(elapsedTime); @@ -371,7 +375,24 @@ namespace CarFire public long Draw(SpriteBatch spriteBatch) { - mDisplay.Draw(spriteBatch); + bool allCharactersSelected = true; + for (int i = 0; i < State.NumberOfPlayers; i++) + { + //If player has not selected a player yet let them select one. + if (State.mCharacters[i] == null) + { + allCharactersSelected = false; + if (State.GetKeysDown(i).Contains(Keys.Enter)) + { + State.mCharacters[i] = new Human(this, "", State.Map.GetStartingPositionForPlayer(i + 1)); + State.mCharacters[i].LoadContent(mContentManager); + } + } + } + if (allCharactersSelected) + { + State.mDisplay.Draw(spriteBatch); + } return CurrentFrameNumber; } diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 6c03794..5b4c6a0 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -24,23 +24,19 @@ namespace CarFire MovementManager mMotion; bool visible; - Display theDisplay; //Used to draw projectiles int projectileSpeed; int projectileCoolDown; - public Human(Game theGame, String Name, Texture2D model, Texture2D projectile, Display mDisplay, Point position) + public Human(Game theGame, String Name, Point position) { game = theGame; CharName = Name; - theDisplay = mDisplay; health = 100; score = 0; visible = false; - charModel = model; - projectileModel = projectile; projectileSpeed = 8; // Speed is the number of grid cells you can move through per second. @@ -145,7 +141,7 @@ namespace CarFire toShoot.Normalize(); toShoot *= projectileSpeed; projectileCoolDown = shootCoolDown; - theDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel, + game.State.mDisplay.AddProjectiles(new Projectile(game.State.Map, projectileModel, toShoot, new Point(startX, startY)));