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.
30 /// The Constructor for a projectile object.
32 /// <param name="_currentMap">The map that this character will interact with</param>
33 /// <param name="_projectileModel">The model for this projectile</param>
34 /// <param name="_velocity">How fast the projectile moves</param>
35 /// <param name="_gridX">The starting X position in the map grid</param>
36 /// <param name="_gridY">The starting Y position in the map grid</param>
37 /// <param name="_pixelX">The absolute X pixel position on the map</param>
38 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
39 public Projectile(Map _currentMap,
40 Texture2D _projectileModel,
49 projectileModel = _projectileModel;
53 pixelX = _gridX * (int)Map.PixelsToUnitSquares;
54 pixelY = _gridY * (int)Map.PixelsToUnitSquares;
57 public void Update(TimeSpan timespan)
60 //See if something moved onto this projectile.
61 if(theMap.isOpenSquare(gridX, gridY))
63 theMap.damageSquare(gridX, gridY, damage);
66 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
67 if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)
69 //bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));
70 //If open just move this projectile there
71 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
72 // to move into the path of projectiles.
75 //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);
76 pixelX += (int)velocity.X;
77 pixelY += (int)velocity.Y;
78 gridX = (int)(pixelX /Map.PixelsToUnitSquares);
79 gridY = (int)(pixelY / Map.PixelsToUnitSquares);
81 //If the square isn't open then just damage whatever is there
82 //TODO: A projectile must be deleted after this happens
85 //theMap.damageSquare(gridX, gridY, damage);
88 //If it is not moving grid positions just increment pixelX and pixelY
91 pixelX += (int)velocity.X;
92 pixelY += (int)velocity.Y;
97 /// This method will draw a projectile to the screen
99 /// <param name="spriteBatch"></param>
100 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
101 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
102 public void Draw(SpriteBatch spriteBatch)
104 //Console.WriteLine(gridX + " " + gridY);
105 //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));
106 Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));
107 //spriteBatch.Draw(projectileModel, position, Color.White);
108 Rectangle position2 = new Rectangle((int)(pixelX), (int)(pixelY), (int)Map.PixelsToUnitSquares, (int)Map.PixelsToUnitSquares);
109 Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));
110 spriteBatch.Draw(projectileModel, position3, Color.White);
114 /// Basic getters and setters
116 public int GridX { get { return gridX; } set { gridX = value; } }
117 public int GridY { get { return gridY; } set { gridY = value; } }
118 public int PixelX { get { return pixelX; } set { pixelX = value; } }
119 public int PixelY { get { return pixelY; } set { pixelY = value; } }
120 public Map TheMap { get { return theMap; } set { theMap = value; } }
121 public int Damage { get { return damage; } set { damage = value; } }