Пример #1
0
        protected override void LoadContent()
        {
            //Load game content
            model = new Landscape(this, this.scale);
            water = new Water(this);
            lightsource = new Sun(this);
            this.camera = new Camera(this);

            base.LoadContent();
        }
Пример #2
0
        public void LoadLevel(int level)
        {
            this.level = level;
            landscape = new Landscape(this, level);

            // Create game objects.

            //for (int i = 0; i < 100; i++)
            //{
            //    Random random = new Random();
            //    xtree = (float)random.NextDouble() * 4;
            //    ytree = (float)random.NextDouble() * 4;

            //    if (landscape.getHeight(xtree, ytree) > -0.1)
            //    {
            //        Debug.WriteLine("works");
            //        Tree tree;
            //        tree = new Tree(this);
            //        gameObjects.Add(tree);
            //        tree.basicEffect.World = Matrix.Scaling(0.001f) * Matrix.Translation(xtree, (landscape.getHeight(xtree, ytree) + 1f), ytree);
            //    }

            //}

            ballMovement = new BallMovement(this);
            cannonModel = new CannonModel(this);
            arrow = new Arrow(this);

            gameObjects.Add(ballMovement);
            gameObjects.Add(new SkyBoxController(this));

            //this.cannonTargetVect = new Vector2(x1 - x0, z1 - z0);
            gameObjects.Add(landscape);
            gameObjects.Add(cannonModel);
            gameObjects.Add(arrow);

            //Set the inital postion of the ball
            ballMovement.pos = landscape.getCannonPos().Position;
            y0 = landscape.getCannonPos().Position.Y;
            x0 = landscape.getCannonPos().Position.X;
            z0 = landscape.getCannonPos().Position.Z;

            //inital the postion of the arrow
            x1 = landscape.getTargetPos().Position.X;
            y1 = landscape.getTargetPos().Position.Y;
            z1 = landscape.getTargetPos().Position.Z;
        }
Пример #3
0
        protected override void LoadContent()
        {
            float x = worldSize/2f;
            float y = 0f;
            float z = (float)Math.PI;
            float rotationSpeed = 0.005f;
            float sideLength = 50f;
            model = new Landscape(this, rotationSpeed, worldSize);
            sun = new Sun(this, x, y, z, sideLength, rotationSpeed, worldSize);

            // Create an input layout from the vertices

            base.LoadContent();
        }
Пример #4
0
        public Sun(Game game, Landscape landscape)
        {
            this.landscape = landscape;
            this.terrain = landscape.Terrain;
            float sunsize = terrain.max / 4;
            numberUpdates = 80f;
            frontBottomLeftNormal = new Vector3(-0.333f, -0.333f,-0.333f);
            frontTopLeftNormal = new Vector3(-0.333f, 0.333f, -0.333f);
            frontTopRightNormal = new Vector3(0.333f, 0.333f, -0.333f);
            frontBottomRightNormal = new Vector3(0.333f,-0.333f, -0.333f);
            backBottomLeftNormal = new Vector3(-0.333f, -0.333f, 0.333f);
            backBottomRightNormal = new Vector3(0.333f, -0.333f, 0.333f);
            backTopLeftNormal = new Vector3(-0.333f,0.333f,0.333f);
            backTopRightNormal = new Vector3(0.333f, 0.333f , 0.333f);

            float sunX, sunY, sunZ, sunOffset;
            sunX = terrain.size; sunY = terrain.maxHeight + 10f; sunZ = terrain.size/2; sunOffset = 40f;
            frontBottomLeft = new Vector3(sunX-sunOffset, sunY - sunOffset, sunZ-sunOffset);
            frontTopLeft = new Vector3(sunX-sunOffset, sunY + sunOffset, sunZ-sunOffset);
            frontTopRight = new Vector3(sunX + sunOffset, sunY + sunOffset, sunZ-sunOffset);
            frontBottomRight = new Vector3(sunX + sunOffset, sunY - sunOffset, sunZ-sunOffset);
            backBottomLeft = new Vector3(sunX-sunOffset, sunY - sunOffset, sunZ + sunOffset);
            backBottomRight = new Vector3(sunX + sunOffset, sunY - sunOffset, sunZ + sunOffset);
            backTopLeft = new Vector3(sunX-sunOffset, sunY + sunOffset, sunZ + sunOffset);
            backTopRight = new Vector3(sunX + sunOffset, sunY + sunOffset, sunZ + sunOffset);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
                    {
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow), // Front
                    new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, Color.Yellow), // BACK
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, Color.Yellow), // Top
                    new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow), // Bottom
                    new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow), // Left
                    new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, Color.Yellow), // Right
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, Color.Yellow),
                    new VertexPositionNormalColor(backTopRight, backTopRightNormal, Color.Yellow),
            });

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(landscape.currentPosition, landscape.currentTarget, landscape.currentUp),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, -10.0f, (float)terrain.size * 2),
                World = Matrix.Identity,
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
        protected override void LoadContent()
        {
            model = new Landscape(this, 1, 1, 1, 1, 11);

            // Camera object containing all Camera specific controls and info
            int camX = 50;
            int camZ = 50;
            Vector3 pos = new Vector3(camX, model.heightMap[camX][camX] + 50, camZ);
            Vector3 target = pos + new Vector3(1, 0, 1);
            this.camera = new Camera(pos, target, Vector3.UnitY, this);

            // Create an input layout from the vertices

            base.LoadContent();
        }