X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FProjectile.cs;h=3f5b1368466a9496318ae47a3b63a86d315ff388;hb=16658241429e8befc3cb171a62163f36dedb6a33;hp=1dd5e08eaf1e1ac40a9f5e73e056fe81960eada6;hpb=89e5ee7d83cfb353b6c98dcbf6ed6b87833b9866;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs
index 1dd5e08..3f5b136 100644
--- a/CarFire/CarFire/CarFire/Projectile.cs
+++ b/CarFire/CarFire/CarFire/Projectile.cs
@@ -25,7 +25,9 @@ namespace CarFire
//these will have to be transformed to the coordinate system that the drawable screen is using.
int pixelX;
int pixelY;
-
+ MovementManager mMotion;
+ Point mPosition;
+
///
/// The Constructor for a projectile object.
///
@@ -39,56 +41,34 @@ namespace CarFire
public Projectile(Map _currentMap,
Texture2D _projectileModel,
Vector2 _velocity,
- int _gridX,
- int _gridY,
- int _pixelX,
- int _pixelY)
+ Point _position)
+
{
theMap = _currentMap;
projectileModel = _projectileModel;
velocity = _velocity;
- gridX = _gridX;
- gridY = _gridY;
- pixelX = _pixelX;
- pixelY = _pixelY;
+ mPosition = _position;
+ damage = 20;
+ // Speed is the number of grid cells you can move through per second.
+ mMotion = new MovementManager(mPosition, velocity.Length());
}
- public void Update(TimeSpan timespan)
+ public void Update(TimeSpan timeSpan)
{
- /*
- //See if something moved onto this projectile.
- if(theMap.isOpenSquare(gridX, gridY))
- {
- theMap.damageSquare(gridX, gridY, damage);
- }
- */
- //If the projectile will be moving to a new grid position we need to check to see if it is occupied.
- if ((int)((pixelX + velocity.X) / Map.PixelsToUnitSquares) != gridX || (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares) != gridY)
- {
- bool open = theMap.IsCellOpen((int)((pixelX + velocity.X) /Map.PixelsToUnitSquares), (int)((pixelY + velocity.Y) / Map.PixelsToUnitSquares));
- //If open just move this projectile there
- //***Map doesn't need to know that this projectile is there because players/monsters are allowed
- // to move into the path of projectiles.
- if (open)
- {
- Console.WriteLine("pixelX:" + pixelX + " " + " pixelY: "+ pixelY);
- pixelX += (int)velocity.X;
- pixelY += (int)velocity.Y;
- gridX = (int)(pixelX /Map.PixelsToUnitSquares);
- gridY = (int)(pixelY / Map.PixelsToUnitSquares);
- }
- //If the square isn't open then just damage whatever is there
- //TODO: A projectile must be deleted after this happens
- //else
- {
- //theMap.damageSquare(gridX, gridY, damage);
- }
- }
- //If it is not moving grid positions just increment pixelX and pixelY
- else
- {
- pixelX += (int)velocity.X;
- pixelY += (int)velocity.Y;
- }
+ bool moveRight = false;
+ bool moveLeft = false;
+ bool moveUp = false;
+ bool moveDown = false;
+ if (velocity.X > 0)
+ moveRight = true;
+ else if (velocity.X < 0)
+ moveLeft = true;
+ if (velocity.Y > 0)
+ moveDown = true;
+ else if (velocity.Y < 0)
+ moveUp = true;
+ Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
+
}
///
@@ -99,12 +79,9 @@ namespace CarFire
/// The map Y pixel position of the topLeft of the display
public void Draw(SpriteBatch spriteBatch)
{
- //Console.WriteLine(gridX + " " + gridY);
- //Console.WriteLine(theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY)));
- Rectangle position = theMap.GetRectangleFromCoordinates(new Vector2(gridX, gridY));
+ Rectangle position = theMap.GetRectangleFromCoordinates(mMotion.Position);
spriteBatch.Draw(projectileModel, position, Color.White);
- //Rectangle position2 = new Rectangle(pixelX-30, pixelY-30, 60, 60);
- //spriteBatch.Draw(projectileModel, position2, Color.White);
+
}
///
@@ -116,5 +93,7 @@ namespace CarFire
public int PixelY { get { return pixelY; } set { pixelY = value; } }
public Map TheMap { get { return theMap; } set { theMap = value; } }
public int Damage { get { return damage; } set { damage = value; } }
+ public Vector2 Position { get { return mMotion.Position; } }
+ public Point Coordinates { get { return mMotion.Coordinates; } }
}
}