示例#1
0
 public MainPage()
 {
     InitializeComponent();
     game = new LabGame(this);
     game.Run(this);
     mainMenu = new MainMenu(this);
     this.Children.Add(mainMenu);
 }
示例#2
0
        public Cube(LabGame game)
        {
            rand = new Random();
            Vector3 frontNormal  = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 backNormal   = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 topNormal    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
            {
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), frontNormal, Color.Orange),     // Front
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, -1.0f), frontNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, -1.0f), frontNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), frontNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, -1.0f), frontNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, -1.0f), frontNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, 1.0f), backNormal, Color.Orange),     // BACK
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), backNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, 1.0f), backNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, 1.0f), backNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, 1.0f), backNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), backNormal, Color.Orange),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, -1.0f), topNormal, Color.OrangeRed),     // Top
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, 1.0f), topNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), topNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, -1.0f), topNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), topNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, -1.0f), topNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), bottomNormal, Color.OrangeRed),     // Bottom
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, 1.0f), bottomNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, 1.0f), bottomNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), bottomNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, -1.0f), bottomNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, 1.0f), bottomNormal, Color.OrangeRed),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), leftNormal, Color.DarkOrange),     // Left
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, 1.0f), leftNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, 1.0f), leftNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(-1.0f, -1.0f, -1.0f), leftNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, 1.0f), leftNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(-1.0f, 1.0f, -1.0f), leftNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, -1.0f), rightNormal, Color.DarkOrange),     // Right
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), rightNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, 1.0f), rightNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(1.0f, -1.0f, -1.0f), rightNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, -1.0f), rightNormal, Color.DarkOrange),
                new VertexPositionNormalColor(new Vector3(1.0f, 1.0f, 1.0f), rightNormal, Color.DarkOrange),
            });

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

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game   = game;
        }
示例#3
0
 // Ensures that all objects are being rendered from a consistent viewpoint
 public Camera(LabGame game)
 {
     this.cameraPos    = game.player.pos;
     this.cameraTarget = cameraPos + new Vector3(0, 0, 10);
     View = Matrix.LookAtLH(cameraPos, cameraTarget, Vector3.UnitY);
     //Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f);
     Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.01f, 10000.0f);
     this.game  = game;
 }
示例#4
0
        public Player(LabGame game)
        {
            this.pos    = new Vector3(16, 10, 0);
            this.target = new Vector3(16, 12, 10);
            this.XAxis  = Vector3.UnitX;
            this.YAxis  = Vector3.UnitY;
            this.ZAxis  = Vector3.UnitZ;
            this.game   = game;
            type        = GameObjectType.Player;
            this.hp     = 100;

            enemySoundEffect = new SoundEffect(@"Content\UFO.wav", true);
        }
示例#5
0
        public Landscape(LabGame game)
        {
            this.game = game;
            type      = GameObjectType.Landscape;

            List <VertexPositionNormalTexture> landscapeVertices = new List <VertexPositionNormalTexture>();

            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(0.0f, LANDSCAPEHEIGHT, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 0.0f)));
            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(0.0f, LANDSCAPEHEIGHT, LANDSCAPEWIDTH), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 0.0f)));
            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(LANDSCAPEWIDTH, LANDSCAPEHEIGHT, LANDSCAPEWIDTH), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 1.0f)));

            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(0.0f, LANDSCAPEHEIGHT, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 0.0f)));
            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(LANDSCAPEWIDTH, LANDSCAPEHEIGHT, LANDSCAPEWIDTH), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(1.0f, 1.0f)));
            landscapeVertices.Add(new VertexPositionNormalTexture(new Vector3(LANDSCAPEWIDTH, LANDSCAPEHEIGHT, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 1.0f)));

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

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
        }
示例#6
0
 static void Main()
 {
     using (var program = new LabGame())
         program.Run();
 }
示例#7
0
        public Portal(LabGame game)
        {
            this.game    = game;
            type         = GameObjectType.Portal;
            this.pos     = new Vector3(r.Next(0, (int)game.landscape.getWidth()), 10, r.Next(0, (int)game.landscape.getWidth()));
            this.cubeCol = randomColor();

            float   size             = 2;
            Vector3 frontBottomLeft  = new Vector3(-size, -size, -size);
            Vector3 frontTopLeft     = new Vector3(-size, size, -size);
            Vector3 frontTopRight    = new Vector3(size, size, -size);
            Vector3 frontBottomRight = new Vector3(size, -size, -size);
            Vector3 backBottomLeft   = new Vector3(-size, -size, size);
            Vector3 backBottomRight  = new Vector3(size, -size, size);
            Vector3 backTopLeft      = new Vector3(-size, size, size);
            Vector3 backTopRight     = new Vector3(size, size, size);

            Vector3 frontNormal  = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 backNormal   = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 topNormal    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            Vector3 frontBottomLeftNormal  = new Vector3(-0.333f, -0.333f, -0.333f);
            Vector3 frontTopLeftNormal     = new Vector3(-0.333f, 0.333f, -0.333f);
            Vector3 frontTopRightNormal    = new Vector3(0.333f, 0.333f, -0.333f);
            Vector3 frontBottomRightNormal = new Vector3(0.333f, -0.333f, -0.333f);
            Vector3 backBottomLeftNormal   = new Vector3(-0.333f, -0.333f, 0.333f);
            Vector3 backBottomRightNormal  = new Vector3(0.333f, -0.333f, 0.333f);
            Vector3 backTopLeftNormal      = new Vector3(-0.333f, 0.333f, 0.333f);
            Vector3 backTopRightNormal     = new Vector3(0.333f, 0.333f, 0.333f);

            Color portalColor = Color.White;

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

            //basicEffect = new BasicEffect(game.GraphicsDevice)
            //{
            //    VertexColorEnabled = true,
            //    View = Matrix.LookAtLH(game.camera.cameraPos, game.camera.cameraTarget, 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);

            hitSoundEffect = new SoundEffect(@"Content\eat.wav", false);
        }
示例#8
0
 // Constructor.
 public EnemyController(LabGame game)
 {
     this.type = GameObjectType.Controller;
     this.game = game;
 }
示例#9
0
        public Enemy(LabGame game, Vector3 pos, EnemyType enemyType, float speed)
        {
            this.game      = game;
            type           = GameObjectType.Enemy;
            this.pos       = pos;
            this.enemyType = enemyType;

            this.wanderAngle = 0;
            //this.velocity = new Vector3(this.r.NextFloat(-1, 0), 0, this.r.NextFloat(-1, 0));
            this.velocity = new Vector3(0, 0, 0);


            setAttribute(enemyType, speed);

            float   size             = 3;
            Vector3 frontBottomLeft  = new Vector3(-size, -size, -size);
            Vector3 frontTopLeft     = new Vector3(-size, size, -size);
            Vector3 frontTopRight    = new Vector3(size, size, -size);
            Vector3 frontBottomRight = new Vector3(size, -size, -size);
            Vector3 backBottomLeft   = new Vector3(-size, -size, size);
            Vector3 backBottomRight  = new Vector3(size, -size, size);
            Vector3 backTopLeft      = new Vector3(-size, size, size);
            Vector3 backTopRight     = new Vector3(size, size, size);

            Vector3 frontNormal  = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 backNormal   = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 topNormal    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            Vector3 frontBottomLeftNormal  = new Vector3(-0.333f, -0.333f, -0.333f);
            Vector3 frontTopLeftNormal     = new Vector3(-0.333f, 0.333f, -0.333f);
            Vector3 frontTopRightNormal    = new Vector3(0.333f, 0.333f, -0.333f);
            Vector3 frontBottomRightNormal = new Vector3(0.333f, -0.333f, -0.333f);
            Vector3 backBottomLeftNormal   = new Vector3(-0.333f, -0.333f, 0.333f);
            Vector3 backBottomRightNormal  = new Vector3(0.333f, -0.333f, 0.333f);
            Vector3 backTopLeftNormal      = new Vector3(-0.333f, 0.333f, 0.333f);
            Vector3 backTopRightNormal     = new Vector3(0.333f, 0.333f, 0.333f);

            Color enemyColor  = Color.Crimson;
            Color bottomColor = Color.White;

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
            {
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, enemyColor),     // Front
                new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, enemyColor),
                new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, enemyColor),
                new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, enemyColor),     // BACK
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
                new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, enemyColor),
                new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, enemyColor),
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, enemyColor),     // Top
                new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, bottomColor),     // Bottom
                new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, bottomColor),
                new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, bottomColor),
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, bottomColor),
                new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, bottomColor),
                new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, bottomColor),
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, enemyColor),     // Left
                new VertexPositionNormalColor(backBottomLeft, backBottomLeftNormal, enemyColor),
                new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomLeft, frontBottomLeftNormal, enemyColor),
                new VertexPositionNormalColor(backTopLeft, backTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(frontTopLeft, frontTopLeftNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, enemyColor),     // Right
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
                new VertexPositionNormalColor(backBottomRight, backBottomRightNormal, enemyColor),
                new VertexPositionNormalColor(frontBottomRight, frontBottomRightNormal, enemyColor),
                new VertexPositionNormalColor(frontTopRight, frontTopRightNormal, enemyColor),
                new VertexPositionNormalColor(backTopRight, backTopRightNormal, enemyColor),
            });
            //effect = game.Content.Load<Effect>("Phong");

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game   = game;
        }