Beispiel #1
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="type">Type</param>
        /// <param name="positionMatrix">Position matrix</param>
        public static void Add(AnimatedTypes type, Matrix positionMatrix,
			AnimatedGameObject.DropObject dropObject)
        {
            animatedObjects.Add(new AnimatedGameObject(type, positionMatrix,
                dropObject));
        }
 /// <summary>
 /// Reset
 /// </summary>
 public override void Reset()
 {
     playerPos = InitialPlayerPosition;
     wannaHavePlayerPos = InitialPlayerPosition;
     xRotation = InitialXRotation;
     zRotation = InitialZRotation;
     playerRotation = InitialPlayerRotation;
     wannaHaveXRotation = InitialXRotation;
     wannaHaveZRotation = InitialZRotation;
     wannaHavePlayerRotation = InitialPlayerRotation;
     playerObject = new AnimatedGameObject(
         GameManager.AnimatedTypes.Hero, Matrix.Identity);
 }
        /// <summary>
        /// TestPlayerColladaModelScene
        /// </summary>
        public static void TestPlayerColladaModelScene()
        {
            AnimatedGameObject player = null;
            AnimatedColladaModel playerModel = null;
            //obs: PlaneRenderer groundPlane = null;

            TestGame.Start("TestPlayerColladaModelScene",
                delegate
                {
                    // Load Player
                    player = new AnimatedGameObject(
                        GameManager.AnimatedTypes.Hero,
                        Matrix.Identity);
                    playerModel = new AnimatedColladaModel(
                        //"Hero");
                        //"Goblin");
                        //"GoblinMaster");
                        "GoblinWizard");
                        //"Ogre");
                        //"BigOgre");

                    // Play background music :)
                    //Sound.StartMusic();

              /*obs
                    // Create ground plane
                    groundPlane = new PlaneRenderer(
                        new Vector3(0, 0, -0.001f),
                        new Plane(new Vector3(0, 0, 1), 0),
                        new Material(
                            "CaveDetailGround", "CaveDetailGroundNormal",
                            "CaveDetailGroundHeight"),
                        28);
              */

                    // Set light direction (light is coming from the front right pos).
                    BaseGame.LightDirection = new Vector3(-18, -20, 16);
                },
                delegate
                {
                    // Start glow shader
                    //BaseGame.GlowShader.Start();

                    // Clear background with white color, looks much cooler for the
                    // post screen glow effect.
                    //BaseGame.Device.Clear(Color.White);

                    // Render goblin always in center, but he is really big, bring him
                    // down to a more normal size that fits better in our test scene.
                    Matrix renderMatrix =
                        Input.Keyboard.IsKeyDown(Keys.LeftControl) ?
                        Matrix.CreateScale(0.8f) *
                        Matrix.CreateRotationZ(1.4f) *
                        Matrix.CreateTranslation(1, 1, 0) :
                        Input.Keyboard.IsKeyDown(Keys.LeftAlt) ?
                        Matrix.CreateTranslation(1, 1, 0) :
                        Matrix.CreateTranslation(0, 0, -1);
                        //Matrix.Identity; // should work!
                        //Matrix.CreateScale(0.01f);

                    // Restore z buffer state
                    BaseGame.Device.RenderState.DepthBufferEnable = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;
            //TODO: when we got more time to test
                    /*
                    // Make sure we use skinned tangent vertex format for shadow mapping
                    BaseGame.Device.VertexDeclaration =
                        SkinnedTangentVertex.VertexDeclaration;

                    // Generate shadows
                    ShaderEffect.shadowMapping.GenerateShadows(
                        delegate
                        {
                            playerModel.GenerateShadow(renderMatrix);
                        });

                    // Render shadows
                    ShaderEffect.shadowMapping.RenderShadows(
                        delegate
                        {
                            playerModel.UseShadow(renderMatrix);
                            groundPlane.UseShadow();
                        });
                    //*/

                    /*obs
                    // Show ground with DiffuseSpecular material and use parallax mapping!
                    groundPlane.Render(
                        //ShaderEffect.normalMapping, "DiffuseSpecular30");
                        );//just used for testing, looks good: ShaderEffect.parallaxMapping);
                     */

                    // Update game time
                    Player.SetGameTimeMs(BaseGame.TotalTimeMs);

                    // Cycle around with Z/X
                    if (Input.KeyboardKeyJustPressed(Keys.Z))
                        player.state = (AnimatedGameObject.States)
                            (((int)player.state + 1) % NumberOfAnimationTypes);
                    else if (Input.KeyboardKeyJustPressed(Keys.X))
                        player.state = (AnimatedGameObject.States)
                            (((int)player.state + NumberOfAnimationTypes - 1) %
                            NumberOfAnimationTypes);
                    // And update all blend states
                    player.UpdateState();

                    // Render the model with the current animation
                    playerModel.Render(
                        renderMatrix,
                        //Matrix.Identity,
                        player.blendedStates);
                        //new float[] { 1, 0, 0, 0, 0 });

                    TextureFont.WriteText(2, 30, "Press Z/X to change the animation");

                    TextureFont.WriteText(2, 60, "Blended states: " +
                        StringHelper.WriteArrayData(player.blendedStates));

                    // show fire flare at weapon for testing, use wizard!
                    Vector3 weaponPos = playerModel.GetWeaponPos(renderMatrix);
                    EffectManager.AddFireBallEffect(weaponPos, 0, 0.25f);
                    BaseGame.effectManager.HandleAllEffects();

                    /*obs
                    // And show all goblins
                    for (int x = 0; x < 2; x++)
                        for (int y = 0; y < 3; y++)
                            playerModel.Render(
                                renderMatrix *
                                Matrix.CreateTranslation(-5 + 10 * x, -10 + 10 * y, 0));
                     */

                    // And show shadows on top of the scene (with shadow blur effect).
                    //TODO: ShaderEffect.shadowMapping.ShowShadows();

                    // And finally show glow shader on top of everything
                    /*BaseGame.GlowShader.Show();
                     */

                    // If you press the right mouse button or B you can see all
                    // shadow map and post screen render targets (for testing/debugging)
                    if (Input.MouseRightButtonPressed ||
                        Input.GamePadBPressed)
                    {
                        BaseGame.AlphaBlending = false;
                        BaseGame.Device.RenderState.AlphaTestEnable = false;
                        // Line 1 (3 render targets, 2 shadow mapping, 1 post screen)
                        ShaderEffect.shadowMapping.shadowMapTexture.RenderOnScreen(
                            new Rectangle(10, 10, 256, 256));
                        ShaderEffect.shadowMapping.shadowMapBlur.SceneMapTexture.
                            RenderOnScreen(
                            new Rectangle(10 + 256 + 10, 10, 256, 256));
                        PostScreenGlow.sceneMapTexture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10 + 256 + 10, 10, 256, 256));
                        // Line 2 (3 render targets, 2 post screen blurs, 1 final scene)
                        PostScreenGlow.downsampleMapTexture.RenderOnScreenNoAlpha(
                            new Rectangle(10, 10 + 256 + 10, 256, 256));
                        PostScreenGlow.blurMap1Texture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10, 10 + 256 + 10, 256, 256));
                        PostScreenGlow.blurMap2Texture.RenderOnScreenNoAlpha(
                            new Rectangle(10 + 256 + 10 + 256 + 10, 10 + 256 + 10, 256, 256));
                    } // if (Input.MouseRightButtonPressed)
                    //*/
                });
        }
        /// <summary>
        /// Update player position
        /// </summary>
        /// <param name="playerPos">Player position</param>
        /// <param name="movement">Movement</param>
        /// <param name="isMonster">Is monster</param>
        public static void UpdatePlayerPosition(ref Vector3 playerPos,
			Vector3 movement, bool isMonster, AnimatedGameObject obj)
        {
            if (caveCollision == null)
                Load();

            float movementAmount = movement.Length();

            // Do not do anything if we are not moving!
            if (obj.isFlyingCounter == 0 &&
                movementAmount < 0.001f)
                return;

            // Check the door, we can only move through it when we got the key!
            if (Player.gotKey == false)
            {
                // No key, then stop moving here!
                BounceOff(playerPos, GameManager.doorPosition, 3.5f, ref movement);
            } // if (Vector3.Distance)

            // Also bounce of every enemy and the player except ourself (see obj)
            if (obj != BaseGame.camera.playerObject)
                BounceOff(playerPos, BaseGame.camera.PlayerPos, 1.25f, ref movement);
            foreach (AnimatedGameObject model in GameManager.animatedObjects)
                if (model != obj &&
                    // Should be alive
                    model.state != AnimatedGameObject.States.Die)
                    BounceOff(playerPos, model.positionMatrix.Translation,
                        0.25f + model.sizeVariation, ref movement);

            // Use 9.81m/s gravitation (use /2.75 because it is getting hard
            // getting up some tunnels and it stafes back all the time).
            movement.Z = -9.81f * BaseGame.MoveFactorPerSecond * 0.85f;// / 2.75f;
            // Monsters move slower and this will make it too hard to move up hills!
            //if (obj.wasAboveGroundLastFrame == false)
            //	movement.Z /= 2.0f;
            if (isMonster)
                movement.Z /= 2.5746523f;

            Vector3 newPosition = playerPos + movement;
            Vector3 newVelocity = Vector3.Zero;

            Vector3 oldPosition = playerPos;
            newPosition = playerPos + movement;// +new Vector3(0, 0, 0);
            Vector3 polyPoint;
            caveCollision.PointMove(
                // Always add a little height to the player position just
                // to make sure we never fall out of the level!
                playerPos,// + new Vector3(0, 0, 0.00005f),
                newPosition, 1.0f, 0.1f, 3,
                out newPosition, ref newVelocity, out polyPoint);

            float groundDist = playerPos.Z - polyPoint.Z;
            playerPos = newPosition;

            // Reached ground? Then stop flying mode and stop moving
            // if no movement is used.
            if (obj.isFlyingCounter > 0 &&
                //(isMonster == false || groundDist > 0) &&
                groundDist > 0 &&
                Math.Abs(groundDist) < 0.05f * 50 * BaseGame.MoveFactorPerSecond)
                obj.isFlyingCounter--;
                // Flying again? Then allow dropping to the ground
            else if (obj.isFlyingCounter == 0 &&
                Math.Abs(groundDist) > 0.5f)
                obj.isFlyingCounter = 1;

            // If we are below the ground, fix it.
            if (obj.isFlyingCounter == 0 &&
                groundDist < -0.25f)
                playerPos.Z += -groundDist +0.0025f;
        }