Exemplo n.º 1
0
        public Player(Project2Game game)
        {
            size = initSize;
            moveSpeed = mSpeed;
            spinSpeed = sSpeed;
            Random rand = new Random();
            color = rand.NextColor();

            pos = game.landscape.getStartPoint();
            pos.Y += size;
            oldPos = Vector3.Zero;
            rot = Matrix.Identity;

            generateSphere(size, color);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                originalPoints);

            this.effect = game.Content.Load<Effect>("Phong");

            effect.Parameters["lightPntCol"].SetValue(game.sun.color.ToColor4());

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Exemplo n.º 2
0
        public Enemy(Project2Game game, Vector3 pos, float size, Color color)
        {
            this.size = size;
            this.pos = pos;
            this.pos.Y += size;
            this.color = color;
            oldPos = Vector3.Zero;
            rot = Matrix.Identity;
            moveSpeed = 0.2f / this.size * 0.006f;

            // Speed is inversely proportional to size
            if (game.hardDifficulty == true)
            {
                moveSpeed = 0.4f / this.size * 0.008f;
            }

            spinSpeed = 0.05f;

            generateSphere(size, color);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                originalPoints);

            this.effect = game.Content.Load<Effect>("Cel");

            effect.Parameters["lightPntCol"].SetValue(game.sun.color.ToColor4());

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Exemplo n.º 3
0
 public MainPage()
 {
     InitializeComponent();
     game = new Project2Game(this);
     game.Run(this);
     mainMenu = new MainMenu(this);
     this.Children.Add(mainMenu);
     GameElements.Visibility = Visibility.Collapsed;
 }
Exemplo n.º 4
0
        public Sun(Project2Game game)
        {
            // start position of the sun.
            pos = new Vector3(centre, 0, centre);

            generateSphere(size, color);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                originalPoints);

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, -10), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f),
                World = Matrix.Identity
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Exemplo n.º 5
0
        public Landscape(Project2Game game)
        {
            r = new Random(seed);

            // generate the height map
            heightMap = DiamondSquareGrid(gridSize, seed, minHeight, maxHeight, roughness / 10.0f);

            // the number of vertices we will need
            int vertexCount = (gridSize - 1) * (gridSize - 1) * 6 + 12; // 12 for water

            // initialise the mesh
            VertexPositionNormalColor[] mesh = new VertexPositionNormalColor[vertexCount];

            // calculate the average height in Y off which to base colour.
            float sum = 0;
            for (int x = 0; x < gridSize - 1; x++)
            {
                for (int z = 0; z < gridSize - 1; z++)
                {
                    float y = heightMap[x][z];
                    sum += y;
                    if (y > biggestY)
                    {
                        biggestY = y;
                    }
                    else if (y < smallestY)
                    {
                        smallestY = y;
                    }
                }
            }
            averageHeight = sum / ((gridSize - 1)* (gridSize - 1));
            rangeY = biggestY - smallestY;
            waterHeight = smallestY + (rangeY / 2) - rangeY * 0.1f;

            // adjust camera to be above land and water (STATIC IN CAMERA CLASS NOW)
            // float heightAtCamera = heightAtPoint(cameraPosition.X, cameraPosition.Y);
            // cameraPosition.Y += ((waterHeight >= heightAtCamera) ? waterHeight : heightAtCamera);

            // generate vertices for the triangles based on the height map
            int counter = 0;
            for (int x=0; x<gridSize-1; x++)
            {
                for (int z=0; z<gridSize-1; z++)
                {
                    // pos Z
                    // tl - - tr
                    //  | \   |
                    //  |   \ |
                    // bl - - br  pos X

                    float botLeft = heightMap[x][z];
                    float topLeft = heightMap[x][z + 1];
                    float botRight = heightMap[x + 1][z];
                    float topRight = heightMap[x + 1][z + 1];

                    // Triangle A
                    Vector3 a1 = new Vector3(x * scale, botLeft * scale, z * scale);
                    Vector3 a2 = new Vector3(x * scale, topLeft * scale, z * scale + scale);
                    Vector3 a3 = new Vector3(x * scale + scale, botRight * scale, z * scale);
                    Vector3 aNormal = -Vector3.Cross(a1 - a2, a3  - a1);

                    mesh[counter++] = new VertexPositionNormalColor(a1, aNormal, getColor(a1.Y));
                    mesh[counter++] = new VertexPositionNormalColor(a2, aNormal, getColor(a2.Y));
                    mesh[counter++] = new VertexPositionNormalColor(a3, aNormal, getColor(a3.Y));

                    // Triangle B
                    Vector3 b1 = new Vector3(x * scale, topLeft * scale, z * scale + scale);
                    Vector3 b2 = new Vector3(x * scale + scale, topRight * scale, z * scale + scale);
                    Vector3 b3 = new Vector3(x * scale + scale, botRight * scale, z * scale);
                    Vector3 bNormal = -Vector3.Cross(b1 - b2, b3 - b1);

                    mesh[counter++] = new VertexPositionNormalColor(b1, bNormal, getColor(b1.Y));
                    mesh[counter++] = new VertexPositionNormalColor(b2, bNormal, getColor(b2.Y));
                    mesh[counter++] = new VertexPositionNormalColor(b3, bNormal, getColor(b3.Y));
                }
            }

            // WATER !
            // Top Triangle A
            Vector3 wt11 = new Vector3(0.0f, waterHeight * scale, 0.0f);
            Vector3 wt12 = new Vector3(0.0f, waterHeight * scale, (gridSize - 1) * scale);
            Vector3 wt13 = new Vector3((gridSize - 1) * scale, waterHeight * scale, 0.0f);

            mesh[counter++] = new VertexPositionNormalColor(wt11, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt12, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt13, Vector3.UnitY, waterColor);

            // Top Triangle B
            Vector3 wt21 = new Vector3(0.0f, waterHeight * scale, (gridSize - 1) * scale);
            Vector3 wt22 = new Vector3((gridSize - 1) * scale, waterHeight * scale, (gridSize - 1) * scale);
            Vector3 wt23 = new Vector3((gridSize - 1) * scale, waterHeight * scale, 0.0f);

            mesh[counter++] = new VertexPositionNormalColor(wt21, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt22, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt23, Vector3.UnitY, waterColor);

            // Bottom (reverse triangle definitions)
            mesh[counter++] = new VertexPositionNormalColor(wt11, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt13, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt12, Vector3.UnitY, waterColor);

            mesh[counter++] = new VertexPositionNormalColor(wt21, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt23, Vector3.UnitY, waterColor);
            mesh[counter++] = new VertexPositionNormalColor(wt22, Vector3.UnitY, waterColor);

            // Create vertex buffer
            vertices = Buffer.Vertex.New(game.GraphicsDevice, mesh);
            this.effect = game.Content.Load<Effect>("Phong");

            // Setup parameters

            this.World = Matrix.Identity;
            this.WorldInverseTranspose = Matrix.Transpose(Matrix.Invert(this.World));

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World = Matrix.Identity
            };

            // Lighting
            basicEffect.LightingEnabled = true;
            basicEffect.AmbientLightColor = new Vector3(0.15f, 0.15f, 0.15f);
            basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.4f, 0.4f, 0.4f);
            basicEffect.DirectionalLight0.SpecularColor = new Vector3(0.8f, 0.8f, 0.8f);

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Exemplo n.º 6
0
 // Constructor.
 public EnemyController(Project2Game game)
 {
     this.game = game;
     enemies = new List<Enemy>();
     spawnEnemies();
 }
Exemplo n.º 7
0
 public Camera(Project2Game game)
 {
     freeCamera = false;
     Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f);
 }