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,
48 projectileModel = _projectileModel;
57 //See if something moved onto this projectile.
58 if(theMap.isOpenSquare(gridX, gridY))
60 theMap.damageSquare(gridX, gridY, damage);
62 //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
63 if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
65 bool open = theMap.isOpenSquare((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
66 //If open just move this projectile there
67 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
68 // to move into the path of projectiles.
73 gridX = pixelX / theMap.gridToPixelRatio;
74 gridY = pixelY / theMap.gridToPixelRatio;
76 //If the square isn't open then just damage whatever is there
77 //TODO: A projectile must be deleted after this happens
80 theMap.damageSquare(gridX, gridY, damage);
83 //If it is not moving grid positions just increment pixelX and pixelY
92 /// This method will draw a projectile to the screen
94 /// <param name="spriteBatch"></param>
95 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
96 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
97 public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
99 spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
103 /// Basic getters and setters
105 public int GridX { get { return gridX; } set { gridX = value; } }
106 public int GridY { get { return gridY; } set { gridY = value; } }
107 public int PixelX { get { return pixelX; } set { pixelX = value; } }
108 public int PixelY { get { return pixelY; } set { pixelY = value; } }
109 public int Health { get { return health; } set { health = value; } }
110 public Map TheMap { get { return theMap; } set { theMap = value; } }