blob: 0775d225fb95d67bc1bd652523d07d285135e922 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
);
}
}
|