Beispiel #1
0
        public async ValueTask Step()
        {
            var sceneGraph = _game.GetService <SceneGraph>();

            await _context.ClearRectAsync(0, 0, _game.Display.Size.Width, _game.Display.Size.Height);

            await _context.BeginBatchAsync();

            await Render(sceneGraph.Root, _game);

            await _context.EndBatchAsync();
        }
Beispiel #2
0
        private async ValueTask RenderFrame(SortedList <int, IList <IRenderable> > layers)
        {
            await _context.ClearRectAsync(0, 0, _game.Display.Size.Width, _game.Display.Size.Height)
            .ConfigureAwait(false);

            await _context.BeginBatchAsync().ConfigureAwait(false);

            foreach (var layer in layers.Values)
            {
                foreach (var renderable in layer)
                {
                    await renderable.Render(_game, _context).ConfigureAwait(false);
                }
            }

            await _context.EndBatchAsync().ConfigureAwait(false);
        }
Beispiel #3
0
        public async ValueTask Render()
        {
            await _context.ClearRectAsync(0, 0, _width, _height);

            await _context.BeginBatchAsync();

            await _context.SetFillStyleAsync("white");

            await _context.SetFontAsync("32px consolas");

            var text   = $"Points: {_points.ToString("D3")} High score: {HighScore} {HighScoreName} Lives: {_lives.ToString("D3")}";
            var length = await _context.MeasureTextAsync(text);

            await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 25);

            if (GameOver)
            {
                await RenderGameOver();
            }
            else if (Won)
            {
                await RenderWonGame();
            }
            else if (Started)
            {
                await RenderGameFrame();
            }
            else if (!Started)
            {
                await _context.SetFillStyleAsync("white");

                text   = $"Use arrow keys to move, space to fire";
                length = await _context.MeasureTextAsync(text);

                await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 150);

                text   = $"Press space to start";
                length = await _context.MeasureTextAsync(text);

                await _context.FillTextAsync(text, _width / 2 - (length.Width / 2), 200);
            }

            await _context.EndBatchAsync();
        }