2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
13 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
15 public class Projectile
19 Texture2D projectileModel;
23 //The pixel position should be the pixel position on the map. When a projectile is drawn
24 //these will have to be transformed to the coordinate system that the drawable screen is using.
27 MovementManager mMotion;
33 /// The Constructor for a projectile object.
35 /// <param name="_currentMap">The map that this character will interact with</param>
36 /// <param name="_projectileModel">The model for this projectile</param>
37 /// <param name="_velocity">How fast the projectile moves</param>
38 /// <param name="_gridX">The starting X position in the map grid</param>
39 /// <param name="_gridY">The starting Y position in the map grid</param>
40 /// <param name="_pixelX">The absolute X pixel position on the map</param>
41 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
42 public Projectile(Game theGame,
43 Texture2D _projectileModel,
50 mCharacterIndex = characterNumber;
51 projectileModel = _projectileModel;
53 mPosition = _position;
55 // Speed is the number of grid cells you can move through per second.
56 mMotion = new MovementManager(mPosition, velocity.Length());
58 public void Update(TimeSpan timeSpan)
60 bool moveRight = false;
61 bool moveLeft = false;
63 bool moveDown = false;
66 else if (velocity.X < 0)
70 else if (velocity.Y < 0)
72 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
73 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
78 /// This method will draw a projectile to the screen
80 /// <param name="spriteBatch"></param>
81 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
82 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
83 public void Draw(SpriteBatch spriteBatch)
85 Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position);
86 spriteBatch.Draw(projectileModel, position, Color.White);
91 /// Basic getters and setters
93 public int GridX { get { return gridX; } set { gridX = value; } }
94 public int GridY { get { return gridY; } set { gridY = value; } }
95 public int PixelX { get { return pixelX; } set { pixelX = value; } }
96 public int PixelY { get { return pixelY; } set { pixelY = value; } }
97 public int Damage { get { return damage; } set { damage = value; } }
98 public Vector2 Position { get { return mMotion.Position; } }
99 public Point Coordinates { get { return mMotion.Coordinates; } }