private void ResetReload(IShootingEntity shooter, float dt) { if (shooter != null) { if (shooter.Recharge > 0) { shooter.Recharge -= dt; } } }
/// <summary> /// Fires a bullet for the entity if based on the behavior. /// </summary> /// <param name="entity">The source entity shooting.</param> /// <param name="gameTime">The elapsed game time.</param> /// <param name="bulletManager">A bullet manager to shoot bullets with.</param> public void FireWhenReady(IShootingEntity entity, GameTime gameTime) { if (gameTime.TotalGameTime > this.LastShot + this.FireRate) { this.LastShot = gameTime.TotalGameTime; var lBullet = new BulletEntity { Damage = this.BulletDamage, Renderer = new BasicRenderer(this.BulletTexture), MovementBehavior = new StraightMovementBehavior { Acceleration = Vector2.Zero, Velocity = Vector2.Normalize(this.BulletDirection) * this.BulletSpeed, Position = entity.Position + (entity.Size / 2f), }, IsFriendly = entity.IsFriendly, }; this.FireBullet(lBullet); } }
/// <summary> /// This will never fire a bullet. /// </summary> /// <param name="entity">The source entity shooting.</param> /// <param name="gameTime">The elapsed game time.</param> /// <param name="bulletManager">A bullet manager to shoot bullets with.</param> public void FireWhenReady(IShootingEntity entity, GameTime gameTime) { }
/// <summary> /// Fires a bullet for the entity if based on the behavior. /// </summary> /// <param name="entity">The source entity shooting.</param> /// <param name="gameTime">The elapsed game time.</param> /// <param name="bulletManager">A bullet manager to shoot bullets with.</param> public void FireWhenReady(IShootingEntity entity, GameTime gameTime) { if (gameTime.TotalGameTime > this.LastShot + this.FireRate) { this.LastShot = gameTime.TotalGameTime; var lDirectionOffset = MathHelper.ToRadians(this.Spread); var lDirection = Math.Atan2(this.BulletDirection.Y, this.BulletDirection.X); var lTopDirection = lDirection - lDirectionOffset; var lBottomDirection = lDirection + lDirectionOffset; var lTopVector = this.BulletSpeed * new Vector2( (float)Math.Cos(lTopDirection), (float)Math.Sin(lTopDirection)); var lBottomVector = this.BulletSpeed * new Vector2( (float)Math.Cos(lBottomDirection), (float)Math.Sin(lBottomDirection)); var lBulletTop = new BulletEntity { Damage = this.BulletDamage, MovementBehavior = new StraightMovementBehavior { Acceleration = Vector2.Zero, Velocity = lTopVector, Position = entity.Position + (entity.Size / 2f), }, Renderer = new BasicRenderer(this.BulletTexture), IsFriendly = entity.IsFriendly, }; var lBulletBottom = new BulletEntity { Damage = this.BulletDamage, Renderer = new BasicRenderer(this.BulletTexture), MovementBehavior = new StraightMovementBehavior { Acceleration = Vector2.Zero, Velocity = lBottomVector, Position = entity.Position + (entity.Size / 2f), }, IsFriendly = entity.IsFriendly, }; this.FireBullet(lBulletTop); this.FireBullet(lBulletBottom); } }