From: Kyle Date: Fri, 23 Apr 2010 02:27:53 +0000 (+0000) Subject: Melee and Ranged now inheret from Player X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=0470a7b148c79aaacf0d8107b5bd40fa1e81ac0a;p=chaz%2Fcarfire Melee and Ranged now inheret from Player git-svn-id: https://bd85.net/svn/cs3505_group@134 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index d7f666f..b067b27 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -86,6 +86,7 @@ + diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index c6a1e44..01fbbba 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -20,7 +20,6 @@ namespace CarFire /// public class Display { - bool playerChosen = false; List mProjectiles = new List(); //List mCharacters = new List(); //IPlayer[] mCharacters = new IPlayer[4]; diff --git a/CarFire/CarFire/CarFire/Game.cs b/CarFire/CarFire/CarFire/Game.cs index 3fd5ef0..dce6ba4 100644 --- a/CarFire/CarFire/CarFire/Game.cs +++ b/CarFire/CarFire/CarFire/Game.cs @@ -24,7 +24,7 @@ namespace CarFire public Map Map; public List Entities = new List(); - public IPlayer[] mCharacters = new IPlayer[4]; + public Player[] mCharacters = new Player[4]; public Display mDisplay; #endregion diff --git a/CarFire/CarFire/CarFire/IPlayer.cs b/CarFire/CarFire/CarFire/IPlayer.cs index a22a9de..3e20f83 100644 --- a/CarFire/CarFire/CarFire/IPlayer.cs +++ b/CarFire/CarFire/CarFire/IPlayer.cs @@ -24,6 +24,11 @@ namespace CarFire bool alive { get; } void Attack(); void UpdatePosition(TimeSpan timeSpan, List keysPressed); + /* + void AddHealth(int healthBoost); + void IncreaseDamage(int damageBoost); + void PlayAttackSound(); + void PlayDieSound();*/ } public interface IMonster : ICharacter diff --git a/CarFire/CarFire/CarFire/Melee.cs b/CarFire/CarFire/CarFire/Melee.cs index 0d69287..299f2e7 100644 --- a/CarFire/CarFire/CarFire/Melee.cs +++ b/CarFire/CarFire/CarFire/Melee.cs @@ -9,137 +9,55 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { - public class Melee : IPlayer + public class Melee : Player { - //The number of frames between each projectile is spawned. - const int shootCoolDown = 18; - String CharName; - Game game; + #region Member Variables + const int hitCoolDown = 18; + const int baseHealth = 200; + const int baseDamage = 30; Texture2D charModel; Texture2D projectileModel; - int health; - int damage; - int range; - int score; - - MovementManager mMotion; - bool visible; - - //Used to draw projectiles - int projectileSpeed; - int projectileCoolDown; - int mPlayerIndex; - + #endregion + #region Public Methods public Melee(Game theGame, String Name, Point position, int playerIndex) + : base(theGame, Name, position, playerIndex, baseHealth, baseDamage) { - game = theGame; - CharName = Name; - health = 100; - score = 0; - visible = false; projectileSpeed = 8; - mPlayerIndex = playerIndex; - - // Speed is the number of grid cells you can move through per second. - mMotion = new MovementManager(position, 4.0f); } + #endregion - public void LoadContent(ContentManager contentManager) + #region Overridden Methods From Player + public override void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("cs"); //change to charModel when designed projectileModel = contentManager.Load("projectile"); //change to a projectile model later } - - - public void Update(TimeSpan timeSpan) - { - } /// /// This method will draw a character to the screen. /// /// - public void Draw(SpriteBatch spriteBatch) + public override void Draw(SpriteBatch spriteBatch) { - Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position); + Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position); spriteBatch.Draw(charModel, position, Color.White); } - public int Health { get { return health; } } - public int Score { get { return score; } } - public bool alive { get { return health > 0; } } - - public Vector2 Position { get { return mMotion.Position; } } - public Point Coordinates { get { return mMotion.Coordinates; } } - - 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 UpdateInput(TimeSpan timeSpan, List keysPressed) + public override void Attack(List keysPressed) { - - UpdatePosition(timeSpan, keysPressed); - - if (projectileCoolDown > 0) - projectileCoolDown--; - else if (projectileCoolDown == 0) + if (hitCoolDown > 0) + hitCoolDown--; + else if (hitCoolDown == 0) { if (keysPressed.Contains(Keys.Space)) { - Attack(); + } } - } - public void UpdatePosition(TimeSpan timeSpan, List keysPressed) - { - bool moveLeft = keysPressed.Contains(Keys.Left); - bool moveRight = keysPressed.Contains(Keys.Right); - bool moveUp = keysPressed.Contains(Keys.Up); - bool moveDown = keysPressed.Contains(Keys.Down); - Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); - if (!keysPressed.Contains(Keys.LeftControl)) - { - if (game.IsCellOpen(destination)) - { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - else - { - mMotion.Update(timeSpan); - } - } - else - { - mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - } - public void Attack() - { - //melee attack - } - public void powerUp(int amount) - { - health += amount; - } - public void Spawn(Vector2 spawn) - { - //gridX = (int)spawn.X; - //gridY = (int)spawn.Y; - visible = true; } - - + #endregion } } \ No newline at end of file diff --git a/CarFire/CarFire/CarFire/Player.cs b/CarFire/CarFire/CarFire/Player.cs new file mode 100644 index 0000000..f1d121c --- /dev/null +++ b/CarFire/CarFire/CarFire/Player.cs @@ -0,0 +1,126 @@ +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 Player : ICharacter + { + #region Member variables + //The number of frames between each projectile is spawned. + const int shootCoolDown = 18; + String CharName; + Game game; + int playerHealth; + int playerDamage; + int score; + MovementManager mMotion; + int mPlayerIndex; + #endregion + + + public Player(Game theGame, String Name, Point position, int playerIndex, int health, int damage) + { + game = theGame; + CharName = Name; + score = 0; + playerHealth = health; + playerDamage = damage; + mPlayerIndex = playerIndex; + + // Speed is the number of grid cells you can move through per second. + mMotion = new MovementManager(position, 4.0f); + } + + public virtual void LoadContent(ContentManager contentManager) + { + + } + /// + /// This method will draw a character to the screen. + /// + /// + public virtual void Draw(SpriteBatch spriteBatch) + { + } + + public int Health { get { return playerHealth; } } + public int Score { get { return score; } } + public bool alive { get { return playerHealth > 0; } } + public Game Game { get { return game; } } + public MovementManager Motion { get { return mMotion; } } + public int PlayerIndex { get { return mPlayerIndex; } } + public Vector2 Position { get { return mMotion.Position; } } + public Point Coordinates { get { return mMotion.Coordinates; } } + public int Damage { get { return playerDamage; } } + + public void causeDamageTo(int amount) + { + playerHealth -= amount; + } + + public void Update(TimeSpan timeSpan) + { + + } + /// + /// 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 UpdateInput(TimeSpan timeSpan, List keysPressed) + { + + UpdatePosition(timeSpan, keysPressed); + Attack(keysPressed); + + } + public void UpdatePosition(TimeSpan timeSpan, List keysPressed) + { + bool moveLeft = keysPressed.Contains(Keys.Left); + bool moveRight = keysPressed.Contains(Keys.Right); + bool moveUp = keysPressed.Contains(Keys.Up); + bool moveDown = keysPressed.Contains(Keys.Down); + Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); + if (!keysPressed.Contains(Keys.LeftControl)) + { + if (game.IsCellOpen(destination)) + { + mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); + } + else + { + mMotion.Update(timeSpan); + } + } + else + { + mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); + } + } + public virtual void Attack(List keysPressed) + { + + } + public void powerUp(int amount) + { + playerHealth += amount; + } + + public void Spawn(Vector2 spawn) + { + + } + + + } + +} diff --git a/CarFire/CarFire/CarFire/Ranged.cs b/CarFire/CarFire/CarFire/Ranged.cs index b859cd6..874aa2f 100644 --- a/CarFire/CarFire/CarFire/Ranged.cs +++ b/CarFire/CarFire/CarFire/Ranged.cs @@ -9,142 +9,70 @@ using Microsoft.Xna.Framework.Input; namespace CarFire { - public class Ranged : IPlayer + public class Ranged : Player { //The number of frames between each projectile is spawned. const int shootCoolDown = 18; - String CharName; - Game game; + const int baseHealth = 100; + const int baseDamage = 20; Texture2D charModel; Texture2D projectileModel; - int health; - int damage; - int range; - int score; - - MovementManager mMotion; - bool visible; //Used to draw projectiles int projectileSpeed; int projectileCoolDown; - int mPlayerIndex; - + public Ranged(Game theGame, String Name, Point position, int playerIndex) + : base(theGame, Name, position, playerIndex, baseHealth, baseDamage) { - game = theGame; - CharName = Name; - health = 100; - score = 0; - visible = false; projectileSpeed = 8; - mPlayerIndex = playerIndex; - - // Speed is the number of grid cells you can move through per second. - mMotion = new MovementManager(position, 4.0f); } - public void LoadContent(ContentManager contentManager) + public override void LoadContent(ContentManager contentManager) { charModel = contentManager.Load("cs"); //change to charModel when designed projectileModel = contentManager.Load("projectile"); //change to a projectile model later } - - - public void Update(TimeSpan timeSpan) - { - } /// /// This method will draw a character to the screen. /// /// - public void Draw(SpriteBatch spriteBatch) + public override void Draw(SpriteBatch spriteBatch) { - Rectangle position = game.State.Map.GetRectangleFromCoordinates(mMotion.Position); + Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position); spriteBatch.Draw(charModel, position, Color.White); } - public int Health { get { return health; } } - public int Score { get { return score; } } - public bool alive { get { return health > 0; } } - - public Vector2 Position { get { return mMotion.Position; } } - public Point Coordinates { get { return mMotion.Coordinates; } } - - 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 UpdateInput(TimeSpan timeSpan, List keysPressed) + public override void Attack(List keysPressed) { - - UpdatePosition(timeSpan, keysPressed); - if (projectileCoolDown > 0) projectileCoolDown--; else if (projectileCoolDown == 0) { if (keysPressed.Contains(Keys.Space)) { - Attack(); - } - } - } - public void UpdatePosition(TimeSpan timeSpan, List keysPressed) - { - bool moveLeft = keysPressed.Contains(Keys.Left); - bool moveRight = keysPressed.Contains(Keys.Right); - bool moveUp = keysPressed.Contains(Keys.Up); - bool moveDown = keysPressed.Contains(Keys.Down); - Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); - if (!keysPressed.Contains(Keys.LeftControl)) - { - if (game.IsCellOpen(destination)) - { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - else - { - mMotion.Update(timeSpan); - } - } - else - { - mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); - } - } - public void Attack() - { - float velocityX = 0; + float velocityX = 0; float velocityY = 0; int startX = Coordinates.X; int startY = Coordinates.Y; - if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight) + if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight) { velocityY = 1; startY = Coordinates.Y + 1; } - else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight) + else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight) { velocityY = -1; startY = Coordinates.Y - 1; } - if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight) + if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight) { velocityX = 1; startX = Coordinates.X + 1; } - else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft) + else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft) { velocityX = -1; startX = Coordinates.X - 1; @@ -153,21 +81,14 @@ namespace CarFire toShoot.Normalize(); toShoot *= projectileSpeed; projectileCoolDown = shootCoolDown; - game.State.mDisplay.AddProjectiles(new Projectile(game, projectileModel, - toShoot, new Point(startX, startY), mPlayerIndex, damage)); + Game.State.mDisplay.AddProjectiles(new Projectile(Game, projectileModel, + toShoot, new Point(startX, startY), PlayerIndex, Damage)); + } + } + } - public void powerUp(int amount) - { - health += amount; - } - - public void Spawn(Vector2 spawn) - { - //gridX = (int)spawn.X; - //gridY = (int)spawn.Y; - visible = true; - } + }