public void Draw(DrawParams dparams) { if (State != InvaderState.Alive) { return; } var graphics = dparams.Graphics; var offset = dparams.Offset; var data = GetTextureDrawData(offset); //draw the entity itself graphics.DrawImage(data, Color, offset, Orientation); // compute the bounds of the life bar GsVector barPosition = data.Position - (Size.ToVector() * .5f); barPosition.Y -= 4f; GsRectangle bar = new GsRectangle(barPosition, new GsSize(Width, 3f)); // draw the life bar float width = bar.Width * Calculator.CalculatePercent(CurrentLife, 0, MaximumLife); graphics.FillRectangle(GsColor.Green, bar.X, bar.Y, width, bar.Height); graphics.DrawRectangle(GsColor.Black, bar); // draw the level var font = FontProvider.InvaderLevelFont; string text = Level.ToString(); GsVector pos = new GsVector(bar.X, bar.Y - (GsTextMeasurer.MeasureString(font, text).Height + 5f)); graphics.DrawString(font, text, pos, GsColor.Gold); }
public SharpDXGraphics(GraphicsDevice device) { GsTextMeasurer.Register(this); GraphicsDevice = device; spriteBatch = new SpriteBatch(device); primitiveBatch = new PrimitiveBatch <VertexPositionColor>(device); basicEffect = new BasicEffect(device); basicEffect.VertexColorEnabled = true; }
public OpenGLGraphics() { fonts = new Dictionary <string, Font>(); fonts["Tahoma"] = new Font("Tahoma", 10f); measureBitmap = new Bitmap(128, 128); measureGraphics = Graphics.FromImage(measureBitmap); stringTextures = new Dictionary <string, TextureData>(); centerCenter = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, }; GsTextMeasurer.Register(this); }