From 25fdc90968a14ffd44dae65d6fdb3d50e6df9082 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Fri, 27 Mar 2026 16:29:32 -0700 Subject: Initial Commit --- TankBattleCore/Objects/Tank.cs | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 TankBattleCore/Objects/Tank.cs (limited to 'TankBattleCore/Objects/Tank.cs') diff --git a/TankBattleCore/Objects/Tank.cs b/TankBattleCore/Objects/Tank.cs new file mode 100644 index 0000000..927d053 --- /dev/null +++ b/TankBattleCore/Objects/Tank.cs @@ -0,0 +1,79 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace TankBattleCore.Objects; + +internal class Tank +{ + private const float Speed = 200; + private const float TurnSpeed = 2; //In Rad/Sec + private const float Scale = 0.6f; + private const int PoweredUpShotInterval = 4; + + private Vector2 _position; + private float _angle = 0; + private Texture2D _bodyTexture; + private int _numShots = 0; + private float ShotSpeed + { + get + { + if (_numShots % PoweredUpShotInterval == PoweredUpShotInterval - 1) + { + return Bullet.FastSpeed; + } else + { + return Bullet.SlowSpeed; + } + } + } + + public Tank(Vector2 postion, Texture2D bodyTexture) + { + _position = postion; + _bodyTexture = bodyTexture; + } + + public void Update(float dt) + { + _position += new Vector2(MathF.Cos(_angle), MathF.Sin(_angle)) * Speed * dt; + + var keyboardState = Keyboard.GetState(); + if (keyboardState.IsKeyDown(Keys.A)) + { + _angle -= TurnSpeed * dt; + } else if (keyboardState.IsKeyDown(Keys.D)) { + _angle += TurnSpeed * dt; + } + } + + public void Draw(SpriteBatch _spriteBatch) + { + _spriteBatch.Draw( + _bodyTexture, + _position, + null, + Color.White, + _angle - MathF.PI / 2, //Texture is rotated 90 degrees downwards + 0.5f * new Vector2(_bodyTexture.Width, _bodyTexture.Height), + Scale, + SpriteEffects.None, + 1.0f + ); + } + + public BulletData GetNextShot() + { + var shotSpeed = ShotSpeed; + _numShots++; + + return new BulletData + { + Position = _position, + Angle = _angle, + Speed = shotSpeed + }; + } +} \ No newline at end of file -- cgit v1.2.3