Пример #1
0
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GameScreenManager.GraphicsDevice);
            background  = content.Load <Texture2D>("back");

            // Setting up render target
            PresentationParameters pp = ScreenManager.GraphicsDevice.PresentationParameters;

            renderTarget = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, SurfaceFormat.Color, DepthFormat.Depth24);
            postProcess  = content.Load <Effect>("PostProcess");
            postProcess.Parameters["darkenFactor"].SetValue(1f);

            virtualTerrain               = content.Load <Effect>("virtualTerrain");
            CustomTerrainRenderer.wire   = content.Load <Texture2D>("wire");
            CustomTerrainRenderer.effect = virtualTerrain;

            terrainRenderer = new CustomTerrainRenderer(Vector2.One * 200);

            terrainObject       = GameObject3d.Initialize();
            terrainRenderer.obj = terrainObject;

            terrainObject.material = terrainRenderer;

            //SET CAM
            camera = new Camera();
            camera.Transform.LocalPosition += new Vector3(100, 0, 10);
            camera.Transform.Rotate(Vector3.Up, (float)Math.PI);
            Vector3 pos = camera.Transform.Position;

            pos.Y = 2 + terrainRenderer.GetAltitude(camera.Transform.Position);
            camera.Transform.LocalPosition = pos;
            camera.NearPlane = 0.001f;

            // Setup skybox
            camera.skybox = new Skybox {
                skyboxModel = content.Load <Model>("Box"), skyboxTexture = background
            };
            Skybox.shader = content.Load <Effect>("skybox");

            //SET HOOP
            hoopLogic.player   = camera;
            hoopObject.lastPos = camera.Transform.LocalPosition + new Vector3(0, 2, 100);
            hoopObject.Initialize();

            //sfx
            staticNoise        = content.Load <Song>("static");
            MediaPlayer.Volume = 0.2f;

            foreach (GameObject3d gameObject in GameObject3d.activeGameObjects)
            {
                gameObject.Start();
            }
            GameObject.gameStarted = true;
        }
        public void getNextHoopPos()
        {
            float   xOffset       = -(lastPos.X - 100) / 2; // should normalize around the center
            Vector3 nextPos       = lastPos + new Vector3(ran.Next(-25, 25) + xOffset, ran.Next(-8, 5) + (float)Math.Pow(MathHelper.Clamp(-(lastPos.Y - 23), 0, 5), 2), +80);
            float   terrainHeight = CustomTerrainRenderer.GetHeight(nextPos.X, nextPos.Z);

            if (nextPos.Y < terrainHeight)
            {
                nextPos.Y = terrainHeight;
            }
            transform.LocalPosition = nextPos;
            lastPos = transform.LocalPosition;
        }