private void SendProjectileWithCastTime(GameTime gameTime) { if (!Data.IsCasting) { Data.IsCasting = true; _castStart = gameTime.TotalGameTime; } Data.TimeToCast = (gameTime.TotalGameTime - _castStart.Value).TotalMilliseconds; if ((gameTime.TotalGameTime - _castStart.Value).TotalMilliseconds > Data.EquipedWeapon.CastTime) { SendProjectile = false; var projectile = new Projectile(_contentManager.Load<Texture2D>(_projectileAssetName), 1, 2, Data.EquipedWeapon); projectile.Fire(_firePosition, new Vector2(500, 0), new Vector2(1, 0), GetProjectileDirection(), gameTime.TotalGameTime); Projectiles.Add(projectile); _lastProjectileTime = gameTime.TotalGameTime; Data.IsCasting = false; } }
private void SendProjectileWithNoCastTime(GameTime gameTime) { _isCasting = true; SendProjectile = false; var projectile = new Projectile(_contentManager.Load<Texture2D>(_projectileAssetName), 1, 2, Data.EquipedWeapon); projectile.Fire(_firePosition, new Vector2(500, 0), new Vector2(1, 0), GetProjectileDirection(), gameTime.TotalGameTime); Projectiles.Add(projectile); _lastProjectileTime = gameTime.TotalGameTime; }
public void Update(GameTime gameTime) { if (CurrentMovement.Direction == MoveDirection.Left) { _lastDirection = CurrentMovement.Direction; if (CurrentMovement.Type == MovementType.Crouch) { _currentFrameIndex = 3; } else { _currentFrameIndex = 1; } } else if (CurrentMovement.Direction == MoveDirection.Right) { _lastDirection = CurrentMovement.Direction; if (CurrentMovement.Type == MovementType.Crouch) { _currentFrameIndex = 2; } else { _currentFrameIndex = 0; } } else if (CurrentMovement.Direction == MoveDirection.Stop) { if (CurrentMovement.Type == MovementType.Crouch) { if (_lastDirection == MoveDirection.Right) _currentFrameIndex = 2; if (_lastDirection == MoveDirection.Left) _currentFrameIndex = 3; } else if (CurrentMovement.Type == MovementType.Walking) { if (_lastDirection == MoveDirection.Right) _currentFrameIndex = 0; if (_lastDirection == MoveDirection.Left) _currentFrameIndex = 1; } } UpdateMovement(CurrentMovement); base.Update(gameTime, mSpeed, mDirection); if (SendProjectile && Data.EquipedWeapon.CastTime > 0) { SendProjectileWithCastTime(gameTime); } else if (SendProjectile && CanFire(gameTime) && Data.EquipedWeapon.CastTime == 0) { SendProjectileWithNoCastTime(gameTime); } foreach (var ability in Data.Abilities) { if (!ability.Send) continue; if (!ability.IsProjectile) continue; var projectile = new Projectile(_contentManager.Load<Texture2D>(ability.TextureName), 1, 2, Data.EquipedWeapon); projectile.Data.Effect = ProjectileEffect.Burn; projectile.Fire(_firePosition, new Vector2(500, 0), new Vector2(1, 0), GetProjectileDirection(), gameTime.TotalGameTime); Projectiles.Add(projectile); ability.Send = false; } foreach (var projectile in Projectiles) { projectile.Update(gameTime, CurrentMovement); } }