3 using System.Collections.Generic;
6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Content;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework.Input;
14 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
16 public class Projectile
21 Texture2D projectileModel;
25 //The pixel position should be the pixel position on the map. When a projectile is drawn
26 //these will have to be transformed to the coordinate system that the drawable screen is using.
31 /// The Constructor for a projectile object.
33 /// <param name="_currentMap">The map that this character will interact with</param>
34 /// <param name="_projectileModel">The model for this projectile</param>
35 /// <param name="_velocity">How fast the projectile moves</param>
36 /// <param name="_gridX">The starting X position in the map grid</param>
37 /// <param name="_gridY">The starting Y position in the map grid</param>
38 /// <param name="_pixelX">The absolute X pixel position on the map</param>
39 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
40 public Projectile(Map _currentMap,
41 Texture2D _projectileModel,
49 projectileModel = _projectileModel;
56 public void Update(TimeSpan timespan)
59 //See if something moved onto this projectile.
60 if(theMap.isOpenSquare(gridX, gridY))
62 theMap.damageSquare(gridX, gridY, damage);
65 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
66 if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)
68 bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));
69 //If open just move this projectile there
70 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
71 // to move into the path of projectiles.
74 Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);
75 pixelX += (int)velocity.X;
76 pixelY += (int)velocity.Y;
77 gridX = (int)(pixelX /Map.PixelsToUnitSquares);
78 gridY = (int)(pixelY / Map.PixelsToUnitSquares);
80 //If the square isn't open then just damage whatever is there
81 //TODO: A projectile must be deleted after this happens
84 //theMap.damageSquare(gridX, gridY, damage);
87 //If it is not moving grid positions just increment pixelX and pixelY
90 pixelX += (int)velocity.X;
91 pixelY += (int)velocity.Y;
96 /// This method will draw a projectile to the screen
98 /// <param name="spriteBatch"></param>
99 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
100 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
101 public void Draw(SpriteBatch spriteBatch)
103 Console.WriteLine(gridX + " " + gridY);
104 Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));
105 Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));
106 spriteBatch.Draw(projectileModel, position, Color.White);
107 //spriteBatch.Draw(projectileModel, new Vector2(40, 40), Color.White);
111 /// Basic getters and setters
113 public int GridX { get { return gridX; } set { gridX = value; } }
114 public int GridY { get { return gridY; } set { gridY = value; } }
115 public int PixelX { get { return pixelX; } set { pixelX = value; } }
116 public int PixelY { get { return pixelY; } set { pixelY = value; } }
117 public Map TheMap { get { return theMap; } set { theMap = value; } }
118 public int Damage { get { return damage; } set { damage = value; } }
123 using System.Collections.Generic;
126 using Microsoft.Xna.Framework;
127 using Microsoft.Xna.Framework.Content;
128 using Microsoft.Xna.Framework.Graphics;
129 using Microsoft.Xna.Framework.Input;
134 /// This class represents a projectile object that will be spawned whenever a player or a monster fires.
136 public class Projectile
141 Texture2D projectileModel;
145 //The pixel position should be the pixel position on the map. When a projectile is drawn
146 //these will have to be transformed to the coordinate system that the drawable screen is using.
151 /// The Constructor for a projectile object.
153 /// <param name="_currentMap">The map that this character will interact with</param>
154 /// <param name="_projectileModel">The model for this projectile</param>
155 /// <param name="_velocity">How fast the projectile moves</param>
156 /// <param name="_gridX">The starting X position in the map grid</param>
157 /// <param name="_gridY">The starting Y position in the map grid</param>
158 /// <param name="_pixelX">The absolute X pixel position on the map</param>
159 /// <param name="_pixelY"> The absolute Y pixel position on the map</param>
160 public Projectile(Map _currentMap,
161 Texture2D _projectileModel,
168 theMap = _currentMap;
169 projectileModel = _projectileModel;
170 velocity = _velocity;
178 //See if something moved onto this projectile.
179 if(theMap.IsCellOpen(gridX, gridY))
181 //theMap.damageSquare(gridX, gridY, damage);
183 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
185 if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
187 bool open = theMap.IsCellOpen((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
188 //If open just move this projectile there
189 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
190 // to move into the path of projectiles.
193 pixelX += (int)velocity.X;
194 pixelY += (int)velocity.Y;
195 gridX = pixelX / theMap.gridToPixelRatio;
196 gridY = pixelY / theMap.gridToPixelRatio;
198 //If the square isn't open then just damage whatever is there
199 //TODO: A projectile must be deleted after this happens
202 //theMap.damageSquare(gridX, gridY, damage);
206 //If it is not moving grid positions just increment pixelX and pixelY
209 pixelX += (int)velocity.X;
210 pixelY += (int)velocity.Y;
215 /// This method will draw a projectile to the screen
217 /// <param name="spriteBatch"></param>
218 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
219 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
220 public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
222 spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
226 /// Basic getters and setters
228 public int GridX { get { return gridX; } set { gridX = value; } }
229 public int GridY { get { return gridY; } set { gridY = value; } }
230 public int PixelX { get { return pixelX; } set { pixelX = value; } }
231 public int PixelY { get { return pixelY; } set { pixelY = value; } }
232 public Map TheMap { get { return theMap; } set { theMap = value; } }
233 public int Damage { get { return damage; } set { damage = value; } }