コード例 #1
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            var fps = 1000f / game.GameTime.ElapsedMilliseconds;

            await context.SetFillStyleAsync("green");

            await context.FillRectAsync(10, 50, 300, _height);

            await context.SetFillStyleAsync("#fff");

            await context.SetFontAsync("18px verdana");

            y = startY;

            await WriteLine($"Total game time (s): {game.GameTime.TotalMilliseconds / 1000}", context);
            await WriteLine($"Frame time (ms): {game.GameTime.ElapsedMilliseconds}", context);
            await WriteLine($"FPS: {fps:###}", context);

            if (AsteroidsSpawner is not null)
            {
                await WriteLine($"Asteroids alive: {AsteroidsSpawner.Alive:###}", context);
            }

            if (BulletSpawner is not null)
            {
                await WriteLine($"Bullets spawned: {BulletSpawner.Alive:###}", context);
            }
        }
コード例 #2
0
        internal async Task DrawRectangleAsync(Color fillColor, Color borderColor, float borderWidth, Rectangle rectangle)
        {
            if (fillColor != null)
            {
                await this.SetFillColor(fillColor);

                await ctx.FillRectAsync(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
            }

            if (borderColor != null)
            {
                await this.SetStrokeColor(borderColor);

                await this.SetLineWidth(borderWidth);

                await ctx.StrokeRectAsync(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
            }
        }
コード例 #3
0
        private async Task DrawRect(RenderElement element, string style)
        {
            var oldStyle = _context.FillStyle;
            await _context.SetFillStyleAsync(style);

            await _context.FillRectAsync(element.Position.X, element.Position.Y,
                                         element.Dimensions.Width, element.Dimensions.Height);

            await _context.SetFillStyleAsync(oldStyle);
        }
コード例 #4
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            var fps = 1000f / game.GameTime.ElapsedMilliseconds;

            await context.SetFillStyleAsync("green");

            await context.FillRectAsync(10, 50, 400, 100);

            await context.SetFontAsync("24px verdana");

            await context.StrokeTextAsync($"Total game time (s): {game.GameTime.TotalMilliseconds / 1000}", 20, 80);

            await context.StrokeTextAsync($"Frame time (ms): {game.GameTime.ElapsedMilliseconds}", 20, 110);

            await context.StrokeTextAsync($"FPS: {fps:###}", 20, 140);
        }
コード例 #5
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            this._context = await this._canvasReference.CreateCanvas2DAsync();

            await this._context.SetFillStyleAsync("green");

            await _context.FillRectAsync(0, 0, _canvasReference.Width, _canvasReference.Height);

            await this._context.SetFillStyleAsync("yellow");

            await this._context.FillRectAsync(10, 100, 100, 100);

            await this._context.SetFontAsync("48px serif");

            await this._context.StrokeTextAsync("Event test", 10, 100);
        }
コード例 #6
0
        public static async Task DrawBar(this Canvas2DContext con, int barValue, string color, int xPos, int chartHeight)
        {
            await con.MoveToAsync(barWidth + xPos + spaceX, chartHeight - spaceY);

            await con.LineToAsync(barWidth + xPos + spaceX, chartHeight - spaceY);

            await con.StrokeAsync();

            int barHeight = -barValue * 2;

            await con.SetFillStyleAsync(color);

            await con.FillRectAsync(xPos + spaceX, chartHeight - spaceY - 1, barWidth, barHeight);

            await con.FillTextAsync(barValue.ToString(), xPos + spaceX + 5, chartHeight - spaceY + barHeight - 2);

            await con.SetFillStyleAsync(COLOR.Black);
        }
コード例 #7
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            var fps = 1000f / game.GameTime.ElapsedMilliseconds;

            await context.SetFillStyleAsync("green");

            await context.FillRectAsync(10, 50, 300, _height);

            await context.SetFillStyleAsync("#fff");

            await context.SetFontAsync("18px verdana");

            y = startY;

            await WriteLine($"Total game time (s): {game.GameTime.TotalMilliseconds / 1000}", context);
            await WriteLine($"Frame time (ms): {game.GameTime.ElapsedMilliseconds}", context);
            await WriteLine($"FPS: {fps:###}", context);
        }
コード例 #8
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            int maxWidth     = 300;
            int maxHeight    = 30;
            int bottomOffset = 20;
            int rightOffset  = 20;

            float healthRatio = (float)this.PlayerBrain.Stats.Health / this.PlayerBrain.Stats.MaxHealth;
            int   width       = (int)(healthRatio * maxWidth);

            int x = game.Display.Size.Width - width - rightOffset;
            int y = game.Display.Size.Height - maxHeight - bottomOffset;

            var color = healthRatio > .5 ? "green" : "red";

            await context.SetFillStyleAsync(color);

            await context.FillRectAsync(x, y, width, maxHeight);
        }
コード例 #9
0
        async ValueTask drawPage(Page p)
        {
            await _outputCanvasContext.ClearRectAsync(0, 0, _canvasReference.Width, _canvasReference.Height);

            await _outputCanvasContext.SetFillStyleAsync("black");

            await _outputCanvasContext.FillRectAsync(0, 0, _canvasReference.Width, _canvasReference.Height);

            for (int i = 0; i < p.elements.Count; i++)
            {
                PageElement e = p.elements[i];
                await _outputCanvasContext.SetFontAsync(fontCode(e.font));

                await _outputCanvasContext.SetFillStyleAsync("#ffffff");

                await _outputCanvasContext.FillTextAsync(e.text, e.x *skala, e.y *skala);
            }
            await Task.Delay(p.time * 1000);
        }
コード例 #10
0
        public async ValueTask Render(GameContext game, Canvas2DContext context)
        {
            if (!this.Owner.Enabled || !this.Initialized)
            {
                return;
            }

            var oldPattern = context.FillStyle;

            var pattern = await context.CreatePatternAsync(Sprite.ElementRef, RepeatPattern);

            await context.SetFillStyleAsync(pattern);

            var w = _transform.World.Scale.X * this.Sprite.Bounds.Width;
            var h = _transform.World.Scale.Y * this.Sprite.Bounds.Height;

            await context.FillRectAsync(_transform.World.Position.X, _transform.World.Position.X, w, h);

            await context.SetFillStyleAsync(oldPattern);
        }
コード例 #11
0
        public async ValueTask DrawRectangle(int left, int top, int width, int height, string color = "", string fillColor = "")
        {
            await _canvas.SetStrokeStyleAsync(color);

            if (color != "")
            {
                await _canvas.StrokeRectAsync(left, top, width, height);

                await _canvas.SetStrokeStyleAsync("");
            }

            await _canvas.SetFillStyleAsync(fillColor);

            if (fillColor != "")
            {
                await _canvas.FillRectAsync(left, top, width, height);

                await _canvas.SetFillStyleAsync("");
            }
        }
コード例 #12
0
        public async ValueTask FillRect(int x, int y, int width, int height, Color color)
        {
            await _canvas2DContext.SetFillStyleAsync(color.Name);

            await _canvas2DContext.FillRectAsync(x + _origin.X, y + _origin.Y, width, height);
        }
コード例 #13
0
ファイル: Paddle.cs プロジェクト: SimonBonnier/BlazorGameApp
        public override async Task Draw(Canvas2DContext context)
        {
            await context.SetFillStyleAsync("green");

            await context.FillRectAsync(Position.X, Position.Y, Width, Height);
        }
コード例 #14
0
 public void Apply(RectangleNode node)
 {
     _canvas2DContext.FillRectAsync(node.Position.X, node.Position.Y, node.Size.X, node.Size.Y);
 }