for (int i = 0; i < mProjectiles.Count; i++ )\r
{\r
bool removed = false;\r
- if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))\r
+ if (!mMap.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
{\r
\r
mProjectiles.RemoveAt(i);\r
if(mCharacters[j] != null)\r
for (int i = 0; i < mProjectiles.Count; i++)\r
{\r
- if (mProjectiles[i].GridX == mCharacters[j].Coordinates.X && mProjectiles[i].GridY == mCharacters[j].Coordinates.Y)\r
+ if (mProjectiles[i].Coordinates.X == mCharacters[j].Coordinates.X && mProjectiles[i].Coordinates.Y == mCharacters[j].Coordinates.Y)\r
{\r
mCharacters[j].causeDamageTo(mProjectiles[i].Damage);\r
Console.WriteLine(mCharacters[j].Health);\r
//Handle wall collisions of projectiles again...\r
for (int i = 0; i < mProjectiles.Count; i++)\r
{\r
- if (!mMap.IsCellOpen(new Point(mProjectiles[i].GridX, mProjectiles[i].GridY)))\r
+ if (!mMap.IsCellOpen(new Point(mProjectiles[i].Coordinates.X, mProjectiles[i].Coordinates.Y)))\r
{\r
mProjectiles.RemoveAt(i);\r
i--;\r
{\r
if (keysPressed.Contains<Keys>(Keys.Space))\r
{\r
- //TODO spawn projectile... needs to be added to display though\r
+ float velocityX = 0;\r
+ float velocityY = 0;\r
+ int startX = Coordinates.X;\r
+ int startY = Coordinates.Y;\r
+ if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight)\r
+ {\r
+ velocityY = 1;\r
+ startY = Coordinates.Y + 1;\r
+ }\r
+ else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight)\r
+ {\r
+ velocityY = -1;\r
+ startY = Coordinates.Y - 1;\r
+ }\r
+ if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight)\r
+ {\r
+ velocityX = 1;\r
+ startX = Coordinates.X + 1;\r
+ }\r
+ else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft)\r
+ {\r
+ velocityX = -1;\r
+ startX = Coordinates.X - 1;\r
+ }\r
+ Vector2 toShoot = new Vector2(velocityX, velocityY);\r
+ toShoot.Normalize();\r
+ toShoot *= projectileSpeed;\r
+ projectileCoolDown = shootCoolDown;\r
+ theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
+ toShoot, new Point(startX, startY)));\r
+\r
+ /*\r
if (state == State.up)\r
{\r
projectileCoolDown = shootCoolDown;\r
theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
- new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1));\r
+ new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1)));\r
}\r
if (state == State.down)\r
{\r
projectileCoolDown = shootCoolDown;\r
theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
- new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1));\r
+ new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1)));\r
}\r
if (state == State.right)\r
{\r
projectileCoolDown = shootCoolDown;\r
theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
- new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y));\r
+ new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y)));\r
}\r
if (state == State.left)\r
{\r
projectileCoolDown = shootCoolDown;\r
theDisplay.AddProjectiles(new Projectile(theMap, projectileModel,\r
- new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y));\r
+ new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y)));\r
}\r
+ */\r
}\r
}\r
}\r
\r
void RecalculatePosition(float alpha)\r
{\r
- Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha);\r
+ //Console.WriteLine("last: " + mLastCoordinates + ", now: " + mCoordinates + ", alpha: " + alpha);\r
mPosition.X = (float)mLastCoordinates.X + alpha * ((float)mCoordinates.X - (float)mLastCoordinates.X);\r
mPosition.Y = (float)mLastCoordinates.Y + alpha * ((float)mCoordinates.Y - (float)mLastCoordinates.Y);\r
}\r
//these will have to be transformed to the coordinate system that the drawable screen is using.\r
int pixelX;\r
int pixelY;\r
- \r
+ MovementManager mMotion;\r
+ Point mPosition;\r
+\r
/// <summary>\r
/// The Constructor for a projectile object.\r
/// </summary>\r
public Projectile(Map _currentMap,\r
Texture2D _projectileModel,\r
Vector2 _velocity,\r
- int _gridX,\r
- int _gridY)\r
- /*,\r
- int _pixelX,\r
- int _pixelY)*/\r
+ Point _position)\r
+ \r
{\r
theMap = _currentMap;\r
projectileModel = _projectileModel;\r
velocity = _velocity;\r
- gridX = _gridX;\r
- gridY = _gridY;\r
- pixelX = _gridX * (int)Map.PixelsToUnitSquares;\r
- pixelY = _gridY * (int)Map.PixelsToUnitSquares;\r
+ mPosition = _position;\r
damage = 20;\r
+ // Speed is the number of grid cells you can move through per second.\r
+ mMotion = new MovementManager(mPosition, velocity.Length());\r
}\r
- public void Update(TimeSpan timespan)\r
+ public void Update(TimeSpan timeSpan)\r
{\r
- /*\r
- //See if something moved onto this projectile.\r
- if(theMap.isOpenSquare(gridX, gridY))\r
- {\r
- theMap.damageSquare(gridX, gridY, damage);\r
- }\r
- */\r
- //If the projectile will be moving to a new grid position we need to check to see if it is occupied.\r
- if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)\r
- {\r
- //bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));\r
- //If open just move this projectile there\r
- //***Map doesn't need to know that this projectile is there because players/monsters are allowed\r
- // to move into the path of projectiles.\r
- //if (open)\r
- {\r
- //Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);\r
- pixelX += (int)velocity.X;\r
- pixelY += (int)velocity.Y;\r
- gridX = (int)(pixelX /Map.PixelsToUnitSquares);\r
- gridY = (int)(pixelY / Map.PixelsToUnitSquares);\r
- }\r
- //If the square isn't open then just damage whatever is there\r
- //TODO: A projectile must be deleted after this happens\r
- //else\r
- {\r
- //theMap.damageSquare(gridX, gridY, damage);\r
- }\r
- }\r
- //If it is not moving grid positions just increment pixelX and pixelY\r
- else\r
- {\r
- pixelX += (int)velocity.X;\r
- pixelY += (int)velocity.Y;\r
- }\r
+ bool moveRight = false;\r
+ bool moveLeft = false;\r
+ bool moveUp = false;\r
+ bool moveDown = false;\r
+ if (velocity.X > 0)\r
+ moveRight = true;\r
+ else if (velocity.X < 0)\r
+ moveLeft = true;\r
+ if (velocity.Y > 0)\r
+ moveDown = true;\r
+ else if (velocity.Y < 0)\r
+ moveUp = true;\r
+ Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);\r
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);\r
+ \r
\r
}\r
/// <summary>\r
/// <param name="topLeftY">The map Y pixel position of the topLeft of the display</param>\r
public void Draw(SpriteBatch spriteBatch)\r
{\r
- //Console.WriteLine(gridX + " " + gridY);\r
- //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));\r
- Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));\r
- //spriteBatch.Draw(projectileModel, position, Color.White);\r
- Rectangle position2 = new Rectangle((int)(pixelX), (int)(pixelY), (int)Map.PixelsToUnitSquares, (int)Map.PixelsToUnitSquares);\r
- Rectangle position3 = theMap.GetRectangleFromCoordinates(new Vector2(pixelX / Map.PixelsToUnitSquares, pixelY / Map.PixelsToUnitSquares));\r
- spriteBatch.Draw(projectileModel, position3, Color.White);\r
+ Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);\r
+ spriteBatch.Draw(projectileModel, position, Color.White);\r
+ \r
}\r
\r
/// <summary>\r
public int PixelY { get { return pixelY; } set { pixelY = value; } }\r
public Map TheMap { get { return theMap; } set { theMap = value; } }\r
public int Damage { get { return damage; } set { damage = value; } }\r
+ public Vector2 Position { get { return mMotion.Position; } }\r
+ public Point Coordinates { get { return mMotion.Coordinates; } }\r
}\r
}\r