Пример #1
0
        internal void DrawEnemyWalk(Model model)
        {
            const uint spritesPerColumn = 2;
            const uint spritesPerRow    = 4;

            foreach (Enemy enemy in model.Enemies)
            {
                GL.BindTexture(TextureTarget.Texture2D, texEnemyWalk);
                //NormalizedAnimationTime ist 0 am anfang der animation und nahe bei 1 am ende
                var spriteId  = (uint)Math.Round(enemy.NormalizedAnimationTime * (spritesPerRow * spritesPerColumn - 1));       //Zahl zwischen 0 und 7
                var texCoords = SpriteSheetTools.CalcTexCoords(spriteId, spritesPerRow, spritesPerColumn);
                GL.Disable(EnableCap.Blend);
                GL.PushMatrix();
                GL.Translate(new Vector3(enemy.Position.X, enemy.Position.Y, 0));
                GL.Rotate(enemy.AngleToPlayer + 90, new Vector3d(0, 0, 1));
                GL.Begin(PrimitiveType.Quads);
                GL.TexCoord2(texCoords.MinX, texCoords.MinY);
                GL.Vertex2(new Vector2((-enemy.RadiusDraw), (-enemy.RadiusDraw)));
                GL.TexCoord2(texCoords.MaxX, texCoords.MinY);
                GL.Vertex2(new Vector2((enemy.RadiusDraw), (-enemy.RadiusDraw)));
                GL.TexCoord2(texCoords.MaxX, texCoords.MaxY);
                GL.Vertex2(new Vector2((enemy.RadiusDraw), (enemy.RadiusDraw)));
                GL.TexCoord2(texCoords.MinX, texCoords.MaxY);
                GL.Vertex2(new Vector2((-enemy.RadiusDraw), (enemy.RadiusDraw)));
                GL.End();
                GL.PopMatrix();
                GL.Enable(EnableCap.Blend);
                //Draws enemy helathbar
                DrawObject(this.texHealthBackground, enemy.Position + new Vector2(0, enemy.RadiusDraw + 0.001f), enemy.RadiusDraw + 0.01f, enemy.RadiusDraw, 0.6f, 0, 0);
                DrawObject(this.texHealth, enemy.Position + new Vector2(0, enemy.RadiusDraw + 0.001f), (enemy.RadiusDraw + 0.01f) * enemy.Hitpoints, enemy.RadiusDraw, 0.6f, 0, 0);
            }
        }
Пример #2
0
        private void DrawFont(string text, float x, float y, float size)
        {
            const uint firstCharacter      = 32;          // the ASCII code of the first character stored in the bitmap font
            const uint charactersPerColumn = 10;          // how many characters are in each column
            const uint charactersPerRow    = 10;          // how many characters are in each row
            var        rect = new Rect(x, y, size, size); // rectangle of the first character

            foreach (var spriteId in SpriteSheetTools.StringToSpriteIds(text, firstCharacter))
            {
                var texCoords = SpriteSheetTools.CalcTexCoords(spriteId, charactersPerRow, charactersPerColumn);
                DrawRect(rect, texCoords);
                rect.MinX += rect.SizeX;
            }
        }