コード例 #1
0
ファイル: CarGame.cs プロジェクト: csombok/autonomous
        private void CheckIfGameFinished(GameStateInternal internalState, TimeSpan gameTimeTotalGameTime)
        {
            float firstPlayerFront = internalState.FirstPlayer.BoundingBox.Bottom;

            if (firstPlayerFront >= _finishline.Y - 10)
            {
                _slowdown = true;
                _viewportManager.SetViewports(new List <GameObject>()
                {
                    _finishline
                });
            }

            if (firstPlayerFront >= _finishline.Y)
            {
                ExportPlayerScores(gameTimeTotalGameTime);
                Stop(gameTimeTotalGameTime);
            }

            if (internalState.GameObjects.OfType <Car>().All(car => car.Stopped))
            {
                ExportPlayerScores(gameTimeTotalGameTime);
                Stop(gameTimeTotalGameTime);
            }

            if (CanExit(gameTimeTotalGameTime))
            {
                Exit();
            }
        }
コード例 #2
0
        private void CheckIfGameFinished(GameStateInternal internalState, TimeSpan gameTimeTotalGameTime)
        {
            float firstPlayerFront = internalState.FirstPlayer.BoundingBox.Bottom;

            if (firstPlayerFront >= _finishline.Y - 10)
            {
                _slowdown = true;
                _viewportManager.SetViewports(new List <GameObject>()
                {
                    _finishline
                });
            }

            if (firstPlayerFront >= _finishline.Y)
            {
                ExportPlayerScores(gameTimeTotalGameTime);
                Stopped = true;
            }

            if (internalState.GameObjects.OfType <Car>().All(car => car.Stopped))
            {
                ExportPlayerScores(gameTimeTotalGameTime);
                if (!Failed)
                {
                    failedAt = gameTimeTotalGameTime;
                }
                Stopped = Failed = true;
            }

            if ((firstPlayerFront >= _finishline.Y + 20) ||
                (Failed && (gameTimeTotalGameTime - failedAt).TotalMilliseconds > 2000))
            {
                Exit();
            }
        }
コード例 #3
0
        public void UpdateModel(GameTime gameTime)
        {
            // Hold cars at the start line for 2 sec
            if (gameTime.TotalGameTime.TotalMilliseconds < 2000)
            {
                return;
            }

            var agentObjects = this._gameObjects
                               .Where(go => go.GetType() == typeof(Car) || go.GetType() == typeof(CarAgent) || go.GetType() == typeof(FinishLine)).OrderBy(g => g.Y);
            var internalState = new GameStateInternal()
            {
                GameObjects = agentObjects.ToList(), Stopped = Stopped, PlayerCollision = _playerCollision
            };

            CheckIfGameFinished(internalState, gameTime.TotalGameTime);
            if (Stopped)
            {
                internalState.Stopped = Stopped;
            }

            _gameStateManager.GameStateInternal = internalState;
            _gameStateManager.GameState         = GameStateMapper.GameStateToPublic(internalState);
            _gameStateManager.GameStateCounter++;


            if (_slowdown)
            {
                gameTime.ElapsedGameTime = TimeSpan.FromMilliseconds(gameTime.ElapsedGameTime.TotalMilliseconds / 5);
            }

            _gameObjects.ForEach(go => go.Update(gameTime));
            UpdateGameCourse(gameTime);
            CheckCollision(gameTime, _playerCollision);
        }
コード例 #4
0
 public static GameState GameStateToPublic(GameStateInternal state)
 {
     return(new GameState(state.GameObjects.Select(GameObjectStateToPublic).ToList(), state.Stopped, state.PlayerCollision));
 }