From 4974b4845e3f1cff3667bd79130a877535f3f256 Mon Sep 17 00:00:00 2001 From: brady Date: Thu, 15 Apr 2010 04:42:53 +0000 Subject: [PATCH 01/16] Began basic interface for Character, Player and Monster, Began Human Class git-svn-id: https://bd85.net/svn/cs3505_group@86 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Human.cs | 142 +++++++++++++++++++++++++++++ CarFire/CarFire/CarFire/IPlayer.cs | 35 +++++++ 2 files changed, 177 insertions(+) create mode 100644 CarFire/CarFire/CarFire/Human.cs create mode 100644 CarFire/CarFire/CarFire/IPlayer.cs diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs new file mode 100644 index 0000000..e0f6cc5 --- /dev/null +++ b/CarFire/CarFire/CarFire/Human.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + public class Human : IPlayer + { + //Member Variables + String CharName; + Map theMap; + int movementSpeed; + int gridX; + int gridY; + Texture2D charModel; + int health; + int damage; + int range; + int score; + bool isMoving; + int pixelX; + int pixelY; + bool visible; + + public Human(Map _theMap, String Name) + { + theMap = _theMap; + CharName = Name; + + movementSpeed = 20; // randomly set now + health = 100; + score = 0; + visible = false; + } + + public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) + { + charModel = contentManager.Load("deselectBox"); //change to charModel when designed + } + + public void UnloadContent() + { + + } + + public long Update(GameTime gameTime, NetworkManager networkGame) + { + return 0; + + } + + public long Draw(SpriteBatch spriteBatch) + { + return 0; + } + + public int Health { get { return health; } } + public int Score { get { return score; } } + public bool alive { get { return health > 0; } } + + public void causeDamageTo(int amount) + { + health -= amount; + } + + /// + /// Moves the current player being controlled based on a given set of key presses. + /// The player can only move one grid space per movePlayer call. Thus this method + /// is made to be called ever update. The player will only move if the grid space + /// that is being moved to is an open space. + /// + /// A general list of keys that are pressed. Other keys can be included but only direction keys will be used + public void MovePlayer(List keysPressed) + { + // move upleft + keysPressed.Contains(Keys.Left); + if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1)) + { + gridX -= 1; + gridY -= 1; + } + // move upright + else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) + { + gridX += 1; + gridY -= 1; + } + // move downleft + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) + { + gridX -= 1; + gridY += 1; + } + // move downright + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) + { + gridX += 1; + gridY += 1; + } + // move up + else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) + { + gridY -= 1; + } + // move down + else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) + { + gridY += 1; + } + // move left + else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) + { + gridX -= 1; + } + // move right + else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) + { + gridX += 1; + } + } + + + public void powerUp(int amount) + { + health += amount; + } + + public void Spawn(Point mapPoint) + { + gridX = mapPoint.X; + gridY = mapPoint.Y; + visible = true; + } + + + } +} \ No newline at end of file diff --git a/CarFire/CarFire/CarFire/IPlayer.cs b/CarFire/CarFire/CarFire/IPlayer.cs new file mode 100644 index 0000000..7eb7611 --- /dev/null +++ b/CarFire/CarFire/CarFire/IPlayer.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + public interface ICharacter + { + void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics); + void UnloadContent(); + long Update(GameTime gameTime, NetworkManager networkGame); + long Draw(SpriteBatch spriteBatch); + int Health { get; } + void causeDamageTo(int amount); + } + + public interface IPlayer : ICharacter + { + void MovePlayer(List keysPressed); + int Score { get; } + void powerUp(int amount); + void Spawn(Point mapPoint); + bool alive { get; } + } + + public interface IMonster : ICharacter + { + bool visible { get; } + } +} -- 2.44.0 From f2ad5f34ad4e6192a9e30f87b5c87c1d241c26d1 Mon Sep 17 00:00:00 2001 From: brady Date: Thu, 15 Apr 2010 04:48:25 +0000 Subject: [PATCH 02/16] git-svn-id: https://bd85.net/svn/cs3505_group@87 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 1271138..d213f2e 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -12,7 +12,7 @@ namespace CarFire public class Game : IDeterministicGame { #region IDeterministicGame Members - List mPlayers; + List mPlayers; Display mDisplay; Map mMap; -- 2.44.0 From 7bda677bc747f6e7130dd42bb906b501eb35b53f Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 05:13:21 +0000 Subject: [PATCH 03/16] More test projectiles git-svn-id: https://bd85.net/svn/cs3505_group@88 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 98f91ed..9bfefef 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -68,22 +68,28 @@ namespace CarFire /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { - mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); - foreach (Projectile projectile in mProjectiles) + + for (int i = 0; i < mProjectiles.Count; i++ ) { - projectile.Update(timespan); + mProjectiles[i].Update(timespan); + if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY))) + { + + mProjectiles.RemoveAt(i); + i--; + } } //Check for collisons - foreach (Character character in mCharacters) + for (int j = 0; j < mCharacters.Count; j++) { - foreach (Projectile projectile in mProjectiles) + for (int i = 0; i < mProjectiles.Count; i++) { - if (projectile.GridX == character.GridX && projectile.GridY == character.GridY) + 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(projectile); - character.Health -= projectile.Damage; + mProjectiles.Remove(mProjectiles[i]); + mCharacters[j].Health -= mProjectiles[i].Damage; } } } @@ -98,15 +104,16 @@ namespace CarFire mMap.Draw(spriteBatch); foreach(Projectile projectile in 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(Character character in mCharacters) { character.Draw(spriteBatch); - } - - + } } } } -- 2.44.0 From b4115cbc63a031622aefd3ebc078b57334270bc9 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 05:13:47 +0000 Subject: [PATCH 04/16] Projectiles disappear when they hit a wall(or occupied square) git-svn-id: https://bd85.net/svn/cs3505_group@89 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Projectile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index 1dd5e08..a294a78 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -64,11 +64,11 @@ namespace CarFire //If the projectile will be moving to a new grid position we need to check to see if it is occupied. if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY) { - bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares)); + //bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares)); //If open just move this projectile there //***Map doesn't need to know that this projectile is there because players/monsters are allowed // to move into the path of projectiles. - if (open) + //if (open) { Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY); pixelX += (int)velocity.X; -- 2.44.0 From 5929d5818dbc0a0c22838678ee8a34f4c512d2ba Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 05:25:15 +0000 Subject: [PATCH 05/16] git-svn-id: https://bd85.net/svn/cs3505_group@90 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/CarFire.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index dc31e03..da68b92 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -84,8 +84,8 @@ - + -- 2.44.0 From d0bdd76b2cfd38fe985a7493f42b5d6e0f79ac91 Mon Sep 17 00:00:00 2001 From: brady Date: Thu, 15 Apr 2010 07:29:46 +0000 Subject: [PATCH 06/16] Basic Changes to Character, Small Changes to Display as well to make it so a Player is Created and Drawn, things still need to be moved around and tweeked. Feel free to change anything git-svn-id: https://bd85.net/svn/cs3505_group@91 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 12 ++++-- CarFire/CarFire/CarFire/Game.cs | 61 ++++++++++++++++++++++++++++++ CarFire/CarFire/CarFire/Human.cs | 11 ++++-- CarFire/CarFire/CarFire/IPlayer.cs | 6 ++- 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 9bfefef..ed6ab45 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -15,7 +15,7 @@ namespace CarFire public class Display { List mProjectiles = new List(); - List mCharacters = new List(); + List mCharacters = new List(); Map mMap; int currentCenterX = 5; int currentCenterY = 5; @@ -49,6 +49,7 @@ namespace CarFire 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 } @@ -89,7 +90,7 @@ namespace CarFire //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].Health -= mProjectiles[i].Damage; + mCharacters[j].causeDamageTo(mProjectiles[i].Damage); } } } @@ -110,11 +111,16 @@ namespace CarFire projectile.Draw(spriteBatch); } - foreach(Character character in mCharacters) + foreach(IPlayer character in mCharacters) { character.Draw(spriteBatch); } } + + public void AddCharacters(IPlayer player) + { + mCharacters.Add(player); + } } } diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index d213f2e..a2b6caf 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -9,27 +9,76 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { + //code from Prof Jensen's TestHarness + // This class encapsulates inputs from the players. + public class NextInputs + { + public List[] keysPressed; + public List[] keysReleased; + public int[] mouseLocationX; + public int[] mouseLocationY; + public bool[] mouseLocationChanged; + public bool[] mousePressed; + public bool[] mousePressedChanged; + + public NextInputs() + { + keysPressed = new List[4]; + keysReleased = new List[4]; + mouseLocationX = new int[4]; + mouseLocationY = new int[4]; + mouseLocationChanged = new bool[4]; + mousePressed = new bool[4]; + mousePressedChanged = new bool[4]; + for (int i = 0; i < 4; i++) + keysPressed[i] = new List(); + for (int i = 0; i < 4; i++) + keysReleased[i] = new List(); + } + } + public class Game : IDeterministicGame { #region IDeterministicGame Members List mPlayers; + NextInputs inputs; + Object[] playerIdentifiers; Display mDisplay; Map mMap; public Game() { mDisplay = new Display(); + mPlayers = new List(); } public void LoadContent(ContentManager contentManager) { //Texture2D everything = contentManager.Load("default"); mDisplay.LoadContent(contentManager); + int currentCenterX = 5; //Creates a map like the one in Display + int currentCenterY = 5; + mMap = contentManager.Load("Maps/stable"); + Map.DefaultTile = contentManager.Load("default"); + mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); + + Human player = new Human(mMap, ""); + player.LoadContent(contentManager); + mPlayers.Add(player); + mDisplay.AddCharacters(player); } public void UnloadContent() { } + private int idPlayer(Object playerIdentifier) + { + for (int i = 0; i < playerIdentifiers.Length; i++) + if (playerIdentifiers[i] == playerIdentifier) + return i; + throw new Exception("Illegal player identifier" + playerIdentifier); + } + public Vector2 PreferredScreenSize { get { return new Vector2(800, 600); } @@ -47,6 +96,10 @@ namespace CarFire public void ResetGame(object[] playerIdentifiers, object thisPlayer) { + foreach (IPlayer player in mPlayers) + { + player.Spawn(mMap.CenterCell); + } } public long CurrentFrameNumber @@ -61,6 +114,14 @@ namespace CarFire public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed) { + //code from Prof Jensen's TestHarness + int player = idPlayer(playerIdentifier); + + if (isKeyPressed && !inputs.keysPressed[player].Contains(key)) + inputs.keysPressed[player].Add(key); + + if (!isKeyPressed && !inputs.keysReleased[player].Contains(key)) + inputs.keysReleased[player].Add(key); } public void ApplyMouseLocationInput(object playerIdentifier, int x, int y) diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index e0f6cc5..acb0d3b 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -38,7 +38,7 @@ namespace CarFire visible = false; } - public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) + public void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("deselectBox"); //change to charModel when designed } @@ -56,9 +56,12 @@ namespace CarFire public long Draw(SpriteBatch spriteBatch) { + spriteBatch.Draw(charModel, theMap.GetRectangleFromCoordinates(gridX, gridY), Color.White); return 0; } + public int GridX { get { return gridX; } set { gridX = value; } } + public int GridY { get { return gridY; } set { gridY = value; } } public int Health { get { return health; } } public int Score { get { return score; } } public bool alive { get { return health > 0; } } @@ -130,10 +133,10 @@ namespace CarFire health += amount; } - public void Spawn(Point mapPoint) + public void Spawn(Vector2 spawn) { - gridX = mapPoint.X; - gridY = mapPoint.Y; + gridX = (int)spawn.X; + gridY = (int)spawn.Y; visible = true; } diff --git a/CarFire/CarFire/CarFire/IPlayer.cs b/CarFire/CarFire/CarFire/IPlayer.cs index 7eb7611..3b98301 100644 --- a/CarFire/CarFire/CarFire/IPlayer.cs +++ b/CarFire/CarFire/CarFire/IPlayer.cs @@ -11,12 +11,14 @@ namespace CarFire { public interface ICharacter { - void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics); + void LoadContent(ContentManager contentManager); void UnloadContent(); long Update(GameTime gameTime, NetworkManager networkGame); long Draw(SpriteBatch spriteBatch); int Health { get; } void causeDamageTo(int amount); + int GridX { get; set; } + int GridY { get; set; } } public interface IPlayer : ICharacter @@ -24,7 +26,7 @@ namespace CarFire void MovePlayer(List keysPressed); int Score { get; } void powerUp(int amount); - void Spawn(Point mapPoint); + void Spawn(Vector2 spawn); bool alive { get; } } -- 2.44.0 From e0c80253cb799426fc412aa9cfd773c111f50565 Mon Sep 17 00:00:00 2001 From: brady Date: Thu, 15 Apr 2010 07:57:00 +0000 Subject: [PATCH 07/16] git-svn-id: https://bd85.net/svn/cs3505_group@92 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/CarFire.csproj | 2 ++ CarFire/CarFire/CarFire/ScreenManager.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index da68b92..fd92b88 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -87,7 +87,9 @@ + + diff --git a/CarFire/CarFire/CarFire/ScreenManager.cs b/CarFire/CarFire/CarFire/ScreenManager.cs index 39d95dd..e4dc0f4 100644 --- a/CarFire/CarFire/CarFire/ScreenManager.cs +++ b/CarFire/CarFire/CarFire/ScreenManager.cs @@ -348,7 +348,7 @@ namespace CarFire } if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) networkManager.LocalGamer.IsReady = true; - + if (networkManager.HasActiveSession) { localPlayer = networkManager.LocalGamer; -- 2.44.0 From f1390d70a75797ad27bde6471ab9581e8a2a5f87 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 19:07:03 +0000 Subject: [PATCH 08/16] git-svn-id: https://bd85.net/svn/cs3505_group@93 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 44 ++++++++++++++++++++++++--- CarFire/CarFire/CarFire/Projectile.cs | 3 +- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index ed6ab45..eda3711 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,6 @@ -using System; +#define SINGLE_TEST + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -16,9 +18,13 @@ namespace CarFire { List mProjectiles = new List(); List mCharacters = new List(); + Texture2D everything; Map mMap; int currentCenterX = 5; int currentCenterY = 5; +#if SINGLE_TEST + List mLastPressedKeys = new List(); +#endif public Display() { /* @@ -33,12 +39,13 @@ namespace CarFire /// public void LoadContent(ContentManager contentManager) { - Texture2D everything = contentManager.Load("cs"); + 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)); @@ -48,6 +55,7 @@ namespace CarFire 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 @@ -69,6 +77,30 @@ namespace CarFire /// Provides a snapshot of timing values. public void Update(TimeSpan timespan) { + //INPUT - testing input... has to be through network later +#if SINGLE_TEST + KeyboardState keyState = Keyboard.GetState(); + + List pressedKeys = new List(); + List releasedKeys = new List(); + + Keys[] pressedKeysArray = keyState.GetPressedKeys(); + foreach (Keys k in pressedKeysArray) + { + if (!mLastPressedKeys.Contains(k)) pressedKeys.Add(k); + else mLastPressedKeys.Remove(k); + } + + releasedKeys = mLastPressedKeys; + mLastPressedKeys = new List(pressedKeysArray); + //Just apply input for the first player + mCharacters[0].MovePlayer(pressedKeys); + if (pressedKeys.Contains(Keys.Enter) && !releasedKeys.Contains(Keys.Enter)) + { + 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)); + } + mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); +#endif for (int i = 0; i < mProjectiles.Count; i++ ) { @@ -83,14 +115,16 @@ namespace CarFire //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); + Console.WriteLine(mCharacters[j].Health); + mProjectiles.RemoveAt(i); + i--; } } } diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index a294a78..cabb38d 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -51,6 +51,7 @@ namespace CarFire gridY = _gridY; pixelX = _pixelX; pixelY = _pixelY; + damage = 20; } public void Update(TimeSpan timespan) { @@ -70,7 +71,7 @@ namespace CarFire // to move into the path of projectiles. //if (open) { - Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY); + //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY); pixelX += (int)velocity.X; pixelY += (int)velocity.Y; gridX = (int)(pixelX /Map.PixelsToUnitSquares); -- 2.44.0 From e55c1fd13b13e01468b622f0c5b3f6a4846aed0b Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 19:16:48 +0000 Subject: [PATCH 09/16] Single Player test - Player will shoot in one direction and screen will follow him. git-svn-id: https://bd85.net/svn/cs3505_group@94 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index eda3711..8f4fbdc 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -139,9 +139,6 @@ namespace CarFire mMap.Draw(spriteBatch); foreach(Projectile projectile in 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); } -- 2.44.0 From 32de3ceb04ed8123614002551d7cecd6dd5f41d0 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 15 Apr 2010 19:48:37 +0000 Subject: [PATCH 10/16] git-svn-id: https://bd85.net/svn/cs3505_group@95 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 2 ++ CarFire/CarFire/CarFire/NetworkManager.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index a2b6caf..7374522 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -126,10 +126,12 @@ namespace CarFire public void ApplyMouseLocationInput(object playerIdentifier, int x, int y) { + } public void ApplyMouseButtonInput(object playerIdentifier, bool isButtonPressed) { + } public bool IsGameOver(object playerIdentifier) diff --git a/CarFire/CarFire/CarFire/NetworkManager.cs b/CarFire/CarFire/CarFire/NetworkManager.cs index 3fd4ca4..c045dc8 100644 --- a/CarFire/CarFire/CarFire/NetworkManager.cs +++ b/CarFire/CarFire/CarFire/NetworkManager.cs @@ -363,6 +363,7 @@ namespace CarFire } else if (mNetworkSession.SessionState == NetworkSessionState.Playing) { + mGame.Draw(spriteBatch); } } -- 2.44.0 From a67a04fbbf048dc08edd2ed726aa8c6da4c26a6b Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 16 Apr 2010 18:11:19 +0000 Subject: [PATCH 11/16] New map method Map.GetStartingPositionForPlayer to, uh, get the starting positions for the players... git-svn-id: https://bd85.net/svn/cs3505_group@96 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Map.cs | 22 +++++++++++++++++++--- CarFire/CarFire/CarFire/MapReader.cs | 2 +- CarFire/CarFire/CarFire/Parse.cs | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index ddfa9d5..f3d59d4 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -154,9 +154,9 @@ namespace CarFire /// The metadata. /// The grid. /// The entities. - public Map(Metadata metadata, char[,] grid, List entities) + public Map(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) { - mData = new Modal(metadata, grid, entities); + mData = new Modal(metadata, grid, entities, playerPositions); mView = new View(mData); } @@ -236,6 +236,19 @@ namespace CarFire } + /// + /// Get the starting position of a player. + /// + /// The number of the player (i.e. 1-4). + /// This number must be a valid player number. + /// The starting position of the player. + public Point GetStartingPositionForPlayer(int playerNumber) + { + Debug.Assert(1 <= playerNumber && playerNumber <= NumPlayers.Max()); + return mData.PlayerPositions[playerNumber]; + } + + /// /// Get all the entities loaded from the map file. Exceptions could be /// thrown if there are entities without associated classes. @@ -267,8 +280,9 @@ namespace CarFire Metadata mMetadata; char[,] mGrid; List mEntities; + Point[] mPlayerPositions; - public Modal(Metadata metadata, char[,] grid, List entities) + public Modal(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) { Debug.Assert(metadata != null); Debug.Assert(grid != null); @@ -278,6 +292,7 @@ namespace CarFire mMetadata = metadata; mGrid = grid; mEntities = entities; + mPlayerPositions = playerPositions; #if DEBUG Console.WriteLine("Loaded map {0} of type {1} written by {2}.", @@ -290,6 +305,7 @@ namespace CarFire public Metadata Metadata { get { return mMetadata; } } public List Entities { get { return mEntities; } } + public Point[] PlayerPositions { get { return mPlayerPositions; } } public bool IsCellOpen(int x, int y) diff --git a/CarFire/CarFire/CarFire/MapReader.cs b/CarFire/CarFire/CarFire/MapReader.cs index 3d43f36..8eb7e16 100644 --- a/CarFire/CarFire/CarFire/MapReader.cs +++ b/CarFire/CarFire/CarFire/MapReader.cs @@ -96,7 +96,7 @@ namespace CarFire public Map GetMap() { - return new Map(mMetadata, mGrid, mEntities); + return new Map(mMetadata, mGrid, mEntities, mPlayerPositions); } diff --git a/CarFire/CarFire/CarFire/Parse.cs b/CarFire/CarFire/CarFire/Parse.cs index be11a9a..bb2e9c1 100644 --- a/CarFire/CarFire/CarFire/Parse.cs +++ b/CarFire/CarFire/CarFire/Parse.cs @@ -10,7 +10,7 @@ namespace CarFire /// /// Class with handy static methods taking strings and returning objects /// parsed from those strings. For all of these functions, white space is - /// generally ignored, but any superfluous characters will make the parse fail. + /// generally ignored, but superfluous characters are not allowed. /// public class Parse { @@ -30,7 +30,7 @@ namespace CarFire /// Parses a comment of an INI file. /// /// Text. - /// The comment. + /// The comment, or null if parsing failed. public static string IniComment(string line) { Match match = Regex.Match(line, @"^;\s*(.*)\s*$"); -- 2.44.0 From b92963913e205b5370c112dd5cbf96f91194bc50 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 16 Apr 2010 18:42:51 +0000 Subject: [PATCH 12/16] New map methods Map.SetCell and Map.ClearCell to modify the tiles of the map. These will be needed by the script class. git-svn-id: https://bd85.net/svn/cs3505_group@97 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Map.cs | 91 ++++++++++++++++++++++++++-- CarFire/CarFire/CarFire/MapReader.cs | 5 +- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/CarFire/CarFire/CarFire/Map.cs b/CarFire/CarFire/CarFire/Map.cs index f3d59d4..6727133 100644 --- a/CarFire/CarFire/CarFire/Map.cs +++ b/CarFire/CarFire/CarFire/Map.cs @@ -128,14 +128,27 @@ namespace CarFire public string Tileset { get { return mData.Metadata.Tileset; } } /// - /// Get a list of the raw entity containers loaded with the map. + /// Get the current grid of open cells. On the grid, true means + /// the cell is open (i.e. an entity can occupy that cell), and false + /// means the cell is closed. Note that, just like Map.IsCellOpen, + /// only static scenery is considered; the grid cannot tell you + /// whether or not an entity is already occupying the cell. + /// + public bool[,] Grid { get { return mData.Grid; } } + + /// + /// Get a list of the raw entity containers loaded with the map. If you + /// want to get the actual entity objects, use Map.GetEntities and + /// Map.GetAllEntities instead. /// public List RawEntities { get { return mData.Entities; } } /// /// Get and set the coordinate of the grid cell that should be in - /// the center of the screen when the map is drawn. + /// the center of the screen when the map is drawn. Setting this + /// will change the viewport of the map and will effect the return + /// values of Map.GetPointFromCoordinates and Map.GetRectangleFromCoordinates. /// public Vector2 CenterCell { @@ -154,9 +167,10 @@ namespace CarFire /// The metadata. /// The grid. /// The entities. - public Map(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) + public Map(Metadata metadata, char[,] grid, char defaultTile, + List entities, Point[] playerPositions) { - mData = new Modal(metadata, grid, entities, playerPositions); + mData = new Modal(metadata, grid, defaultTile, entities, playerPositions); mView = new View(mData); } @@ -270,6 +284,48 @@ namespace CarFire return mData.GetEntities(); } + + /// + /// Set the tile of a cell. + /// + /// X-coordinate. + /// Y-coordinate. + /// The character representing the tile. + public void SetCell(int x, int y, char tile) + { + mData.SetCell(x, y, tile); + } + + /// + /// Set the tile of a cell. + /// + /// X,Y-coordinates. + /// The character representing the tile. + public void SetCell(Point point, char tile) + { + mData.SetCell(point.X, point.Y, tile); + } + + + /// + /// Clear a cell to the default tile. + /// + /// X-coordinate. + /// Y-coordinate. + public void ClearCell(int x, int y) + { + mData.ClearCell(x, y); + } + + /// + /// Clear a cell to the default tile. + /// + /// X,Y-coordinates. + public void ClearCell(Point point) + { + mData.ClearCell(point.X, point.Y); + } + #endregion @@ -279,10 +335,13 @@ namespace CarFire { Metadata mMetadata; char[,] mGrid; + char mDefaultTile; List mEntities; Point[] mPlayerPositions; + bool[,] mBooleanGrid; - public Modal(Metadata metadata, char[,] grid, List entities, Point[] playerPositions) + public Modal(Metadata metadata, char[,] grid, char defaultTile, + List entities, Point[] playerPositions) { Debug.Assert(metadata != null); Debug.Assert(grid != null); @@ -291,9 +350,19 @@ namespace CarFire mMetadata = metadata; mGrid = grid; + mDefaultTile = defaultTile; mEntities = entities; mPlayerPositions = playerPositions; + mBooleanGrid = new bool[mMetadata.GridWidth, mMetadata.GridHeight]; + for (int x = 0; x < mMetadata.GridWidth; x++) + { + for (int y = 0; y < mMetadata.GridHeight; y++) + { + mBooleanGrid[x, y] = IsCellOpen(x, y); + } + } + #if DEBUG Console.WriteLine("Loaded map {0} of type {1} written by {2}.", metadata.Name, @@ -306,6 +375,7 @@ namespace CarFire public Metadata Metadata { get { return mMetadata; } } public List Entities { get { return mEntities; } } public Point[] PlayerPositions { get { return mPlayerPositions; } } + public bool[,] Grid { get { return mBooleanGrid; } } public bool IsCellOpen(int x, int y) @@ -314,6 +384,17 @@ namespace CarFire return mGrid[x, y] == ' '; } + public void SetCell(int x, int y, char tile) + { + mGrid[x, y] = tile; + mBooleanGrid[x, y] = IsCellOpen(x, y); + } + + public void ClearCell(int x, int y) + { + SetCell(x, y, mDefaultTile); + } + public List GetAllEntities() { diff --git a/CarFire/CarFire/CarFire/MapReader.cs b/CarFire/CarFire/CarFire/MapReader.cs index 8eb7e16..ae03ff9 100644 --- a/CarFire/CarFire/CarFire/MapReader.cs +++ b/CarFire/CarFire/CarFire/MapReader.cs @@ -96,7 +96,7 @@ namespace CarFire public Map GetMap() { - return new Map(mMetadata, mGrid, mEntities, mPlayerPositions); + return new Map(mMetadata, mGrid, mDefaultTile, mEntities, mPlayerPositions); } @@ -425,10 +425,9 @@ namespace CarFire char[,] mGrid; List mEntities; Point[] mPlayerPositions; - - Dictionary> mEntitySections = new Dictionary>(); char mDefaultTile = ' '; + Dictionary> mEntitySections = new Dictionary>(); LineReader mInput; } -- 2.44.0 From 577ff3be4678ec954c84d1b7eb3639ac04c08009 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Apr 2010 02:11:40 +0000 Subject: [PATCH 13/16] Now uses network to update character position git-svn-id: https://bd85.net/svn/cs3505_group@98 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 40 +++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 8f4fbdc..27f151e 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -1,4 +1,4 @@ -#define SINGLE_TEST +#undef SINGLE_TEST using System; using System.Collections.Generic; @@ -16,8 +16,10 @@ namespace CarFire /// public class Display { + bool playerChosen = false; List mProjectiles = new List(); - List mCharacters = new List(); + //List mCharacters = new List(); + IPlayer[] mCharacters = new IPlayer[4]; Texture2D everything; Map mMap; int currentCenterX = 5; @@ -75,8 +77,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) { + //INPUT - testing input... has to be through network later #if SINGLE_TEST KeyboardState keyState = Keyboard.GetState(); @@ -101,7 +104,24 @@ namespace CarFire } mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); #endif - + + for (int i = 0; i < 4; i++) + { + if (mCharacters[i] == null) + { + if(state.keysDown[i].Contains(Keys.Enter)) + { + mCharacters[i] = (new Human(mMap, "", everything)); + mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i+1).X; + mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i+1).Y; + } + } + else + { + mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); + mCharacters[i].MovePlayer(state.keysDown[i]); + } + } for (int i = 0; i < mProjectiles.Count; i++ ) { mProjectiles[i].Update(timespan); @@ -113,10 +133,10 @@ namespace CarFire } } //Check for collisons - for (int j = 0; j < mCharacters.Count; j++) + for (int j = 0; j < mCharacters.Length; j++) { - + if(mCharacters[j] != null) for (int i = 0; i < mProjectiles.Count; i++) { if (mProjectiles[i].GridX == mCharacters[j].GridX && mProjectiles[i].GridY == mCharacters[j].GridY) @@ -142,15 +162,17 @@ namespace CarFire projectile.Draw(spriteBatch); } - foreach(IPlayer character in mCharacters) + for(int i = 0; i < 4; i++)//IPlayer character in mCharacters) { - character.Draw(spriteBatch); + if(mCharacters[i] != null) + mCharacters[i].Draw(spriteBatch); } } public void AddCharacters(IPlayer player) { - mCharacters.Add(player); + mCharacters[mCharacters.Length] = player; + //mCharacters.Add(player); } } } -- 2.44.0 From f5b00f187579c137436bb023c5f4c71dbeb02847 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Apr 2010 02:11:57 +0000 Subject: [PATCH 14/16] Incorporated networking into the game git-svn-id: https://bd85.net/svn/cs3505_group@99 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Game.cs | 186 +++++++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 12 deletions(-) diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 7374522..b1b7238 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -9,6 +9,135 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { + // Everything in objects built from this class represent the critical game state + public class GameState + { + public long frameNumber; + + private long checksum; + public long Checksum { get { return checksum; } } + + public bool[] isGameOver; + public bool[] isTerminated; + + // Since this is not a game, I'll just keep track of the user inputs as the game state. + + public int[] mouseLocationX; + public int[] mouseLocationY; + public bool[] mouseButton; + public List[] keysDown; + public int[] keypressCount; + + public long elapsedTime; + + /* Constructor */ + public GameState() + { + frameNumber = 0; + checksum = 0; + + isGameOver = new bool[4]; + isTerminated = new bool[4]; + + mouseLocationX = new int[4]; + mouseLocationY = new int[4]; + mouseButton = new bool[4]; + keysDown = new List[4]; + for (int i = 0; i < 4; i++) + keysDown[i] = new List(); + keypressCount = new int[4]; + + elapsedTime = 0; + + checksum = 0; + } + + /* The game engine! */ + public void advanceFrame(NextInputs inputs, long milliseconds) + { + // Advance frame number + frameNumber++; + + // Advance game - for the test harness, just record statistics and input states. + + elapsedTime += milliseconds; + + for (int player = 0; player < 4; player++) + { + + //if (isGameOver[player]) + // continue; + + if (inputs.mousePressedChanged[player]) + mouseButton[player] = inputs.mousePressed[player]; + + if (inputs.mouseLocationChanged[player]) + { + mouseLocationX[player] = inputs.mouseLocationX[player]; + mouseLocationY[player] = inputs.mouseLocationY[player]; + } + + foreach (Keys k in inputs.keysPressed[player]) + if (!keysDown[player].Contains(k)) + { + keysDown[player].Add(k); + keypressCount[player]++; + } + + foreach (Keys k in inputs.keysReleased[player]) + keysDown[player].Remove(k); + + // If the mouse was pressed for a certain player, activate game over or terminated states as appropriate + + if (inputs.mousePressed[player]) + for (int p = 0; p < 4; p++) + { + int x = 200 * p + 10; + int y = 220; + + if (mouseLocationX[player] >= x && mouseLocationY[player] >= y && + mouseLocationX[player] < x + 25 && mouseLocationY[player] < y + 25) + { + isGameOver[p] = true; + } + y += 25; + if (mouseLocationX[player] >= x && mouseLocationY[player] >= y && + mouseLocationX[player] < x + 25 && mouseLocationY[player] < y + 25) + { + isGameOver[p] = true; + isTerminated[p] = true; + } + } + + + } + + // Advance the checksum. + + computeChecksum(); + + } + + /* Just hash the values */ + private long computeChecksum() + { + checksum += frameNumber; + for (int i = 0; i < 4; i++) + { + checksum = checksum + keypressCount[i]; + checksum = checksum * 3 + (isGameOver[i] ? 1 : 2); + checksum = checksum * 3 + (isTerminated[i] ? 1 : 2); + foreach (Keys k in keysDown[i]) + checksum = checksum * 257 + (int)k; + checksum = checksum * 25789 + mouseLocationX[i] * 259 + mouseLocationY[i] + 375; + checksum = checksum * 3 + (mouseButton[i] ? 1 : 2); + + } + checksum += elapsedTime; + + return checksum; + } + } //code from Prof Jensen's TestHarness // This class encapsulates inputs from the players. public class NextInputs @@ -35,6 +164,7 @@ namespace CarFire for (int i = 0; i < 4; i++) keysReleased[i] = new List(); } + } public class Game : IDeterministicGame @@ -46,10 +176,14 @@ namespace CarFire Display mDisplay; Map mMap; + GameState state; + int thisPlayerID; + public Game() { mDisplay = new Display(); mPlayers = new List(); + playerIdentifiers = new Object[4]; } public void LoadContent(ContentManager contentManager) { @@ -60,11 +194,7 @@ namespace CarFire mMap = contentManager.Load("Maps/stable"); Map.DefaultTile = contentManager.Load("default"); mMap.CenterCell = new Vector2(currentCenterX, currentCenterY); - - Human player = new Human(mMap, ""); - player.LoadContent(contentManager); - mPlayers.Add(player); - mDisplay.AddCharacters(player); + } public void UnloadContent() @@ -94,17 +224,44 @@ namespace CarFire get { return 4; } } - public void ResetGame(object[] playerIdentifiers, object thisPlayer) + public void ResetGame(object[] PlayerIdentifiers, object thisPlayer) { - foreach (IPlayer player in mPlayers) + // Now the test harness will at least run with less than 4 players... + int numPlayers = PlayerIdentifiers.Count(); + for (int i = 0; i < numPlayers; i++) + this.playerIdentifiers[i] = PlayerIdentifiers[i]; + + // Create new game state and inputs objects. + + state = new GameState(); + inputs = new NextInputs(); + + // Record 'this' player. + + this.thisPlayerID = idPlayer(thisPlayer); + /* + mPlayers.Clear(); + for (int i = 0; i < PlayerIdentifiers.Length; i++) { - player.Spawn(mMap.CenterCell); + Human player = new Human(mMap, ""); + mPlayers.Add(player); + mDisplay.AddCharacters(player); + mPlayers.Add(player); + mDisplay.AddCharacters(player); } + this.playerIdentifiers = PlayerIdentifiers; + for (int i = 0; i < mPlayers.Count; i++) + { + Point starting = mMap.GetStartingPositionForPlayer(i + 1); + mPlayers[i].Spawn(new Vector2(starting.X, starting.Y)); + } + */ + } public long CurrentFrameNumber { - get { return 0; } + get { return state.frameNumber; } } public long CurrentChecksum @@ -122,6 +279,7 @@ namespace CarFire if (!isKeyPressed && !inputs.keysReleased[player].Contains(key)) inputs.keysReleased[player].Add(key); + } public void ApplyMouseLocationInput(object playerIdentifier, int x, int y) @@ -144,10 +302,14 @@ namespace CarFire return false; } - public long Update(TimeSpan timespan) + public long Update(TimeSpan elapsedTime) { - mDisplay.Update(timespan); - return CurrentFrameNumber; + state.advanceFrame(inputs, elapsedTime.Milliseconds); // Apply the inputs, advance game state. + mDisplay.Update(elapsedTime, state); + inputs = new NextInputs(); // Start with inputs cleared on the next frame. + //mDisplay.Update(elapsedTime); + return state.frameNumber; + } public long Draw(SpriteBatch spriteBatch) -- 2.44.0 From 98a1207447757d2e01f5fba091acf87f8795c8ad Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Apr 2010 02:12:20 +0000 Subject: [PATCH 15/16] Added a few member fariables and parameter to constructor git-svn-id: https://bd85.net/svn/cs3505_group@100 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Human.cs | 123 ++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 43 deletions(-) diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index acb0d3b..7a926a6 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -11,13 +11,22 @@ namespace CarFire { public class Human : IPlayer { + public enum State + { + left, + right, + up, + down + }; //Member Variables + State state; String CharName; Map theMap; int movementSpeed; int gridX; int gridY; Texture2D charModel; + Texture2D projectileModel; int health; int damage; int range; @@ -26,21 +35,28 @@ namespace CarFire int pixelX; int pixelY; bool visible; + int movementCoolDown; - public Human(Map _theMap, String Name) + public Human(Map _theMap, String Name, Texture2D model) { theMap = _theMap; CharName = Name; - movementSpeed = 20; // randomly set now + movementSpeed = 12; // randomly set now health = 100; score = 0; visible = false; + //default state + state = State.up; + charModel = model; + movementCoolDown = movementSpeed; } public void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("deselectBox"); //change to charModel when designed + projectileModel = contentManager.Load("emptySelectBox"); //change to a projectile model later + } public void UnloadContent() @@ -80,50 +96,71 @@ namespace CarFire /// A general list of keys that are pressed. Other keys can be included but only direction keys will be used public void MovePlayer(List keysPressed) { - // move upleft - keysPressed.Contains(Keys.Left); - if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1)) - { - gridX -= 1; - gridY -= 1; - } - // move upright - else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) - { - gridX += 1; - gridY -= 1; - } - // move downleft - else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) - { - gridX -= 1; - gridY += 1; - } - // move downright - else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) - { - gridX += 1; - gridY += 1; - } - // move up - else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) - { - gridY -= 1; - } - // move down - else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) - { - gridY += 1; - } - // move left - else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) + if(movementCoolDown > 0) + movementCoolDown--; + else if (movementCoolDown == 0) { - gridX -= 1; + // move upleft + keysPressed.Contains(Keys.Left); + if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY - 1)) + { + gridX -= 1; + gridY -= 1; + movementCoolDown = movementSpeed; + } + // move upright + else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) + { + gridX += 1; + gridY -= 1; + movementCoolDown = movementSpeed; + } + // move downleft + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) + { + gridX -= 1; + gridY += 1; + movementCoolDown = movementSpeed; + } + // move downright + else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) + { + gridX += 1; + gridY += 1; + movementCoolDown = movementSpeed; + } + // move up + else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) + { + gridY -= 1; + movementCoolDown = movementSpeed; + } + // move down + else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) + { + gridY += 1; + movementCoolDown = movementSpeed; + } + // move left + else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) + { + gridX -= 1; + movementCoolDown = movementSpeed; + } + // move right + else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) + { + gridX += 1; + movementCoolDown = movementSpeed; + } } - // move right - else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) + if (keysPressed.Contains(Keys.Space)) { - gridX += 1; + //TODO spawn projectile... needs to be added to display though + if (state == State.up) + { + + } } } -- 2.44.0 From 5776c1910247848ab45b111b6a9df4265483a894 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Apr 2010 02:59:32 +0000 Subject: [PATCH 16/16] Players now spawn projectiles... still kind of buggy. git-svn-id: https://bd85.net/svn/cs3505_group@101 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- CarFire/CarFire/CarFire/Display.cs | 13 +++++++++---- CarFire/CarFire/CarFire/Human.cs | 25 +++++++++++++++++++++++-- CarFire/CarFire/CarFire/Projectile.cs | 9 +++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 27f151e..774833b 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -47,7 +47,7 @@ namespace CarFire 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)); @@ -57,7 +57,7 @@ namespace CarFire 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 @@ -111,7 +111,7 @@ namespace CarFire { if(state.keysDown[i].Contains(Keys.Enter)) { - mCharacters[i] = (new Human(mMap, "", everything)); + mCharacters[i] = (new Human(mMap, "", everything, everything, this)); mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i+1).X; mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i+1).Y; } @@ -168,12 +168,17 @@ namespace CarFire mCharacters[i].Draw(spriteBatch); } } - + /* public void AddCharacters(IPlayer player) { mCharacters[mCharacters.Length] = player; //mCharacters.Add(player); } + */ + public void AddProjectiles(Projectile projectile) + { + mProjectiles.Add(projectile); + } } } diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 7a926a6..30546f3 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -36,11 +36,14 @@ namespace CarFire int pixelY; bool visible; int movementCoolDown; + Display theDisplay; + int projectileSpeed; - public Human(Map _theMap, String Name, Texture2D model) + public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay) { theMap = _theMap; CharName = Name; + theDisplay = mDisplay; movementSpeed = 12; // randomly set now health = 100; @@ -49,7 +52,9 @@ namespace CarFire //default state state = State.up; charModel = model; + projectileModel = projectile; movementCoolDown = movementSpeed; + projectileSpeed = 30; } public void LoadContent(ContentManager contentManager) @@ -132,24 +137,28 @@ namespace CarFire // move up else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) { + state = State.up; gridY -= 1; movementCoolDown = movementSpeed; } // move down else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) { + state = State.down; gridY += 1; movementCoolDown = movementSpeed; } // move left else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) { + state = State.left; gridX -= 1; movementCoolDown = movementSpeed; } // move right else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) { + state = State.right; gridX += 1; movementCoolDown = movementSpeed; } @@ -159,7 +168,19 @@ namespace CarFire //TODO spawn projectile... needs to be added to display though if (state == State.up) { - + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY)); + } + if (state == State.down) + { + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1)); + } + if (state == State.right) + { + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX +1, GridY)); + } + if (state == State.left) + { + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX, GridY)); } } } diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index cabb38d..23e103a 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -40,17 +40,18 @@ namespace CarFire Texture2D _projectileModel, Vector2 _velocity, int _gridX, - int _gridY, + int _gridY) + /*, int _pixelX, - int _pixelY) + int _pixelY)*/ { theMap = _currentMap; projectileModel = _projectileModel; velocity = _velocity; gridX = _gridX; gridY = _gridY; - pixelX = _pixelX; - pixelY = _pixelY; + pixelX = _gridX * (int)Map.PixelsToUnitSquares; + pixelY = _gridY * (int)Map.PixelsToUnitSquares; damage = 20; } public void Update(TimeSpan timespan) -- 2.44.0