public GameTransaction GetInput()
        {
            ticks++;
            if ((speedTicks <= 1) || (ticks % speedTicks) == 0)
            {
                speedX = (2 * intensity * rand.NextDouble()) - intensity;
                speedY = (2 * intensity * rand.NextDouble()) - intensity;
            }


            //We can lerp, but we will go with exponential smoothing for position.
            double newPosX = (posX + speedX) * (1 - smoothingFactor) + (posX) * smoothingFactor;
            double newPosY = (posY + speedY) * (1 - smoothingFactor) + (posY) * smoothingFactor;

            posX = Clamp(newPosX, 0, maxX);
            posY = Clamp(newPosY, 0, maxY); //Don't get it too close to the bottom.

            Point mouseInput = Mouse.GetPosition(canvas);

            GameTransaction gameTransaction = new GameTransaction
            {
                MousePoint = mouseInput,
                GamePoint  = new Point(posX, posY)
            };

            return(gameTransaction);
        }
Beispiel #2
0
        private void GameDisplay(GameTransaction gameTransactionNow)
        {
            if (gameTransactionNow != null)
            {
                Canvas.SetLeft(DotMain, gameTransactionNow.GamePoint.X);
                Canvas.SetTop(DotMain, gameTransactionNow.GamePoint.Y);

                Canvas.SetLeft(DotReplay, gameTransactionNow.MousePoint.X);
                Canvas.SetTop(DotReplay, gameTransactionNow.MousePoint.Y);
            }

            DisplayTimer();
        }
Beispiel #3
0
        private void GameTrackTimerTick(object sender, EventArgs e)
        {
            GameTransaction gameTransactionNow = null;

            //Stop Game Timer.
            if (timerForCountDown <= 0)
            {
                GameTrackTimer.Stop();
            }
            else
            {
                //Process Input.
                gameTransactionNow = inputSource.GetInput();
                if (gameTransactionNow != null)
                {
                    gameTransactionLog.Add(gameTransactionNow);
                }
            }

            //Display Objects.
            GameDisplay(gameTransactionNow);
        }