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
20 Texture2D projectileModel;
24 //The pixel position should be the pixel position on the map. When a projectile is drawn
25 //these will have to be transformed to the coordinate system that the drawable screen is using.
28 MovementManager mMotion;
32 /// The Constructor for a projectile object.
34 /// <param name="_currentMap">The map that this character will interact with</param>
35 /// <param name="_projectileModel">The model for this projectile</param>
36 /// <param name="_velocity">How fast the projectile moves</param>
37 /// <param name="_gridX">The starting X position in the map grid</param>
38 /// <param name="_gridY">The starting Y position in the map grid</param>
39 /// <param name="_pixelX">The absolute X pixel position on the map</param>
40 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
41 public Projectile(Map _currentMap,
42 Texture2D _projectileModel,
48 projectileModel = _projectileModel;
50 mPosition = _position;
52 // Speed is the number of grid cells you can move through per second.
53 mMotion = new MovementManager(mPosition, velocity.Length());
55 public void Update(TimeSpan timeSpan)
57 bool moveRight = false;
58 bool moveLeft = false;
60 bool moveDown = false;
63 else if (velocity.X < 0)
67 else if (velocity.Y < 0)
69 Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
70 mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
75 /// This method will draw a projectile to the screen
77 /// <param name="spriteBatch"></param>
78 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
79 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
80 public void Draw(SpriteBatch spriteBatch)
82 Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
83 spriteBatch.Draw(projectileModel, position, Color.White);
88 /// Basic getters and setters
90 public int GridX { get { return gridX; } set { gridX = value; } }
91 public int GridY { get { return gridY; } set { gridY = value; } }
92 public int PixelX { get { return pixelX; } set { pixelX = value; } }
93 public int PixelY { get { return pixelY; } set { pixelY = value; } }
94 public Map TheMap { get { return theMap; } set { theMap = value; } }
95 public int Damage { get { return damage; } set { damage = value; } }
96 public Vector2 Position { get { return mMotion.Position; } }
97 public Point Coordinates { get { return mMotion.Coordinates; } }