diff options
Diffstat (limited to 'TankBattleCore/Objects/Bullet.cs')
| -rw-r--r-- | TankBattleCore/Objects/Bullet.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/TankBattleCore/Objects/Bullet.cs b/TankBattleCore/Objects/Bullet.cs new file mode 100644 index 0000000..0775d22 --- /dev/null +++ b/TankBattleCore/Objects/Bullet.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace TankBattleCore.Objects; + +struct BulletData +{ + public Vector2 Position; + public float Angle; + public float Speed; +} + +class Bullet +{ + public const float SlowSpeed = 250f; + public const float FastSpeed = 400f; + + private Vector2 _position; + private Texture2D _bulletTexture; + float _speed; + float _angle; + + public Vector2 Position { get => _position; } + + public Bullet(Vector2 position, Texture2D bulletTexture, float speed, float angle) + { + _position = position; + _bulletTexture = bulletTexture; + _speed = speed; + _angle = angle; + } + + public void Update(float dt) + { + _position += new Vector2(MathF.Cos(_angle), MathF.Sin(_angle)) * _speed * dt; + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw( + _bulletTexture, + _position, + Color.White + ); + } +}
\ No newline at end of file |
