, , , . # , XNA , Dark GDK.NET "TheGameCreators".
, , "" . "" - , - (, , , , , , ..). , , , .. , , .., . , .
- , -, . , -, -. , .
public class MySweetGame : Game
{
Player _player = new Player(this);
List<Bullet> _bullets = new List<Bullet>();
public List<Bullet> AllBullets()
{
get { return _bullets; }
}
public void Update()
{
if(leftMouseButtonClicked)
{
_player.Shoot();
}
foreach(Bullet blt in _bullets)
{
blt.Update(elapsedGameTime);
}
}
}
public class Player()
{
Vector2 _position = new Vector2(0,0);
int _ammunition = 50;
MySweetGame _game;
public Player(MySweetGame game)
{
_game = game;
}
public void Shoot()
{
if(_ammunition > 0){
_game.AllBullets.Add(new Bullet(50, _position));
_ammunition--;
}
}
}
public class Bullet()
{
float _metersPerSecond = 0;
Vector2 _position = new Vector2(0, 0);
public Bullet(float metersPerSecond, Vector3 position)
{
_metersPerSecond = metersPerSecond;
_position = position;
}
public void Update(float elapsedGameTime)
{
distanceTraveled = metersPerSecond * elapsedGameTime;
_position.x += distanceTraveled;
}
}