Update() публичный Метод

public Update ( ) : void
Результат void
Пример #1
0
 private void updateMapCamera(float timeSinceLastFrame)
 {
     if (playerAgent == null)
     {
         cameraHanlder.Update(timeSinceLastFrame);
     }
     else
     {
         playerAgent.Update(timeSinceLastFrame);
     }
 }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            mMenu.CheckRegisteredEvents();

            mCameraHandler.Update(gameTime.ElapsedGameTime.Milliseconds);

            mCamera.mLocation.Y = mScene.mTerrain.GetHeight(mCamera.mLocation) + 1.5f;

            // We need to calculate the collision of the camera with the terrain
            var location = mCamera.mLocation - mCamera.mThirdPersonDistance * mCamera.Direction;

            var height         = mScene.mTerrain.GetHeight(location);
            var relativeHeight = height - mCamera.mLocation.Y + 1.0f;
            var terrainAngle   = Math.Sinh(relativeHeight / mCamera.mThirdPersonDistance);

            if (mCamera.mRotation.Y < terrainAngle)
            {
                mCamera.mRotation.Y        = (float)terrainAngle;
                mCameraHandler.mRotation.Y = (float)terrainAngle;
            }

            if (mCamera.mRotation.Y > Math.PI / 3.5f)
            {
                mCamera.mRotation.Y        = (float)Math.PI / 3.5f;
                mCameraHandler.mRotation.Y = (float)Math.PI / 3.5f;
            }

            mScene.Update(mCamera, gameTime);

            mSilverback.Update(mScene.mTerrain, mCamera, mCameraHandler, mScene, gameTime);

            mLabel.Text = gameTime.ElapsedGameTime.Milliseconds + "ms 1002 movable actors";

            if (InputManager.MouseRightButtonPressed())
            {
                var raycast = RayCasting.CalculateMouseRayTerrainIntersection(mViewport, mCamera, mScene.mTerrain);

                if (!raycast.mIntersected)
                {
                    return;
                }

                mSubApe.SetTarget(raycast.mLocation);
            }
        }
Пример #3
0
        public void Update(GameTime gameTime)
        {
            Statistic.Time            += gameTime.ElapsedGameTime.Milliseconds;
            Statistic.CurrentSaveTime += gameTime.ElapsedGameTime.Milliseconds;

            var oldLocation = mCameraHandler.mLocation;

            mCameraHandler.Update(gameTime.ElapsedGameTime.Milliseconds);

            if (mLevel.mTerrain.GetSlope(mCameraHandler.mLocation) > Math.PI / 6.0f)
            {
                mCameraHandler.mLocation = oldLocation;
            }

            mLevel.Update(mCamera, mCameraHandler, gameTime);

            SoundManager.Update(gameTime, mLevel, mCamera);
        }
Пример #4
0
 private void Update()
 {
     _messageHub.Notify();
     _cameraHandler.Update();
     _unitHandler.Update();
 }
Пример #5
0
        public void Update(GameTime gameTime)
        {
            if (mSelectedMesh != null && mSelectedActor == null && !mSelectMode)
            {
                mSelectedActor       = new Actor(mSelectedMesh);
                mSelectedActor.Color = new Vector3(.3f, 0.3f, 0.3f);
                mLevel.Add(mSelectedActor);
            }

            SoundManager.Update(gameTime, mLevel, mCamera);

            mCameraHandler.Update(gameTime.ElapsedGameTime.Milliseconds);

            var state = Keyboard.GetState();

            // if (state.IsKeyDown(Keys.LeftShift))
            if (InputManager.AllKeysDown(Keys.LeftShift))
            {
                mShiftDown = true;
            }

            // if (state.IsKeyUp(Keys.LeftShift) && mShiftDown)
            if (InputManager.AllKeysUp(Keys.LeftShift) && mShiftDown)
            {
                if (mSelectMode)
                {
                    if (mLevel.mActorBatches.Count > 1)
                    {
                        mSelectedMesh = mLevel.mActorBatches[0].mMesh == mLevel.mTerrain.Actor.mMesh ? mLevel.mActorBatches[1].mMesh : mLevel.mActorBatches[0].mMesh;
                    }
                    mSelectMode = false;
                }
                else
                {
                    mSelectMode = true;
                    mLevel.Remove(mSelectedActor);
                    mSelectedActor = null;
                    mSelectedMesh  = null;
                }

                mShiftDown = false;
            }

            // if (state.IsKeyDown(Keys.Left))
            if (InputManager.AllKeysDown(Keys.Left))
            {
                mActorYRotation -= 0.005f * gameTime.ElapsedGameTime.Milliseconds;
            }

            // if (state.IsKeyDown(Keys.Right))
            if (InputManager.AllKeysDown(Keys.Right))
            {
                mActorYRotation += 0.005f * gameTime.ElapsedGameTime.Milliseconds;
            }

            // if (state.IsKeyDown(Keys.Up))
            if (InputManager.AllKeysDown(Keys.Up))
            {
                mActorYOffset += 0.005f * gameTime.ElapsedGameTime.Milliseconds;
            }

            // if (state.IsKeyDown(Keys.Down))
            if (InputManager.AllKeysDown(Keys.Down))
            {
                mActorYOffset -= 0.005f * gameTime.ElapsedGameTime.Milliseconds;
            }

            // if (state.IsKeyDown(Keys.Delete) && mSelectMode && mSelectedActor != null)
            if (InputManager.AllKeysDown(Keys.Delete) && mSelectMode && mSelectedActor != null)
            {
                mDeleteDown = true;
            }

            // if (state.IsKeyUp(Keys.Delete) && mDeleteDown)
            if (InputManager.AllKeysUp(Keys.Delete) && mDeleteDown)
            {
                if (mSelectedActor != null)
                {
                    mLevel.Remove(mSelectedActor);
                }
                mSelectedActor = null;
            }

            var mouseState = Mouse.GetState();

            if (!mSelectMode)
            {
                var intersection =
                    RayCasting.CalculateMouseRayTerrainIntersection(mViewport, mCamera, mLevel.mTerrain);

                if (intersection.mIntersected && mSelectedActor != null)
                {
                    intersection.mLocation.Y += mActorYOffset;
                    var matrix = Matrix.CreateRotationY(mActorYRotation) *
                                 Matrix.CreateTranslation(intersection.mLocation);
                    mSelectedActor.ModelMatrix = matrix;

                    // if (mouseState.RightButton == ButtonState.Pressed)
                    if (InputManager.MouseRightButtonPressed())
                    {
                        mRightMouseButtonDown = true;
                    }

                    // if (mouseState.RightButton != ButtonState.Pressed && mRightMouseButtonDown)
                    if (InputManager.MouseRightButtonReleased() && mRightMouseButtonDown)
                    {
                        mSelectedActor.Color  = new Vector3(1.0f);
                        mSelectedActor        = null;
                        mRightMouseButtonDown = false;
                        if (mSetOnce)
                        {
                            mSetOnce      = false;
                            mSelectMode   = true;
                            mSelectedMesh = null;
                        }
                    }
                }
            }
            else
            {
                // if (mouseState.RightButton == ButtonState.Pressed && mSelectedActor == null && !mDeleteDown)
                if (InputManager.MouseRightButtonPressed() && mSelectedActor == null && !mDeleteDown)
                {
                    var intersection =
                        RayCasting.CalculateMouseRayIntersection(mViewport, mCamera, mLevel, mLevel.mTerrain);

                    if (intersection.mIntersected && !intersection.mIsTerrainIntersection)
                    {
                        mSelectedActor       = intersection.mActor;
                        mSelectedActor.Color = new Vector3(0.3f);
                        mActorYRotation      = 0.0f;
                        mActorYOffset        = 0.0f;
                        mSelectedMesh        = mSelectedActor.mMesh;
                    }
                }

                // We need to check if the button is still pressed
                if (Mouse.GetState().RightButton == ButtonState.Pressed && mSelectedActor != null)
                {
                    var intersection =
                        RayCasting.CalculateMouseRayTerrainIntersection(mViewport, mCamera, mLevel.mTerrain);

                    if (intersection.mIntersected)
                    {
                        intersection.mLocation.Y  += mActorYOffset;
                        mSelectedActor.ModelMatrix = Matrix.CreateRotationY(mActorYRotation) * Matrix.CreateTranslation(intersection.mLocation);
                    }
                }

                // if (mouseState.RightButton == ButtonState.Released)
                if (InputManager.MouseRightButtonReleased())
                {
                    if (mSelectedActor != null)
                    {
                        mSelectedActor.Color = new Vector3(1.0f);
                    }
                    mSelectedActor = null;
                    mDeleteDown    = false;
                }
            }

            mLevel.Update(mCamera, mCameraHandler, gameTime);
        }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        InputHandler.HandleInputs();
        CameraHandler.Update();
        DisasterHandler.Update();

        switch (GameState)
        {
        case GameState.Idle:
            break;

        case GameState.DayCycle:
            // Time update
            CurCycleRealTime    += Time.deltaTime;
            _lastUpdateCycleTime = CycleTime;
            CycleTime            = (int)(CurCycleRealTime / CYCLE_REAL_TIME * CYCLE_TIME);

            // Cycle actions
            foreach (Building b in Buildings)
            {
                if (b.Health > 0 && b.CycleActionTime < CycleTime && b.CycleActionTime >= _lastUpdateCycleTime)
                {
                    b.CycleAction();
                }
            }
            foreach (Disaster d in CycleDisasters)
            {
                if (d.CycleTime < CycleTime && d.CycleTime >= _lastUpdateCycleTime)
                {
                    DisastersToShow.Enqueue(d);
                }
            }

            if (DisastersToShow.Count > 0)
            {
                ShowDisaster(DisastersToShow.Dequeue());
            }

            // New day
            if (CurCycleRealTime >= CYCLE_REAL_TIME)
            {
                StartNewDay();
            }

            // Light adjustments
            Vector3 sunRotation = Vector3.Lerp(new Vector3(50, -30, 0), new Vector3(410, 330, 0), CurCycleRealTime / CYCLE_REAL_TIME);
            Sun.transform.rotation = Quaternion.Euler(sunRotation);
            if (sunRotation.x < 140)
            {
                Moon.intensity = 0f;
            }
            else if (sunRotation.x < 220)
            {
                Moon.intensity = (sunRotation.x - 140) / 80 * MAX_MOON_INTENSITY;
            }
            else if (sunRotation.x < 320)
            {
                Moon.intensity = MAX_MOON_INTENSITY;
            }
            else if (sunRotation.x < 400)
            {
                Moon.intensity = MAX_MOON_INTENSITY - ((sunRotation.x - 320) / 80 * MAX_MOON_INTENSITY);
            }
            else
            {
                Moon.intensity = 0f;
            }
            if ((int)sunRotation.x == 180)
            {
                foreach (City city in Cities)
                {
                    city.CityLight.intensity = 1f;
                }
            }
            if ((int)sunRotation.x == 360)
            {
                foreach (City city in Cities)
                {
                    city.CityLight.intensity = 0f;
                }
            }
            break;

        case GameState.AlertFlash:
            _disasterTime += Time.deltaTime;
            if (_disasterTime > DISASTER_ALERT_TIME)
            {
                _disasterTime = 0f;
                CameraHandler.MoveTo(ActiveDisaster.Center);
                GameState = GameState.MoveToDisaster;
            }
            break;

        case GameState.MoveToDisaster:
            if (CameraHandler.State == CameraState.Idle)
            {
                _disasterTime += Time.deltaTime;
                if (_disasterTime > DISASTER_START_TIME_OFFSET)
                {
                    ActiveDisaster.CastVisualEffect();
                    ActiveDisaster.ApplyEffect();
                    GameState     = GameState.DisasterOccuring;
                    _disasterTime = 0f;
                }
            }
            break;

        case GameState.DisasterOccuring:
            _disasterTime += Time.deltaTime;
            if (_disasterTime > DISASTER_END_TIME_OFFSET)
            {
                GameUI.Alert_StopFlash();
                GameState = GameState.DayCycle;
            }

            break;
        }
    }