Ejemplo n.º 1
0
        public PlanesSample()
            : base()
        {
            this.Window.Title = "Samurai Planes Sample";

            this.spriteRenderer = new SpriteRenderer(this.Graphics);
            this.shaderProgram = new BasicSpriteShaderProgram(this.Graphics);

            this.planesTexture = Texture2D.LoadFromFile(this.Graphics, "Planes.png", new TextureParams()
                {
                });

            this.planeSpriteSheet = SpriteSheet.Build(this.planesTexture, 64, 64);

            this.font = TextureFont.Build(this.Graphics, "Segoe UI", 72, new TextureFontParams()
                {
                    Color = Color4.White,
                    BackgroundColor = Color4.Transparent,
                });

            Random random = new Random();

            this.planes = new List<Plane>();

            for (int i = 0; i < PlaneCount; i++)
            {
                this.planes.Add(new Plane(
                    random.Next(4) * 3,
                    new Vector2(random.Next(this.Window.Width), random.Next(this.Window.Height)),
                    (float)random.Next(360),
                    new Size(this.Window.Width, this.Window.Height)
                ));
            }
        }
Ejemplo n.º 2
0
        public void DrawString(TextureFont font, string text, Vector2 position, Color4 color)
        {
            if (font == null)
                font = this.DefaultFont;

            if (font == null)
                throw new SamuraiException("No font set on control and no default font provided.");

            this.spriteBatch.DrawString(font, text, position, color);
        }
Ejemplo n.º 3
0
        public Demo2DGame()
            : base(new GameOptions()
            {
                AutoResizeViewport = true,
                WindowResizable = true
            })
        {
            this.Window.Title = "Samurai 2D Demo";

            this.Graphics.DepthBufferState = DepthBufferState.LessThanOrEqual;

            this.Graphics.BlendState = BlendState.AlphaBlend;
            this.Graphics.RasterizerState = RasterizerState.Default;

            this.spriteRenderer = new SpriteRenderer(this.Graphics, 1024);
            this.shaderProgram = new BasicSpriteShaderProgram(this.Graphics);

            this.planesTexture = Texture2D.LoadFromFile(this.Graphics, "Planes.png", new TextureParams()
                {
                });

            this.planeSpriteSheet = SpriteSheet.Build(this.planesTexture, 64, 64);

            this.font = TextureFont.Build(this.Graphics, "Segoe UI", 72, new TextureFontParams()
                {
                    Color = Color4.White,
                    BackgroundColor = Color4.Transparent,
                    //ColorKey = Color4.Black
                });

            this.keyboard = new Keyboard();
            this.mouse = new Mouse(this.Window);

            Random random = new Random();

            this.planes = new List<Plane>();

            for (int i = 0; i < PlaneCount; i++)
            {
                this.planes.Add(new Plane(
                    random.Next(4) * 3,
                    new Vector2(random.Next(this.Window.Width), random.Next(this.Window.Height)),
                    (float)random.Next(360),
                    this.Window.Size
                ));
            }
        }
Ejemplo n.º 4
0
        public Vector2 DrawString(
			TextureFont font,
			string text,
			Rectangle destination,
			Color4? tint = null,
			Vector2? origin = null,
			Vector2? scale = null,
			float rotation = 0.0f,
			float layerDepth = 0.0f)
        {
            if (font == null)
                throw new ArgumentNullException("font");

            if (text == null)
                throw new ArgumentNullException("text");

            if (text.Length == 0)
                return new Vector2(destination.X, destination.Y);

            if (tint == null)
                tint = Color4.White;

            if (origin == null)
                origin = Vector2.Zero;

            if (scale == null)
                scale = Vector2.One;

            float heightOfSingleLine = font.LineHeight * scale.Value.Y;

            if (heightOfSingleLine > destination.Height) // We can't draw anything
                return new Vector2(destination.X, destination.Y);

            Vector2 cursor = new Vector2(destination.X, destination.Y);

            for (int i = 0; i < text.Length; i++)
            {
                // Skip characters we can't render.
                if (text[i] == '\r')
                    continue;

                float widthOfChar = 0;

                if (text[i] == '\n' || cursor.X + (widthOfChar = font[text[i]].Width * scale.Value.X) > destination.Right)
                {
                    cursor.X = destination.X;
                    cursor.Y += heightOfSingleLine + font.LineSpacing;

                    // If the next line extends past the destination, quit.
                    if (cursor.Y + heightOfSingleLine > destination.Bottom)
                        return cursor;

                    // We can't render a new line.
                    if (text[i] == '\n')
                        continue;
                }

                Vector2 characterOrigin = origin.Value;
                characterOrigin.X -= cursor.X - destination.X;
                characterOrigin.Y -= cursor.Y - destination.Y;

                Rectangle letterSource = font[text[i]];
                Rectangle letterDestination = new Rectangle((int)cursor.X + (int)characterOrigin.X, (int)cursor.Y + (int)characterOrigin.Y, (int)widthOfChar, (int)heightOfSingleLine);

                this.Draw(
                    font.Texture,
                    letterDestination,
                    letterSource,
                    tint,
                    characterOrigin,
                    scale,
                    rotation,
                    layerDepth);

                cursor.X += widthOfChar + font.CharacterSpacing;
            }

            return cursor;
        }
Ejemplo n.º 5
0
        public Vector2 DrawString(
			TextureFont font,
			string text,
			Vector2 position,
			Color4? tint = null,
			Vector2? origin = null,
			Vector2? scale = null,
			float rotation = 0.0f,
			float layerDepth = 0.0f)
        {
            if (font == null)
                throw new ArgumentNullException("font");

            if (text == null)
                throw new ArgumentNullException("text");

            if (text.Length == 0)
                return position;

            Size textSize = font.MeasureString(text);

            return this.DrawString(font, text, new Rectangle((int)position.X, (int)position.Y, textSize.Width, textSize.Height), tint, origin, scale, rotation, layerDepth);
        }