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 { /// /// This class represents a projectile object that will be spawned whenever a player or a monster fires. /// public class Projectile { //Member Variables Vector2 velocity; Texture2D projectileModel; int damage; int gridX; int gridY; //The pixel position should be the pixel position on the map. When a projectile is drawn //these will have to be transformed to the coordinate system that the drawable screen is using. int pixelX; int pixelY; MovementManager mMotion; Point mPosition; int mCharacterIndex; Game mGame; /// /// The Constructor for a projectile object. /// /// The map that this character will interact with /// The model for this projectile /// How fast the projectile moves /// The starting X position in the map grid /// The starting Y position in the map grid /// The absolute X pixel position on the map /// The absolute Y pixel position on the map public Projectile(Game theGame, Texture2D _projectileModel, Vector2 _velocity, Point _position, int characterNumber, int _damage) { mGame = theGame; mCharacterIndex = characterNumber; projectileModel = _projectileModel; velocity = _velocity; mPosition = _position; damage = _damage; // Speed is the number of grid cells you can move through per second. mMotion = new MovementManager(mPosition, velocity.Length()); } public void Update(TimeSpan timeSpan) { bool moveRight = false; bool moveLeft = false; bool moveUp = false; bool moveDown = false; if (velocity.X > 0) moveRight = true; else if (velocity.X < 0) moveLeft = true; if (velocity.Y > 0) moveDown = true; else if (velocity.Y < 0) moveUp = true; Point destination = MovementManager.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); } /// /// This method will draw a projectile to the screen /// /// /// The map X pixel position of the topLeft of the display /// The map Y pixel position of the topLeft of the display public void Draw(SpriteBatch spriteBatch) { Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position); spriteBatch.Draw(projectileModel, position, Color.White); } /// /// Basic getters and setters /// public int GridX { get { return gridX; } set { gridX = value; } } public int GridY { get { return gridY; } set { gridY = value; } } public int PixelX { get { return pixelX; } set { pixelX = value; } } public int PixelY { get { return pixelY; } set { pixelY = value; } } public int Damage { get { return damage; } set { damage = value; } } public int CharacterIndex { get { return mCharacterIndex; } } public Vector2 Position { get { return mMotion.Position; } } public Point Coordinates { get { return mMotion.Coordinates; } } } }