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.IsCellOpen(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.
64 if ((int)((pixelX + velocity.X) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
66 bool open = theMap.IsCellOpen((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
67 //If open just move this projectile there
68 //***Map doesn't need to know that this projectile is there because players/monsters are allowed
69 // to move into the path of projectiles.
72 pixelX += (int)velocity.X;
73 pixelY += (int)velocity.Y;
74 gridX = pixelX / theMap.gridToPixelRatio;
75 gridY = pixelY / theMap.gridToPixelRatio;
77 //If the square isn't open then just damage whatever is there
78 //TODO: A projectile must be deleted after this happens
81 //theMap.damageSquare(gridX, gridY, damage);
85 //If it is not moving grid positions just increment pixelX and pixelY
88 pixelX += (int)velocity.X;
89 pixelY += (int)velocity.Y;
94 /// This method will draw a projectile to the screen
96 /// <param name="spriteBatch"></param>
97 /// <param name="topLeftX">The map X pixel position of the topLeft of the display</param>
98 /// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>
99 public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
101 spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
105 /// Basic getters and setters
107 public int GridX { get { return gridX; } set { gridX = value; } }
108 public int GridY { get { return gridY; } set { gridY = value; } }
109 public int PixelX { get { return pixelX; } set { pixelX = value; } }
110 public int PixelY { get { return pixelY; } set { pixelY = value; } }
111 public Map TheMap { get { return theMap; } set { theMap = value; } }
112 public int Damage { get { return damage; } set { damage = value; } }