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 Ranged : Player { #region Member Variables //The number of frames between each projectile is spawned. const int shootCoolDown = 18; const int baseHealth = 100; const int baseDamage = 20; Texture2D charModel; Texture2D projectileModel; //Used to draw projectiles const int baseProjectileSpeed = 18; int projectileSpeed; int projectileCoolDown; #endregion #region Public Methods public Ranged(Game theGame, String Name, Point position, int playerIndex) : base(theGame, Name, position, playerIndex, baseHealth, baseDamage) { projectileSpeed = baseProjectileSpeed; } #endregion #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 } /// /// This method will draw a character to the screen. /// /// public override void Draw(SpriteBatch spriteBatch) { Rectangle position = Game.State.Map.GetRectangleFromCoordinates(Motion.Position); spriteBatch.Draw(charModel, position, Color.White); } public override void Attack(List keysPressed) { if (projectileCoolDown > 0) projectileCoolDown--; else if (projectileCoolDown == 0) { if (keysPressed.Contains(Keys.Space)) { float velocityX = 0; float velocityY = 0; int startX = Coordinates.X; int startY = Coordinates.Y; if (Motion.Direction == Direction.Down || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.LowerRight) { velocityY = 1; startY = Coordinates.Y + 1; } else if (Motion.Direction == Direction.Up || Motion.Direction == Direction.UpperLeft || Motion.Direction == Direction.UpperRight) { velocityY = -1; startY = Coordinates.Y - 1; } if (Motion.Direction == Direction.Right || Motion.Direction == Direction.LowerRight || Motion.Direction == Direction.UpperRight) { velocityX = 1; startX = Coordinates.X + 1; } else if (Motion.Direction == Direction.Left || Motion.Direction == Direction.LowerLeft || Motion.Direction == Direction.UpperLeft) { velocityX = -1; startX = Coordinates.X - 1; } Vector2 toShoot = new Vector2(velocityX, velocityY); toShoot.Normalize(); toShoot *= projectileSpeed; projectileCoolDown = shootCoolDown; Game.State.mProjectiles.Add(new Projectile(Game, projectileModel, toShoot, new Point(startX, startY), PlayerIndex, Damage)); } } } public override void PlayAttackSound() { } public override void PlayDieSound() { } #endregion } }