From: Kyle Date: Mon, 19 Apr 2010 02:59:32 +0000 (+0000) Subject: Players now spawn projectiles... still kind of buggy. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=5776c1910247848ab45b111b6a9df4265483a894;p=chaz%2Fcarfire Players now spawn projectiles... still kind of buggy. git-svn-id: https://bd85.net/svn/cs3505_group@101 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- 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)