/// </summary>\r
public class Display\r
{\r
- List<Projectile> mProjectiles = new List<Projectile>();\r
- //List<IPlayer> mCharacters = new List<IPlayer>();\r
- //IPlayer[] mCharacters = new IPlayer[4];\r
Texture2D everything;\r
Texture2D projectile1;\r
Game mGame;\r
+ GameLogic mGameLogic;\r
#if SINGLE_TEST\r
List<Keys> mLastPressedKeys = new List<Keys>();\r
#endif\r
public Display(Game game)\r
{\r
mGame = game;\r
+ mGameLogic = new GameLogic(game);\r
/*\r
mMap = aMap;\r
mCharacters = characters;\r
/// checking for collisions, gathering input, and playing audio.\r
/// </summary>\r
/// <param name="gameTime">Provides a snapshot of timing values.</param>\r
- public void Update(TimeSpan timespan, GameState state, int thisPlayer)\r
+ public void Update(TimeSpan timeSpan,int thisPlayer)\r
{\r
- \r
- //INPUT - testing input... has to be through network later\r
-#if SINGLE_TEST\r
- KeyboardState keyState = Keyboard.GetState();\r
-\r
- List<Keys> pressedKeys = new List<Keys>();\r
- List<Keys> releasedKeys = new List<Keys>();\r
-\r
- Keys[] pressedKeysArray = keyState.GetPressedKeys();\r
- foreach (Keys k in pressedKeysArray)\r
- {\r
- if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k);\r
- else mLastPressedKeys.Remove(k);\r
- }\r
-\r
- releasedKeys = mLastPressedKeys;\r
- mLastPressedKeys = new List<Keys>(pressedKeysArray);\r
- //Just apply input for the first player\r
- mCharacters[0].MovePlayer(pressedKeys);\r
- if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter))\r
- {\r
- 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));\r
- }\r
- mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY);\r
-#endif\r
- \r
- //Handle projectiles - update and check for wall collisions\r
- for (int i = 0; i < mProjectiles.Count; i++ )\r
- {\r
- bool removed = false;\r
- if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
- {\r
- \r
- mProjectiles.RemoveAt(i);\r
- removed = true;\r
- i--;\r
- }\r
- if(!removed)\r
- mProjectiles[i].Update(timespan);\r
- \r
- }\r
- //Check for collisons\r
- for (int j = 0; j < mGame.State.mCharacters.Length; j++) \r
- {\r
- \r
- if(mGame.State.mCharacters[j] != null)\r
- for (int i = 0; i < mProjectiles.Count; i++)\r
- {\r
- if (mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)\r
- {\r
- mGame.State.mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
- Console.WriteLine(mGame.State.mCharacters[j].Health);\r
- mProjectiles.RemoveAt(i);\r
- i--;\r
- }\r
- }\r
- }\r
- //Update input for each player\r
- for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
- {\r
- //If player has not selected a player yet let them select one.\r
- if (mGame.State.mCharacters[i] == null)\r
- {\r
- if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
- {\r
- //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
- }\r
- }\r
- //Regular player input updates\r
- else\r
- {\r
-\r
- mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
- \r
- }\r
- }\r
- if (mGame.State.mCharacters[thisPlayer] != null)\r
- {\r
- mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;\r
- }\r
- //Handle wall collisions of projectiles again...\r
- for (int i = 0; i < mProjectiles.Count; i++)\r
- {\r
- if (!mGame.State.Map.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
- {\r
- mProjectiles.RemoveAt(i);\r
- i--;\r
- } \r
-\r
- }\r
+ mGameLogic.Update(timeSpan, thisPlayer);\r
\r
#if INGAME_ZOOM\r
if (Keyboard.GetState().IsKeyDown(Keys.PageUp)) mGame.State.Map.Zoom = mGame.State.Map.Zoom + 0.5f;\r
mGame.State.Map.Draw(spriteBatch);\r
mGame.State.Entities.ForEach(delegate(IEntity e) { e.Draw(spriteBatch); });\r
\r
- foreach(Projectile projectile in mProjectiles)\r
+ foreach(Projectile projectile in mGame.State.mProjectiles)\r
{\r
projectile.Draw(spriteBatch);\r
}\r
}\r
\r
}\r
- /// <summary>\r
- /// Add a projectile to the Display.\r
- /// </summary>\r
- /// <param name="projectile"></param>\r
- public void AddProjectiles(Projectile projectile)\r
- {\r
- mProjectiles.Add(projectile);\r
- }\r
+ \r
}\r
}\r
\r
--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Input;\r
+\r
+namespace CarFire\r
+{\r
+ class GameLogic\r
+ {\r
+ Game mGame;\r
+ public GameLogic(Game game)\r
+ {\r
+ mGame = game;\r
+ }\r
+ public void Update(TimeSpan timespan, int thisPlayer)\r
+ {\r
+ //Handle projectiles - update and check for wall collisions\r
+ for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+ {\r
+ bool removed = false;\r
+ if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+ {\r
+\r
+ mGame.State.mProjectiles.RemoveAt(i);\r
+ removed = true;\r
+ i--;\r
+ }\r
+ if (!removed)\r
+ mGame.State.mProjectiles[i].Update(timespan);\r
+\r
+ }\r
+ //Check for collisons\r
+ for (int j = 0; j < mGame.State.mCharacters.Length; j++)\r
+ {\r
+\r
+ if (mGame.State.mCharacters[j] != null)\r
+ for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+ {\r
+ if (mGame.State.mProjectiles[i].Coordinates.X == mGame.State.mCharacters[j].Coordinates.X && mGame.State.mProjectiles[i].Coordinates.Y == mGame.State.mCharacters[j].Coordinates.Y)\r
+ {\r
+ mGame.State.mCharacters[j].causeDamageTo(mGame.State.mProjectiles[i].Damage);\r
+ Console.WriteLine(mGame.State.mCharacters[j].Health);\r
+ mGame.State.mProjectiles.RemoveAt(i);\r
+ i--;\r
+ }\r
+ }\r
+ }\r
+ //Update input for each player\r
+ for (int i = 0; i < mGame.State.NumberOfPlayers; i++)\r
+ {\r
+ //If player has not selected a player yet let them select one.\r
+ if (mGame.State.mCharacters[i] == null)\r
+ {\r
+ if (mGame.State.GetKeysDown(i).Contains(Keys.Enter))\r
+ {\r
+ //mCharacters[i] = new Human(mGame, "", everything, projectile1, this, mGame.State.Map.GetStartingPositionForPlayer(i + 1));\r
+ }\r
+ }\r
+ //Regular player input updates\r
+ else\r
+ {\r
+\r
+ mGame.State.mCharacters[i].UpdateInput(timespan, mGame.State.GetKeysDown(i));\r
+\r
+ }\r
+ }\r
+ if (mGame.State.mCharacters[thisPlayer] != null)\r
+ {\r
+ mGame.State.Map.CenterCell = mGame.State.mCharacters[thisPlayer].Position;\r
+ }\r
+ //Handle wall collisions of projectiles again...\r
+ for (int i = 0; i < mGame.State.mProjectiles.Count; i++)\r
+ {\r
+ if (!mGame.State.Map.IsCellOpen(new Point(mGame.State.mProjectiles[i].Coordinates.X, mGame.State.mProjectiles[i].Coordinates.Y)))\r
+ {\r
+ mGame.State.mProjectiles.RemoveAt(i);\r
+ i--;\r
+ }\r
+\r
+ }\r
+ }\r
+ }\r
+}\r