예제 #1
0
        public Main()
        {
            mGraphics = new GraphicsDeviceManager(this)
            {
                GraphicsProfile = GraphicsProfile.HiDef, PreferredBackBufferWidth = 1280, PreferredBackBufferHeight = 720
            };

            mCamera = new Camera(fieldOfView: 55.0f, aspectRatio: 2.0f, nearPlane: 1.0f, farPlane: 400.0f);
            mCamera.UpdatePerspective();

            mCamera.mLocation = new Vector3(0.0f, 0.0f, -10.0f);

            mScene = new Scene();
            mLight = new Light();

            mLight.mAmbient  = 0.1f;
            mLight.mLocation = new Vector3(1.0f, 1.0f, 0.0f) * 2000.0f;

            mCameraHandler = new CameraHandler(mCamera, 2.0f, 0.3f);

            mScene.Add(mLight);

            IsMouseVisible = true;

            Content.RootDirectory = "Content";
        }
예제 #2
0
        public void Update(Camera camera, CameraHandler handler, GameTime gameTime)
        {
            if (!mEditMode)
            {
                camera.mLocation.Y = mTerrain.GetHeight(camera.mLocation) + 1.5f;

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

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

                if (camera.mRotation.Y < terrainAngle)
                {
                    camera.mRotation.Y  = (float)terrainAngle;
                    handler.mRotation.Y = (float)terrainAngle;
                }

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

            Update(camera, gameTime);

            if (mTerrain != null)
            {
                // We have to disable this every frame
                mTerrain.Actor.mCastShadow = false;
                mTerrain.Actor.mRender     = true;
            }

            if (!mEditMode)
            {
                var removableActors = new List <Actor>();

                //Remove Dead actors from scene
                foreach (var actorbatch in mActorBatches)
                {
                    foreach (var actor in actorbatch.mActors)
                    {
                        if (actor.IActor is IEscape)
                        {
                            var current = (IEscape)actor.IActor;
                            if (current.IsAlive && current.HP <= 0)
                            {
                                if (current is DoubleAxeKiller || current is Lumberjack)
                                {
                                    Statistic.EscapedLumberjacks++;
                                    if (Statistic.EscapedLumberjacks >= 42)
                                    {
                                        Achievements.LumberjacksNightmare = true;
                                    }
                                }
                                if (current is Capuchin || current is Chimpanezee || current is Gibbon || current is OrangUtan)
                                {
                                    Statistic.EscapedApes++;
                                }

                                current.IsAlive = false;
                                current.Escape();
                                removableActors.Add(actor);
                            }
                        }
                    }
                }

                if (mSilverback.IsAlive && mSilverback.HP <= 0)
                {
                    removableActors.Add(mSilverback.Actor);
                }

                foreach (var actor in removableActors)
                {
                    Remove(actor);
                    mQuadTree.Remove(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                }

                var removableHuts = new List <Hut>();

                foreach (var hut in mHuts)
                {
                    if (hut.HP <= 0)
                    {
                        removableHuts.Add(hut);
                    }
                }
                foreach (var hut in removableHuts)
                {
                    mHuts.Remove(hut);
                    Remove(hut);
                    mQuadTree.Remove(hut.Actor, hut.Actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                }

                mSilverback.Update(mTerrain, camera, handler, this, gameTime);
            }
        }