예제 #1
0
        public void AddTexture(float left, float right, float bottom, float top, Color color, Texture texture, float left_texture, float right_texture, float bottom_texture, float top_texture)
        {
            PolygonTextured pt = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(left, top));
            pt.AddTex(new Vector2(left_texture, top_texture));
            pt.AddVertex(new Vector2(right, top));
            pt.AddTex(new Vector2(left_texture, bottom_texture));
            pt.AddVertex(new Vector2(right, bottom));
            pt.AddTex(new Vector2(right_texture, bottom_texture));
            pt.AddVertex(new Vector2(left, bottom));
            pt.AddTex(new Vector2(right_texture, top_texture));
            pt.Color = color;
            world.Add(pt);
        }
예제 #2
0
        private void AddTriangle(Vector2 location, float width, float height, string texture)
        {
            Texture         t = TextureLoader.FromFile(device, texture);
            PolygonTextured p = new PolygonTextured();

            p.Tex = t;
            p.AddVertex(new Vector2(location.X - width / 2, location.Y + height / 2));
            p.AddTex(new Vector2(0, 1));

            p.AddVertex(new Vector2(location.X + width / 2, location.Y + height / 2));
            p.AddTex(new Vector2(1, 1));

            p.AddVertex(new Vector2(location.X, location.Y - height / 2));
            p.AddTex(new Vector2(.5f, 0));

            world.Add(p);
        }
예제 #3
0
파일: Game.cs 프로젝트: klugaman/CSE471
        public void AddTexture(float left, float right, float bottom, float top, Color color, Texture texture, float left_texture, float right_texture, float bottom_texture, float top_texture)
        {
            PolygonTextured pool = new PolygonTextured();

            pool.Tex = texture;
            pool.AddVertex(new Vector2(left, bottom));
            pool.AddTex(new Vector2(left_texture, top_texture));
            pool.AddVertex(new Vector2(left, top));
            pool.AddTex(new Vector2(left_texture, bottom_texture));
            pool.AddVertex(new Vector2(right, top));
            pool.AddTex(new Vector2(right_texture, bottom_texture));
            pool.AddVertex(new Vector2(right, bottom));
            pool.AddTex(new Vector2(right_texture, top_texture));
            pool.Color       = color;
            pool.Transparent = true;
            world.Add(pool);
        }
예제 #4
0
        public void addTexturedPolygon(float left, float right, float bottom, float top, float outer, Texture texture)
        {
            PolygonTextured pt = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(left, top));                    //A
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(right, top));                   //B
            pt.AddTex(new Vector2(0.5f, 0));
            pt.AddVertex(new Vector2(right, bottom));                //C
            pt.AddTex(new Vector2(1, 0.5f));
            pt.AddVertex(new Vector2((left + right) / 2.0f, outer)); //D
            pt.AddTex(new Vector2(1, 1));
            pt.AddVertex(new Vector2(left, bottom));
            pt.AddTex(new Vector2(0, 0.5f));
            pt.Color = Color.Transparent;
            world.Add(pt);
        }
예제 #5
0
        public void ReadFileAndTexture(string fileName, PolygonTextured pt, float shiftX, float shiftY)
        {
            try
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    int    counter = 0;
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (counter % 2 == 0)
                        {
                            // Read the vertex line
                            String   v_line = line;
                            string[] v_arry = v_line.Split(',');

                            pt.AddVertex(new Vector2(float.Parse(v_arry[0]) + shiftX, float.Parse(v_arry[1]) + shiftY));
                        }
                        else
                        {
                            // Read the texture line
                            String   t_line = line;
                            string[] t_arry = t_line.Split(',');

                            pt.AddTex(new Vector2(float.Parse(t_arry[0]), float.Parse(t_arry[1])));
                        }
                        counter++;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }
예제 #6
0
        public Game()
        {
            InitializeComponent();
            if (!InitializeDirect3D())
            {
                return;
            }
            // To create a triangle

            /*  vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
             *                            3,      // How many
             *                            device, // What device
             *                            0,      // No special usage
             *                            CustomVertex.PositionColored.Format,
             *                            Pool.Managed);*/

            // To create a rectangle
            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);
            verticeshex = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                           6,                                    // How many
                                           device,                               // What device
                                           0,                                    // No special usage
                                           CustomVertex.PositionColored.Format,
                                           Pool.Managed);

            background = new Background(device, playingW, playingH);

            //font = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 20f));

            sound = new GameSounds(this);

            // Add a polygon

            /* floor.AddVertex(new Vector2(0, 1));
             * floor.AddVertex(new Vector2(playingW, 1));
             * floor.AddVertex(new Vector2(playingW, 0.9f));
             * floor.AddVertex(new Vector2(0, 0.9f));
             * floor.Color = Color.CornflowerBlue;*/

            // Add multiple polygons to form the world
            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, 1));
            floor.AddVertex(new Vector2(playingW, 1));
            floor.AddVertex(new Vector2(playingW, 0.9f));
            floor.AddVertex(new Vector2(0, 0.9f));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);
            for (int i = 0; i < 10; i++)
            {
                Texture         coin_texture = TextureLoader.FromFile(device, "../../coin.png");
                PolygonTextured hexagon      = new PolygonTextured();
                hexagon.Transparent = true;
                hexagon.Tex         = coin_texture;

                float x = (float)random.Next(2, 10);
                float y = (float)random.Next(1, 6);

                hexagon.AddVertex(new Vector2(x + 0.5f / 6, y));
                hexagon.AddTex(new Vector2(0.75f, 1f));
                hexagon.AddVertex(new Vector2(x, y + 1.732f / 12));
                hexagon.AddTex(new Vector2(1f, 0.5f));
                hexagon.AddVertex(new Vector2(x + 0.5f / 6, y + 1.732f / 6));
                hexagon.AddTex(new Vector2(0.75f, 0f));
                hexagon.AddVertex(new Vector2(x + 1.5f / 6, y + 1.732f / 6));
                hexagon.AddTex(new Vector2(0.25f, 0f));
                hexagon.AddVertex(new Vector2(x + 2f / 6, y + 1.732f / 12));
                hexagon.AddTex(new Vector2(0f, 0.5f));
                hexagon.AddVertex(new Vector2(x + 1.5f / 6, y));
                hexagon.AddTex(new Vector2(0.25f, 1f));
                hexagon.Color = Color.Transparent;
                coins.Add(hexagon);
            }

            Texture flag_texture = TextureLoader.FromFile(device, "../../../textures/flag.png");

            flag.AddVertex(new Vector2(9.7f, 2));
            flag.AddVertex(new Vector2(10.7f, 2));
            flag.AddVertex(new Vector2(10.7f, 1));
            flag.Tex = flag_texture;
            flag.AddTex(new Vector2(0, 0));
            flag.AddTex(new Vector2(1, 0));
            flag.AddTex(new Vector2(1, 1));
            //world.Add(flag);
            //basketball
            Texture basketballtexture = TextureLoader.FromFile(device, "../../basketball.png");

            basketball.Transparent = true;
            basketball.P           = new Vector2(2, 2);
            //basketball.V = new Vector2(0.1f,-0.1f);
            basketball.Tex = basketballtexture;

            basketball.AddVertex(new Vector2(-0.5f / 3, 1.732f / 6));
            basketball.AddTex(new Vector2(0, 1));
            basketball.AddVertex(new Vector2(0.5f / 3, 1.732f / 6));
            basketball.AddTex(new Vector2(0, 0));
            basketball.AddVertex(new Vector2(0.5f / 3, 0));
            basketball.AddTex(new Vector2(1, 0));
            basketball.AddVertex(new Vector2(-0.5f / 3, 0));
            basketball.AddTex(new Vector2(1, 1));
            basketball.Color = Color.Transparent;
            //powerup.Add(basketball);
            //Vector2 v_b = basketball.V;
            //v_b.Y = -0.5f;
            //basketball.V = v_b;

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);
            AddObstacle(8.5f, 9.5f, 1.0f, 1.2f, Color.AliceBlue);

            Platform platform = new Platform();

            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(3.9f, 2));
            platform.AddVertex(new Vector2(3.9f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.Black;
            world.Add(platform);

            Texture texture = TextureLoader.FromFile(device, "../../stone08.bmp");

            //PolygonTextured pt = new PolygonTextured();
            pt.Tex = texture;
            pt.AddVertex(new Vector2(1.2f, 3.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(1.9f, 3.5f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(1.9f, 3.3f));
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(1.2f, 3.3f));
            pt.AddTex(new Vector2(1, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            //Texture spritetexture = TextureLoader.FromFile(device, "../../guy8.bmp");
            spritetexture      = TextureLoader.FromFile(device, "../../../textures/small_mario.png");
            spritepowertexture = TextureLoader.FromFile(device, "../../../textures/big_mario.png");
            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);
            player.Tex         = spritetexture;

            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;

            /*
             * Texture wolverineTex = TextureLoader.FromFile(device, "../../../textures/wolverine.bmp");
             * wolverine = new Wolverine(2, 2);
             * wolverine.Tex = wolverineTex;
             */
            Texture wolvSprite = TextureLoader.FromFile(device, "../../../textures/wolverine.png");

            for (int i = 0; i < 1; i++)
            {
                //wolverine = new Wolverine((float)random.Next(3, 5) + (float)random.NextDouble(),  .5f);
                wolverine = new Wolverine(3, .5f);

                //wolverine.Transparent = true;
                //wolverine.P = new Vector2(0.5f, 1);
                wolverine.Tex = wolvSprite;
                wolverines.Add(wolverine);
            }

            /*
             * wolverine.AddVertex(new Vector2(-0.2f, 0));
             * wolverine.AddTex(new Vector2(0, 1));
             * wolverine.AddVertex(new Vector2(-0.2f, 1));
             * wolverine.AddTex(new Vector2(0, 0));
             * wolverine.AddVertex(new Vector2(0.2f, 1));
             * wolverine.AddTex(new Vector2(0.125f, 0));
             * wolverine.AddVertex(new Vector2(0.2f, 0));
             * wolverine.AddTex(new Vector2(0.125f, 1));
             * wolverine.Color = Color.Transparent;
             */

            /*
             * Texture swordtexture = TextureLoader.FromFile(device, "../../sword_alpha.png");
             * sword_sprite.Transparent = true;
             * //sword_sprite.P = new Vector2(2,2);
             * sword_sprite.Tex = swordtexture;
             * sword_sprite.AddVertex(new Vector2(1, 0));
             * sword_sprite.AddTex(new Vector2(0,1));
             * sword_sprite.AddVertex(new Vector2(2, 0.5f));
             * sword_sprite.AddTex(new Vector2(1,0.5f));
             * sword_sprite.AddVertex(new Vector2(1, 1));
             * sword_sprite.AddTex(new Vector2(0,0));
             * sword_sprite.Color = Color.Transparent;
             */
            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;
        }
예제 #7
0
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
            {
                return;
            }
            score = new Score();
            score.start();
            end = false;

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW, playingH);

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Polygon floor = new Polygon();

            floor.AddVertex(new Vector2(0, .1f));
            floor.AddVertex(new Vector2(playingW, .1f));
            floor.AddVertex(new Vector2(playingW, 0));
            floor.AddVertex(new Vector2(0, 0));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);

            Texture         texture = TextureLoader.FromFile(device, "../../stone08.bmp");
            PolygonTextured pt      = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(1.2f, 3.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(1.9f, 3.5f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(1.9f, 3.3f));
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(1.2f, 3.3f));
            pt.AddTex(new Vector2(1, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            Texture spritetexture = TextureLoader.FromFile(device, "../../sprite_guy.png");

            player.Tex = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, .8f));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, .8f));
            player.Color       = Color.Transparent;
            player.Transparent = true;
            player.P           = new Vector2(0.5f, .1f);

            Texture skytexture = TextureLoader.FromFile(device, "../../night-sky.png");

            sky.Tex = skytexture;
            sky.AddVertex(new Vector2(0, 0));
            sky.AddTex(new Vector2(0, 1));
            sky.AddVertex(new Vector2(0, playingH));
            sky.AddTex(new Vector2(0, 0));
            sky.AddVertex(new Vector2((float)Width / (float)Height * playingH, playingH));
            sky.AddTex(new Vector2(1, 0));
            sky.AddVertex(new Vector2((float)Width / (float)Height * playingH, 0));
            sky.AddTex(new Vector2(1, 1));

            AddTriangle(new Vector2(1.5f, 1.1f), 1.5f, .2f, "../../crazy.png");
            AddTriangle(new Vector2(3f, 2.3f), 1, .6f, "../../irontop.png");
            AddTriangle(new Vector2(4f, 2.5f), .8f, .5f, "../../bluething.jpg");
            AddTriangle(new Vector2(5f, 3f), .2f, .4f, "../../stone08.bmp");
            AddTriangle(new Vector2(6f, 2f), 1.2f, .35f, "../../planet.png");
            AddTriangle(new Vector2(7f, 4f), 1.11f, 1, "../../irontop.png");
        }
예제 #8
0
파일: Game.cs 프로젝트: klugaman/CSE471
        public Game()
        {
            InitializeComponent();
            if (!InitializeDirect3D())
            {
                return;
            }

            sounds = new GameSound(this);
            sounds.Victory();

            font = new Microsoft.DirectX.Direct3D.Font(device,                         // Device we are drawing on
                                                       20,                             // Font height in pixels
                                                       0,                              // Font width in pixels or zero to match height
                                                       FontWeight.Bold,                // Font weight (Normal, Bold, etc.)
                                                       0,                              // mip levels (0 for default)
                                                       false,                          // italics?
                                                       CharacterSet.Default,           // Character set to use
                                                       Precision.Default,              // The font precision, try some of them...
                                                       FontQuality.Default,            // Quality?
                                                       PitchAndFamily.FamilyDoNotCare, // Pitch and family, we don't care
                                                       "Arial");                       // And the name of the font



            // To create a rectangle
            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,                                    // How many
                                        device,                               // What device
                                        0,                                    // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);
            background = new Background(device, playingW, playingH);


            //draw floor /////////////////////////////////////////////////////////////
            Texture floor = TextureLoader.FromFile(device, "../../../floor.jpg");

            AddTexture(0, playingW / 3, 0, 1, Color.Transparent, floor, 0, 1, 0, 1);

            Texture poolTexture = TextureLoader.FromFile(device, "../../../pool.png");

            AddBadPoly(playingW / 3, playingW / 3 * (1 + 0.5f), 0, 0.7f, Color.Transparent, poolTexture, 0, 1, 0, 1);

            AddTexture(playingW / 3 * (1 + 0.5f), playingW, 0, 1, Color.Transparent, floor, 0, 1, 0, 1);


            //create a platform
            AddPlatform(3.2f, 3.9f, 1.8f, 2, Color.CornflowerBlue);

            //create a platform
            AddPlatform2(playingW / 3, playingW / 3 + 0.7f, 0.8f, 1, Color.Black);

            AddCoins();


            Texture c1 = TextureLoader.FromFile(device, "../../../candy1.png");
            Texture c2 = TextureLoader.FromFile(device, "../../../candy2.png");

            AddBadPoly(13.1f, 13.9f, 3.2f, 3.4f, Color.Transparent, c1, 0.3f, 1, 0.55f, 0.85f);

            AddBadPoly(7.1f, 8.1f, 2.2f, 2.8f, Color.Transparent, c2, 0.2f, 1, 0.05f, 0.45f);

            AddBadPoly(26, 27, 1.5f, 2.1f, Color.Transparent, c2, 0.2f, 1, 0.05f, 0.45f);

            AddObstacle(27.1f, 27.7f, 3.0f, 3.2f, Color.BlanchedAlmond);

            /////////////////////////////////////////////////////////////////////////////////////////////////////



            ////Game
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 1.4f, 1.6f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(8.5f, 9.5f, 2.5f, 2.7f, Color.Brown);


            AddObstacle(10.5f, 11.5f, 1.5f, 1.7f, Color.AliceBlue);

            ///add

            AddObstacle(11.5f, 12.5f, 2.2f, 2.4f, Color.PeachPuff);
            // AddObstacle(13.5f, 15f, 3.2f, 3.4f, Color.BlanchedAlmond);
            AddObstacle(14.5f, 15.5f, 2f, 2.2f, Color.Aqua);

            AddObstacle(22.5f, 24f, 3.0f, 3.2f, Color.Crimson);//red
            AddObstacle(29.1f, 29.9f, 2.5f, 2.8f, Color.Chocolate);



            Platform platform = new Platform();

            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(3.9f, 2));
            platform.AddVertex(new Vector2(3.9f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.Black;
            world.Add(platform);


            ///OBJECT1
            Texture weird_texture = TextureLoader.FromFile(device, "../../../green.jpg");
            Weird   wd            = new Weird();

            wd.Tex = weird_texture;
            //triangle  offset=0
            wd.AddVertex(new Vector2(1.5f, 1.1f));
            wd.AddVertex(new Vector2(1f, 1.5f));
            wd.AddVertex(new Vector2(2f, 1.5f));
            world.Add(wd);



            ///OBJECT2
            Texture         texture = TextureLoader.FromFile(device, "../../../stone08.bmp");
            PolygonTextured pt      = new PolygonTextured();

            pt.Tex = texture;
            pt.AddVertex(new Vector2(17.5f, 1f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(17f, 1.5f));
            pt.AddTex(new Vector2(0, 1));

            pt.AddVertex(new Vector2(19f, 1.5f));
            pt.AddTex(new Vector2(1, 1));

            pt.AddVertex(new Vector2(18.5f, 1f));
            pt.AddTex(new Vector2(1, 0));



            pt.Color = Color.Transparent;
            world.Add(pt);


            ///OBJECT3
            Texture         texture3 = TextureLoader.FromFile(device, "../../../brown.jpg");
            PolygonTextured pt3      = new PolygonTextured();

            pt3.Tex = texture3;
            pt3.AddVertex(new Vector2(20, 2.7f));            //A
            pt3.AddTex(new Vector2(0, 1));
            pt3.AddVertex(new Vector2(21, 2.7f));            //B
            pt3.AddTex(new Vector2(0.5f, 0));
            pt3.AddVertex(new Vector2(21, 2.5f));            //C
            pt3.AddTex(new Vector2(1, 0.5f));
            pt3.AddVertex(new Vector2((20 + 21) / 2.0f, 2)); //D
            pt3.AddTex(new Vector2(1, 1));
            pt3.AddVertex(new Vector2(20, 2.5f));
            pt3.AddTex(new Vector2(0, 0.5f));
            world.Add(pt3);



            ///Object4
            Texture         texture4 = TextureLoader.FromFile(device, "../../../green.jpg");
            PolygonTextured pt4      = new PolygonTextured();

            pt4.Tex = texture4;


            pt4.AddVertex(new Vector2(5.375f, 1f));
            pt4.AddTex(new Vector2(1, 0.5f));
            pt4.AddVertex(new Vector2(5f, 1.2f));
            pt4.AddTex(new Vector2(0, 0));
            pt4.AddVertex(new Vector2(5.5f, 1.4f));
            pt4.AddTex(new Vector2(0, 0.5f));
            pt4.AddVertex(new Vector2(5.5f, 1.2f));
            pt4.AddTex(new Vector2(0.5f, 0));
            pt4.AddVertex(new Vector2(6f, 1.2f));
            pt4.AddTex(new Vector2(0.5f, 0.5f));
            pt4.AddVertex(new Vector2(5.625f, 1f));
            pt4.AddTex(new Vector2(0.5f, 1));


            world.Add(pt4);


            Texture spritetexture = TextureLoader.FromFile(device, "../../../guy8.bmp");

            player.Transparent = true;
            player.P           = new Vector2(0.5f, 1);
            player.Tex         = spritetexture;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;
            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;
        }
예제 #9
0
        public Game()
        {
            InitializeComponent();

            if (!InitializeDirect3D())
                return;

            vertices = new VertexBuffer(typeof(CustomVertex.PositionColored), // Type of vertex
                                        4,      // How many
                                        device, // What device
                                        0,      // No special usage
                                        CustomVertex.PositionColored.Format,
                                        Pool.Managed);

            background = new Background(device, playingW, playingH);

            score = new Score(device);

            lives = new Lives(device);
            lives.lives_number = 3;

            game_over = new GameOver(device);

            //create the font
            font = new Microsoft.DirectX.Direct3D.Font(device,  // Device we are drawing on
                20,         // Font height in pixels
                0,          // Font width in pixels or zero to match height
                FontWeight.Bold,    // Font weight (Normal, Bold, etc.)
                0,          // mip levels (0 for default)
                false,      // italics?
                CharacterSet.Default,   // Character set to use
                Precision.Default,      // The font precision, try some of them...
                FontQuality.Default,    // Quality?
                PitchAndFamily.FamilyDoNotCare,     // Pitch and family, we don't care
                "Arial");               // And the name of the font

            // Determine the last time
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;

            Polygon floor = new Polygon();
            floor.AddVertex(new Vector2(0, 1));
            floor.AddVertex(new Vector2(playingW, 1));
            floor.AddVertex(new Vector2(playingW, 0.9f));
            floor.AddVertex(new Vector2(0, 0.9f));
            floor.Color = Color.CornflowerBlue;
            world.Add(floor);

            AddObstacle(2, 3, 1.7f, 1.9f, Color.Crimson);
            AddObstacle(4, 4.2f, 1, 2.1f, Color.Coral);
            AddObstacle(5, 6, 2.2f, 2.4f, Color.BurlyWood);
            AddObstacle(5.5f, 6.5f, 3.2f, 3.4f, Color.PeachPuff);
            AddObstacle(6.5f, 7.5f, 2.5f, 2.7f, Color.Chocolate);

            Platform platform = new Platform();
            platform.AddVertex(new Vector2(3.2f, 2));
            platform.AddVertex(new Vector2(3.9f, 2));
            platform.AddVertex(new Vector2(3.9f, 1.8f));
            platform.AddVertex(new Vector2(3.2f, 1.8f));
            platform.Color = Color.CornflowerBlue;
            world.Add(platform);

            Texture texture = TextureLoader.FromFile(device, "../../stone08.bmp");
            PolygonTextured pt = new PolygonTextured();
            pt.Tex = texture;
            pt.AddVertex(new Vector2(1.2f, 3.5f));
            pt.AddTex(new Vector2(0, 1));
            pt.AddVertex(new Vector2(1.9f, 3.5f));
            pt.AddTex(new Vector2(0, 0));
            pt.AddVertex(new Vector2(1.9f, 3.3f));
            pt.AddTex(new Vector2(1, 0));
            pt.AddVertex(new Vector2(1.2f, 3.3f));
            pt.AddTex(new Vector2(1, 1));
            pt.Color = Color.Transparent;
            world.Add(pt);

            Texture spritetexture = TextureLoader.FromFile(device, "../../guy8.bmp");
            player.P = new Vector2(0.5f, 1);
            player.Tex = spritetexture;
            player.Transparent = true;
            player.AddVertex(new Vector2(-0.2f, 0));
            player.AddTex(new Vector2(0, 1));
            player.AddVertex(new Vector2(-0.2f, 1));
            player.AddTex(new Vector2(0, 0));
            player.AddVertex(new Vector2(0.2f, 1));
            player.AddTex(new Vector2(0.125f, 0));
            player.AddVertex(new Vector2(0.2f, 0));
            player.AddTex(new Vector2(0.125f, 1));
            player.Color = Color.Transparent;

            stood = true;
        }