public class Display\r
{\r
List<Projectile> mProjectiles = new List<Projectile>();\r
- List<Character> mCharacters = new List<Character>();\r
+ List<IPlayer> mCharacters = new List<IPlayer>();\r
Map mMap;\r
int currentCenterX = 5;\r
int currentCenterY = 5;\r
mProjectiles.Add(new Projectile(mMap, everything, new Vector2(5, 0), 10, 10, 300, 300));\r
mProjectiles.Add(new Projectile(mMap, everything, new Vector2(0, -5), 10, 10, 300, 300));\r
\r
+ \r
// TODO: use this.Content to load your game content here\r
}\r
\r
//Debug - not sure if you can remove while doing for each\r
//Alternative - while loop, and decrement projectile counter if projectile is removed.\r
mProjectiles.Remove(mProjectiles[i]);\r
- mCharacters[j].Health -= mProjectiles[i].Damage;\r
+ mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
}\r
}\r
}\r
projectile.Draw(spriteBatch);\r
\r
}\r
- foreach(Character character in mCharacters)\r
+ foreach(IPlayer character in mCharacters)\r
{\r
character.Draw(spriteBatch);\r
} \r
}\r
+\r
+ public void AddCharacters(IPlayer player)\r
+ {\r
+ mCharacters.Add(player);\r
+ }\r
}\r
}\r
\r
\r
namespace CarFire\r
{\r
+ //code from Prof Jensen's TestHarness\r
+ // This class encapsulates inputs from the players.\r
+ public class NextInputs\r
+ {\r
+ public List<Keys>[] keysPressed;\r
+ public List<Keys>[] keysReleased;\r
+ public int[] mouseLocationX;\r
+ public int[] mouseLocationY;\r
+ public bool[] mouseLocationChanged;\r
+ public bool[] mousePressed;\r
+ public bool[] mousePressedChanged;\r
+\r
+ public NextInputs()\r
+ {\r
+ keysPressed = new List<Keys>[4];\r
+ keysReleased = new List<Keys>[4];\r
+ mouseLocationX = new int[4];\r
+ mouseLocationY = new int[4];\r
+ mouseLocationChanged = new bool[4];\r
+ mousePressed = new bool[4];\r
+ mousePressedChanged = new bool[4];\r
+ for (int i = 0; i < 4; i++)\r
+ keysPressed[i] = new List<Keys>();\r
+ for (int i = 0; i < 4; i++)\r
+ keysReleased[i] = new List<Keys>();\r
+ }\r
+ }\r
+\r
public class Game : IDeterministicGame\r
{\r
#region IDeterministicGame Members\r
List<IPlayer> mPlayers;\r
+ NextInputs inputs;\r
+ Object[] playerIdentifiers;\r
Display mDisplay;\r
Map mMap;\r
\r
public Game()\r
{\r
mDisplay = new Display();\r
+ mPlayers = new List<IPlayer>();\r
}\r
public void LoadContent(ContentManager contentManager)\r
{\r
//Texture2D everything = contentManager.Load<Texture2D>("default");\r
mDisplay.LoadContent(contentManager);\r
+ int currentCenterX = 5; //Creates a map like the one in Display\r
+ int currentCenterY = 5;\r
+ mMap = contentManager.Load<Map>("Maps/stable");\r
+ Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
+ mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);\r
+\r
+ Human player = new Human(mMap, "");\r
+ player.LoadContent(contentManager);\r
+ mPlayers.Add(player);\r
+ mDisplay.AddCharacters(player);\r
}\r
\r
public void UnloadContent()\r
{\r
}\r
\r
+ private int idPlayer(Object playerIdentifier)\r
+ {\r
+ for (int i = 0; i < playerIdentifiers.Length; i++)\r
+ if (playerIdentifiers[i] == playerIdentifier)\r
+ return i;\r
+ throw new Exception("Illegal player identifier" + playerIdentifier);\r
+ }\r
+\r
public Vector2 PreferredScreenSize\r
{\r
get { return new Vector2(800, 600); }\r
\r
public void ResetGame(object[] playerIdentifiers, object thisPlayer)\r
{\r
+ foreach (IPlayer player in mPlayers)\r
+ {\r
+ player.Spawn(mMap.CenterCell);\r
+ }\r
}\r
\r
public long CurrentFrameNumber\r
\r
public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed)\r
{\r
+ //code from Prof Jensen's TestHarness\r
+ int player = idPlayer(playerIdentifier);\r
+\r
+ if (isKeyPressed && !inputs.keysPressed[player].Contains(key))\r
+ inputs.keysPressed[player].Add(key);\r
+\r
+ if (!isKeyPressed && !inputs.keysReleased[player].Contains(key))\r
+ inputs.keysReleased[player].Add(key);\r
}\r
\r
public void ApplyMouseLocationInput(object playerIdentifier, int x, int y)\r
visible = false;\r
}\r
\r
- public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
+ public void LoadContent(ContentManager contentManager)\r
{\r
charModel = contentManager.Load<Texture2D>("deselectBox"); //change to charModel when designed\r
}\r
\r
public long Draw(SpriteBatch spriteBatch)\r
{\r
+ spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White);\r
return 0;\r
}\r
\r
+ public int GridX { get { return gridX; } set { gridX = value; } }\r
+ public int GridY { get { return gridY; } set { gridY = value; } }\r
public int Health { get { return health; } }\r
public int Score { get { return score; } }\r
public bool alive { get { return health > 0; } }\r
health += amount;\r
}\r
\r
- public void Spawn(Point mapPoint)\r
+ public void Spawn(Vector2 spawn)\r
{\r
- gridX = mapPoint.X;\r
- gridY = mapPoint.Y;\r
+ gridX = (int)spawn.X;\r
+ gridY = (int)spawn.Y;\r
visible = true;\r
}\r
\r
{\r
public interface ICharacter\r
{\r
- void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics);\r
+ void LoadContent(ContentManager contentManager);\r
void UnloadContent();\r
long Update(GameTime gameTime, NetworkManager networkGame);\r
long Draw(SpriteBatch spriteBatch);\r
int Health { get; }\r
void causeDamageTo(int amount);\r
+ int GridX { get; set; }\r
+ int GridY { get; set; }\r
}\r
\r
public interface IPlayer : ICharacter\r
void MovePlayer(List<Keys> keysPressed);\r
int Score { get; }\r
void powerUp(int amount);\r
- void Spawn(Point mapPoint);\r
+ void Spawn(Vector2 spawn);\r
bool alive { get; }\r
}\r
\r