X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FProjectile.cs;h=a1d7f2779ccb7d8de22f23885d44817f4b2fdab8;hb=6c92b5649c27a690a8c32dca3a7388a4674ac4e8;hp=e9fd47b2cc95b06eb8b5cbc379a1728e48b1cda3;hpb=65c7b1983e25cd16f2e00b83f23542854e8345af;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Projectile.cs b/CarFire/CarFire/CarFire/Projectile.cs
index e9fd47b..a1d7f27 100644
--- a/CarFire/CarFire/CarFire/Projectile.cs
+++ b/CarFire/CarFire/CarFire/Projectile.cs
@@ -15,7 +15,6 @@ namespace CarFire
public class Projectile
{
//Member Variables
- Map theMap;
Vector2 velocity;
Texture2D projectileModel;
int damage;
@@ -25,7 +24,11 @@ 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;
+ int mCharacterIndex;
+ Game mGame;
+
///
/// The Constructor for a projectile object.
///
@@ -36,58 +39,40 @@ namespace CarFire
/// The starting Y position in the map grid
/// The absolute X pixel position on the map
/// The absolute Y pixel position on the map
- public Projectile(Map _currentMap,
+ public Projectile(Game theGame,
Texture2D _projectileModel,
Vector2 _velocity,
- int _gridX,
- int _gridY,
- int _pixelX,
- int _pixelY)
+ Point _position,
+ int characterNumber,
+ int _damage)
+
{
- theMap = _currentMap;
+ mGame = theGame;
+ mCharacterIndex = characterNumber;
projectileModel = _projectileModel;
velocity = _velocity;
- gridX = _gridX;
- gridY = _gridY;
- pixelX = _pixelX;
- pixelY = _pixelY;
+ mPosition = _position;
+ damage = _damage;
+ // Speed is the number of grid cells you can move through per second.
+ mMotion = new MovementManager(mPosition, velocity.Length());
}
- public void Update()
+ public void Update(TimeSpan timeSpan)
{
- //See if something moved onto this projectile.
- if(theMap.IsCellOpen(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) / theMap.gridToPixelRatio) != gridX || (int)((pixelY + velocity.Y) / Map.gridToPixelRatio) != gridY)
- {
- bool open = theMap.IsCellOpen((pixelX + velocity.X) / theMap.gridToPixelRatio, (pixelY + velocity.Y) / Map.gridToPixelRatio);
- //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)
- {
- pixelX += (int)velocity.X;
- pixelY += (int)velocity.Y;
- gridX = pixelX / theMap.gridToPixelRatio;
- gridY = pixelY / theMap.gridToPixelRatio;
- }
- //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.GetNeighbor(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown);
+ mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown);
+
}
///
@@ -96,9 +81,11 @@ namespace CarFire
///
/// The map X pixel position of the topLeft of the display
/// The map Y pixel position of the topLeft of the display
- public void Draw(SpriteBatch spriteBatch, int topLeftX, int topLeftY)
+ public void Draw(SpriteBatch spriteBatch)
{
- spriteBatch.Draw(projectileModel, new Vector2(topLeftX - pixelX, topLeftY - pixelY), null, Color.White, 0, new Vector2(0f, 0f), 1f, SpriteEffects.None, 0);
+ Rectangle position = mGame.State.Map.GetRectangleFromCoordinates(mMotion.Position);
+ spriteBatch.Draw(projectileModel, position, Color.White);
+
}
///
@@ -108,7 +95,9 @@ namespace CarFire
public int GridY { get { return gridY; } set { gridY = value; } }
public int PixelX { get { return pixelX; } set { pixelX = value; } }
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 int CharacterIndex { get { return mCharacterIndex; } }
+ public Vector2 Position { get { return mMotion.Position; } }
+ public Point Coordinates { get { return mMotion.Coordinates; } }
}
}