Game Development Reference
In-Depth Information
Gl.glEnd();
Gl.glEnable(Gl.GL_TEXTURE_2D);
}
}
}
The Entity class contains a sprite and some code to render that sprite's
bounding box.
With this entity definition, the Enemy class can be greatly simplified.
public class Enemy : Entity
{
double _scale ¼ 0.3;
public Enemy(TextureManager textureManager)
{
_sprite.Texture ¼ textureManager.Get("enemy_ship");
_sprite.SetScale(_scale , _scale);
_sprite.SetRotation(Math.PI); // make it face the player
_sprite.SetPosition(200, 0); // put it somewhere easy to see
}
public void Update(double elapsedTime)
{
}
public void Render(Renderer renderer)
{
renderer.DrawSprite(_sprite);
Render_Debug();
}
public void SetPosition(Vector position)
{
_ sprite.SetPosition(position);
}
}
The Enemy is now a type of Entity and no longer needs its own reference
to a sprite. This same refactoring can be applied to the PlayerCharacter
class.
 
Search WWH ::




Custom Search