Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void Update(GameTime time)
        {
            if (IsVisible && !mWasVisible)
            {
                mWasVisible = true;
                mGameScreen.mCameraHandler.Unlock();
            }

            if (mGameScreen.IsVisible)
            {
                IsVisible = true;
            }

            if (mHudStartTime == 0)
            {
                mHudStartTime = time.TotalGameTime.TotalMilliseconds;
            }

            var hudTime  = time.TotalGameTime.TotalMilliseconds - mHudStartTime;
            var timeSpan = TimeSpan.FromMilliseconds(hudTime);

            mTimeLabel.Text = "Time: " + timeSpan.Minutes + ":" + timeSpan.Seconds;

            if (mGameScreen.mLevel.mLevelStory != null)
            {
                mContinueLabel.mTextColor = Color.White *
                                            (float)(Math.Sin(time.TotalGameTime.TotalMilliseconds / 200.0f) * 0.5f +
                                                    0.5f);
            }

            if (mGameScreen.mLevel.mSilverback != null)
            {
                mHPLabel.Text = "HP: " + mGameScreen.mLevel.mSilverback.HP.ToString() + " / " + mGameScreen.mLevel.mSilverback.mMaxHP.ToString();
            }

            DisableUnusedApeSelectorButtons();

            // Iterate over all Menu elements
            foreach (var menu in mMenuList)
            {
                if (!menu.mIsVisible)
                {
                    continue;
                }
                menu.CheckRegisteredEvents();
            }

            if (mActorBatch != null && InputManager.MouseRightButtonPressed())
            {
                var raycast = RayCasting.CalculateMouseRayTerrainIntersection(mGameScreen.mViewport, mGameScreen.mCamera, mGameScreen.mLevel.mTerrain);

                if (!raycast.mIntersected)
                {
                    return;
                }

                foreach (var actor in mActorBatch.mActors)
                {
                    var movable = (IMoveable)actor.IActor;
                    movable.SetTarget(raycast.mLocation);
                }
            }

            if (mGameScreen.mLevel.mSilverback.HP <= 0)
            {
                ScreenManager.Remove(this);
                ScreenManager.Add(mLoseScreen);
                Statistic.Lost++;
            }

            if (mGameScreen.mLevel.mHuts.Count == 0)
            {
                ScreenManager.Remove(this);
                ScreenManager.Add(mWinScreen);
                Statistic.Win++;
            }
        }