Exemplo n.º 1
0
        public void ToggleFollow(Train train)
        {
            // if we're already following the train specified, toggle it off
            Train?trainToSet = train.Follow ? null : train;

            foreach (Train t in _gameBoard.GetMovables <Train>())
            {
                t.Follow = (t == trainToSet);
            }
            Changed?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 2
0
 public void Render(ICanvas canvas, int width, int height, IPixelMapper pixelMapper)
 {
     foreach (Train train in _gameBoard.GetMovables())
     {
         var _paint = new PaintBrush
         {
             Color = _painter.GetPalette(train).FrontSectionEndColor with {
                 A = 200
             },
        public void Render(ICanvas canvas, int width, int height)
        {
            foreach (Train train in _gameBoard.GetMovables())
            {
                foreach (var position in _gameBoard.GetNextSteps(train, train.LookaheadDistance))
                {
                    (int x, int y) = _pixelMapper.CoordsToPixels(position.Column, position.Row);

                    canvas.DrawRect(x, y, _parameters.CellSize, _parameters.CellSize, _paint);
                }
            }
        }
Exemplo n.º 4
0
        public void Render(ICanvas canvas, int width, int height)
        {
            foreach (Train train in _gameBoard.GetMovables())
            {
                canvas.Save();

                (int x, int y) = _pixelMapper.CoordsToPixels(train.Column, train.Row);

                canvas.Translate(x, y);

                _trainRenderer.Render(canvas, train);

                canvas.Restore();
            }
        }
Exemplo n.º 5
0
        //public void Dispose()
        //{
        //    _paint.Dispose();
        //}

        public void Render(ICanvas canvas, int width, int height)
        {
            long now = _stopwatch.ElapsedMilliseconds;
            long timeSinceLastUpdate = now - _lastDrawTime;

            _lastDrawTime = now;

            int y = 1;

            canvas.DrawText((1000 / timeSinceLastUpdate) + " FPS", 0, (y++) * 25, _paint);

            canvas.DrawText(_gameBoard.GetTracks().Count() + " Tracks", 0, (y++) * 25, _paint);

            canvas.DrawText(_gameBoard.GetMovables().Count() + " Trains", 0, (y++) * 25, _paint);
        }
Exemplo n.º 6
0
        public void AdjustViewPortIfNecessary()
        {
            foreach (IMovable?vehicle in _gameBoard.GetMovables())
            {
                if (vehicle.Follow)
                {
                    (int x, int y) = _pixelMapper.CoordsToViewPortPixels(vehicle.Column, vehicle.Row);

                    double easing  = 10;
                    int    adjustX = Convert.ToInt32(((_pixelMapper.ViewPortWidth / 2) - x) / easing);
                    int    adjustY = Convert.ToInt32(((_pixelMapper.ViewPortHeight / 2) - y) / easing);

                    if (adjustX != 0 || adjustY != 0)
                    {
                        _pixelMapper.AdjustViewPort(adjustX, adjustY);
                    }
                    break;
                }
            }
        }
Exemplo n.º 7
0
        public void Render(ICanvas canvas, int width, int height)
        {
            foreach (Train train in _gameBoard.GetMovables())
            {
                PaintBrush _paint = new PaintBrush
                {
                    Color = _painter.GetPalette(train).FrontSectionEndColor,
                    Style = PaintStyle.Fill
                };

                (int x, int y) = _pixelMapper.CoordsToViewPortPixels(train.Column, train.Row);

                canvas.DrawRect(x, y, _parameters.CellSize, _parameters.CellSize, _paint);

                float speedModifier = 0.005f * ((_gameTimer?.TimeSinceLastTick / 16f) ?? 1);
                foreach (var position in _gameBoard.GetNextSteps(train, train.LookaheadDistance * speedModifier))
                {
                    (x, y) = _pixelMapper.CoordsToViewPortPixels(position.Column, position.Row);

                    canvas.DrawRect(x, y, _parameters.CellSize, _parameters.CellSize, _paint);
                }
            }
        }
Exemplo n.º 8
0
        public void Render(ICanvas canvas, int width, int height, IPixelMapper pixelMapper)
        {
            foreach (Train train in _gameBoard.GetMovables())
            {
                using (canvas.Scope())
                {
                    (int x, int y, bool onScreen) = pixelMapper.CoordsToViewPortPixels(train.Column, train.Row);

                    if (!onScreen)
                    {
                        continue;
                    }

                    canvas.Translate(x, y);

                    float scale = pixelMapper.CellSize / 100.0f;

                    canvas.Scale(scale, scale);

                    _trainRenderer.Render(canvas, train);
                }
            }
        }