From: Kyle Date: Mon, 19 Apr 2010 03:49:40 +0000 (+0000) Subject: Improved projectiles X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=6f4eff30ee197a57bbedb2067f94b12ab0d69d48;p=chaz%2Fcarfire Improved projectiles git-svn-id: https://bd85.net/svn/cs3505_group@102 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index 774833b..d40c7e8 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -21,6 +21,7 @@ namespace CarFire //List mCharacters = new List(); IPlayer[] mCharacters = new IPlayer[4]; Texture2D everything; + Texture2D projectile1; Map mMap; int currentCenterX = 5; int currentCenterY = 5; @@ -42,6 +43,7 @@ namespace CarFire public void LoadContent(ContentManager contentManager) { everything = contentManager.Load("cs"); + projectile1 = contentManager.Load("projectile"); mMap = contentManager.Load("Maps/stable"); Map.DefaultTile = contentManager.Load("default"); mMap.CenterCell = new Vector2(currentCenterX,currentCenterY); @@ -105,23 +107,7 @@ 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, everything, this)); - 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); @@ -148,6 +134,25 @@ namespace CarFire } } } + for (int i = 0; i < 4; i++) + { + //If player has not selected a player yet let them select one. + if (mCharacters[i] == null) + { + if (state.keysDown[i].Contains(Keys.Enter)) + { + mCharacters[i] = (new Human(mMap, "", everything, projectile1, this)); + mCharacters[i].GridX = mMap.GetStartingPositionForPlayer(i + 1).X; + mCharacters[i].GridY = mMap.GetStartingPositionForPlayer(i + 1).Y; + } + } + else + { + + mCharacters[i].MovePlayer(state.keysDown[i]); + mMap.CenterCell = new Vector2(mCharacters[0].GridX, mCharacters[0].GridY); + } + } } /// diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 30546f3..9350d86 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -18,6 +18,8 @@ namespace CarFire up, down }; + const int moveCoolDown = 12; + const int shootCoolDown = 10; //Member Variables State state; String CharName; @@ -38,6 +40,7 @@ namespace CarFire int movementCoolDown; Display theDisplay; int projectileSpeed; + int projectileCoolDown; public Human(Map _theMap, String Name, Texture2D model, Texture2D projectile, Display mDisplay) { @@ -53,8 +56,8 @@ namespace CarFire state = State.up; charModel = model; projectileModel = projectile; - movementCoolDown = movementSpeed; projectileSpeed = 30; + } public void LoadContent(ContentManager contentManager) @@ -111,76 +114,85 @@ namespace CarFire { gridX -= 1; gridY -= 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move upright else if (keysPressed.Contains(Keys.Up) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY - 1)) { gridX += 1; gridY -= 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move downleft else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY + 1)) { gridX -= 1; gridY += 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move downright else if (keysPressed.Contains(Keys.Down) && keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY + 1)) { gridX += 1; gridY += 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move up else if (keysPressed.Contains(Keys.Up) && theMap.IsCellOpen(gridX, gridY - 1)) { state = State.up; gridY -= 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move down else if (keysPressed.Contains(Keys.Down) && theMap.IsCellOpen(gridX, gridY + 1)) { state = State.down; gridY += 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move left else if (keysPressed.Contains(Keys.Left) && theMap.IsCellOpen(gridX - 1, gridY)) { state = State.left; gridX -= 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } // move right else if (keysPressed.Contains(Keys.Right) && theMap.IsCellOpen(gridX + 1, gridY)) { state = State.right; gridX += 1; - movementCoolDown = movementSpeed; + movementCoolDown = moveCoolDown; } } - if (keysPressed.Contains(Keys.Space)) + if (projectileCoolDown > 0) + projectileCoolDown--; + else if (projectileCoolDown == 0) { - //TODO spawn projectile... needs to be added to display though - if (state == State.up) + if (keysPressed.Contains(Keys.Space)) { - 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)); + //TODO spawn projectile... needs to be added to display though + if (state == State.up) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, -projectileSpeed), GridX, GridY - 1)); + } + if (state == State.down) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(0, projectileSpeed), GridX, GridY + 1)); + } + if (state == State.right) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(projectileSpeed, 0), GridX + 1, GridY)); + } + if (state == State.left) + { + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, new Vector2(-projectileSpeed, 0), GridX - 1, GridY)); + } } } } diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs index 23e103a..308e313 100644 --- a/CarFire/CarFire/CarFire/Projectile.cs +++ b/CarFire/CarFire/CarFire/Projectile.cs @@ -104,9 +104,10 @@ namespace CarFire //Console.WriteLine(gridX + " " + gridY); //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY))); Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)); - spriteBatch.Draw(projectileModel, position, Color.White); - //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60); - //spriteBatch.Draw(projectileModel, position2, Color.White); + //spriteBatch.Draw(projectileModel, position, Color.White); + Rectangle position2 = new Rectangle((int)(pixelX), (int)(pixelY), (int)Map.PixelsToUnitSquares, (int)Map.PixelsToUnitSquares); + Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares)); + spriteBatch.Draw(projectileModel, position3, Color.White); } ///