Game Development Reference
In-Depth Information
}
public void SetColor(Color color)
{
_sprite.SetColor(color);
}
public Bullet(Texture bulletTexture)
{
_sprite.Texture ¼ bulletTexture;
// Some default values
Dead ¼ false;
Direction ¼ new Vector(1, 0, 0);
Speed ¼ 512;// pixels per second
}
public void Render(Renderer renderer)
{
if (Dead)
{
return;
}
renderer.DrawSprite(_sprite);
}
public void Update(double elapsedTime)
{
if (Dead)
{
return;
}
Vector position ¼ _sprite.GetPosition();
position += Direction * Speed * elapsedTime;
_sprite.SetPosition(position);
}
}
The bullet has three members: the direction the bullet will travel, the speed it will
travel, and a flag to tell if the bullet is dead or not. There are also position setters
and getters for the bullet sprite. There is also a setter for the color; it makes sense
to allow the bullets to be colored. The player bullets will only hurt the enemies
 
Search WWH ::




Custom Search