Beispiel #1
0
        private void CreateCircleGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Scale(1, Width / Height);
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();
            ctx.Alpha     = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
Beispiel #2
0
        private void CreateDonutGeometry(RenderContext renderContext)
        {
            //todo move to dashed lines in future
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Scale(1, Height / Width);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width / 2, 0, Math.PI * 2, false);

            ctx.ClosePath();
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
Beispiel #3
0
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0)
                    {
                        TimeLeft = 0;
                    }
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0)
                    {
                        context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    }
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth   = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
Beispiel #4
0
        public void Update()
        {
            // Calculate next position of fish
            double fps = FishTank.FramesPerSecond;

            _velocity = Math.Max(Math.Floor(fps * fps * .5 / 3), 1);

            double nextX     = _x + _xAngle * _velocity * FishTank.TimeDelta;
            double nextY     = _y + _yAngle * _velocity * FishTank.TimeDelta;
            double nextZ     = _z + _zAngle * .1 * _velocity * FishTank.TimeDelta;
            double nextScale = Math.Abs(nextZ) / (FishTank.ZFar - FishTank.ZNear);

            // If fish is going to move off right side of screen
            if (nextX + FishTank.FishWidth / 2 * _scale > _tank.Width)
            {
                // If angle is between 3 o'clock and 6 o'clock
                if ((_angle >= 0 && _angle < Math.PI / 2))
                {
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI / 2 * 3)
                {
                    // If angle is between 12 o'clock and 3 o'clock
                    _angle  = _angle - (_angle - Math.PI / 2 * 3) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off left side of screen
            if (nextX - FishTank.FishWidth / 2 * _scale < 0)
            {
                if ((_angle > Math.PI / 2 && _angle < Math.PI))
                {
                    // If angle is between 6 o'clock and 9 o'clock
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI && _angle < Math.PI / 2 * 3)
                {
                    // If angle is between 9 o'clock and 12 o'clock
                    _angle  = _angle + (Math.PI / 2 * 3 - _angle) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off bottom side of screen
            if (nextY + FishTank.FishHeight / 2 * _scale > _tank.Height)
            {
                // If angle is between 3 o'clock and 9 o'clock
                if ((_angle > 0 && _angle < Math.PI))
                {
                    _angle  = Math.PI * 2 - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                }
            }

            // If fish is going to move off top side of screen
            if (nextY - FishTank.FishHeight / 2 * _scale < 0)
            {
                // If angle is between 9 o'clock and 3 o'clock
                if ((_angle > Math.PI && _angle < Math.PI * 2))
                {
                    _angle  = _angle - (_angle - Math.PI) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle);
                }
            }

            // If fish is going too far (getting too small)
            if (nextZ <= FishTank.ZNear && _zAngle < 0)
            {
                _zAngle = -_zAngle;
            }

            // If fish is getting to close (getting too large)
            if (((_tank.Width / FishTank.FishWidth) * 10) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .3;
            }
            else if (((_tank.Width / FishTank.FishWidth) * 2) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .5;
            }
            else
            {
                _zFactor = 1;
            }

            if (nextZ >= FishTank.ZFar * _zFactor && _zAngle > 0)
            {
                _zAngle = -_zAngle;
            }

            if (_scale < .1)
            {
                // Don't let fish get too tiny
                _scale = .1;
            }

            // Draw the fish
            _context.Save();

            // Move the fish to where it is within the fish tank
            _context.Translate(_x, _y);

            // Make the fish bigger or smaller depending on how far away it is.
            _context.Scale(_scale, _scale);

            // Make the fish face the way it is swimming.
            _context.Transform(_flip, 0, 0, 1, 0, 0);

            _context.DrawImage(_fishStrip,
                               FishTank.FishWidth * _cellIndex, FishTank.FishHeight * _species,
                               FishTank.FishWidth, FishTank.FishHeight,
                               -FishTank.FishWidth / 2, -FishTank.FishHeight / 2,
                               FishTank.FishWidth, FishTank.FishHeight);
            _context.Restore();

            // Increment to next state
            _x     = nextX;
            _y     = nextY;
            _z     = nextZ;
            _scale = nextScale;

            if ((_cellIndex >= FishTank.CellsInFishStrip - 1) || (_cellIndex <= 0))
            {
                // Go through each cell in the animation
                _cellReverse = -_cellReverse;
            }

            // Go back down once we hit the end of the animation
            _cellIndex = _cellIndex + _cellReverse;
        }