X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FHuman.cs;h=519d9d02f14908767e150112472c01d7638d6bd1;hp=168fa06f627a0d9024489cf8a7e23c59247cc46f;hb=851a2f1efb5e981fad8f517170809b61d630e8b7;hpb=f31f4ae920ff902f4cd4fb64f5e6ccf0d5e58402 diff --git a/CarFire/CarFire/CarFire/Human.cs b/CarFire/CarFire/CarFire/Human.cs index 168fa06..519d9d0 100644 --- a/CarFire/CarFire/CarFire/Human.cs +++ b/CarFire/CarFire/CarFire/Human.cs @@ -18,8 +18,6 @@ namespace CarFire up, down }; - //The number of frames between each square movements - const int moveCoolDown = 15; //The number of frames between each projectile is spawned. const int shootCoolDown = 10; State state; @@ -114,15 +112,30 @@ namespace CarFire bool moveRight = keysPressed.Contains(Keys.Right); bool moveUp = keysPressed.Contains(Keys.Up); bool moveDown = keysPressed.Contains(Keys.Down); + if (moveLeft) + state = State.left; + else if (moveRight) + state = State.right; + else if (moveUp) + state = State.up; + else if (moveDown) + state = State.down; Point destination = MovementManager.GetNeighborCell(mMotion.Coordinates, moveLeft, moveRight, moveUp, moveDown); - if (theMap.IsCellOpen(destination)) + if (!keysPressed.Contains(Keys.LeftControl)) { - mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); + if (theMap.IsCellOpen(destination)) + { + mMotion.Update(timeSpan, moveLeft, moveRight, moveUp, moveDown); + } + else + { + mMotion.Update(timeSpan); + } } else { - mMotion.Update(timeSpan); + mMotion.LockUpdate(timeSpan, moveLeft, moveRight, moveUp, moveDown); } @@ -132,31 +145,63 @@ namespace CarFire { if (keysPressed.Contains(Keys.Space)) { - //TODO spawn projectile... needs to be added to display though + float velocityX = 0; + float velocityY = 0; + int startX = Coordinates.X; + int startY = Coordinates.Y; + if (mMotion.Direction == Direction.Down || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.LowerRight) + { + velocityY = 1; + startY = Coordinates.Y + 1; + } + else if (mMotion.Direction == Direction.Up || mMotion.Direction == Direction.UpperLeft || mMotion.Direction == Direction.UpperRight) + { + velocityY = -1; + startY = Coordinates.Y - 1; + } + if (mMotion.Direction == Direction.Right || mMotion.Direction == Direction.LowerRight || mMotion.Direction == Direction.UpperRight) + { + velocityX = 1; + startX = Coordinates.X + 1; + } + else if (mMotion.Direction == Direction.Left || mMotion.Direction == Direction.LowerLeft || mMotion.Direction == Direction.UpperLeft) + { + velocityX = -1; + startX = Coordinates.X - 1; + } + Vector2 toShoot = new Vector2(velocityX, velocityY); + toShoot.Normalize(); + toShoot *= projectileSpeed; + projectileCoolDown = shootCoolDown; + theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, + toShoot, new Point(startX, startY))); + + /* if (state == State.up) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, - new Vector2(0, -projectileSpeed), Coordinates.X, Coordinates.Y - 1)); + new Vector2(0, -projectileSpeed), new Point(Coordinates.X, Coordinates.Y - 1))); } if (state == State.down) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, - new Vector2(0, projectileSpeed), Coordinates.X, Coordinates.Y + 1)); + new Vector2(0, projectileSpeed), new Point(Coordinates.X, Coordinates.Y + 1))); } if (state == State.right) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, - new Vector2(projectileSpeed, 0), Coordinates.X + 1, Coordinates.Y)); + new Vector2(projectileSpeed, 0), new Point (Coordinates.X + 1, Coordinates.Y))); } if (state == State.left) { projectileCoolDown = shootCoolDown; theDisplay.AddProjectiles(new Projectile(theMap, projectileModel, - new Vector2(-projectileSpeed, 0), Coordinates.X - 1, Coordinates.Y)); + new Vector2(-projectileSpeed, 0), new Point(Coordinates.X - 1, Coordinates.Y))); } + */ } } }